mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-05 16:20:10 +00:00
75fd7f09af
2001-06-25 Alexander Larsson <alexl@redhat.com> * configure.in: Added --enable-fbmanager. This is some experimental code that lets several GtkFB apps coordinate their access to the framebuffer. * acconfig.h: Added ENABLE_FB_MANAGER. * gdk/linux-fb/Makefile.am: Added gdkfbmanager and gdkfbswitch. * gdk/linux-fb/gdkkeyboard-fb.c: * gdk/linux-fb/gdkmouse-fb.c: * gdk/linux-fb/gdkprivate-fb.h: Split device init and open so that they can be opened and closed while switched away. * gdk/linux-fb/gdkmain-fb.c: Add the basic manager communication. * gdk/linux-fb/gdkrender-fb.c: Don't update to the shadow fb if we're blocked by the fb manager.
76 lines
1.8 KiB
C
76 lines
1.8 KiB
C
#include <glib.h>
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/un.h>
|
|
|
|
#include "gdkfbmanager.h"
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
int fd;
|
|
struct sockaddr_un addr;
|
|
struct msghdr msg = {0};
|
|
struct cmsghdr *cmsg;
|
|
struct ucred credentials;
|
|
struct FBManagerMessage init_msg;
|
|
struct iovec iov;
|
|
char buf[CMSG_SPACE (sizeof (credentials))]; /* ancillary data buffer */
|
|
int *fdptr;
|
|
int res;
|
|
|
|
if (argc != 2)
|
|
{
|
|
g_print ("usage: fbswitch <pid>\n");
|
|
return 1;
|
|
}
|
|
|
|
fd = socket (PF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (fd < 0)
|
|
return 1;
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
strcpy (addr.sun_path, "/tmp/.fb.manager");
|
|
|
|
if (connect(fd, (struct sockaddr *)&addr, sizeof (addr)) < 0)
|
|
{
|
|
g_print ("connect failed\n");
|
|
close (fd);
|
|
return 1;
|
|
}
|
|
|
|
credentials.pid = getpid ();
|
|
credentials.uid = geteuid ();
|
|
credentials.gid = getegid ();
|
|
|
|
init_msg.msg_type = FB_MANAGER_NEW_CLIENT;
|
|
iov.iov_base = &init_msg;
|
|
iov.iov_len = sizeof (init_msg);
|
|
|
|
msg.msg_name = NULL;
|
|
msg.msg_namelen = 0;
|
|
msg.msg_iov = &iov;
|
|
msg.msg_iovlen = 1;
|
|
msg.msg_control = buf;
|
|
msg.msg_controllen = sizeof buf;
|
|
cmsg = CMSG_FIRSTHDR(&msg);
|
|
cmsg->cmsg_level = SOL_SOCKET;
|
|
cmsg->cmsg_type = SCM_CREDENTIALS;
|
|
cmsg->cmsg_len = CMSG_LEN (sizeof (credentials));
|
|
/* Initialize the payload: */
|
|
fdptr = (int *)CMSG_DATA (cmsg);
|
|
memcpy (fdptr, &credentials, sizeof (credentials));
|
|
/* Sum of the length of all control messages in the buffer: */
|
|
msg.msg_controllen = cmsg->cmsg_len;
|
|
|
|
res = sendmsg (fd, &msg, 0);
|
|
|
|
init_msg.msg_type = FB_MANAGER_REQUEST_SWITCH_TO_PID;
|
|
init_msg.data = atoi (argv[1]);
|
|
/* Request a switch-to */
|
|
send (fd, &init_msg, sizeof (init_msg), 0);
|
|
g_print ("requested a switch to pid %d\n", init_msg.data);
|
|
}
|