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