X11: Move to XSetWMProperties and add support to _NET_WM_PID
Use the convenience function XSetWMProperties to set size, input and class hints, it also automatically sets the WM_CLIENT_MACHINE (this one needed by _NET_WM_PID) and WM_LOCALE_NAME windows hints. Plus we add support to the _NET_WM_PID atom which is needed by many windows managers to correctly associate a SDL window to its process and to related .desktop file and icon for the given host.
This commit is contained in:
parent
0108ce2260
commit
8279896de9
3 changed files with 32 additions and 31 deletions
|
@ -328,6 +328,9 @@ X11_VideoInit(_THIS)
|
||||||
/* Get the window class name, usually the name of the application */
|
/* Get the window class name, usually the name of the application */
|
||||||
data->classname = get_classname();
|
data->classname = get_classname();
|
||||||
|
|
||||||
|
/* Get the process PID to be associated to the window */
|
||||||
|
data->pid = getpid();
|
||||||
|
|
||||||
/* Open a connection to the X input manager */
|
/* Open a connection to the X input manager */
|
||||||
#ifdef X_HAVE_UTF8_STRING
|
#ifdef X_HAVE_UTF8_STRING
|
||||||
if (SDL_X11_HAVE_UTF8) {
|
if (SDL_X11_HAVE_UTF8) {
|
||||||
|
|
|
@ -69,6 +69,7 @@ typedef struct SDL_VideoData
|
||||||
{
|
{
|
||||||
Display *display;
|
Display *display;
|
||||||
char *classname;
|
char *classname;
|
||||||
|
pid_t pid;
|
||||||
XIM im;
|
XIM im;
|
||||||
Uint32 screensaver_activity;
|
Uint32 screensaver_activity;
|
||||||
int numwindows;
|
int numwindows;
|
||||||
|
|
|
@ -258,11 +258,12 @@ X11_CreateWindow(_THIS, SDL_Window * window)
|
||||||
int depth;
|
int depth;
|
||||||
XSetWindowAttributes xattr;
|
XSetWindowAttributes xattr;
|
||||||
Window w;
|
Window w;
|
||||||
XSizeHints *sizehints;
|
XSizeHints sizehints;
|
||||||
XWMHints *wmhints;
|
XWMHints wmhints;
|
||||||
XClassHint *classhints;
|
XClassHint classhints;
|
||||||
Atom _NET_WM_WINDOW_TYPE;
|
Atom _NET_WM_WINDOW_TYPE;
|
||||||
Atom _NET_WM_WINDOW_TYPE_NORMAL;
|
Atom _NET_WM_WINDOW_TYPE_NORMAL;
|
||||||
|
Atom _NET_WM_PID;
|
||||||
int wmstate_count;
|
int wmstate_count;
|
||||||
Atom wmstate_atoms[3];
|
Atom wmstate_atoms[3];
|
||||||
Uint32 fevent = 0;
|
Uint32 fevent = 0;
|
||||||
|
@ -414,20 +415,6 @@ X11_CreateWindow(_THIS, SDL_Window * window)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sizehints = XAllocSizeHints();
|
|
||||||
if (sizehints) {
|
|
||||||
if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
|
|
||||||
sizehints->min_width = sizehints->max_width = window->w;
|
|
||||||
sizehints->min_height = sizehints->max_height = window->h;
|
|
||||||
sizehints->flags = PMaxSize | PMinSize;
|
|
||||||
}
|
|
||||||
sizehints->x = window->x;
|
|
||||||
sizehints->y = window->y;
|
|
||||||
sizehints->flags |= USPosition;
|
|
||||||
XSetWMNormalHints(display, w, sizehints);
|
|
||||||
XFree(sizehints);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window->flags & SDL_WINDOW_BORDERLESS) {
|
if (window->flags & SDL_WINDOW_BORDERLESS) {
|
||||||
SDL_bool set;
|
SDL_bool set;
|
||||||
Atom WM_HINTS;
|
Atom WM_HINTS;
|
||||||
|
@ -511,22 +498,32 @@ X11_CreateWindow(_THIS, SDL_Window * window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the input hints so we get keyboard input */
|
/* Setup the normal size hints */
|
||||||
wmhints = XAllocWMHints();
|
if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
|
||||||
if (wmhints) {
|
sizehints.min_width = sizehints.max_width = window->w;
|
||||||
wmhints->input = True;
|
sizehints.min_height = sizehints.max_height = window->h;
|
||||||
wmhints->flags = InputHint;
|
sizehints.flags = PMaxSize | PMinSize;
|
||||||
XSetWMHints(display, w, wmhints);
|
|
||||||
XFree(wmhints);
|
|
||||||
}
|
}
|
||||||
|
sizehints.x = window->x;
|
||||||
|
sizehints.y = window->y;
|
||||||
|
sizehints.flags |= USPosition;
|
||||||
|
|
||||||
/* Set the class hints so we can get an icon (AfterStep) */
|
/* Setup the input hints so we get keyboard input */
|
||||||
classhints = XAllocClassHint();
|
wmhints.input = True;
|
||||||
if (classhints != NULL) {
|
wmhints.flags = InputHint;
|
||||||
classhints->res_name = data->classname;
|
|
||||||
classhints->res_class = data->classname;
|
/* Setup the class hints so we can get an icon (AfterStep) */
|
||||||
XSetClassHint(display, w, classhints);
|
classhints.res_name = data->classname;
|
||||||
XFree(classhints);
|
classhints.res_class = data->classname;
|
||||||
|
|
||||||
|
/* Set the size, input and class hints, and define WM_CLIENT_MACHINE and WM_LOCALE_NAME */
|
||||||
|
XSetWMProperties(display, w, NULL, NULL, NULL, 0, &sizehints, &wmhints, &classhints);
|
||||||
|
|
||||||
|
/* Set the PID related to the window for the given hostname, if possible */
|
||||||
|
if (data->pid > 0) {
|
||||||
|
_NET_WM_PID = XInternAtom(display, "_NET_WM_PID", False);
|
||||||
|
XChangeProperty(display, w, _NET_WM_PID, XA_CARDINAL, 32, PropModeReplace,
|
||||||
|
(unsigned char *)&data->pid, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the window manager state */
|
/* Set the window manager state */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue