Skip to content

Commit

Permalink
Improvements to setTitle on Linux
Browse files Browse the repository at this point in the history
WM_CLASS should not change after window creation. It's illegal (may only change while the window is in the Withdrawn state) and causes flickering issues on the taskbar.

The native setTitle implementation has been changed to use a better fallback when XChangeProperty fails and _NET_WM_ICON_NAME is also set, in addition to _NET_WM_NAME.
  • Loading branch information
Spasi committed Dec 30, 2014
1 parent 85e5488 commit ee2a1c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/java/org/lwjgl/opengl/LinuxDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,6 @@ public void setTitle(String title) {
} finally {
unlockAWT();
}

// also update the class hint value as some WM's use it for the window title
if (Display.isCreated()) setClassHint(title, wm_class);
}
private static native void nSetTitle(long display, long window, long title, int len);

Expand Down
22 changes: 16 additions & 6 deletions src/native/linux/opengl/org_lwjgl_opengl_Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,25 @@ static bool isLegacyFullscreen(jint window_mode) {
}

static void setWindowTitle(Display *disp, Window window, jlong title, jint len) {
Atom UTF8_STRING = XInternAtom(disp, "UTF8_STRING", True);
Atom _NET_WM_NAME = XInternAtom(disp, "_NET_WM_NAME", True);
Atom _NET_WM_ICON_NAME = XInternAtom(disp, "_NET_WM_ICON_NAME", True);

// ASCII fallback if XChangeProperty fails.
XStoreName(disp, window, (const char *)(intptr_t)title);
XmbSetWMProperties(disp, window, (const char *)(intptr_t)title, (const char *)(intptr_t)title, NULL, 0, NULL, NULL, NULL);

// Set the UTF-8 encoded title
XChangeProperty(disp, window,
XInternAtom(disp, "_NET_WM_NAME", False),
XInternAtom(disp, "UTF8_STRING", False),
8, PropModeReplace, (const unsigned char *)(intptr_t)title,
len);
if ( _NET_WM_NAME )
XChangeProperty(
disp, window, _NET_WM_NAME, UTF8_STRING,
8, PropModeReplace, (const unsigned char *)(intptr_t)title, len
);

if ( _NET_WM_ICON_NAME )
XChangeProperty(
disp, window, _NET_WM_ICON_NAME, UTF8_STRING,
8, PropModeReplace, (const unsigned char *)(intptr_t)title, len
);
}

static void setClassHint(Display *disp, Window window, jlong wm_name, jlong wm_class) {
Expand Down

0 comments on commit ee2a1c7

Please sign in to comment.