From d56ccaa7e1249be656448213ae4f26cf0b5f798c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 28 Jan 2005 17:25:50 +0000 Subject: [PATCH] Use an X context to associated the x11drv private window data to a window handle instead of accessing the WND structure directly. --- dlls/x11drv/desktop.c | 2 +- dlls/x11drv/event.c | 3 -- dlls/x11drv/window.c | 72 ++++++++++++++++++------------------------- dlls/x11drv/winpos.c | 20 +++++++++--- dlls/x11drv/x11drv.h | 4 ++- include/win.h | 1 - 6 files changed, 49 insertions(+), 53 deletions(-) diff --git a/dlls/x11drv/desktop.c b/dlls/x11drv/desktop.c index 77cf8f1a9c..ecd58ae132 100644 --- a/dlls/x11drv/desktop.c +++ b/dlls/x11drv/desktop.c @@ -76,11 +76,11 @@ static DWORD CALLBACK desktop_thread( LPVOID driver_data ) /* patch the desktop window queue to point to our queue */ win = WIN_GetPtr( hwnd ); win->tid = GetCurrentThreadId(); - X11DRV_register_window( display, hwnd, win->pDriverData ); WIN_ReleasePtr( win ); SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)desktop_winproc ); wine_tsx11_lock(); + XSaveContext( display, root_window, winContext, (char *)hwnd ); XChangeProperty ( display, root_window, x11drv_atom(WM_PROTOCOLS), XA_ATOM, 32, PropModeReplace, (char *)&atom, 1 ); XMapWindow( display, root_window ); diff --git a/dlls/x11drv/event.c b/dlls/x11drv/event.c index f6ab92bfc6..15361ecc2b 100644 --- a/dlls/x11drv/event.c +++ b/dlls/x11drv/event.c @@ -50,9 +50,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(event); WINE_DECLARE_DEBUG_CHANNEL(clipboard); -/* X context to associate a hwnd to an X window */ -extern XContext winContext; - extern BOOL ximInComposeMode; #define DndNotDnd -1 /* OffiX drag&drop */ diff --git a/dlls/x11drv/window.c b/dlls/x11drv/window.c index 35f13335c8..b34b9f5e90 100644 --- a/dlls/x11drv/window.c +++ b/dlls/x11drv/window.c @@ -50,6 +50,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(x11drv); /* X context to associate a hwnd to an X window */ XContext winContext = 0; +/* X context to associate a struct x11drv_win_data to an hwnd */ +static XContext win_data_context; + Atom X11DRV_Atoms[NB_XATOMS - FIRST_XATOM]; static const char * const atom_names[NB_XATOMS - FIRST_XATOM] = @@ -743,20 +746,6 @@ int X11DRV_sync_client_window_position( Display *display, struct x11drv_win_data } -/*********************************************************************** - * X11DRV_register_window - * - * Associate an X window to a HWND. - */ -void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data ) -{ - wine_tsx11_lock(); - XSaveContext( display, data->whole_window, winContext, (char *)hwnd ); - XSaveContext( display, data->client_window, winContext, (char *)hwnd ); - wine_tsx11_unlock(); -} - - /********************************************************************** * create_desktop */ @@ -828,6 +817,7 @@ static Window create_whole_window( Display *display, struct x11drv_win_data *dat wine_tsx11_unlock(); return 0; } + XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd ); /* non-maximized child must be at bottom of Z order */ if ((style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) @@ -878,6 +868,7 @@ static Window create_client_window( Display *display, struct x11drv_win_data *da 0, screen_depth, InputOutput, visual, CWEventMask | CWBitGravity | CWBackingStore, &attr ); + XSaveContext( display, data->client_window, winContext, (char *)data->hwnd ); if (data->client_window && is_mapped) XMapWindow( display, data->client_window ); wine_tsx11_unlock(); return data->client_window; @@ -947,9 +938,9 @@ BOOL X11DRV_DestroyWindow( HWND hwnd ) struct x11drv_thread_data *thread_data = x11drv_thread_data(); Display *display = thread_data->display; WND *wndPtr = WIN_GetPtr( hwnd ); - struct x11drv_win_data *data = wndPtr->pDriverData; + struct x11drv_win_data *data; - if (!data) goto done; + if (!(data = X11DRV_get_win_data( hwnd ))) goto done; if (data->whole_window) { @@ -972,8 +963,11 @@ BOOL X11DRV_DestroyWindow( HWND hwnd ) if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap ); if (data->hWMIconMask) DeleteObject( data->hWMIconMask); + wine_tsx11_lock(); + XDeleteContext( gdi_display, (XID)hwnd, win_data_context ); + wine_tsx11_unlock(); HeapFree( GetProcessHeap(), 0, data ); - wndPtr->pDriverData = NULL; + done: WIN_ReleasePtr( wndPtr ); return TRUE; @@ -988,7 +982,7 @@ BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode ) Display *display = thread_display(); WND *wndPtr; struct x11drv_win_data *data; - HWND insert_after; + HWND parent, insert_after; RECT rect; DWORD style; CBT_CREATEWNDA cbtc; @@ -1024,20 +1018,22 @@ BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode ) data->hWMIconBitmap = 0; data->hWMIconMask = 0; - wndPtr = WIN_GetPtr( hwnd ); - wndPtr->pDriverData = data; + /* use gdi_display so that it's available from all threads (FIXME) */ + wine_tsx11_lock(); + if (!win_data_context) win_data_context = XUniqueContext(); + XSaveContext( gdi_display, (XID)hwnd, win_data_context, (char *)data ); + wine_tsx11_unlock(); /* initialize the dimensions before sending WM_GETMINMAXINFO */ SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy ); X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER, 0 ); - if (!wndPtr->parent) + parent = GetAncestor( hwnd, GA_PARENT ); + if (!parent) { create_desktop( display, data ); - WIN_ReleasePtr( wndPtr ); return TRUE; } - WIN_ReleasePtr( wndPtr ); if (!create_whole_window( display, data, cs->style )) goto failed; if (!create_client_window( display, data )) goto failed; @@ -1103,7 +1099,6 @@ BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode ) insert_after = ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP; X11DRV_set_window_pos( hwnd, insert_after, &wndPtr->rectWindow, &rect, 0, 0 ); - X11DRV_register_window( display, hwnd, data ); TRACE( "win %p window %ld,%ld,%ld,%ld client %ld,%ld,%ld,%ld whole %ld,%ld,%ld,%ld X client %ld,%ld,%ld,%ld xwin %x/%x\n", hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top, @@ -1179,15 +1174,9 @@ BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode ) */ struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd ) { - struct x11drv_win_data *ret = NULL; - WND *win = WIN_GetPtr( hwnd ); - - if (win && win != WND_OTHER_PROCESS) - { - ret = win->pDriverData; - WIN_ReleasePtr( win ); - } - return ret; + char *data; + if (XFindContext( gdi_display, (XID)hwnd, win_data_context, &data )) data = NULL; + return (struct x11drv_win_data *)data; } @@ -1239,27 +1228,27 @@ XIC X11DRV_get_ic( HWND hwnd ) HWND X11DRV_SetParent( HWND hwnd, HWND parent ) { Display *display = thread_display(); - WND *wndPtr; - HWND retvalue; + HWND old_parent; /* Windows hides the window first, then shows it again * including the WM_SHOWWINDOW messages and all */ BOOL was_visible = ShowWindow( hwnd, SW_HIDE ); if (!IsWindow( parent )) return 0; - if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return 0; - retvalue = wndPtr->parent; /* old parent */ - if (parent != retvalue) + old_parent = GetAncestor( hwnd, GA_PARENT ); + if (parent != old_parent) { - struct x11drv_win_data *data = wndPtr->pDriverData; + struct x11drv_win_data *data; Window new_parent = X11DRV_get_client_window( parent ); + if (!(data = X11DRV_get_win_data( hwnd ))) return 0; + WIN_LinkWindow( hwnd, parent, HWND_TOP ); if (parent != GetDesktopWindow()) /* a child window */ { - if (!(wndPtr->dwStyle & WS_CHILD)) + if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) { HMENU menu = (HMENU)SetWindowLongPtrW( hwnd, GWLP_ID, 0 ); if (menu) DestroyMenu( menu ); @@ -1273,7 +1262,6 @@ HWND X11DRV_SetParent( HWND hwnd, HWND parent ) data->whole_rect.left, data->whole_rect.top ); wine_tsx11_unlock(); } - WIN_ReleasePtr( wndPtr ); /* SetParent additionally needs to make hwnd the topmost window in the x-order and send the expected WM_WINDOWPOSCHANGING and @@ -1284,7 +1272,7 @@ HWND X11DRV_SetParent( HWND hwnd, HWND parent ) /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */ - return retvalue; + return old_parent; } diff --git a/dlls/x11drv/winpos.c b/dlls/x11drv/winpos.c index d151b0a639..69f6458491 100644 --- a/dlls/x11drv/winpos.c +++ b/dlls/x11drv/winpos.c @@ -240,7 +240,6 @@ BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags ) { HWND top = get_top_clipping_window( hwnd ); WND *win = WIN_GetPtr( hwnd ); - struct x11drv_win_data *data = win->pDriverData; struct x11drv_escape_set_drawable escape; escape.mode = IncludeInferiors; @@ -282,6 +281,14 @@ BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags ) } else { + struct x11drv_win_data *data; + + if (!(data = X11DRV_get_win_data( hwnd ))) + { + WIN_ReleasePtr( win ); + return FALSE; + } + if (IsIconic( hwnd )) { escape.drawable = data->icon_window ? data->icon_window : data->whole_window; @@ -683,12 +690,14 @@ void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style ) BOOL X11DRV_set_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow, const RECT *rectClient, UINT swp_flags, UINT wvr_flags ) { + struct x11drv_win_data *data; HWND top = get_top_clipping_window( hwnd ); - WND *win = WIN_GetPtr( hwnd ); + WND *win; DWORD old_style, new_style; BOOL ret; - if (!win) return FALSE; + if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE; + if (!(win = WIN_GetPtr( hwnd ))) return FALSE; if (win == WND_OTHER_PROCESS) { if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd ); @@ -717,7 +726,6 @@ BOOL X11DRV_set_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow if (ret) { - struct x11drv_win_data *data = win->pDriverData; Display *display = thread_display(); /* invalidate DCEs */ @@ -1188,16 +1196,18 @@ END: */ void X11DRV_MapNotify( HWND hwnd, XMapEvent *event ) { + struct x11drv_win_data *data; HWND hwndFocus = GetFocus(); WND *win; + if (!(data = X11DRV_get_win_data( hwnd ))) return; + if (!(win = WIN_GetPtr( hwnd ))) return; if ((win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE) && (win->dwExStyle & WS_EX_MANAGED)) { - struct x11drv_win_data *data = win->pDriverData; int x, y; unsigned int width, height, border, depth; Window root, top; diff --git a/dlls/x11drv/x11drv.h b/dlls/x11drv/x11drv.h index 6b80a4615d..3b4423f8ac 100644 --- a/dlls/x11drv/x11drv.h +++ b/dlls/x11drv/x11drv.h @@ -553,6 +553,9 @@ inline static BOOL is_window_top_level( HWND hwnd ) GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow()); } +/* X context to associate a hwnd to an X window */ +extern XContext winContext; + extern void X11DRV_SetFocus( HWND hwnd ); extern Cursor X11DRV_GetCursor( Display *display, struct tagCURSORICONINFO *ptr ); @@ -560,7 +563,6 @@ typedef int (*x11drv_error_callback)( Display *display, XErrorEvent *event, void extern void X11DRV_expect_error( Display *display, x11drv_error_callback callback, void *arg ); extern int X11DRV_check_error(void); -extern void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data ); extern void X11DRV_set_iconic_state( HWND hwnd ); extern void X11DRV_window_to_X_rect( HWND hwnd, RECT *rect ); extern void X11DRV_X_to_window_rect( HWND hwnd, RECT *rect ); diff --git a/include/win.h b/include/win.h index cb4c30064a..eb985692c7 100644 --- a/include/win.h +++ b/include/win.h @@ -62,7 +62,6 @@ typedef struct tagWND int cbWndExtra; /* class cbWndExtra at window creation */ int irefCount; /* window's reference count*/ DWORD userdata; /* User private data */ - void *pDriverData; /* Window driver data */ DWORD wExtra[1]; /* Window extra bytes */ } WND; -- 2.32.0.93.g670b81a890