Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Window related functions |
| 3 | * |
| 4 | * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard |
| 5 | * Copyright 1993 David Metcalfe |
| 6 | * Copyright 1995, 1996 Alex Korobka |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include "config.h" |
| 24 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 25 | #include <stdarg.h> |
Dmitry Timoshkov | de70d2b | 2001-06-19 03:32:44 +0000 | [diff] [blame] | 26 | #include <stdlib.h> |
James Liggett | 60a9750 | 2006-08-22 17:14:11 -0700 | [diff] [blame] | 27 | #include <stdio.h> |
Patrik Stridvall | ba78aac | 2003-08-08 21:07:23 +0000 | [diff] [blame] | 28 | #ifdef HAVE_UNISTD_H |
| 29 | # include <unistd.h> |
| 30 | #endif |
Dmitry Timoshkov | de70d2b | 2001-06-19 03:32:44 +0000 | [diff] [blame] | 31 | |
Alexandre Julliard | 64c0e2a | 2003-11-21 21:48:36 +0000 | [diff] [blame] | 32 | #include <X11/Xlib.h> |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 33 | #include <X11/Xresource.h> |
| 34 | #include <X11/Xutil.h> |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 35 | #ifdef HAVE_LIBXSHAPE |
| 36 | #include <X11/extensions/shape.h> |
| 37 | #endif /* HAVE_LIBXSHAPE */ |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 38 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 39 | #include "windef.h" |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 40 | #include "winbase.h" |
| 41 | #include "wingdi.h" |
| 42 | #include "winuser.h" |
Ilya Konstantinov | 560ca32 | 2001-10-02 18:44:56 +0000 | [diff] [blame] | 43 | #include "wine/unicode.h" |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 44 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 45 | #include "x11drv.h" |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 46 | #include "xcomposite.h" |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 47 | #include "wine/debug.h" |
| 48 | #include "wine/server.h" |
Ove Kaaven | 77e7fd7 | 2002-01-21 18:41:27 +0000 | [diff] [blame] | 49 | #include "mwm.h" |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 50 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 51 | WINE_DEFAULT_DEBUG_CHANNEL(x11drv); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 52 | |
Alexandre Julliard | 24dbaa0 | 2008-04-17 16:13:34 +0200 | [diff] [blame] | 53 | #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 |
| 54 | #define _NET_WM_MOVERESIZE_SIZE_TOP 1 |
| 55 | #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2 |
| 56 | #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3 |
| 57 | #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4 |
| 58 | #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5 |
| 59 | #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6 |
| 60 | #define _NET_WM_MOVERESIZE_SIZE_LEFT 7 |
| 61 | #define _NET_WM_MOVERESIZE_MOVE 8 |
| 62 | #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 |
| 63 | #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 |
| 64 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 65 | /* X context to associate a hwnd to an X window */ |
| 66 | XContext winContext = 0; |
| 67 | |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 68 | /* X context to associate a struct x11drv_win_data to an hwnd */ |
| 69 | static XContext win_data_context; |
| 70 | |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 71 | static const char whole_window_prop[] = "__wine_x11_whole_window"; |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 72 | static const char client_window_prop[]= "__wine_x11_client_window"; |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 73 | static const char icon_window_prop[] = "__wine_x11_icon_window"; |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 74 | static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id"; |
Chris Robinson | a8124f9 | 2007-09-25 10:20:58 -0700 | [diff] [blame] | 75 | static const char gl_drawable_prop[] = "__wine_x11_gl_drawable"; |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 76 | static const char pixmap_prop[] = "__wine_x11_pixmap"; |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 77 | static const char managed_prop[] = "__wine_x11_managed"; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 78 | |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 79 | extern int usexcomposite; |
| 80 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 81 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 82 | * is_window_managed |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 83 | * |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 84 | * Check if a given window should be managed |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 85 | */ |
Alexandre Julliard | effdfa7 | 2007-08-27 12:37:14 +0200 | [diff] [blame] | 86 | BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 87 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 88 | DWORD style, ex_style; |
| 89 | |
Alexandre Julliard | 8913182 | 2008-01-24 10:21:07 +0100 | [diff] [blame] | 90 | if (!managed_mode) return FALSE; |
| 91 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 92 | /* child windows are not managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 93 | style = GetWindowLongW( hwnd, GWL_STYLE ); |
Peter Dons Tychsen | d0b21ab | 2007-07-25 04:09:50 +0200 | [diff] [blame] | 94 | if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE; |
Alexandre Julliard | effdfa7 | 2007-08-27 12:37:14 +0200 | [diff] [blame] | 95 | /* activated windows are managed */ |
| 96 | if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE; |
| 97 | if (hwnd == GetActiveWindow()) return TRUE; |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 98 | /* windows with caption are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 99 | if ((style & WS_CAPTION) == WS_CAPTION) return TRUE; |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 100 | /* tool windows are not managed */ |
Alexandre Julliard | cbdf129 | 2008-01-23 21:40:45 +0100 | [diff] [blame] | 101 | ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE ); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 102 | if (ex_style & WS_EX_TOOLWINDOW) return FALSE; |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 103 | /* windows with thick frame are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 104 | if (style & WS_THICKFRAME) return TRUE; |
Jerry Jenkins | 4e6fab5 | 2003-12-13 00:05:53 +0000 | [diff] [blame] | 105 | /* application windows are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 106 | if (ex_style & WS_EX_APPWINDOW) return TRUE; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 107 | if (style & WS_POPUP) |
Alex Pasadyn | d18c8ca | 2004-02-06 05:17:55 +0000 | [diff] [blame] | 108 | { |
Vitaliy Margolen | abcbcc3 | 2007-02-10 10:40:50 -0700 | [diff] [blame] | 109 | /* popup with sysmenu == caption are managed */ |
| 110 | if (style & WS_SYSMENU) return TRUE; |
| 111 | /* full-screen popup windows are managed */ |
Alexandre Julliard | dba8ad5 | 2008-02-25 19:48:07 +0100 | [diff] [blame] | 112 | if (window_rect->left <= 0 && window_rect->right >= screen_width && |
| 113 | window_rect->top <= 0 && window_rect->bottom >= screen_height) |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 114 | return TRUE; |
Alex Pasadyn | d18c8ca | 2004-02-06 05:17:55 +0000 | [diff] [blame] | 115 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 116 | /* default: not managed */ |
| 117 | return FALSE; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | |
| 121 | /*********************************************************************** |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 122 | * X11DRV_is_window_rect_mapped |
| 123 | * |
| 124 | * Check if the X whole window should be mapped based on its rectangle |
| 125 | */ |
| 126 | BOOL X11DRV_is_window_rect_mapped( const RECT *rect ) |
| 127 | { |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 128 | /* don't map if rect is off-screen */ |
Alexandre Julliard | 3c305f9 | 2006-10-23 14:37:17 +0200 | [diff] [blame] | 129 | if (rect->left >= virtual_screen_rect.right || |
| 130 | rect->top >= virtual_screen_rect.bottom || |
| 131 | rect->right <= virtual_screen_rect.left || |
| 132 | rect->bottom <= virtual_screen_rect.top) |
| 133 | return FALSE; |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 134 | |
| 135 | return TRUE; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /*********************************************************************** |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 140 | * is_window_resizable |
| 141 | * |
| 142 | * Check if window should be made resizable by the window manager |
| 143 | */ |
| 144 | static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style ) |
| 145 | { |
| 146 | if (style & WS_THICKFRAME) return TRUE; |
| 147 | /* Metacity needs the window to be resizable to make it fullscreen */ |
| 148 | return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width && |
| 149 | data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /*********************************************************************** |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 154 | * get_mwm_decorations |
| 155 | */ |
Dmitry Timoshkov | 15c0bcb | 2008-04-16 16:50:29 +0900 | [diff] [blame] | 156 | static unsigned long get_mwm_decorations( struct x11drv_win_data *data, |
| 157 | DWORD style, DWORD ex_style ) |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 158 | { |
| 159 | unsigned long ret = 0; |
| 160 | |
Dmitry Timoshkov | 15c0bcb | 2008-04-16 16:50:29 +0900 | [diff] [blame] | 161 | if (!decorated_mode) return 0; |
| 162 | |
| 163 | if (IsRectEmpty( &data->window_rect )) return 0; |
Matthew D'Asaro | 4217fcb | 2008-04-10 12:53:45 -0700 | [diff] [blame] | 164 | |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 165 | if (ex_style & WS_EX_TOOLWINDOW) return 0; |
| 166 | |
| 167 | if ((style & WS_CAPTION) == WS_CAPTION) |
| 168 | { |
| 169 | ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER; |
| 170 | if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU; |
| 171 | if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE; |
| 172 | if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE; |
| 173 | } |
| 174 | if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER; |
| 175 | else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH; |
| 176 | else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER; |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 177 | return ret; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | /*********************************************************************** |
| 182 | * get_x11_rect_offset |
| 183 | * |
| 184 | * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect. |
| 185 | */ |
| 186 | static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect ) |
| 187 | { |
| 188 | DWORD style, ex_style, style_mask = 0, ex_style_mask = 0; |
| 189 | unsigned long decor; |
| 190 | |
| 191 | rect->top = rect->bottom = rect->left = rect->right = 0; |
| 192 | |
| 193 | style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
| 194 | ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE ); |
Dmitry Timoshkov | 15c0bcb | 2008-04-16 16:50:29 +0900 | [diff] [blame] | 195 | decor = get_mwm_decorations( data, style, ex_style ); |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 196 | |
| 197 | if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION; |
| 198 | if (decor & MWM_DECOR_BORDER) |
| 199 | { |
| 200 | style_mask |= WS_DLGFRAME | WS_THICKFRAME; |
| 201 | ex_style_mask |= WS_EX_DLGMODALFRAME; |
| 202 | } |
| 203 | |
| 204 | AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask ); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 209 | * get_window_attributes |
| 210 | * |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 211 | * Fill the window attributes structure for an X window. |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 212 | */ |
Alexandre Julliard | 6bb18e2 | 2006-03-27 15:33:43 +0200 | [diff] [blame] | 213 | static int get_window_attributes( Display *display, struct x11drv_win_data *data, |
| 214 | XSetWindowAttributes *attr ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 215 | { |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 216 | attr->override_redirect = !data->managed; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 217 | attr->colormap = X11DRV_PALETTE_PaletteXColormap; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 218 | attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0); |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 219 | attr->cursor = x11drv_thread_data()->cursor; |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 220 | attr->bit_gravity = NorthWestGravity; |
| 221 | attr->backing_store = NotUseful; |
| 222 | attr->event_mask = (ExposureMask | PointerMotionMask | |
| 223 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | |
| 224 | KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask); |
Alexandre Julliard | 5a5344b | 2008-02-27 19:11:43 +0100 | [diff] [blame] | 225 | if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask; |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 226 | |
| 227 | return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor | |
| 228 | CWEventMask | CWBitGravity | CWBackingStore); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 229 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 230 | |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 231 | |
| 232 | /*********************************************************************** |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 233 | * create_client_window |
| 234 | */ |
| 235 | static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis ) |
| 236 | { |
| 237 | int cx, cy, mask; |
| 238 | XSetWindowAttributes attr; |
| 239 | Window client; |
| 240 | |
| 241 | attr.bit_gravity = NorthWestGravity; |
| 242 | attr.win_gravity = NorthWestGravity; |
| 243 | attr.backing_store = NotUseful; |
| 244 | attr.event_mask = (ExposureMask | PointerMotionMask | |
| 245 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask); |
| 246 | mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore; |
| 247 | |
| 248 | if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1; |
| 249 | if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1; |
| 250 | |
| 251 | wine_tsx11_lock(); |
| 252 | |
| 253 | if (vis) |
| 254 | { |
| 255 | attr.colormap = XCreateColormap( display, root_window, vis->visual, |
| 256 | (vis->class == PseudoColor || vis->class == GrayScale || |
| 257 | vis->class == DirectColor) ? AllocAll : AllocNone ); |
| 258 | mask |= CWColormap; |
| 259 | } |
| 260 | |
| 261 | client = XCreateWindow( display, data->whole_window, |
| 262 | data->client_rect.left - data->whole_rect.left, |
| 263 | data->client_rect.top - data->whole_rect.top, |
| 264 | cx, cy, 0, screen_depth, InputOutput, |
| 265 | vis ? vis->visual : visual, mask, &attr ); |
| 266 | if (!client) |
| 267 | { |
| 268 | wine_tsx11_unlock(); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | if (data->client_window) |
| 273 | { |
Alexandre Julliard | 51d3d62 | 2008-03-05 20:52:14 +0100 | [diff] [blame] | 274 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
| 275 | if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None; |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 276 | XDeleteContext( display, data->client_window, winContext ); |
| 277 | XDestroyWindow( display, data->client_window ); |
| 278 | } |
| 279 | data->client_window = client; |
| 280 | |
| 281 | if (data->colormap) XFreeColormap( display, data->colormap ); |
| 282 | data->colormap = vis ? attr.colormap : 0; |
| 283 | |
| 284 | XMapWindow( display, data->client_window ); |
| 285 | XSaveContext( display, data->client_window, winContext, (char *)data->hwnd ); |
| 286 | wine_tsx11_unlock(); |
| 287 | |
| 288 | SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window ); |
| 289 | return data->client_window; |
| 290 | } |
| 291 | |
| 292 | |
| 293 | /*********************************************************************** |
Alexandre Julliard | 911a177 | 2002-08-20 00:36:45 +0000 | [diff] [blame] | 294 | * X11DRV_sync_window_style |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 295 | * |
| 296 | * Change the X window attributes when the window style has changed. |
| 297 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 298 | void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 299 | { |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 300 | if (data->whole_window != root_window) |
| 301 | { |
| 302 | XSetWindowAttributes attr; |
| 303 | int mask = get_window_attributes( display, data, &attr ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 304 | |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 305 | wine_tsx11_lock(); |
Alexandre Julliard | 6d5f544 | 2006-03-06 21:02:59 +0100 | [diff] [blame] | 306 | XChangeWindowAttributes( display, data->whole_window, mask, &attr ); |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 307 | wine_tsx11_unlock(); |
| 308 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | |
| 312 | /*********************************************************************** |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 313 | * sync_window_region |
| 314 | * |
| 315 | * Update the X11 window region. |
| 316 | */ |
| 317 | static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn ) |
| 318 | { |
| 319 | #ifdef HAVE_LIBXSHAPE |
| 320 | if (!data->whole_window) return; |
| 321 | |
| 322 | if (!hrgn) |
| 323 | { |
| 324 | wine_tsx11_lock(); |
| 325 | XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet ); |
| 326 | wine_tsx11_unlock(); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 ); |
| 331 | if (pRegionData) |
| 332 | { |
| 333 | wine_tsx11_lock(); |
| 334 | XShapeCombineRectangles( display, data->whole_window, ShapeBounding, |
| 335 | data->window_rect.left - data->whole_rect.left, |
| 336 | data->window_rect.top - data->whole_rect.top, |
| 337 | (XRectangle *)pRegionData->Buffer, |
| 338 | pRegionData->rdh.nCount, ShapeSet, YXBanded ); |
| 339 | wine_tsx11_unlock(); |
| 340 | HeapFree(GetProcessHeap(), 0, pRegionData); |
| 341 | } |
| 342 | } |
| 343 | #endif /* HAVE_LIBXSHAPE */ |
| 344 | } |
| 345 | |
| 346 | |
| 347 | /*********************************************************************** |
Alexandre Julliard | 3ba2025 | 2008-01-23 16:32:55 +0100 | [diff] [blame] | 348 | * sync_window_text |
| 349 | */ |
| 350 | static void sync_window_text( Display *display, Window win, const WCHAR *text ) |
| 351 | { |
| 352 | UINT count; |
| 353 | char *buffer, *utf8_buffer; |
| 354 | XTextProperty prop; |
| 355 | |
| 356 | /* allocate new buffer for window text */ |
| 357 | count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL); |
| 358 | if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return; |
| 359 | WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL); |
| 360 | |
| 361 | count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL); |
| 362 | if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count ))) |
| 363 | { |
| 364 | HeapFree( GetProcessHeap(), 0, buffer ); |
| 365 | return; |
| 366 | } |
| 367 | WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL); |
| 368 | |
| 369 | wine_tsx11_lock(); |
| 370 | if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success) |
| 371 | { |
| 372 | XSetWMName( display, win, &prop ); |
| 373 | XSetWMIconName( display, win, &prop ); |
| 374 | XFree( prop.value ); |
| 375 | } |
| 376 | /* |
| 377 | Implements a NET_WM UTF-8 title. It should be without a trailing \0, |
| 378 | according to the standard |
| 379 | ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ). |
| 380 | */ |
| 381 | XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING), |
| 382 | 8, PropModeReplace, (unsigned char *) utf8_buffer, count); |
| 383 | wine_tsx11_unlock(); |
| 384 | |
| 385 | HeapFree( GetProcessHeap(), 0, utf8_buffer ); |
| 386 | HeapFree( GetProcessHeap(), 0, buffer ); |
| 387 | } |
| 388 | |
| 389 | |
| 390 | /*********************************************************************** |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 391 | * X11DRV_set_win_format |
| 392 | */ |
| 393 | BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id ) |
| 394 | { |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 395 | Display *display = thread_display(); |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 396 | struct x11drv_win_data *data; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 397 | XVisualInfo *vis; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 398 | int w, h; |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 399 | |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 400 | if (!(data = X11DRV_get_win_data(hwnd)) && |
| 401 | !(data = X11DRV_create_win_data(hwnd))) return FALSE; |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 402 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 403 | if (data->fbconfig_id) return FALSE; /* can't change it twice */ |
| 404 | |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 405 | wine_tsx11_lock(); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 406 | vis = visual_from_fbconfig_id(fbconfig_id); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 407 | wine_tsx11_unlock(); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 408 | if (!vis) return FALSE; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 409 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 410 | if (data->whole_window) |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 411 | { |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 412 | Window client = data->client_window; |
| 413 | |
| 414 | if (vis->visualid != XVisualIDFromVisual(visual)) |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 415 | { |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 416 | client = create_client_window( display, data, vis ); |
| 417 | TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id ); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 418 | } |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 419 | wine_tsx11_lock(); |
| 420 | XFree(vis); |
| 421 | wine_tsx11_unlock(); |
| 422 | if (client) goto done; |
| 423 | return FALSE; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | w = data->client_rect.right - data->client_rect.left; |
| 427 | h = data->client_rect.bottom - data->client_rect.top; |
| 428 | |
| 429 | if(w <= 0) w = 1; |
| 430 | if(h <= 0) h = 1; |
| 431 | |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 432 | #ifdef SONAME_LIBXCOMPOSITE |
| 433 | if(usexcomposite) |
| 434 | { |
| 435 | XSetWindowAttributes attrib; |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 436 | Window parent = X11DRV_get_whole_window( GetAncestor( hwnd, GA_ROOT )); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 437 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 438 | if (!parent) parent = root_window; |
| 439 | wine_tsx11_lock(); |
Alexandre Julliard | e9307d0 | 2008-02-21 20:23:32 +0100 | [diff] [blame] | 440 | data->colormap = XCreateColormap(display, parent, vis->visual, |
| 441 | (vis->class == PseudoColor || |
| 442 | vis->class == GrayScale || |
| 443 | vis->class == DirectColor) ? |
| 444 | AllocAll : AllocNone); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 445 | attrib.override_redirect = True; |
Alexandre Julliard | e9307d0 | 2008-02-21 20:23:32 +0100 | [diff] [blame] | 446 | attrib.colormap = data->colormap; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 447 | XInstallColormap(gdi_display, attrib.colormap); |
| 448 | |
| 449 | data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0, |
| 450 | vis->depth, InputOutput, vis->visual, |
| 451 | CWColormap | CWOverrideRedirect, |
| 452 | &attrib); |
| 453 | if(data->gl_drawable) |
| 454 | { |
| 455 | pXCompositeRedirectWindow(display, data->gl_drawable, |
| 456 | CompositeRedirectManual); |
| 457 | XMapWindow(display, data->gl_drawable); |
| 458 | } |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 459 | XFree(vis); |
| 460 | wine_tsx11_unlock(); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 461 | } |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 462 | else |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 463 | #endif |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 464 | { |
| 465 | WARN("XComposite is not available, using GLXPixmap hack\n"); |
| 466 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 467 | wine_tsx11_lock(); |
| 468 | data->pixmap = XCreatePixmap(display, root_window, w, h, vis->depth); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 469 | if(!data->pixmap) |
| 470 | { |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 471 | XFree(vis); |
| 472 | wine_tsx11_unlock(); |
| 473 | return FALSE; |
| 474 | } |
| 475 | |
| 476 | data->gl_drawable = create_glxpixmap(display, vis, data->pixmap); |
| 477 | if(!data->gl_drawable) |
| 478 | { |
| 479 | XFreePixmap(display, data->pixmap); |
| 480 | data->pixmap = 0; |
| 481 | } |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 482 | XFree(vis); |
| 483 | wine_tsx11_unlock(); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 484 | if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 487 | if (!data->gl_drawable) return FALSE; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 488 | |
| 489 | TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n", |
| 490 | data->gl_drawable, fbconfig_id); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 491 | SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 492 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 493 | done: |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 494 | data->fbconfig_id = fbconfig_id; |
| 495 | SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 496 | wine_tsx11_lock(); |
| 497 | XFlush( display ); |
| 498 | wine_tsx11_unlock(); |
Alexandre Julliard | 9727aa8 | 2008-04-21 20:32:22 +0200 | [diff] [blame^] | 499 | /* force DCE invalidation */ |
| 500 | SetWindowPos( hwnd, 0, 0, 0, 0, 0, |
| 501 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | |
| 502 | SWP_NOREDRAW | SWP_NOSENDCHANGING | SWP_STATECHANGED); |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 503 | return TRUE; |
| 504 | } |
| 505 | |
Alexandre Julliard | bbfbe24 | 2008-01-23 12:28:01 +0100 | [diff] [blame] | 506 | /*********************************************************************** |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 507 | * sync_gl_drawable |
Alexandre Julliard | bbfbe24 | 2008-01-23 12:28:01 +0100 | [diff] [blame] | 508 | */ |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 509 | static void sync_gl_drawable(Display *display, struct x11drv_win_data *data) |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 510 | { |
| 511 | int w = data->client_rect.right - data->client_rect.left; |
| 512 | int h = data->client_rect.bottom - data->client_rect.top; |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 513 | XVisualInfo *vis; |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 514 | Drawable glxp; |
| 515 | Pixmap pix; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 516 | |
Alexandre Julliard | f13ef6b | 2008-02-22 16:30:10 +0100 | [diff] [blame] | 517 | if (w <= 0) w = 1; |
| 518 | if (h <= 0) h = 1; |
| 519 | |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 520 | TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h); |
| 521 | #ifdef SONAME_LIBXCOMPOSITE |
| 522 | if(usexcomposite) |
| 523 | { |
| 524 | wine_tsx11_lock(); |
| 525 | XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h); |
| 526 | wine_tsx11_unlock(); |
| 527 | return; |
| 528 | } |
| 529 | #endif |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 530 | |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 531 | wine_tsx11_lock(); |
| 532 | |
| 533 | vis = visual_from_fbconfig_id(data->fbconfig_id); |
Michael Stefaniuc | 4e2eef2 | 2007-10-21 01:15:53 +0200 | [diff] [blame] | 534 | if(!vis) |
| 535 | { |
| 536 | wine_tsx11_unlock(); |
| 537 | return; |
| 538 | } |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 539 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 540 | pix = XCreatePixmap(display, root_window, w, h, vis->depth); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 541 | if(!pix) |
| 542 | { |
| 543 | ERR("Failed to create pixmap for offscreen rendering\n"); |
| 544 | XFree(vis); |
| 545 | wine_tsx11_unlock(); |
| 546 | return; |
| 547 | } |
| 548 | |
| 549 | glxp = create_glxpixmap(display, vis, pix); |
| 550 | if(!glxp) |
| 551 | { |
| 552 | ERR("Failed to create drawable for offscreen rendering\n"); |
| 553 | XFreePixmap(display, pix); |
| 554 | XFree(vis); |
| 555 | wine_tsx11_unlock(); |
| 556 | return; |
| 557 | } |
| 558 | |
| 559 | XFree(vis); |
| 560 | |
| 561 | mark_drawable_dirty(data->gl_drawable, glxp); |
| 562 | |
| 563 | XFreePixmap(display, data->pixmap); |
| 564 | destroy_glxpixmap(display, data->gl_drawable); |
Alexandre Julliard | 9727aa8 | 2008-04-21 20:32:22 +0200 | [diff] [blame^] | 565 | TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, data->gl_drawable ); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 566 | |
| 567 | data->pixmap = pix; |
| 568 | data->gl_drawable = glxp; |
| 569 | |
Alexandre Julliard | 70ef99e | 2008-04-10 14:47:19 +0200 | [diff] [blame] | 570 | XFlush( display ); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 571 | wine_tsx11_unlock(); |
| 572 | |
| 573 | SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable); |
| 574 | SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 577 | |
| 578 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 579 | * get_window_changes |
| 580 | * |
| 581 | * fill the window changes structure |
| 582 | */ |
| 583 | static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new ) |
| 584 | { |
| 585 | int mask = 0; |
| 586 | |
| 587 | if (old->right - old->left != new->right - new->left ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 588 | { |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 589 | if ((changes->width = new->right - new->left) <= 0) changes->width = 1; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 590 | mask |= CWWidth; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 591 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 592 | if (old->bottom - old->top != new->bottom - new->top) |
| 593 | { |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 594 | if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 595 | mask |= CWHeight; |
| 596 | } |
| 597 | if (old->left != new->left) |
| 598 | { |
| 599 | changes->x = new->left; |
| 600 | mask |= CWX; |
| 601 | } |
| 602 | if (old->top != new->top) |
| 603 | { |
| 604 | changes->y = new->top; |
| 605 | mask |= CWY; |
| 606 | } |
| 607 | return mask; |
| 608 | } |
| 609 | |
| 610 | |
| 611 | /*********************************************************************** |
| 612 | * create_icon_window |
| 613 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 614 | static Window create_icon_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 615 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 616 | XSetWindowAttributes attr; |
| 617 | |
| 618 | attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 619 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 620 | attr.bit_gravity = NorthWestGravity; |
| 621 | attr.backing_store = NotUseful/*WhenMapped*/; |
Lionel Ulmer | 1fc39be | 2001-07-12 22:27:56 +0000 | [diff] [blame] | 622 | attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */ |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 623 | |
Alexandre Julliard | 649637f | 2001-06-26 21:10:11 +0000 | [diff] [blame] | 624 | wine_tsx11_lock(); |
| 625 | data->icon_window = XCreateWindow( display, root_window, 0, 0, |
| 626 | GetSystemMetrics( SM_CXICON ), |
| 627 | GetSystemMetrics( SM_CYICON ), |
| 628 | 0, screen_depth, |
| 629 | InputOutput, visual, |
Lionel Ulmer | 1fc39be | 2001-07-12 22:27:56 +0000 | [diff] [blame] | 630 | CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr ); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 631 | XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd ); |
Alexandre Julliard | 731d77f | 2008-04-09 20:24:27 +0200 | [diff] [blame] | 632 | XFlush( display ); /* make sure the window exists before we start painting to it */ |
Alexandre Julliard | 649637f | 2001-06-26 21:10:11 +0000 | [diff] [blame] | 633 | wine_tsx11_unlock(); |
| 634 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 635 | TRACE( "created %lx\n", data->icon_window ); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 636 | SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 637 | return data->icon_window; |
| 638 | } |
| 639 | |
| 640 | |
| 641 | |
| 642 | /*********************************************************************** |
| 643 | * destroy_icon_window |
| 644 | */ |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 645 | static void destroy_icon_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 646 | { |
| 647 | if (!data->icon_window) return; |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 648 | if (x11drv_thread_data()->cursor_window == data->icon_window) |
| 649 | x11drv_thread_data()->cursor_window = None; |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 650 | wine_tsx11_lock(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 651 | XDeleteContext( display, data->icon_window, winContext ); |
| 652 | XDestroyWindow( display, data->icon_window ); |
| 653 | data->icon_window = 0; |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 654 | wine_tsx11_unlock(); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 655 | RemovePropA( data->hwnd, icon_window_prop ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | |
| 659 | /*********************************************************************** |
| 660 | * set_icon_hints |
| 661 | * |
| 662 | * Set the icon wm hints |
| 663 | */ |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 664 | static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 665 | { |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 666 | XWMHints *hints = data->wm_hints; |
| 667 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 668 | if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap ); |
| 669 | if (data->hWMIconMask) DeleteObject( data->hWMIconMask); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 670 | data->hWMIconBitmap = 0; |
| 671 | data->hWMIconMask = 0; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 672 | |
Alexandre Julliard | 12d1d40 | 2008-01-23 16:40:19 +0100 | [diff] [blame] | 673 | if (!hIcon) |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 674 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 675 | if (!data->icon_window) create_icon_window( display, data ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 676 | hints->icon_window = data->icon_window; |
| 677 | hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 678 | } |
| 679 | else |
| 680 | { |
| 681 | HBITMAP hbmOrig; |
| 682 | RECT rcMask; |
| 683 | BITMAP bmMask; |
| 684 | ICONINFO ii; |
| 685 | HDC hDC; |
| 686 | |
| 687 | GetIconInfo(hIcon, &ii); |
| 688 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 689 | GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask); |
| 690 | rcMask.top = 0; |
| 691 | rcMask.left = 0; |
| 692 | rcMask.right = bmMask.bmWidth; |
| 693 | rcMask.bottom = bmMask.bmHeight; |
| 694 | |
| 695 | hDC = CreateCompatibleDC(0); |
| 696 | hbmOrig = SelectObject(hDC, ii.hbmMask); |
| 697 | InvertRect(hDC, &rcMask); |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 698 | SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */ |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 699 | SelectObject(hDC, hbmOrig); |
| 700 | DeleteDC(hDC); |
| 701 | |
| 702 | data->hWMIconBitmap = ii.hbmColor; |
| 703 | data->hWMIconMask = ii.hbmMask; |
| 704 | |
Alexandre Julliard | 5fd1326 | 2005-03-27 18:30:51 +0000 | [diff] [blame] | 705 | hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap); |
| 706 | hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 707 | destroy_icon_window( display, data ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 708 | hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
| 712 | |
| 713 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 714 | * set_size_hints |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 715 | * |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 716 | * set the window size hints |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 717 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 718 | static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 719 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 720 | XSizeHints* size_hints; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 721 | |
Alexandre Julliard | cf9d3e3 | 2008-04-04 11:28:30 +0200 | [diff] [blame] | 722 | if (!(size_hints = XAllocSizeHints())) return; |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 723 | |
Alexandre Julliard | cf9d3e3 | 2008-04-04 11:28:30 +0200 | [diff] [blame] | 724 | /* don't update size hints if window is not in normal state */ |
| 725 | if (!(style & (WS_MINIMIZE | WS_MAXIMIZE))) |
| 726 | { |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 727 | if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */ |
| 728 | { |
| 729 | size_hints->win_gravity = StaticGravity; |
| 730 | size_hints->x = data->whole_rect.left; |
| 731 | size_hints->y = data->whole_rect.top; |
| 732 | size_hints->flags |= PWinGravity | PPosition; |
| 733 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 734 | |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 735 | if (!is_window_resizable( data, style )) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 736 | { |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 737 | size_hints->max_width = data->whole_rect.right - data->whole_rect.left; |
| 738 | size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top; |
| 739 | size_hints->min_width = size_hints->max_width; |
| 740 | size_hints->min_height = size_hints->max_height; |
| 741 | size_hints->flags |= PMinSize | PMaxSize; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 742 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 743 | } |
Alexandre Julliard | cf9d3e3 | 2008-04-04 11:28:30 +0200 | [diff] [blame] | 744 | XSetWMNormalHints( display, data->whole_window, size_hints ); |
| 745 | XFree( size_hints ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | |
| 749 | /*********************************************************************** |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 750 | * get_process_name |
| 751 | * |
| 752 | * get the name of the current process for setting class hints |
| 753 | */ |
| 754 | static char *get_process_name(void) |
| 755 | { |
| 756 | static char *name; |
| 757 | |
| 758 | if (!name) |
| 759 | { |
| 760 | WCHAR module[MAX_PATH]; |
| 761 | DWORD len = GetModuleFileNameW( 0, module, MAX_PATH ); |
| 762 | if (len && len < MAX_PATH) |
| 763 | { |
| 764 | char *ptr; |
| 765 | WCHAR *p, *appname = module; |
| 766 | |
| 767 | if ((p = strrchrW( appname, '/' ))) appname = p + 1; |
| 768 | if ((p = strrchrW( appname, '\\' ))) appname = p + 1; |
| 769 | len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL ); |
| 770 | if ((ptr = HeapAlloc( GetProcessHeap(), 0, len ))) |
| 771 | { |
| 772 | WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL ); |
| 773 | name = ptr; |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | return name; |
| 778 | } |
| 779 | |
| 780 | |
| 781 | /*********************************************************************** |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 782 | * set_initial_wm_hints |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 783 | * |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 784 | * Set the window manager hints that don't change over the lifetime of a window. |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 785 | */ |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 786 | static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 787 | { |
Alexandre Julliard | 3bfa90e | 2008-04-07 11:41:54 +0200 | [diff] [blame] | 788 | long i; |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 789 | Atom protocols[3]; |
| 790 | Atom dndVersion = 4; |
| 791 | XClassHint *class_hints; |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 792 | char *process_name = get_process_name(); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 793 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 794 | wine_tsx11_lock(); |
| 795 | |
| 796 | /* wm protocols */ |
| 797 | i = 0; |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 798 | protocols[i++] = x11drv_atom(WM_DELETE_WINDOW); |
| 799 | protocols[i++] = x11drv_atom(_NET_WM_PING); |
| 800 | if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS); |
| 801 | XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS), |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 802 | XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 803 | |
| 804 | /* class hints */ |
| 805 | if ((class_hints = XAllocClassHint())) |
| 806 | { |
Andrew Talbot | 55e20a7 | 2006-06-26 20:56:16 +0100 | [diff] [blame] | 807 | static char wine[] = "Wine"; |
| 808 | |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 809 | class_hints->res_name = process_name; |
Andrew Talbot | 55e20a7 | 2006-06-26 20:56:16 +0100 | [diff] [blame] | 810 | class_hints->res_class = wine; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 811 | XSetClassHint( display, data->whole_window, class_hints ); |
| 812 | XFree( class_hints ); |
| 813 | } |
| 814 | |
Mike Hearn | 34dd455 | 2003-05-04 02:27:20 +0000 | [diff] [blame] | 815 | /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */ |
| 816 | XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL); |
| 817 | /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */ |
| 818 | i = getpid(); |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 819 | XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID), |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 820 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1); |
Ove Kaaven | 77e7fd7 | 2002-01-21 18:41:27 +0000 | [diff] [blame] | 821 | |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 822 | XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware), |
| 823 | XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 ); |
| 824 | |
Alexandre Julliard | dc07b6f | 2008-01-22 10:17:52 +0100 | [diff] [blame] | 825 | data->wm_hints = XAllocWMHints(); |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 826 | wine_tsx11_unlock(); |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 827 | |
| 828 | if (data->wm_hints) |
| 829 | { |
Alexandre Julliard | e929e3b | 2008-01-23 16:40:54 +0100 | [diff] [blame] | 830 | HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 ); |
| 831 | if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON ); |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 832 | data->wm_hints->flags = 0; |
Alexandre Julliard | e929e3b | 2008-01-23 16:40:54 +0100 | [diff] [blame] | 833 | set_icon_hints( display, data, icon ); |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 834 | } |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | |
| 838 | /*********************************************************************** |
| 839 | * X11DRV_set_wm_hints |
| 840 | * |
| 841 | * Set the window manager hints for a newly-created window |
| 842 | */ |
| 843 | void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data ) |
| 844 | { |
| 845 | Window group_leader; |
| 846 | Atom window_type; |
| 847 | MwmHints mwm_hints; |
Alexandre Julliard | 18f4fb9 | 2008-04-14 13:27:38 +0200 | [diff] [blame] | 848 | DWORD style, ex_style; |
| 849 | HWND owner; |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 850 | |
| 851 | if (data->hwnd == GetDesktopWindow()) |
| 852 | { |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 853 | /* force some styles for the desktop to get the correct decorations */ |
Alexandre Julliard | 18f4fb9 | 2008-04-14 13:27:38 +0200 | [diff] [blame] | 854 | style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; |
| 855 | ex_style = WS_EX_APPWINDOW; |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 856 | owner = 0; |
| 857 | } |
Alexandre Julliard | 18f4fb9 | 2008-04-14 13:27:38 +0200 | [diff] [blame] | 858 | else |
| 859 | { |
| 860 | style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
| 861 | ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE ); |
| 862 | owner = GetWindow( data->hwnd, GW_OWNER ); |
| 863 | } |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 864 | |
| 865 | /* transient for hint */ |
| 866 | if (owner) |
| 867 | { |
| 868 | Window owner_win = X11DRV_get_whole_window( owner ); |
| 869 | wine_tsx11_lock(); |
| 870 | XSetTransientForHint( display, data->whole_window, owner_win ); |
| 871 | wine_tsx11_unlock(); |
| 872 | group_leader = owner_win; |
| 873 | } |
| 874 | else group_leader = data->whole_window; |
| 875 | |
| 876 | wine_tsx11_lock(); |
| 877 | |
| 878 | /* size hints */ |
| 879 | set_size_hints( display, data, style ); |
| 880 | |
Nickolay V. Shmyrev | 1a1b902 | 2006-10-11 19:32:22 +0400 | [diff] [blame] | 881 | /* set the WM_WINDOW_TYPE */ |
Dmitry Timoshkov | 751a71a | 2008-04-07 13:37:44 +0900 | [diff] [blame] | 882 | if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL); |
Alexandre Julliard | 9bf9c0b | 2008-04-14 13:27:19 +0200 | [diff] [blame] | 883 | else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL); |
Nickolay V. Shmyrev | 1a1b902 | 2006-10-11 19:32:22 +0400 | [diff] [blame] | 884 | else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG); |
| 885 | else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG); |
Dmitry Timoshkov | 1bf824e | 2008-04-07 22:17:47 +0900 | [diff] [blame] | 886 | #if 0 /* many window managers don't handle utility windows very well */ |
Dmitry Timoshkov | 751a71a | 2008-04-07 13:37:44 +0900 | [diff] [blame] | 887 | else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY); |
Dmitry Timoshkov | 1bf824e | 2008-04-07 22:17:47 +0900 | [diff] [blame] | 888 | #endif |
Alexandre Julliard | 9bf9c0b | 2008-04-14 13:27:19 +0200 | [diff] [blame] | 889 | else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL); |
Nickolay V. Shmyrev | 1a1b902 | 2006-10-11 19:32:22 +0400 | [diff] [blame] | 890 | |
| 891 | XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE), |
| 892 | XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1); |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 893 | |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 894 | mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; |
Dmitry Timoshkov | 15c0bcb | 2008-04-16 16:50:29 +0900 | [diff] [blame] | 895 | mwm_hints.decorations = get_mwm_decorations( data, style, ex_style ); |
Dmitry Timoshkov | ac387bb | 2006-10-05 23:16:36 +0900 | [diff] [blame] | 896 | mwm_hints.functions = MWM_FUNC_MOVE; |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 897 | if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 898 | if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE; |
| 899 | if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE; |
Alexandre Julliard | 74cd76c | 2007-08-29 12:02:57 +0200 | [diff] [blame] | 900 | if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE; |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 901 | |
| 902 | XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS), |
| 903 | x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace, |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 904 | (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 905 | |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 906 | /* wm hints */ |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 907 | if (data->wm_hints) |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 908 | { |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 909 | data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint; |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 910 | data->wm_hints->input = !(style & WS_DISABLED); |
| 911 | data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState; |
| 912 | data->wm_hints->window_group = group_leader; |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 913 | XSetWMHints( display, data->whole_window, data->wm_hints ); |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 914 | } |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 915 | |
| 916 | wine_tsx11_unlock(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | |
| 920 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 921 | * X11DRV_window_to_X_rect |
| 922 | * |
| 923 | * Convert a rect from client to X window coordinates |
| 924 | */ |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 925 | void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 926 | { |
Alexandre Julliard | 8cd1f71 | 2001-07-20 18:37:37 +0000 | [diff] [blame] | 927 | RECT rc; |
| 928 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 929 | if (!data->managed) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 930 | if (IsRectEmpty( rect )) return; |
| 931 | |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 932 | get_x11_rect_offset( data, &rc ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 933 | |
Alexandre Julliard | 8cd1f71 | 2001-07-20 18:37:37 +0000 | [diff] [blame] | 934 | rect->left -= rc.left; |
| 935 | rect->right -= rc.right; |
| 936 | rect->top -= rc.top; |
| 937 | rect->bottom -= rc.bottom; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 938 | if (rect->top >= rect->bottom) rect->bottom = rect->top + 1; |
| 939 | if (rect->left >= rect->right) rect->right = rect->left + 1; |
| 940 | } |
| 941 | |
| 942 | |
| 943 | /*********************************************************************** |
| 944 | * X11DRV_X_to_window_rect |
| 945 | * |
| 946 | * Opposite of X11DRV_window_to_X_rect |
| 947 | */ |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 948 | void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 949 | { |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 950 | RECT rc; |
Alexandre Julliard | 74cd76c | 2007-08-29 12:02:57 +0200 | [diff] [blame] | 951 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 952 | if (!data->managed) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 953 | if (IsRectEmpty( rect )) return; |
| 954 | |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 955 | get_x11_rect_offset( data, &rc ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 956 | |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 957 | rect->left += rc.left; |
| 958 | rect->right += rc.right; |
| 959 | rect->top += rc.top; |
| 960 | rect->bottom += rc.bottom; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 961 | if (rect->top >= rect->bottom) rect->bottom = rect->top + 1; |
| 962 | if (rect->left >= rect->right) rect->right = rect->left + 1; |
| 963 | } |
| 964 | |
| 965 | |
| 966 | /*********************************************************************** |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 967 | * X11DRV_sync_window_position |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 968 | * |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 969 | * Synchronize the X window position with the Windows one |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 970 | */ |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 971 | void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data, |
Alexandre Julliard | bbfbe24 | 2008-01-23 12:28:01 +0100 | [diff] [blame] | 972 | UINT swp_flags, const RECT *old_client_rect, |
| 973 | const RECT *old_whole_rect ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 974 | { |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 975 | DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 976 | XWindowChanges changes; |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 977 | int mask = CWWidth | CWHeight; |
| 978 | |
| 979 | if (data->managed && data->iconic) return; |
| 980 | |
| 981 | if ((changes.width = data->whole_rect.right - data->whole_rect.left) <= 0) changes.width = 1; |
| 982 | if ((changes.height = data->whole_rect.bottom - data->whole_rect.top) <= 0) changes.height = 1; |
| 983 | |
| 984 | /* only the size is allowed to change for the desktop window */ |
| 985 | if (data->whole_window != root_window) |
| 986 | { |
| 987 | changes.x = data->whole_rect.left - virtual_screen_rect.left; |
| 988 | changes.y = data->whole_rect.top - virtual_screen_rect.top; |
| 989 | mask |= CWX | CWY; |
| 990 | } |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 991 | |
| 992 | if (!(swp_flags & SWP_NOZORDER)) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 993 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 994 | /* find window that this one must be after */ |
| 995 | HWND prev = GetWindow( data->hwnd, GW_HWNDPREV ); |
| 996 | while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE)) |
| 997 | prev = GetWindow( prev, GW_HWNDPREV ); |
| 998 | if (!prev) /* top child */ |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 999 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1000 | changes.stack_mode = Above; |
| 1001 | mask |= CWStackMode; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1002 | } |
Alexandre Julliard | 5787c12 | 2008-03-24 15:47:28 +0100 | [diff] [blame] | 1003 | /* should use stack_mode Below but most window managers don't get it right */ |
| 1004 | /* and Above with a sibling doesn't work so well either, so we ignore it */ |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 1007 | TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n", |
| 1008 | data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top, |
| 1009 | data->whole_rect.right - data->whole_rect.left, |
| 1010 | data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask ); |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1011 | |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 1012 | wine_tsx11_lock(); |
| 1013 | set_size_hints( display, data, style ); |
| 1014 | XReconfigureWMWindow( display, data->whole_window, |
| 1015 | DefaultScreen(display), mask, &changes ); |
| 1016 | wine_tsx11_unlock(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1020 | /*********************************************************************** |
| 1021 | * X11DRV_sync_client_position |
| 1022 | * |
| 1023 | * Synchronize the X client window position with the Windows one |
| 1024 | */ |
| 1025 | void X11DRV_sync_client_position( Display *display, struct x11drv_win_data *data, |
| 1026 | UINT swp_flags, const RECT *old_client_rect, |
| 1027 | const RECT *old_whole_rect ) |
| 1028 | { |
| 1029 | int mask; |
| 1030 | XWindowChanges changes; |
| 1031 | RECT old = *old_client_rect; |
| 1032 | RECT new = data->client_rect; |
| 1033 | |
| 1034 | OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top ); |
| 1035 | OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top ); |
| 1036 | if (!(mask = get_window_changes( &changes, &old, &new ))) return; |
| 1037 | |
| 1038 | if (data->client_window) |
| 1039 | { |
| 1040 | TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n", |
| 1041 | data->client_window, new.left, new.top, |
| 1042 | new.right - new.left, new.bottom - new.top, mask ); |
| 1043 | wine_tsx11_lock(); |
| 1044 | XConfigureWindow( display, data->client_window, mask, &changes ); |
| 1045 | wine_tsx11_unlock(); |
| 1046 | } |
| 1047 | |
| 1048 | if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1052 | /********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1053 | * create_whole_window |
| 1054 | * |
| 1055 | * Create the whole X window for a given window |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1056 | */ |
Alexandre Julliard | d147e02 | 2008-01-23 21:39:32 +0100 | [diff] [blame] | 1057 | static Window create_whole_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1058 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1059 | int cx, cy, mask; |
| 1060 | XSetWindowAttributes attr; |
Alexandre Julliard | 3ba2025 | 2008-01-23 16:32:55 +0100 | [diff] [blame] | 1061 | WCHAR text[1024]; |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 1062 | HRGN hrgn; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1063 | |
Alexandre Julliard | ac98e0c | 2007-08-20 22:06:33 +0200 | [diff] [blame] | 1064 | if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1; |
| 1065 | if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1066 | |
Alexandre Julliard | e6dfbcb | 2008-01-25 12:07:11 +0100 | [diff] [blame] | 1067 | if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect )) |
| 1068 | { |
| 1069 | TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window ); |
| 1070 | data->managed = TRUE; |
| 1071 | SetPropA( data->hwnd, managed_prop, (HANDLE)1 ); |
| 1072 | } |
| 1073 | |
Alexandre Julliard | 6bb18e2 | 2006-03-27 15:33:43 +0200 | [diff] [blame] | 1074 | mask = get_window_attributes( display, data, &attr ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1075 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1076 | wine_tsx11_lock(); |
| 1077 | |
Alexandre Julliard | ac98e0c | 2007-08-20 22:06:33 +0200 | [diff] [blame] | 1078 | data->whole_rect = data->window_rect; |
Alexandre Julliard | a06aeab | 2006-10-26 12:53:59 +0200 | [diff] [blame] | 1079 | data->whole_window = XCreateWindow( display, root_window, |
Alexandre Julliard | ac98e0c | 2007-08-20 22:06:33 +0200 | [diff] [blame] | 1080 | data->window_rect.left - virtual_screen_rect.left, |
| 1081 | data->window_rect.top - virtual_screen_rect.top, |
Alexandre Julliard | a06aeab | 2006-10-26 12:53:59 +0200 | [diff] [blame] | 1082 | cx, cy, 0, screen_depth, InputOutput, |
| 1083 | visual, mask, &attr ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1084 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 1085 | if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd ); |
| 1086 | wine_tsx11_unlock(); |
| 1087 | |
| 1088 | if (!data->whole_window) return 0; |
| 1089 | |
| 1090 | if (!create_client_window( display, data, NULL )) |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 1091 | { |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 1092 | wine_tsx11_lock(); |
| 1093 | XDeleteContext( display, data->whole_window, winContext ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1094 | XDestroyWindow( display, data->whole_window ); |
| 1095 | data->whole_window = 0; |
| 1096 | wine_tsx11_unlock(); |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1100 | set_initial_wm_hints( display, data ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1101 | X11DRV_set_wm_hints( display, data ); |
| 1102 | |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 1103 | SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window ); |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 1104 | |
Alexandre Julliard | 3ba2025 | 2008-01-23 16:32:55 +0100 | [diff] [blame] | 1105 | /* set the window text */ |
| 1106 | if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0; |
| 1107 | sync_window_text( display, data->whole_window, text ); |
| 1108 | |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 1109 | /* set the window region */ |
| 1110 | if ((hrgn = CreateRectRgn( 0, 0, 0, 0 ))) |
| 1111 | { |
| 1112 | if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn ); |
| 1113 | DeleteObject( hrgn ); |
| 1114 | } |
Alexandre Julliard | 731d77f | 2008-04-09 20:24:27 +0200 | [diff] [blame] | 1115 | wine_tsx11_lock(); |
| 1116 | XFlush( display ); /* make sure the window exists before we start painting to it */ |
| 1117 | wine_tsx11_unlock(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1118 | return data->whole_window; |
| 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | /********************************************************************** |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1123 | * destroy_whole_window |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1124 | * |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1125 | * Destroy the whole X window for a given window. |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1126 | */ |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1127 | static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1128 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1129 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1130 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1131 | if (!data->whole_window) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1132 | |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1133 | TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window ); |
| 1134 | if (thread_data->cursor_window == data->whole_window || |
| 1135 | thread_data->cursor_window == data->client_window) |
| 1136 | thread_data->cursor_window = None; |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1137 | wine_tsx11_lock(); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1138 | XDeleteContext( display, data->whole_window, winContext ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1139 | XDeleteContext( display, data->client_window, winContext ); |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1140 | if (!already_destroyed) XDestroyWindow( display, data->whole_window ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1141 | data->whole_window = data->client_window = 0; |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1142 | data->wm_state = WithdrawnState; |
| 1143 | data->net_wm_state = 0; |
| 1144 | data->mapped = FALSE; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1145 | if (data->xic) |
| 1146 | { |
| 1147 | XUnsetICFocus( data->xic ); |
| 1148 | XDestroyIC( data->xic ); |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1149 | data->xic = 0; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1150 | } |
Alexandre Julliard | 975f1b2 | 2006-05-09 17:32:40 +0200 | [diff] [blame] | 1151 | /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */ |
| 1152 | XFlush( display ); |
Alexandre Julliard | dc07b6f | 2008-01-22 10:17:52 +0100 | [diff] [blame] | 1153 | XFree( data->wm_hints ); |
| 1154 | data->wm_hints = NULL; |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1155 | wine_tsx11_unlock(); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 1156 | RemovePropA( data->hwnd, whole_window_prop ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1157 | RemovePropA( data->hwnd, client_window_prop ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | /***************************************************************** |
| 1162 | * SetWindowText (X11DRV.@) |
| 1163 | */ |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 1164 | void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1165 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 1166 | Display *display = thread_display(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1167 | Window win; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1168 | |
Alexandre Julliard | c44410d | 2006-03-28 12:21:37 +0200 | [diff] [blame] | 1169 | if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display)) |
Alexandre Julliard | 3ba2025 | 2008-01-23 16:32:55 +0100 | [diff] [blame] | 1170 | sync_window_text( display, win, text ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | /*********************************************************************** |
| 1175 | * DestroyWindow (X11DRV.@) |
| 1176 | */ |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 1177 | void X11DRV_DestroyWindow( HWND hwnd ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1178 | { |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 1179 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
| 1180 | Display *display = thread_data->display; |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1181 | struct x11drv_win_data *data; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1182 | |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 1183 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1184 | |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 1185 | if (data->pixmap) |
| 1186 | { |
| 1187 | destroy_glxpixmap(display, data->gl_drawable); |
| 1188 | wine_tsx11_lock(); |
| 1189 | XFreePixmap(display, data->pixmap); |
| 1190 | wine_tsx11_unlock(); |
| 1191 | } |
| 1192 | else if (data->gl_drawable) |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 1193 | { |
| 1194 | wine_tsx11_lock(); |
| 1195 | XDestroyWindow(display, data->gl_drawable); |
| 1196 | wine_tsx11_unlock(); |
| 1197 | } |
| 1198 | |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1199 | destroy_whole_window( display, data, FALSE ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1200 | destroy_icon_window( display, data ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1201 | |
Alexandre Julliard | e9307d0 | 2008-02-21 20:23:32 +0100 | [diff] [blame] | 1202 | if (data->colormap) |
| 1203 | { |
| 1204 | wine_tsx11_lock(); |
| 1205 | XFreeColormap( display, data->colormap ); |
| 1206 | wine_tsx11_unlock(); |
| 1207 | } |
| 1208 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1209 | if (thread_data->last_focus == hwnd) thread_data->last_focus = 0; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1210 | if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap ); |
| 1211 | if (data->hWMIconMask) DeleteObject( data->hWMIconMask); |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1212 | wine_tsx11_lock(); |
Alexandre Julliard | e551555 | 2005-02-09 14:01:40 +0000 | [diff] [blame] | 1213 | XDeleteContext( display, (XID)hwnd, win_data_context ); |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1214 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1215 | HeapFree( GetProcessHeap(), 0, data ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1219 | /*********************************************************************** |
| 1220 | * X11DRV_DestroyNotify |
| 1221 | */ |
| 1222 | void X11DRV_DestroyNotify( HWND hwnd, XEvent *event ) |
| 1223 | { |
| 1224 | Display *display = event->xdestroywindow.display; |
| 1225 | struct x11drv_win_data *data; |
| 1226 | |
| 1227 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
| 1228 | |
| 1229 | FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window ); |
| 1230 | destroy_whole_window( display, data, TRUE ); |
| 1231 | } |
| 1232 | |
| 1233 | |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1234 | static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd ) |
| 1235 | { |
| 1236 | struct x11drv_win_data *data; |
| 1237 | |
Alexandre Julliard | 30d84fc | 2008-01-22 10:15:38 +0100 | [diff] [blame] | 1238 | if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data)))) |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1239 | { |
Alexandre Julliard | 30d84fc | 2008-01-22 10:15:38 +0100 | [diff] [blame] | 1240 | data->hwnd = hwnd; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1241 | wine_tsx11_lock(); |
| 1242 | if (!winContext) winContext = XUniqueContext(); |
| 1243 | if (!win_data_context) win_data_context = XUniqueContext(); |
| 1244 | XSaveContext( display, (XID)hwnd, win_data_context, (char *)data ); |
| 1245 | wine_tsx11_unlock(); |
| 1246 | } |
| 1247 | return data; |
| 1248 | } |
| 1249 | |
| 1250 | |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1251 | /* initialize the desktop window id in the desktop manager process */ |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1252 | static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd ) |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 1253 | { |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1254 | struct x11drv_win_data *data; |
| 1255 | VisualID visualid; |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 1256 | |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1257 | if (!(data = alloc_win_data( display, hwnd ))) return NULL; |
| 1258 | wine_tsx11_lock(); |
| 1259 | visualid = XVisualIDFromVisual(visual); |
| 1260 | wine_tsx11_unlock(); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1261 | data->whole_window = data->client_window = root_window; |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1262 | data->managed = TRUE; |
| 1263 | SetPropA( data->hwnd, managed_prop, (HANDLE)1 ); |
| 1264 | SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1265 | SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window ); |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1266 | set_initial_wm_hints( display, data ); |
| 1267 | return data; |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1270 | /********************************************************************** |
| 1271 | * CreateDesktopWindow (X11DRV.@) |
| 1272 | */ |
| 1273 | BOOL X11DRV_CreateDesktopWindow( HWND hwnd ) |
| 1274 | { |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1275 | unsigned int width, height; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1276 | |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1277 | /* retrieve the real size of the desktop */ |
| 1278 | SERVER_START_REQ( get_window_rectangles ) |
| 1279 | { |
| 1280 | req->handle = hwnd; |
| 1281 | wine_server_call( req ); |
| 1282 | width = reply->window.right - reply->window.left; |
| 1283 | height = reply->window.bottom - reply->window.top; |
| 1284 | } |
| 1285 | SERVER_END_REQ; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1286 | |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1287 | if (!width && !height) /* not initialized yet */ |
| 1288 | { |
| 1289 | SERVER_START_REQ( set_window_pos ) |
| 1290 | { |
| 1291 | req->handle = hwnd; |
| 1292 | req->previous = 0; |
| 1293 | req->flags = SWP_NOZORDER; |
| 1294 | req->window.left = virtual_screen_rect.left; |
| 1295 | req->window.top = virtual_screen_rect.top; |
| 1296 | req->window.right = virtual_screen_rect.right; |
| 1297 | req->window.bottom = virtual_screen_rect.bottom; |
| 1298 | req->client = req->window; |
| 1299 | wine_server_call( req ); |
| 1300 | } |
| 1301 | SERVER_END_REQ; |
| 1302 | } |
| 1303 | else |
| 1304 | { |
| 1305 | Window win = (Window)GetPropA( hwnd, whole_window_prop ); |
| 1306 | if (win && win != root_window) X11DRV_init_desktop( win, width, height ); |
| 1307 | } |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1308 | return TRUE; |
| 1309 | } |
| 1310 | |
| 1311 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1312 | /********************************************************************** |
| 1313 | * CreateWindow (X11DRV.@) |
| 1314 | */ |
Alexandre Julliard | d6f6745 | 2008-01-24 11:23:09 +0100 | [diff] [blame] | 1315 | BOOL X11DRV_CreateWindow( HWND hwnd ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1316 | { |
| 1317 | Display *display = thread_display(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1318 | |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1319 | if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display )) |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1320 | { |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1321 | /* the desktop win data can't be created lazily */ |
| 1322 | if (!create_desktop_win_data( display, hwnd )) return FALSE; |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 1323 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1324 | return TRUE; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | /*********************************************************************** |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1329 | * X11DRV_get_win_data |
| 1330 | * |
| 1331 | * Return the X11 data structure associated with a window. |
| 1332 | */ |
| 1333 | struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd ) |
| 1334 | { |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1335 | char *data; |
Alexandre Julliard | e551555 | 2005-02-09 14:01:40 +0000 | [diff] [blame] | 1336 | |
| 1337 | if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL; |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1338 | return (struct x11drv_win_data *)data; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | |
| 1342 | /*********************************************************************** |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1343 | * X11DRV_create_win_data |
| 1344 | * |
| 1345 | * Create an X11 data window structure for an existing window. |
| 1346 | */ |
| 1347 | struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd ) |
| 1348 | { |
| 1349 | Display *display = thread_display(); |
| 1350 | struct x11drv_win_data *data; |
| 1351 | HWND parent; |
| 1352 | |
| 1353 | if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */ |
| 1354 | if (!(data = alloc_win_data( display, hwnd ))) return NULL; |
| 1355 | |
| 1356 | GetWindowRect( hwnd, &data->window_rect ); |
| 1357 | MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 ); |
| 1358 | data->whole_rect = data->window_rect; |
| 1359 | GetClientRect( hwnd, &data->client_rect ); |
| 1360 | MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 ); |
| 1361 | |
| 1362 | if (parent == GetDesktopWindow()) |
| 1363 | { |
| 1364 | if (!create_whole_window( display, data )) |
| 1365 | { |
| 1366 | HeapFree( GetProcessHeap(), 0, data ); |
| 1367 | return NULL; |
| 1368 | } |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1369 | TRACE( "win %p/%lx/%lx window %s whole %s client %s\n", |
| 1370 | hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ), |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1371 | wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect )); |
| 1372 | } |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1373 | return data; |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1378 | * X11DRV_get_whole_window |
| 1379 | * |
| 1380 | * Return the X window associated with the full area of a window |
| 1381 | */ |
| 1382 | Window X11DRV_get_whole_window( HWND hwnd ) |
| 1383 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1384 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 1385 | |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1386 | if (!data) |
| 1387 | { |
| 1388 | if (hwnd == GetDesktopWindow()) return root_window; |
| 1389 | return (Window)GetPropA( hwnd, whole_window_prop ); |
| 1390 | } |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1391 | return data->whole_window; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 1395 | /*********************************************************************** |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1396 | * X11DRV_get_client_window |
| 1397 | * |
| 1398 | * Return the X window associated with the client area of a window |
| 1399 | */ |
| 1400 | Window X11DRV_get_client_window( HWND hwnd ) |
| 1401 | { |
| 1402 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
| 1403 | |
| 1404 | if (!data) |
| 1405 | { |
| 1406 | if (hwnd == GetDesktopWindow()) return root_window; |
| 1407 | return (Window)GetPropA( hwnd, client_window_prop ); |
| 1408 | } |
| 1409 | return data->client_window; |
| 1410 | } |
| 1411 | |
| 1412 | |
| 1413 | /*********************************************************************** |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 1414 | * X11DRV_get_ic |
| 1415 | * |
| 1416 | * Return the X input context associated with a window |
| 1417 | */ |
| 1418 | XIC X11DRV_get_ic( HWND hwnd ) |
| 1419 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1420 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Kusanagi Kouichi | 185157c | 2008-04-04 20:44:36 +0900 | [diff] [blame] | 1421 | XIM xim; |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 1422 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1423 | if (!data) return 0; |
Kusanagi Kouichi | 185157c | 2008-04-04 20:44:36 +0900 | [diff] [blame] | 1424 | if (data->xic) return data->xic; |
| 1425 | if (!(xim = x11drv_thread_data()->xim)) return 0; |
| 1426 | return X11DRV_CreateIC( xim, data ); |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 1430 | /*********************************************************************** |
| 1431 | * X11DRV_GetDC (X11DRV.@) |
| 1432 | */ |
| 1433 | void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect, |
| 1434 | const RECT *top_rect, DWORD flags ) |
| 1435 | { |
| 1436 | struct x11drv_escape_set_drawable escape; |
| 1437 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
| 1438 | |
| 1439 | escape.code = X11DRV_SET_DRAWABLE; |
| 1440 | escape.mode = IncludeInferiors; |
| 1441 | escape.fbconfig_id = 0; |
| 1442 | escape.gl_drawable = 0; |
| 1443 | escape.pixmap = 0; |
| 1444 | |
| 1445 | if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window) |
| 1446 | { |
| 1447 | escape.drawable = data->icon_window; |
| 1448 | } |
| 1449 | else if (top == hwnd && (flags & DCX_WINDOW)) |
| 1450 | { |
| 1451 | escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd ); |
| 1452 | } |
| 1453 | else |
| 1454 | { |
| 1455 | escape.drawable = X11DRV_get_client_window( top ); |
| 1456 | escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop ); |
| 1457 | escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop ); |
| 1458 | escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop ); |
Alexandre Julliard | af36910 | 2008-03-18 12:42:25 +0100 | [diff] [blame] | 1459 | if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren; |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | escape.dc_rect.left = win_rect->left - top_rect->left; |
| 1463 | escape.dc_rect.top = win_rect->top - top_rect->top; |
| 1464 | escape.dc_rect.right = win_rect->right - top_rect->left; |
| 1465 | escape.dc_rect.bottom = win_rect->bottom - top_rect->top; |
| 1466 | escape.drawable_rect.left = top_rect->left; |
| 1467 | escape.drawable_rect.top = top_rect->top; |
| 1468 | escape.drawable_rect.right = top_rect->right; |
| 1469 | escape.drawable_rect.bottom = top_rect->bottom; |
| 1470 | |
| 1471 | ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL ); |
| 1472 | } |
| 1473 | |
| 1474 | |
| 1475 | /*********************************************************************** |
| 1476 | * X11DRV_ReleaseDC (X11DRV.@) |
| 1477 | */ |
| 1478 | void X11DRV_ReleaseDC( HWND hwnd, HDC hdc ) |
| 1479 | { |
| 1480 | struct x11drv_escape_set_drawable escape; |
| 1481 | |
| 1482 | escape.code = X11DRV_SET_DRAWABLE; |
| 1483 | escape.drawable = root_window; |
| 1484 | escape.mode = IncludeInferiors; |
| 1485 | escape.drawable_rect = virtual_screen_rect; |
| 1486 | SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left, |
| 1487 | virtual_screen_rect.bottom - virtual_screen_rect.top ); |
| 1488 | escape.fbconfig_id = 0; |
| 1489 | escape.gl_drawable = 0; |
| 1490 | escape.pixmap = 0; |
| 1491 | ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL ); |
| 1492 | } |
| 1493 | |
| 1494 | |
Alexandre Julliard | dc26f27 | 2008-03-12 15:01:24 +0100 | [diff] [blame] | 1495 | /*********************************************************************** |
| 1496 | * SetCapture (X11DRV.@) |
| 1497 | */ |
| 1498 | void X11DRV_SetCapture( HWND hwnd, UINT flags ) |
| 1499 | { |
| 1500 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
| 1501 | |
Alexandre Julliard | 78de7e3 | 2008-03-24 17:59:40 +0100 | [diff] [blame] | 1502 | if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return; |
Alexandre Julliard | dc26f27 | 2008-03-12 15:01:24 +0100 | [diff] [blame] | 1503 | |
| 1504 | if (hwnd) |
| 1505 | { |
| 1506 | Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) ); |
| 1507 | |
| 1508 | if (!grab_win) return; |
| 1509 | wine_tsx11_lock(); |
| 1510 | XFlush( gdi_display ); |
| 1511 | XGrabPointer( thread_data->display, grab_win, False, |
| 1512 | PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
Alexandre Julliard | 78de7e3 | 2008-03-24 17:59:40 +0100 | [diff] [blame] | 1513 | GrabModeAsync, GrabModeAsync, None, None, CurrentTime ); |
Alexandre Julliard | dc26f27 | 2008-03-12 15:01:24 +0100 | [diff] [blame] | 1514 | wine_tsx11_unlock(); |
| 1515 | thread_data->grab_window = grab_win; |
| 1516 | } |
| 1517 | else /* release capture */ |
| 1518 | { |
| 1519 | wine_tsx11_lock(); |
| 1520 | XFlush( gdi_display ); |
| 1521 | XUngrabPointer( thread_data->display, CurrentTime ); |
| 1522 | wine_tsx11_unlock(); |
| 1523 | thread_data->grab_window = None; |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1528 | /***************************************************************** |
| 1529 | * SetParent (X11DRV.@) |
| 1530 | */ |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1531 | void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1532 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 1533 | Display *display = thread_display(); |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1534 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1535 | |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1536 | if (!data) return; |
| 1537 | if (parent == old_parent) return; |
Alexandre Julliard | fb0ff05 | 2001-10-16 21:58:58 +0000 | [diff] [blame] | 1538 | |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1539 | if (parent != GetDesktopWindow()) /* a child window */ |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 1540 | { |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1541 | if (old_parent == GetDesktopWindow()) |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 1542 | { |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1543 | /* destroy the old X windows */ |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1544 | destroy_whole_window( display, data, FALSE ); |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1545 | destroy_icon_window( display, data ); |
| 1546 | if (data->managed) |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1547 | { |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1548 | data->managed = FALSE; |
| 1549 | RemovePropA( data->hwnd, managed_prop ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1550 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1551 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1552 | } |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1553 | else /* new top level window */ |
| 1554 | { |
| 1555 | /* FIXME: we ignore errors since we can't really recover anyway */ |
Alexandre Julliard | d147e02 | 2008-01-23 21:39:32 +0100 | [diff] [blame] | 1556 | create_whole_window( display, data ); |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 1557 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1561 | /***************************************************************** |
| 1562 | * SetFocus (X11DRV.@) |
| 1563 | * |
| 1564 | * Set the X focus. |
| 1565 | * Explicit colormap management seems to work only with OLVWM. |
| 1566 | */ |
| 1567 | void X11DRV_SetFocus( HWND hwnd ) |
| 1568 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 1569 | Display *display = thread_display(); |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1570 | struct x11drv_win_data *data; |
Alexandre Julliard | 125793d | 2008-02-18 17:22:51 +0100 | [diff] [blame] | 1571 | XWindowChanges changes; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1572 | |
Alexandre Julliard | 125793d | 2008-02-18 17:22:51 +0100 | [diff] [blame] | 1573 | /* If setting the focus to 0, uninstall the colormap */ |
| 1574 | if (!hwnd && root_window == DefaultRootWindow(display)) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1575 | { |
Alexandre Julliard | 2496c08 | 2003-11-21 00:17:33 +0000 | [diff] [blame] | 1576 | wine_tsx11_lock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1577 | if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE) |
Alexandre Julliard | 2496c08 | 2003-11-21 00:17:33 +0000 | [diff] [blame] | 1578 | XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap ); |
| 1579 | wine_tsx11_unlock(); |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1580 | return; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1581 | } |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1582 | |
| 1583 | hwnd = GetAncestor( hwnd, GA_ROOT ); |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1584 | |
| 1585 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Todd Mokros | 88ac4b9 | 2005-08-22 09:14:21 +0000 | [diff] [blame] | 1586 | if (data->managed || !data->whole_window) return; |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1587 | |
| 1588 | /* Set X focus and install colormap */ |
| 1589 | wine_tsx11_lock(); |
Alexandre Julliard | 125793d | 2008-02-18 17:22:51 +0100 | [diff] [blame] | 1590 | changes.stack_mode = Above; |
| 1591 | XConfigureWindow( display, data->whole_window, CWStackMode, &changes ); |
| 1592 | if (root_window == DefaultRootWindow(display)) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1593 | { |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1594 | /* we must not use CurrentTime (ICCCM), so try to use last message time instead */ |
| 1595 | /* FIXME: this is not entirely correct */ |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1596 | XSetInputFocus( display, data->whole_window, RevertToParent, |
Jeremy White | 77502e7 | 2005-01-14 17:06:40 +0000 | [diff] [blame] | 1597 | /* CurrentTime */ |
| 1598 | GetMessageTime() - EVENT_x11_time_to_win32_time(0)); |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1599 | if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE) |
| 1600 | XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1601 | } |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1602 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1606 | /********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1607 | * SetWindowIcon (X11DRV.@) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1608 | * |
| 1609 | * hIcon or hIconSm has changed (or is being initialised for the |
| 1610 | * first time). Complete the X11 driver-specific initialisation |
| 1611 | * and set the window hints. |
| 1612 | * |
| 1613 | * This is not entirely correct, may need to create |
| 1614 | * an icon window and set the pixmap as a background |
| 1615 | */ |
Alexandre Julliard | 446d832 | 2003-12-31 23:51:52 +0000 | [diff] [blame] | 1616 | void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1617 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 1618 | Display *display = thread_display(); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1619 | struct x11drv_win_data *data; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1620 | |
Alexandre Julliard | 446d832 | 2003-12-31 23:51:52 +0000 | [diff] [blame] | 1621 | if (type != ICON_BIG) return; /* nothing to do here */ |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1622 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1623 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1624 | if (!data->whole_window) return; |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1625 | if (!data->managed) return; |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 1626 | |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 1627 | if (data->wm_hints) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1628 | { |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 1629 | set_icon_hints( display, data, icon ); |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 1630 | wine_tsx11_lock(); |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 1631 | XSetWMHints( display, data->whole_window, data->wm_hints ); |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 1632 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1633 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1634 | } |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 1635 | |
| 1636 | |
| 1637 | /*********************************************************************** |
| 1638 | * SetWindowRgn (X11DRV.@) |
| 1639 | * |
| 1640 | * Assign specified region to window (for non-rectangular windows) |
| 1641 | */ |
| 1642 | int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw ) |
| 1643 | { |
| 1644 | struct x11drv_win_data *data; |
| 1645 | |
| 1646 | if ((data = X11DRV_get_win_data( hwnd ))) |
| 1647 | { |
| 1648 | sync_window_region( thread_display(), data, hrgn ); |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 1649 | } |
| 1650 | else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId()) |
| 1651 | { |
| 1652 | FIXME( "not supported on other thread window %p\n", hwnd ); |
| 1653 | SetLastError( ERROR_INVALID_WINDOW_HANDLE ); |
| 1654 | return FALSE; |
| 1655 | } |
| 1656 | |
| 1657 | return TRUE; |
| 1658 | } |
Alexandre Julliard | 24dbaa0 | 2008-04-17 16:13:34 +0200 | [diff] [blame] | 1659 | |
| 1660 | |
| 1661 | /*********************************************************************** |
| 1662 | * is_netwm_supported |
| 1663 | */ |
| 1664 | static BOOL is_netwm_supported( Display *display, Atom atom ) |
| 1665 | { |
| 1666 | static Atom *net_supported; |
| 1667 | static int net_supported_count = -1; |
| 1668 | int i; |
| 1669 | |
| 1670 | wine_tsx11_lock(); |
| 1671 | if (net_supported_count == -1) |
| 1672 | { |
| 1673 | Atom type; |
| 1674 | int format; |
| 1675 | unsigned long count, remaining; |
| 1676 | |
| 1677 | if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0, |
| 1678 | ~0UL, False, XA_ATOM, &type, &format, &count, |
| 1679 | &remaining, (unsigned char **)&net_supported )) |
| 1680 | net_supported_count = get_property_size( format, count ) / sizeof(Atom); |
| 1681 | else |
| 1682 | net_supported_count = 0; |
| 1683 | } |
| 1684 | wine_tsx11_unlock(); |
| 1685 | |
| 1686 | for (i = 0; i < net_supported_count; i++) |
| 1687 | if (net_supported[i] == atom) return TRUE; |
| 1688 | return FALSE; |
| 1689 | } |
| 1690 | |
| 1691 | |
| 1692 | /*********************************************************************** |
| 1693 | * SysCommand (X11DRV.@) |
| 1694 | * |
| 1695 | * Perform WM_SYSCOMMAND handling. |
| 1696 | */ |
| 1697 | LRESULT X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam ) |
| 1698 | { |
| 1699 | WPARAM hittest = wparam & 0x0f; |
| 1700 | DWORD dwPoint; |
| 1701 | int x, y, dir; |
| 1702 | XEvent xev; |
| 1703 | Display *display = thread_display(); |
| 1704 | struct x11drv_win_data *data; |
| 1705 | |
| 1706 | if (!(data = X11DRV_get_win_data( hwnd ))) return -1; |
| 1707 | if (!data->whole_window || !data->managed || !data->mapped) return -1; |
| 1708 | |
| 1709 | switch (wparam & 0xfff0) |
| 1710 | { |
| 1711 | case SC_MOVE: |
| 1712 | if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD; |
| 1713 | else dir = _NET_WM_MOVERESIZE_MOVE; |
| 1714 | break; |
| 1715 | case SC_SIZE: |
| 1716 | /* windows without WS_THICKFRAME are not resizable through the window manager */ |
| 1717 | if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return -1; |
| 1718 | |
| 1719 | switch (hittest) |
| 1720 | { |
| 1721 | case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break; |
| 1722 | case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break; |
| 1723 | case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break; |
| 1724 | case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break; |
| 1725 | case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break; |
| 1726 | case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break; |
| 1727 | case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break; |
| 1728 | case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break; |
| 1729 | default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break; |
| 1730 | } |
| 1731 | break; |
| 1732 | |
| 1733 | case SC_KEYMENU: |
| 1734 | /* prevent a simple ALT press+release from activating the system menu, |
| 1735 | * as that can get confusing on managed windows */ |
| 1736 | if ((WCHAR)lparam) return -1; /* got an explicit char */ |
| 1737 | if (GetMenu( hwnd )) return -1; /* window has a real menu */ |
| 1738 | if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) return -1; /* no system menu */ |
| 1739 | TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam, lparam ); |
| 1740 | return 0; |
| 1741 | |
| 1742 | default: |
| 1743 | return -1; |
| 1744 | } |
| 1745 | |
| 1746 | if (IsZoomed(hwnd)) return -1; |
| 1747 | |
| 1748 | if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) )) |
| 1749 | { |
| 1750 | TRACE( "_NET_WM_MOVERESIZE not supported\n" ); |
| 1751 | return -1; |
| 1752 | } |
| 1753 | |
| 1754 | dwPoint = GetMessagePos(); |
| 1755 | x = (short)LOWORD(dwPoint); |
| 1756 | y = (short)HIWORD(dwPoint); |
| 1757 | |
| 1758 | TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir); |
| 1759 | |
| 1760 | xev.xclient.type = ClientMessage; |
| 1761 | xev.xclient.window = X11DRV_get_whole_window(hwnd); |
| 1762 | xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE); |
| 1763 | xev.xclient.serial = 0; |
| 1764 | xev.xclient.display = display; |
| 1765 | xev.xclient.send_event = True; |
| 1766 | xev.xclient.format = 32; |
| 1767 | xev.xclient.data.l[0] = x; /* x coord */ |
| 1768 | xev.xclient.data.l[1] = y; /* y coord */ |
| 1769 | xev.xclient.data.l[2] = dir; /* direction */ |
| 1770 | xev.xclient.data.l[3] = 1; /* button */ |
| 1771 | xev.xclient.data.l[4] = 0; /* unused */ |
| 1772 | |
| 1773 | /* need to ungrab the pointer that may have been automatically grabbed |
| 1774 | * with a ButtonPress event */ |
| 1775 | wine_tsx11_lock(); |
| 1776 | XUngrabPointer( display, CurrentTime ); |
| 1777 | XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev); |
| 1778 | wine_tsx11_unlock(); |
| 1779 | return 0; |
| 1780 | } |