From 855c10d90803b2f9e1d9589e01eb4992fa0182db Mon Sep 17 00:00:00 2001 From: jtsiomb Date: Wed, 28 Aug 2013 14:33:07 +0000 Subject: [PATCH] Applied James DeLisle's patch adding EWMH _NET_WM_PID support. git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1626 7f0cb862-5218-0410-a997-914c9d46530a --- freeglut/freeglut/src/x11/fg_init_x11.c | 55 ++++++++++++--------- freeglut/freeglut/src/x11/fg_internal_x11.h | 3 ++ freeglut/freeglut/src/x11/fg_window_x11.c | 40 ++++++++++++++- 3 files changed, 72 insertions(+), 26 deletions(-) diff --git a/freeglut/freeglut/src/x11/fg_init_x11.c b/freeglut/freeglut/src/x11/fg_init_x11.c index 0df54f2..49aefe6 100644 --- a/freeglut/freeglut/src/x11/fg_init_x11.c +++ b/freeglut/freeglut/src/x11/fg_init_x11.c @@ -82,9 +82,9 @@ static int fghGetWindowProperty(Window window, "fghGetWindowProperty"); if (type_returned != type) - { - number_of_elements = 0; - } + { + number_of_elements = 0; + } return number_of_elements; } @@ -113,30 +113,30 @@ static int fghNetWMSupported(void) XA_WINDOW, (unsigned char **) window_ptr_1); if (number_of_windows == 1) + { + Window ** window_ptr_2; + + window_ptr_2 = malloc(sizeof(Window *)); + + /* Check that the window has the same property set to the same value. */ + number_of_windows = fghGetWindowProperty(**window_ptr_1, + wm_check, + XA_WINDOW, + (unsigned char **) window_ptr_2); + if ((number_of_windows == 1) && (**window_ptr_1 == **window_ptr_2)) { - Window ** window_ptr_2; - - window_ptr_2 = malloc(sizeof(Window *)); - - /* Check that the window has the same property set to the same value. */ - number_of_windows = fghGetWindowProperty(**window_ptr_1, - wm_check, - XA_WINDOW, - (unsigned char **) window_ptr_2); - if ((number_of_windows == 1) && (**window_ptr_1 == **window_ptr_2)) - { - /* NET WM compliant */ - net_wm_supported = 1; - } - - XFree(*window_ptr_2); - free(window_ptr_2); + /* NET WM compliant */ + net_wm_supported = 1; } - XFree(*window_ptr_1); - free(window_ptr_1); + XFree(*window_ptr_2); + free(window_ptr_2); + } - return net_wm_supported; + XFree(*window_ptr_1); + free(window_ptr_1); + + return net_wm_supported; } /* Check if "hint" is present in "property" for "window". */ @@ -216,8 +216,12 @@ void fgPlatformInitialize( const char* displayName ) /* Create the state and full screen atoms */ fgDisplay.pDisplay.State = None; fgDisplay.pDisplay.StateFullScreen = None; + fgDisplay.pDisplay.NetWMPid = None; + fgDisplay.pDisplay.ClientMachine = None; - if (fghNetWMSupported()) + fgDisplay.pDisplay.NetWMSupported = fghNetWMSupported(); + + if (fgDisplay.pDisplay.NetWMSupported) { const Atom supported = fghGetAtom("_NET_SUPPORTED"); const Atom state = fghGetAtom("_NET_WM_STATE"); @@ -236,6 +240,9 @@ void fgPlatformInitialize( const char* displayName ) fgDisplay.pDisplay.StateFullScreen = full_screen; } } + + fgDisplay.pDisplay.NetWMPid = fghGetAtom("_NET_WM_PID"); + fgDisplay.pDisplay.ClientMachine = fghGetAtom("WM_CLIENT_MACHINE"); } /* Get start time */ diff --git a/freeglut/freeglut/src/x11/fg_internal_x11.h b/freeglut/freeglut/src/x11/fg_internal_x11.h index 2a3020f..64daf72 100644 --- a/freeglut/freeglut/src/x11/fg_internal_x11.h +++ b/freeglut/freeglut/src/x11/fg_internal_x11.h @@ -60,6 +60,9 @@ struct tagSFG_PlatformDisplay Atom DeleteWindow; /* The window deletion atom */ Atom State; /* The state atom */ Atom StateFullScreen; /* The full screen atom */ + int NetWMSupported; /* Flag for EWMH Window Managers */ + Atom NetWMPid; /* The _NET_WM_PID atom */ + Atom ClientMachine; /* The client machine name atom */ #ifdef HAVE_X11_EXTENSIONS_XRANDR_H int prev_xsz, prev_ysz; diff --git a/freeglut/freeglut/src/x11/fg_window_x11.c b/freeglut/freeglut/src/x11/fg_window_x11.c index d2a3bbd..0233f94 100644 --- a/freeglut/freeglut/src/x11/fg_window_x11.c +++ b/freeglut/freeglut/src/x11/fg_window_x11.c @@ -28,8 +28,9 @@ #define FREEGLUT_BUILDING_LIB #include -#include /* LONG_MAX */ -#include /* usleep */ +#include /* LONG_MAX */ +#include /* usleep, gethostname, getpid */ +#include /* pid_t */ #include "../fg_internal.h" #ifdef EGL_VERSION_1_0 @@ -340,6 +341,41 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, XSetWMProtocols( fgDisplay.pDisplay.Display, window->Window.Handle, &fgDisplay.pDisplay.DeleteWindow, 1 ); + if (fgDisplay.pDisplay.NetWMSupported + && fgDisplay.pDisplay.NetWMPid != None + && fgDisplay.pDisplay.ClientMachine != None) + { + char hostname[HOST_NAME_MAX]; + pid_t pid = getpid(); + + if (pid > 0 && gethostname(hostname, sizeof(hostname)) > -1) + { + hostname[sizeof(hostname) - 1] = '\0'; + + XChangeProperty( + fgDisplay.pDisplay.Display, + window->Window.Handle, + fgDisplay.pDisplay.NetWMPid, + XA_CARDINAL, + 32, + PropModeReplace, + (unsigned char *) &pid, + 1 + ); + + XChangeProperty( + fgDisplay.pDisplay.Display, + window->Window.Handle, + fgDisplay.pDisplay.ClientMachine, + XA_STRING, + 8, + PropModeReplace, + (unsigned char *) hostname, + strlen(hostname) + ); + } + } + #ifdef EGL_VERSION_1_0 fghPlatformOpenWindowEGL(window); #else