diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m index 62bf1f918..c52dfd0e8 100644 --- a/hw/darwin/apple/X11Application.m +++ b/hw/darwin/apple/X11Application.m @@ -225,6 +225,8 @@ message_kit_thread (SEL selector, NSObject *arg) if (_x_active) [self activateX:NO]; } else if ([self modalWindow] == nil) { /* Must be an X window. Tell appkit it doesn't have focus. */ + WindowPtr pWin = xprGetXWindowFromAppKit([e windowNumber]); + if (pWin) RootlessReorderWindow(pWin); for_appkit = NO; if ([self isActive]) { diff --git a/hw/darwin/quartz/xpr/xpr.h b/hw/darwin/quartz/xpr/xpr.h index 81bb912e1..09e85f5f3 100644 --- a/hw/darwin/quartz/xpr/xpr.h +++ b/hw/darwin/quartz/xpr/xpr.h @@ -37,6 +37,9 @@ void AppleDRIExtensionInit(void); void xprAppleWMInit(void); Bool xprInit(ScreenPtr pScreen); Bool xprIsX11Window(void *nsWindow, int windowNumber); +WindowPtr xprGetX11Window(xp_window_id wid); +WindowPtr xprGetXWindowFromAppKit(int windowNumber); + void xprHideWindows(Bool hide); Bool QuartzInitCursor(ScreenPtr pScreen); diff --git a/hw/darwin/quartz/xpr/xprFrame.c b/hw/darwin/quartz/xpr/xprFrame.c index 53fbb31f9..54b2035e1 100644 --- a/hw/darwin/quartz/xpr/xprFrame.c +++ b/hw/darwin/quartz/xpr/xprFrame.c @@ -425,6 +425,37 @@ xprGetXWindow(xp_window_id wid) return winRec != NULL ? winRec->win : NULL; } +/* + * Given the id of a physical window, try to find the top-level (or root) + * X window that it represents. + */ +WindowPtr +xprGetXWindowFromAppKit(int windowNumber) +{ + RootlessWindowRec *winRec; + Bool ret; + xp_window_id wid; + + if (window_hash == NULL) + return FALSE; + + /* need to lock, since this function can be called by any thread */ + + pthread_mutex_lock(&window_hash_mutex); + + if (xp_lookup_native_window(windowNumber, &wid)) + ret = xprGetXWindow(wid) != NULL; + else + ret = FALSE; + + pthread_mutex_unlock(&window_hash_mutex); + + if (!ret) return NULL; + winRec = x_hash_table_lookup(window_hash, (void *) wid, NULL); + + return winRec != NULL ? winRec->win : NULL; +} + /* * The windowNumber is an AppKit window number. Returns TRUE if xpr is