Commit ce6136f8 authored by Jon TURNEY's avatar Jon TURNEY

Cygwin/X: Make winOverrrideStyle() thread-safe

Make winOverrrideStyle() thread-safe

winOverrideStyle() is called from the internal WM client thread.

Accessing server-internal data structures to get window name and
class is not safe, as there is no lock to ensure we do not collide
with these data structures being updated in the server thread.

Rewrite so the internal client thread uses X client calls to
obtain this data safely
Signed-off-by: default avatarJon TURNEY <>
Reviewed-by: default avatarColin Harrison <>
Tested-by: default avatarColin Harrison <>
parent 0c603509
......@@ -1576,7 +1576,6 @@ winApplyHints (Display *pDisplay, Window iWindow, HWND hWnd, HWND *zstyle)
Atom type, *pAtom = NULL;
int format;
unsigned long hint = 0, maxmin = 0, style, nitems = 0 , left = 0;
WindowPtr pWin = GetProp (hWnd, WIN_WINDOW_PROP);
MwmHints *mwm_hint = NULL;
if (!hWnd) return;
......@@ -1669,7 +1668,26 @@ winApplyHints (Display *pDisplay, Window iWindow, HWND hWnd, HWND *zstyle)
/* Override hint settings from above with settings from config file */
style = winOverrideStyle((unsigned long)pWin);
XClassHint class_hint = {0,0};
char *window_name = 0;
if (XGetClassHint(pDisplay, iWindow, &class_hint))
XFetchName(pDisplay, iWindow, &window_name);
style = winOverrideStyle(class_hint.res_name, class_hint.res_class, window_name);
if (class_hint.res_name) XFree(class_hint.res_name);
if (class_hint.res_class) XFree(class_hint.res_class);
if (window_name) XFree(window_name);
style = STYLE_NONE;
if (style & STYLE_TOPMOST) *zstyle = HWND_TOPMOST;
else if (style & STYLE_MAXIMIZE) maxmin = (hint & ~HINT_MIN) | HINT_MAX;
else if (style & STYLE_MINIMIZE) maxmin = (hint & ~HINT_MAX) | HINT_MIN;
......@@ -813,40 +813,20 @@ LoadPreferences (void)
* STYLES{} section in the prefs file, and return the style type
unsigned long
winOverrideStyle (unsigned long longpWin)
winOverrideStyle (char *res_name, char *res_class, char *wmName)
WindowPtr pWin = (WindowPtr) longpWin;
char *res_name, *res_class;
int i;
char *wmName;
if (pWin==NULL)
return STYLE_NONE;
/* If we can't find the class, we can't override from default! */
if (!winMultiWindowGetClassHint (pWin, &res_name, &res_class))
return STYLE_NONE;
winMultiWindowGetWMName (pWin, &wmName);
for (i=0; i<pref.styleItems; i++) {
if (!strcmp([i].match, res_name) ||
!strcmp([i].match, res_class) ||
if ((res_name && !strcmp([i].match, res_name)) ||
(res_class && !strcmp([i].match, res_class)) ||
(wmName && strstr(wmName,[i].match)))
free (res_name);
free (res_class);
if ([i].type)
/* Didn't find the style, fail gracefully */
free (res_name);
free (res_class);
return STYLE_NONE;
......@@ -180,7 +180,7 @@ HICON
winOverrideIcon (unsigned long longpWin);
unsigned long
winOverrideStyle (unsigned long longpWin);
winOverrideStyle (char *res_name, char *res_class, char *wmName);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment