Support for setting WM_CLASS on a per-window basis

This commit is contained in:
Kovid Goyal 2017-11-20 20:20:48 +05:30
parent 1fe319d234
commit e195854e00
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 30 additions and 6 deletions

View File

@ -2343,7 +2343,12 @@ GLFWAPI void glfwWindowHint(int hint, int value);
* @remark @x11 The name and class of the `WM_CLASS` window property will by * @remark @x11 The name and class of the `WM_CLASS` window property will by
* default be set to the window title passed to this function. Set the @ref * default be set to the window title passed to this function. Set the @ref
* GLFW_X11_WM_CLASS_NAME and @ref GLFW_X11_WM_CLASS_CLASS init hints before * GLFW_X11_WM_CLASS_NAME and @ref GLFW_X11_WM_CLASS_CLASS init hints before
* initialization to override this. * initialization to override this. You can also set the title int he following
* special format, which allows setting the two parts of the WM_CLASS property
* and the window title independently:
* <01> WM_CLASS name <30> WM_CLASS class <30> title
* Here <01> refers to the byte value 01 (ASCII start-of-header) and <30> refers
* to the byte value 30 (ASCII record separator).
* *
* @remark @wayland The window frame is currently unimplemented, as if * @remark @wayland The window frame is currently unimplemented, as if
* [GLFW_DECORATED](@ref GLFW_DECORATED_hint) was always set to `GLFW_FALSE`. * [GLFW_DECORATED](@ref GLFW_DECORATED_hint) was always set to `GLFW_FALSE`.

View File

@ -703,9 +703,11 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
updateNormalHints(window, wndconfig->width, wndconfig->height); updateNormalHints(window, wndconfig->width, wndconfig->height);
// Set ICCCM WM_CLASS property // Set ICCCM WM_CLASS property and window title
{ {
XClassHint* hint = XAllocClassHint(); XClassHint* hint = XAllocClassHint();
char *wm_cclass = NULL, *wm_cname = NULL;
const char *real_title = wndconfig->title;
if (strlen(_glfw.hints.init.x11.className) && if (strlen(_glfw.hints.init.x11.className) &&
strlen(_glfw.hints.init.x11.classClass)) strlen(_glfw.hints.init.x11.classClass))
@ -713,10 +715,26 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
hint->res_name = (char*) _glfw.hints.init.x11.className; hint->res_name = (char*) _glfw.hints.init.x11.className;
hint->res_class = (char*) _glfw.hints.init.x11.classClass; hint->res_class = (char*) _glfw.hints.init.x11.classClass;
} }
else if (strlen(wndconfig->title)) else if (strlen(real_title))
{ {
hint->res_name = (char*) wndconfig->title; if (*real_title == 1) {
hint->res_class = (char*) wndconfig->title; char *p = strchr(real_title, 30);
if (p && p > real_title + 1) {
wm_cname = calloc(p - real_title + 1, 1);
if (wm_cname) memcpy(wm_cname, real_title + 1, p - real_title - 1);
hint->res_name = wm_cname;
char *q = strchr(p + 1, 30);
if (q && q > p + 1) {
wm_cclass = calloc(q - p + 1, 1);
if (wm_cclass) memcpy(wm_cclass, p + 1, q - p - 1);
hint->res_class = wm_cclass;
real_title = q + 1;
}
}
} else {
hint->res_name = (char*) real_title;
hint->res_class = (char*) real_title;
}
} }
else else
{ {
@ -726,6 +744,8 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
XSetClassHint(_glfw.x11.display, window->x11.handle, hint); XSetClassHint(_glfw.x11.display, window->x11.handle, hint);
XFree(hint); XFree(hint);
free(wm_cclass); free(wm_cname);
_glfwPlatformSetWindowTitle(window, real_title);
} }
// Announce support for Xdnd (drag and drop) // Announce support for Xdnd (drag and drop)
@ -736,7 +756,6 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
PropModeReplace, (unsigned char*) &version, 1); PropModeReplace, (unsigned char*) &version, 1);
} }
_glfwPlatformSetWindowTitle(window, wndconfig->title);
if (_glfw.x11.im) if (_glfw.x11.im)
{ {