From ce6136f8c553bbc6d3e3affa0faa2afbf8054f44 Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Tue, 23 Mar 2010 20:06:33 +0000 Subject: [PATCH] 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: Jon TURNEY Reviewed-by: Colin Harrison Tested-by: Colin Harrison --- hw/xwin/winmultiwindowwm.c | 22 ++++++++++++++++++++-- hw/xwin/winprefs.c | 26 +++----------------------- hw/xwin/winprefs.h | 2 +- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index ef0c7cf0b..67a58a076 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -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); + } + else + { + 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; diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c index 4ccb4ffc2..d941c5169 100644 --- a/hw/xwin/winprefs.c +++ b/hw/xwin/winprefs.c @@ -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