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