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 | |
Damjan Jovanovic | 3613b15 | 2009-01-06 20:59:07 +0200 | [diff] [blame] | 85 | |
| 86 | /*********************************************************************** |
| 87 | * http://standards.freedesktop.org/startup-notification-spec |
| 88 | */ |
| 89 | static void remove_startup_notification(Display *display, Window window) |
| 90 | { |
| 91 | static LONG startup_notification_removed = 0; |
| 92 | char id[1024]; |
| 93 | char message[1024]; |
| 94 | int i; |
| 95 | int pos; |
| 96 | XEvent xevent; |
| 97 | const char *src; |
| 98 | int srclen; |
| 99 | |
| 100 | if (InterlockedCompareExchange(&startup_notification_removed, 1, 0) != 0) |
| 101 | return; |
| 102 | |
| 103 | if (GetEnvironmentVariableA("DESKTOP_STARTUP_ID", id, sizeof(id)) == 0) |
| 104 | return; |
| 105 | SetEnvironmentVariableA("DESKTOP_STARTUP_ID", NULL); |
| 106 | |
| 107 | pos = snprintf(message, sizeof(message), "remove: ID="); |
| 108 | message[pos++] = '"'; |
| 109 | for (i = 0; id[i] && pos < sizeof(message) - 2; i++) |
| 110 | { |
| 111 | if (id[i] == '"' || id[i] == '\\') |
| 112 | message[pos++] = '\\'; |
| 113 | message[pos++] = id[i]; |
| 114 | } |
| 115 | message[pos++] = '"'; |
| 116 | message[pos++] = '\0'; |
| 117 | |
| 118 | xevent.xclient.type = ClientMessage; |
| 119 | xevent.xclient.message_type = x11drv_atom(_NET_STARTUP_INFO_BEGIN); |
| 120 | xevent.xclient.display = display; |
| 121 | xevent.xclient.window = window; |
| 122 | xevent.xclient.format = 8; |
| 123 | |
| 124 | src = message; |
| 125 | srclen = strlen(src) + 1; |
| 126 | |
| 127 | wine_tsx11_lock(); |
| 128 | while (srclen > 0) |
| 129 | { |
| 130 | int msglen = srclen; |
| 131 | if (msglen > 20) |
| 132 | msglen = 20; |
| 133 | memset(&xevent.xclient.data.b[0], 0, 20); |
| 134 | memcpy(&xevent.xclient.data.b[0], src, msglen); |
| 135 | src += msglen; |
| 136 | srclen -= msglen; |
| 137 | |
| 138 | XSendEvent( display, DefaultRootWindow( display ), False, PropertyChangeMask, &xevent ); |
| 139 | xevent.xclient.message_type = x11drv_atom(_NET_STARTUP_INFO); |
| 140 | } |
| 141 | wine_tsx11_unlock(); |
| 142 | } |
| 143 | |
| 144 | |
Alexandre Julliard | 391afac | 2010-02-23 12:34:19 +0100 | [diff] [blame] | 145 | struct has_popup_result |
| 146 | { |
| 147 | HWND hwnd; |
| 148 | BOOL found; |
| 149 | }; |
| 150 | |
| 151 | static BOOL CALLBACK has_popup( HWND hwnd, LPARAM lparam ) |
| 152 | { |
| 153 | struct has_popup_result *result = (struct has_popup_result *)lparam; |
| 154 | |
| 155 | if (hwnd == result->hwnd) return FALSE; /* popups are always above owner */ |
| 156 | result->found = (GetWindow( hwnd, GW_OWNER ) == result->hwnd); |
| 157 | return !result->found; |
| 158 | } |
| 159 | |
| 160 | static BOOL has_owned_popups( HWND hwnd ) |
| 161 | { |
| 162 | struct has_popup_result result; |
| 163 | |
| 164 | result.hwnd = hwnd; |
| 165 | result.found = FALSE; |
| 166 | EnumWindows( has_popup, (LPARAM)&result ); |
| 167 | return result.found; |
| 168 | } |
| 169 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 170 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 171 | * is_window_managed |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 172 | * |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 173 | * Check if a given window should be managed |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 174 | */ |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 175 | 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] | 176 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 177 | DWORD style, ex_style; |
| 178 | |
Alexandre Julliard | 8913182 | 2008-01-24 10:21:07 +0100 | [diff] [blame] | 179 | if (!managed_mode) return FALSE; |
| 180 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 181 | /* child windows are not managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 182 | style = GetWindowLongW( hwnd, GWL_STYLE ); |
Peter Dons Tychsen | d0b21ab | 2007-07-25 04:09:50 +0200 | [diff] [blame] | 183 | if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE; |
Alexandre Julliard | effdfa7 | 2007-08-27 12:37:14 +0200 | [diff] [blame] | 184 | /* activated windows are managed */ |
| 185 | if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE; |
| 186 | if (hwnd == GetActiveWindow()) return TRUE; |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 187 | /* windows with caption are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 188 | if ((style & WS_CAPTION) == WS_CAPTION) return TRUE; |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 189 | /* windows with thick frame are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 190 | if (style & WS_THICKFRAME) return TRUE; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 191 | if (style & WS_POPUP) |
Alex Pasadyn | d18c8ca | 2004-02-06 05:17:55 +0000 | [diff] [blame] | 192 | { |
Dmitry Timoshkov | 15c8206 | 2008-10-07 12:14:52 +0900 | [diff] [blame] | 193 | HMONITOR hmon; |
| 194 | MONITORINFO mi; |
| 195 | |
Vitaliy Margolen | abcbcc3 | 2007-02-10 10:40:50 -0700 | [diff] [blame] | 196 | /* popup with sysmenu == caption are managed */ |
| 197 | if (style & WS_SYSMENU) return TRUE; |
| 198 | /* full-screen popup windows are managed */ |
Dmitry Timoshkov | 15c8206 | 2008-10-07 12:14:52 +0900 | [diff] [blame] | 199 | hmon = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY ); |
| 200 | mi.cbSize = sizeof( mi ); |
| 201 | GetMonitorInfoW( hmon, &mi ); |
| 202 | if (window_rect->left <= mi.rcWork.left && window_rect->right >= mi.rcWork.right && |
| 203 | window_rect->top <= mi.rcWork.top && window_rect->bottom >= mi.rcWork.bottom) |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 204 | return TRUE; |
Alex Pasadyn | d18c8ca | 2004-02-06 05:17:55 +0000 | [diff] [blame] | 205 | } |
Alexandre Julliard | 1f99d80 | 2008-04-25 14:26:52 +0200 | [diff] [blame] | 206 | /* application windows are managed */ |
| 207 | ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE ); |
| 208 | if (ex_style & WS_EX_APPWINDOW) return TRUE; |
Alexandre Julliard | 391afac | 2010-02-23 12:34:19 +0100 | [diff] [blame] | 209 | /* windows that own popups are managed */ |
| 210 | if (has_owned_popups( hwnd )) return TRUE; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 211 | /* default: not managed */ |
| 212 | return FALSE; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | |
| 216 | /*********************************************************************** |
Alexandre Julliard | 2db72e9 | 2010-05-28 12:16:17 +0200 | [diff] [blame^] | 217 | * is_window_rect_mapped |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 218 | * |
| 219 | * Check if the X whole window should be mapped based on its rectangle |
| 220 | */ |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 221 | static BOOL is_window_rect_mapped( const RECT *rect ) |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 222 | { |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 223 | /* don't map if rect is off-screen */ |
Alexandre Julliard | 3c305f9 | 2006-10-23 14:37:17 +0200 | [diff] [blame] | 224 | if (rect->left >= virtual_screen_rect.right || |
| 225 | rect->top >= virtual_screen_rect.bottom || |
| 226 | rect->right <= virtual_screen_rect.left || |
| 227 | rect->bottom <= virtual_screen_rect.top) |
| 228 | return FALSE; |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 229 | |
| 230 | return TRUE; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /*********************************************************************** |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 235 | * is_window_resizable |
| 236 | * |
| 237 | * Check if window should be made resizable by the window manager |
| 238 | */ |
| 239 | static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style ) |
| 240 | { |
| 241 | if (style & WS_THICKFRAME) return TRUE; |
| 242 | /* Metacity needs the window to be resizable to make it fullscreen */ |
| 243 | return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width && |
| 244 | data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height); |
| 245 | } |
| 246 | |
| 247 | |
| 248 | /*********************************************************************** |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 249 | * get_mwm_decorations |
| 250 | */ |
Dmitry Timoshkov | 15c0bcb | 2008-04-16 16:50:29 +0900 | [diff] [blame] | 251 | static unsigned long get_mwm_decorations( struct x11drv_win_data *data, |
| 252 | DWORD style, DWORD ex_style ) |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 253 | { |
| 254 | unsigned long ret = 0; |
| 255 | |
Dmitry Timoshkov | 15c0bcb | 2008-04-16 16:50:29 +0900 | [diff] [blame] | 256 | if (!decorated_mode) return 0; |
| 257 | |
| 258 | if (IsRectEmpty( &data->window_rect )) return 0; |
Alexandre Julliard | 2bbf00e | 2008-04-29 12:46:16 +0200 | [diff] [blame] | 259 | if (data->shaped) return 0; |
Matthew D'Asaro | 4217fcb | 2008-04-10 12:53:45 -0700 | [diff] [blame] | 260 | |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 261 | if (ex_style & WS_EX_TOOLWINDOW) return 0; |
| 262 | |
| 263 | if ((style & WS_CAPTION) == WS_CAPTION) |
| 264 | { |
| 265 | ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER; |
| 266 | if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU; |
| 267 | if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE; |
| 268 | if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE; |
| 269 | } |
| 270 | if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER; |
| 271 | else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH; |
| 272 | 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] | 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | /*********************************************************************** |
| 278 | * get_x11_rect_offset |
| 279 | * |
| 280 | * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect. |
| 281 | */ |
| 282 | static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect ) |
| 283 | { |
| 284 | DWORD style, ex_style, style_mask = 0, ex_style_mask = 0; |
| 285 | unsigned long decor; |
| 286 | |
| 287 | rect->top = rect->bottom = rect->left = rect->right = 0; |
| 288 | |
| 289 | style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
| 290 | ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE ); |
Dmitry Timoshkov | 15c0bcb | 2008-04-16 16:50:29 +0900 | [diff] [blame] | 291 | decor = get_mwm_decorations( data, style, ex_style ); |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 292 | |
| 293 | if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION; |
| 294 | if (decor & MWM_DECOR_BORDER) |
| 295 | { |
| 296 | style_mask |= WS_DLGFRAME | WS_THICKFRAME; |
| 297 | ex_style_mask |= WS_EX_DLGMODALFRAME; |
| 298 | } |
| 299 | |
| 300 | AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask ); |
| 301 | } |
| 302 | |
| 303 | |
| 304 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 305 | * get_window_attributes |
| 306 | * |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 307 | * Fill the window attributes structure for an X window. |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 308 | */ |
Alexandre Julliard | 6bb18e2 | 2006-03-27 15:33:43 +0200 | [diff] [blame] | 309 | static int get_window_attributes( Display *display, struct x11drv_win_data *data, |
| 310 | XSetWindowAttributes *attr ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 311 | { |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 312 | attr->override_redirect = !data->managed; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 313 | attr->colormap = X11DRV_PALETTE_PaletteXColormap; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 314 | attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0); |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 315 | attr->bit_gravity = NorthWestGravity; |
Alexandre Julliard | 6ba06fa | 2008-04-23 15:33:29 +0200 | [diff] [blame] | 316 | attr->win_gravity = StaticGravity; |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 317 | attr->backing_store = NotUseful; |
| 318 | attr->event_mask = (ExposureMask | PointerMotionMask | |
| 319 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | |
Vincent Povirk | 538cf8b | 2008-12-15 18:47:24 -0600 | [diff] [blame] | 320 | KeyPressMask | KeyReleaseMask | FocusChangeMask | |
| 321 | KeymapStateMask | StructureNotifyMask); |
| 322 | if (data->managed) attr->event_mask |= PropertyChangeMask; |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 323 | |
Alexandre Julliard | eed9c63 | 2010-04-20 20:52:17 +0200 | [diff] [blame] | 324 | return (CWOverrideRedirect | CWSaveUnder | CWColormap | |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 325 | CWEventMask | CWBitGravity | CWBackingStore); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 326 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 327 | |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 328 | |
| 329 | /*********************************************************************** |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 330 | * create_client_window |
| 331 | */ |
| 332 | static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis ) |
| 333 | { |
| 334 | int cx, cy, mask; |
| 335 | XSetWindowAttributes attr; |
| 336 | Window client; |
Alexandre Julliard | 30a133f | 2008-05-13 10:43:48 +0200 | [diff] [blame] | 337 | Visual *client_visual = vis ? vis->visual : visual; |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 338 | |
| 339 | attr.bit_gravity = NorthWestGravity; |
| 340 | attr.win_gravity = NorthWestGravity; |
| 341 | attr.backing_store = NotUseful; |
| 342 | attr.event_mask = (ExposureMask | PointerMotionMask | |
| 343 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask); |
| 344 | mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore; |
| 345 | |
| 346 | if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1; |
Alexandre Julliard | a4644f1 | 2009-05-05 15:36:25 +0200 | [diff] [blame] | 347 | else if (cx > 65535) cx = 65535; |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 348 | if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1; |
Alexandre Julliard | a4644f1 | 2009-05-05 15:36:25 +0200 | [diff] [blame] | 349 | else if (cy > 65535) cy = 65535; |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 350 | |
| 351 | wine_tsx11_lock(); |
| 352 | |
| 353 | if (vis) |
| 354 | { |
| 355 | attr.colormap = XCreateColormap( display, root_window, vis->visual, |
| 356 | (vis->class == PseudoColor || vis->class == GrayScale || |
| 357 | vis->class == DirectColor) ? AllocAll : AllocNone ); |
| 358 | mask |= CWColormap; |
| 359 | } |
| 360 | |
| 361 | client = XCreateWindow( display, data->whole_window, |
| 362 | data->client_rect.left - data->whole_rect.left, |
| 363 | data->client_rect.top - data->whole_rect.top, |
| 364 | cx, cy, 0, screen_depth, InputOutput, |
Alexandre Julliard | 30a133f | 2008-05-13 10:43:48 +0200 | [diff] [blame] | 365 | client_visual, mask, &attr ); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 366 | if (!client) |
| 367 | { |
| 368 | wine_tsx11_unlock(); |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | if (data->client_window) |
| 373 | { |
| 374 | XDeleteContext( display, data->client_window, winContext ); |
| 375 | XDestroyWindow( display, data->client_window ); |
| 376 | } |
| 377 | data->client_window = client; |
Alexandre Julliard | 30a133f | 2008-05-13 10:43:48 +0200 | [diff] [blame] | 378 | data->visualid = XVisualIDFromVisual( client_visual ); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 379 | |
| 380 | if (data->colormap) XFreeColormap( display, data->colormap ); |
| 381 | data->colormap = vis ? attr.colormap : 0; |
| 382 | |
| 383 | XMapWindow( display, data->client_window ); |
| 384 | XSaveContext( display, data->client_window, winContext, (char *)data->hwnd ); |
| 385 | wine_tsx11_unlock(); |
| 386 | |
| 387 | SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window ); |
| 388 | return data->client_window; |
| 389 | } |
| 390 | |
| 391 | |
| 392 | /*********************************************************************** |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 393 | * sync_window_style |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 394 | * |
| 395 | * Change the X window attributes when the window style has changed. |
| 396 | */ |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 397 | static void sync_window_style( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 398 | { |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 399 | if (data->whole_window != root_window) |
| 400 | { |
| 401 | XSetWindowAttributes attr; |
| 402 | int mask = get_window_attributes( display, data, &attr ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 403 | |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 404 | wine_tsx11_lock(); |
Alexandre Julliard | 6d5f544 | 2006-03-06 21:02:59 +0100 | [diff] [blame] | 405 | XChangeWindowAttributes( display, data->whole_window, mask, &attr ); |
Alexandre Julliard | 0ce7187 | 2007-08-20 14:23:10 +0200 | [diff] [blame] | 406 | wine_tsx11_unlock(); |
| 407 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
| 411 | /*********************************************************************** |
Alexandre Julliard | 1afd0df | 2010-05-10 12:33:59 +0200 | [diff] [blame] | 412 | * sync_window_cursor |
| 413 | */ |
| 414 | static void sync_window_cursor( struct x11drv_win_data *data ) |
| 415 | { |
| 416 | HCURSOR cursor; |
| 417 | |
| 418 | SERVER_START_REQ( set_cursor ) |
| 419 | { |
| 420 | req->flags = 0; |
| 421 | wine_server_call( req ); |
| 422 | cursor = reply->prev_count >= 0 ? wine_server_ptr_handle( reply->prev_handle ) : 0; |
| 423 | } |
| 424 | SERVER_END_REQ; |
| 425 | |
| 426 | set_window_cursor( data->hwnd, cursor ); |
| 427 | } |
| 428 | |
| 429 | |
| 430 | /*********************************************************************** |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 431 | * sync_window_region |
| 432 | * |
| 433 | * Update the X11 window region. |
| 434 | */ |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 435 | static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN win_region ) |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 436 | { |
| 437 | #ifdef HAVE_LIBXSHAPE |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 438 | HRGN hrgn = win_region; |
| 439 | |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 440 | if (!data->whole_window) return; |
Alexandre Julliard | 2bbf00e | 2008-04-29 12:46:16 +0200 | [diff] [blame] | 441 | data->shaped = FALSE; |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 442 | |
Alexandre Julliard | 61e50e1 | 2010-05-28 12:14:43 +0200 | [diff] [blame] | 443 | if (IsRectEmpty( &data->window_rect )) /* set an empty shape */ |
| 444 | { |
| 445 | static XRectangle empty_rect; |
| 446 | wine_tsx11_lock(); |
| 447 | XShapeCombineRectangles( display, data->whole_window, ShapeBounding, 0, 0, |
| 448 | &empty_rect, 1, ShapeSet, YXBanded ); |
| 449 | wine_tsx11_unlock(); |
| 450 | return; |
| 451 | } |
| 452 | |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 453 | if (hrgn == (HRGN)1) /* hack: win_region == 1 means retrieve region from server */ |
| 454 | { |
| 455 | if (!(hrgn = CreateRectRgn( 0, 0, 0, 0 ))) return; |
| 456 | if (GetWindowRgn( data->hwnd, hrgn ) == ERROR) |
| 457 | { |
| 458 | DeleteObject( hrgn ); |
| 459 | hrgn = 0; |
| 460 | } |
| 461 | } |
| 462 | |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 463 | if (!hrgn) |
| 464 | { |
| 465 | wine_tsx11_lock(); |
| 466 | XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet ); |
| 467 | wine_tsx11_unlock(); |
| 468 | } |
| 469 | else |
| 470 | { |
| 471 | RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 ); |
| 472 | if (pRegionData) |
| 473 | { |
| 474 | wine_tsx11_lock(); |
| 475 | XShapeCombineRectangles( display, data->whole_window, ShapeBounding, |
| 476 | data->window_rect.left - data->whole_rect.left, |
| 477 | data->window_rect.top - data->whole_rect.top, |
| 478 | (XRectangle *)pRegionData->Buffer, |
| 479 | pRegionData->rdh.nCount, ShapeSet, YXBanded ); |
| 480 | wine_tsx11_unlock(); |
| 481 | HeapFree(GetProcessHeap(), 0, pRegionData); |
Alexandre Julliard | 2bbf00e | 2008-04-29 12:46:16 +0200 | [diff] [blame] | 482 | data->shaped = TRUE; |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 483 | } |
| 484 | } |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 485 | if (hrgn && hrgn != win_region) DeleteObject( hrgn ); |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 486 | #endif /* HAVE_LIBXSHAPE */ |
| 487 | } |
| 488 | |
| 489 | |
| 490 | /*********************************************************************** |
Alexandre Julliard | be3c3a5 | 2008-09-12 15:54:02 +0200 | [diff] [blame] | 491 | * sync_window_opacity |
| 492 | */ |
| 493 | static void sync_window_opacity( Display *display, Window win, |
| 494 | COLORREF key, BYTE alpha, DWORD flags ) |
| 495 | { |
| 496 | unsigned long opacity = 0xffffffff; |
| 497 | |
| 498 | if (flags & LWA_ALPHA) opacity = (0xffffffff / 0xff) * alpha; |
| 499 | |
| 500 | if (flags & LWA_COLORKEY) FIXME("LWA_COLORKEY not supported\n"); |
| 501 | |
| 502 | wine_tsx11_lock(); |
| 503 | if (opacity == 0xffffffff) |
| 504 | XDeleteProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY) ); |
| 505 | else |
| 506 | XChangeProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY), |
| 507 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1 ); |
| 508 | wine_tsx11_unlock(); |
| 509 | } |
| 510 | |
| 511 | |
| 512 | /*********************************************************************** |
Alexandre Julliard | 3ba2025 | 2008-01-23 16:32:55 +0100 | [diff] [blame] | 513 | * sync_window_text |
| 514 | */ |
| 515 | static void sync_window_text( Display *display, Window win, const WCHAR *text ) |
| 516 | { |
| 517 | UINT count; |
| 518 | char *buffer, *utf8_buffer; |
| 519 | XTextProperty prop; |
| 520 | |
| 521 | /* allocate new buffer for window text */ |
| 522 | count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL); |
| 523 | if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return; |
| 524 | WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL); |
| 525 | |
| 526 | count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL); |
| 527 | if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count ))) |
| 528 | { |
| 529 | HeapFree( GetProcessHeap(), 0, buffer ); |
| 530 | return; |
| 531 | } |
| 532 | WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL); |
| 533 | |
| 534 | wine_tsx11_lock(); |
| 535 | if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success) |
| 536 | { |
| 537 | XSetWMName( display, win, &prop ); |
| 538 | XSetWMIconName( display, win, &prop ); |
| 539 | XFree( prop.value ); |
| 540 | } |
| 541 | /* |
| 542 | Implements a NET_WM UTF-8 title. It should be without a trailing \0, |
| 543 | according to the standard |
| 544 | ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ). |
| 545 | */ |
| 546 | XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING), |
| 547 | 8, PropModeReplace, (unsigned char *) utf8_buffer, count); |
| 548 | wine_tsx11_unlock(); |
| 549 | |
| 550 | HeapFree( GetProcessHeap(), 0, utf8_buffer ); |
| 551 | HeapFree( GetProcessHeap(), 0, buffer ); |
| 552 | } |
| 553 | |
| 554 | |
| 555 | /*********************************************************************** |
Alexandre Julliard | 370368a | 2008-09-08 15:42:24 +0200 | [diff] [blame] | 556 | * set_win_format |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 557 | */ |
Alexandre Julliard | 370368a | 2008-09-08 15:42:24 +0200 | [diff] [blame] | 558 | static BOOL set_win_format( HWND hwnd, XID fbconfig_id ) |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 559 | { |
| 560 | struct x11drv_win_data *data; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 561 | XVisualInfo *vis; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 562 | int w, h; |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 563 | |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 564 | if (!(data = X11DRV_get_win_data(hwnd)) && |
| 565 | !(data = X11DRV_create_win_data(hwnd))) return FALSE; |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 566 | |
Alexandre Julliard | ed37174 | 2008-05-28 17:02:07 +0200 | [diff] [blame] | 567 | if (!(vis = visual_from_fbconfig_id(fbconfig_id))) return FALSE; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 568 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 569 | if (data->whole_window) |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 570 | { |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 571 | Display *display = thread_display(); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 572 | Window client = data->client_window; |
| 573 | |
Alexandre Julliard | 30a133f | 2008-05-13 10:43:48 +0200 | [diff] [blame] | 574 | if (vis->visualid != data->visualid) |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 575 | { |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 576 | client = create_client_window( display, data, vis ); |
| 577 | 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] | 578 | } |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 579 | wine_tsx11_lock(); |
| 580 | XFree(vis); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 581 | XFlush( display ); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 582 | wine_tsx11_unlock(); |
| 583 | if (client) goto done; |
| 584 | return FALSE; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | w = data->client_rect.right - data->client_rect.left; |
| 588 | h = data->client_rect.bottom - data->client_rect.top; |
| 589 | |
| 590 | if(w <= 0) w = 1; |
| 591 | if(h <= 0) h = 1; |
| 592 | |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 593 | #ifdef SONAME_LIBXCOMPOSITE |
| 594 | if(usexcomposite) |
| 595 | { |
| 596 | XSetWindowAttributes attrib; |
Alexandre Julliard | b605980 | 2008-05-12 19:14:11 +0200 | [diff] [blame] | 597 | static Window dummy_parent; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 598 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 599 | wine_tsx11_lock(); |
Alexandre Julliard | b605980 | 2008-05-12 19:14:11 +0200 | [diff] [blame] | 600 | attrib.override_redirect = True; |
| 601 | if (!dummy_parent) |
| 602 | { |
| 603 | dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, screen_depth, |
| 604 | InputOutput, visual, CWOverrideRedirect, &attrib ); |
| 605 | XMapWindow( gdi_display, dummy_parent ); |
| 606 | } |
| 607 | data->colormap = XCreateColormap(gdi_display, dummy_parent, vis->visual, |
Alexandre Julliard | e9307d0 | 2008-02-21 20:23:32 +0100 | [diff] [blame] | 608 | (vis->class == PseudoColor || |
| 609 | vis->class == GrayScale || |
| 610 | vis->class == DirectColor) ? |
| 611 | AllocAll : AllocNone); |
Alexandre Julliard | e9307d0 | 2008-02-21 20:23:32 +0100 | [diff] [blame] | 612 | attrib.colormap = data->colormap; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 613 | XInstallColormap(gdi_display, attrib.colormap); |
| 614 | |
Roderick Colenbrander | f0307d9 | 2008-04-22 22:15:15 +0000 | [diff] [blame] | 615 | if(data->gl_drawable) XDestroyWindow(gdi_display, data->gl_drawable); |
Alexandre Julliard | b605980 | 2008-05-12 19:14:11 +0200 | [diff] [blame] | 616 | data->gl_drawable = XCreateWindow(gdi_display, dummy_parent, -w, 0, w, h, 0, |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 617 | vis->depth, InputOutput, vis->visual, |
| 618 | CWColormap | CWOverrideRedirect, |
| 619 | &attrib); |
| 620 | if(data->gl_drawable) |
| 621 | { |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 622 | pXCompositeRedirectWindow(gdi_display, data->gl_drawable, |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 623 | CompositeRedirectManual); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 624 | XMapWindow(gdi_display, data->gl_drawable); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 625 | } |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 626 | XFree(vis); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 627 | XFlush( gdi_display ); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 628 | wine_tsx11_unlock(); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 629 | } |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 630 | else |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 631 | #endif |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 632 | { |
| 633 | WARN("XComposite is not available, using GLXPixmap hack\n"); |
| 634 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 635 | wine_tsx11_lock(); |
Roderick Colenbrander | f0307d9 | 2008-04-22 22:15:15 +0000 | [diff] [blame] | 636 | |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 637 | if(data->pixmap) XFreePixmap(gdi_display, data->pixmap); |
| 638 | data->pixmap = XCreatePixmap(gdi_display, root_window, w, h, vis->depth); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 639 | if(!data->pixmap) |
| 640 | { |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 641 | XFree(vis); |
| 642 | wine_tsx11_unlock(); |
| 643 | return FALSE; |
| 644 | } |
| 645 | |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 646 | if(data->gl_drawable) destroy_glxpixmap(gdi_display, data->gl_drawable); |
| 647 | data->gl_drawable = create_glxpixmap(gdi_display, vis, data->pixmap); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 648 | if(!data->gl_drawable) |
| 649 | { |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 650 | XFreePixmap(gdi_display, data->pixmap); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 651 | data->pixmap = 0; |
| 652 | } |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 653 | XFree(vis); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 654 | XFlush( gdi_display ); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 655 | wine_tsx11_unlock(); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 656 | if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 659 | if (!data->gl_drawable) return FALSE; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 660 | |
| 661 | TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n", |
| 662 | data->gl_drawable, fbconfig_id); |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 663 | SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 664 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 665 | done: |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 666 | data->fbconfig_id = fbconfig_id; |
| 667 | SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id); |
Alexandre Julliard | 9727aa8 | 2008-04-21 20:32:22 +0200 | [diff] [blame] | 668 | /* force DCE invalidation */ |
| 669 | SetWindowPos( hwnd, 0, 0, 0, 0, 0, |
| 670 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | |
Alexandre Julliard | fc8c21c | 2008-06-18 20:10:56 +0200 | [diff] [blame] | 671 | SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED); |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 672 | return TRUE; |
| 673 | } |
| 674 | |
Alexandre Julliard | bbfbe24 | 2008-01-23 12:28:01 +0100 | [diff] [blame] | 675 | /*********************************************************************** |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 676 | * sync_gl_drawable |
Alexandre Julliard | bbfbe24 | 2008-01-23 12:28:01 +0100 | [diff] [blame] | 677 | */ |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 678 | static void sync_gl_drawable(struct x11drv_win_data *data) |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 679 | { |
| 680 | int w = data->client_rect.right - data->client_rect.left; |
| 681 | int h = data->client_rect.bottom - data->client_rect.top; |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 682 | XVisualInfo *vis; |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 683 | Drawable glxp; |
| 684 | Pixmap pix; |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 685 | |
Alexandre Julliard | f13ef6b | 2008-02-22 16:30:10 +0100 | [diff] [blame] | 686 | if (w <= 0) w = 1; |
| 687 | if (h <= 0) h = 1; |
| 688 | |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 689 | TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h); |
| 690 | #ifdef SONAME_LIBXCOMPOSITE |
| 691 | if(usexcomposite) |
| 692 | { |
| 693 | wine_tsx11_lock(); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 694 | XMoveResizeWindow(gdi_display, data->gl_drawable, -w, 0, w, h); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 695 | wine_tsx11_unlock(); |
| 696 | return; |
| 697 | } |
| 698 | #endif |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 699 | |
Alexandre Julliard | ed37174 | 2008-05-28 17:02:07 +0200 | [diff] [blame] | 700 | if (!(vis = visual_from_fbconfig_id(data->fbconfig_id))) return; |
| 701 | |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 702 | wine_tsx11_lock(); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 703 | pix = XCreatePixmap(gdi_display, root_window, w, h, vis->depth); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 704 | if(!pix) |
| 705 | { |
| 706 | ERR("Failed to create pixmap for offscreen rendering\n"); |
| 707 | XFree(vis); |
| 708 | wine_tsx11_unlock(); |
| 709 | return; |
| 710 | } |
| 711 | |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 712 | glxp = create_glxpixmap(gdi_display, vis, pix); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 713 | if(!glxp) |
| 714 | { |
| 715 | ERR("Failed to create drawable for offscreen rendering\n"); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 716 | XFreePixmap(gdi_display, pix); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 717 | XFree(vis); |
| 718 | wine_tsx11_unlock(); |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | XFree(vis); |
| 723 | |
| 724 | mark_drawable_dirty(data->gl_drawable, glxp); |
| 725 | |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 726 | XFreePixmap(gdi_display, data->pixmap); |
| 727 | destroy_glxpixmap(gdi_display, data->gl_drawable); |
Alexandre Julliard | 9727aa8 | 2008-04-21 20:32:22 +0200 | [diff] [blame] | 728 | 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] | 729 | |
| 730 | data->pixmap = pix; |
| 731 | data->gl_drawable = glxp; |
| 732 | |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 733 | XFlush( gdi_display ); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 734 | wine_tsx11_unlock(); |
| 735 | |
| 736 | SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable); |
| 737 | SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Chris Robinson | d9571c9 | 2007-09-15 13:02:32 -0700 | [diff] [blame] | 740 | |
| 741 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 742 | * get_window_changes |
| 743 | * |
| 744 | * fill the window changes structure |
| 745 | */ |
| 746 | static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new ) |
| 747 | { |
| 748 | int mask = 0; |
| 749 | |
| 750 | if (old->right - old->left != new->right - new->left ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 751 | { |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 752 | if ((changes->width = new->right - new->left) <= 0) changes->width = 1; |
Alexandre Julliard | a4644f1 | 2009-05-05 15:36:25 +0200 | [diff] [blame] | 753 | else if (changes->width > 65535) changes->width = 65535; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 754 | mask |= CWWidth; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 755 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 756 | if (old->bottom - old->top != new->bottom - new->top) |
| 757 | { |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 758 | if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1; |
Alexandre Julliard | a4644f1 | 2009-05-05 15:36:25 +0200 | [diff] [blame] | 759 | else if (changes->height > 65535) changes->height = 65535; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 760 | mask |= CWHeight; |
| 761 | } |
| 762 | if (old->left != new->left) |
| 763 | { |
| 764 | changes->x = new->left; |
| 765 | mask |= CWX; |
| 766 | } |
| 767 | if (old->top != new->top) |
| 768 | { |
| 769 | changes->y = new->top; |
| 770 | mask |= CWY; |
| 771 | } |
| 772 | return mask; |
| 773 | } |
| 774 | |
| 775 | |
| 776 | /*********************************************************************** |
| 777 | * create_icon_window |
| 778 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 779 | static Window create_icon_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 780 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 781 | XSetWindowAttributes attr; |
| 782 | |
| 783 | attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 784 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 785 | attr.bit_gravity = NorthWestGravity; |
| 786 | attr.backing_store = NotUseful/*WhenMapped*/; |
Lionel Ulmer | 1fc39be | 2001-07-12 22:27:56 +0000 | [diff] [blame] | 787 | attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */ |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 788 | |
Alexandre Julliard | 649637f | 2001-06-26 21:10:11 +0000 | [diff] [blame] | 789 | wine_tsx11_lock(); |
| 790 | data->icon_window = XCreateWindow( display, root_window, 0, 0, |
| 791 | GetSystemMetrics( SM_CXICON ), |
| 792 | GetSystemMetrics( SM_CYICON ), |
| 793 | 0, screen_depth, |
| 794 | InputOutput, visual, |
Lionel Ulmer | 1fc39be | 2001-07-12 22:27:56 +0000 | [diff] [blame] | 795 | CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr ); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 796 | XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd ); |
Alexandre Julliard | 731d77f | 2008-04-09 20:24:27 +0200 | [diff] [blame] | 797 | 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] | 798 | wine_tsx11_unlock(); |
| 799 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 800 | TRACE( "created %lx\n", data->icon_window ); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 801 | SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 802 | return data->icon_window; |
| 803 | } |
| 804 | |
| 805 | |
| 806 | |
| 807 | /*********************************************************************** |
| 808 | * destroy_icon_window |
| 809 | */ |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 810 | static void destroy_icon_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 811 | { |
| 812 | if (!data->icon_window) return; |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 813 | wine_tsx11_lock(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 814 | XDeleteContext( display, data->icon_window, winContext ); |
| 815 | XDestroyWindow( display, data->icon_window ); |
| 816 | data->icon_window = 0; |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 817 | wine_tsx11_unlock(); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 818 | RemovePropA( data->hwnd, icon_window_prop ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | |
| 822 | /*********************************************************************** |
Alexandre Julliard | 4253120 | 2010-04-19 11:13:34 +0200 | [diff] [blame] | 823 | * get_bitmap_argb |
| 824 | * |
| 825 | * Return the bitmap bits in ARGB format. Helper for setting icon hints. |
| 826 | */ |
| 827 | static unsigned long *get_bitmap_argb( HDC hdc, HBITMAP color, HBITMAP mask, unsigned int *size ) |
| 828 | { |
| 829 | BITMAP bm; |
| 830 | BITMAPINFO *info; |
Alexandre Julliard | f0644c6 | 2010-04-19 14:49:26 +0200 | [diff] [blame] | 831 | unsigned int *ptr, *bits = NULL; |
| 832 | unsigned char *mask_bits = NULL; |
| 833 | int i, j, has_alpha = 0; |
Alexandre Julliard | 4253120 | 2010-04-19 11:13:34 +0200 | [diff] [blame] | 834 | |
| 835 | if (!GetObjectW( color, sizeof(bm), &bm )) return NULL; |
| 836 | if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) return NULL; |
| 837 | info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 838 | info->bmiHeader.biWidth = bm.bmWidth; |
| 839 | info->bmiHeader.biHeight = -bm.bmHeight; |
| 840 | info->bmiHeader.biPlanes = 1; |
| 841 | info->bmiHeader.biBitCount = 32; |
| 842 | info->bmiHeader.biCompression = BI_RGB; |
| 843 | info->bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4; |
| 844 | info->bmiHeader.biXPelsPerMeter = 0; |
| 845 | info->bmiHeader.biYPelsPerMeter = 0; |
| 846 | info->bmiHeader.biClrUsed = 0; |
| 847 | info->bmiHeader.biClrImportant = 0; |
| 848 | *size = bm.bmWidth * bm.bmHeight + 2; |
| 849 | if (!(bits = HeapAlloc( GetProcessHeap(), 0, *size * sizeof(long) ))) goto failed; |
| 850 | if (!GetDIBits( hdc, color, 0, bm.bmHeight, bits + 2, info, DIB_RGB_COLORS )) goto failed; |
| 851 | |
| 852 | bits[0] = bm.bmWidth; |
| 853 | bits[1] = bm.bmHeight; |
| 854 | |
Alexandre Julliard | f0644c6 | 2010-04-19 14:49:26 +0200 | [diff] [blame] | 855 | for (i = 0; i < bm.bmWidth * bm.bmHeight; i++) |
| 856 | if ((has_alpha = (bits[i + 2] & 0xff000000) != 0)) break; |
| 857 | |
| 858 | if (!has_alpha) |
| 859 | { |
| 860 | unsigned int width_bytes = (bm.bmWidth + 31) / 32 * 4; |
| 861 | /* generate alpha channel from the mask */ |
| 862 | info->bmiHeader.biBitCount = 1; |
| 863 | info->bmiHeader.biSizeImage = width_bytes * bm.bmHeight; |
| 864 | if (!(mask_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto failed; |
| 865 | if (!GetDIBits( hdc, mask, 0, bm.bmHeight, mask_bits, info, DIB_RGB_COLORS )) goto failed; |
| 866 | ptr = bits + 2; |
| 867 | for (i = 0; i < bm.bmHeight; i++) |
| 868 | for (j = 0; j < bm.bmWidth; j++, ptr++) |
Alexandre Julliard | 9ff982f | 2010-04-22 14:16:44 +0200 | [diff] [blame] | 869 | if (!((mask_bits[i * width_bytes + j / 8] << (j % 8)) & 0x80)) *ptr |= 0xff000000; |
Alexandre Julliard | f84f939 | 2010-04-20 13:55:11 +0200 | [diff] [blame] | 870 | HeapFree( GetProcessHeap(), 0, mask_bits ); |
Alexandre Julliard | f0644c6 | 2010-04-19 14:49:26 +0200 | [diff] [blame] | 871 | } |
Alexandre Julliard | f84f939 | 2010-04-20 13:55:11 +0200 | [diff] [blame] | 872 | HeapFree( GetProcessHeap(), 0, info ); |
Alexandre Julliard | f0644c6 | 2010-04-19 14:49:26 +0200 | [diff] [blame] | 873 | |
Alexandre Julliard | 4253120 | 2010-04-19 11:13:34 +0200 | [diff] [blame] | 874 | /* convert to array of longs */ |
| 875 | if (bits && sizeof(long) > sizeof(int)) |
| 876 | for (i = *size - 1; i >= 0; i--) ((unsigned long *)bits)[i] = bits[i]; |
| 877 | |
| 878 | return (unsigned long *)bits; |
| 879 | |
| 880 | failed: |
| 881 | HeapFree( GetProcessHeap(), 0, info ); |
| 882 | HeapFree( GetProcessHeap(), 0, bits ); |
Alexandre Julliard | f0644c6 | 2010-04-19 14:49:26 +0200 | [diff] [blame] | 883 | HeapFree( GetProcessHeap(), 0, mask_bits ); |
Alexandre Julliard | 4253120 | 2010-04-19 11:13:34 +0200 | [diff] [blame] | 884 | return NULL; |
| 885 | } |
| 886 | |
| 887 | |
| 888 | /*********************************************************************** |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 889 | * set_icon_hints |
| 890 | * |
| 891 | * Set the icon wm hints |
| 892 | */ |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 893 | static void set_icon_hints( Display *display, struct x11drv_win_data *data, |
| 894 | HICON icon_big, HICON icon_small ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 895 | { |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 896 | XWMHints *hints = data->wm_hints; |
| 897 | |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 898 | if (!icon_big) |
| 899 | { |
| 900 | icon_big = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 ); |
| 901 | if (!icon_big) icon_big = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON ); |
| 902 | } |
| 903 | if (!icon_small) |
| 904 | { |
| 905 | icon_small = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_SMALL, 0 ); |
| 906 | if (!icon_small) icon_small = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICONSM ); |
| 907 | } |
| 908 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 909 | if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap ); |
| 910 | if (data->hWMIconMask) DeleteObject( data->hWMIconMask); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 911 | data->hWMIconBitmap = 0; |
| 912 | data->hWMIconMask = 0; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 913 | |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 914 | if (!icon_big) |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 915 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 916 | if (!data->icon_window) create_icon_window( display, data ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 917 | hints->icon_window = data->icon_window; |
| 918 | hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 919 | } |
| 920 | else |
| 921 | { |
| 922 | HBITMAP hbmOrig; |
| 923 | RECT rcMask; |
Alexandre Julliard | ea1d71c | 2010-04-16 16:23:33 +0200 | [diff] [blame] | 924 | BITMAP bm; |
Alexandre Julliard | 0d84ccb | 2010-05-20 17:37:28 +0200 | [diff] [blame] | 925 | ICONINFO ii, ii_small; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 926 | HDC hDC; |
Alexandre Julliard | 4253120 | 2010-04-19 11:13:34 +0200 | [diff] [blame] | 927 | unsigned int size; |
| 928 | unsigned long *bits; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 929 | |
Alexandre Julliard | 0d84ccb | 2010-05-20 17:37:28 +0200 | [diff] [blame] | 930 | if (!GetIconInfo(icon_big, &ii)) return; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 931 | |
Alexandre Julliard | ea1d71c | 2010-04-16 16:23:33 +0200 | [diff] [blame] | 932 | GetObjectW(ii.hbmMask, sizeof(bm), &bm); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 933 | rcMask.top = 0; |
| 934 | rcMask.left = 0; |
Alexandre Julliard | ea1d71c | 2010-04-16 16:23:33 +0200 | [diff] [blame] | 935 | rcMask.right = bm.bmWidth; |
| 936 | rcMask.bottom = bm.bmHeight; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 937 | |
| 938 | hDC = CreateCompatibleDC(0); |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 939 | bits = get_bitmap_argb( hDC, ii.hbmColor, ii.hbmMask, &size ); |
Alexandre Julliard | 0d84ccb | 2010-05-20 17:37:28 +0200 | [diff] [blame] | 940 | if (bits && GetIconInfo( icon_small, &ii_small )) |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 941 | { |
| 942 | unsigned int size_small; |
| 943 | unsigned long *bits_small, *new; |
| 944 | |
Alexandre Julliard | 0d84ccb | 2010-05-20 17:37:28 +0200 | [diff] [blame] | 945 | if ((bits_small = get_bitmap_argb( hDC, ii_small.hbmColor, ii_small.hbmMask, &size_small )) && |
Alexandre Julliard | 09dc601 | 2010-04-22 14:47:57 +0200 | [diff] [blame] | 946 | (bits_small[0] != bits[0] || bits_small[1] != bits[1])) /* size must be different */ |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 947 | { |
| 948 | if ((new = HeapReAlloc( GetProcessHeap(), 0, bits, |
| 949 | (size + size_small) * sizeof(unsigned long) ))) |
| 950 | { |
| 951 | bits = new; |
| 952 | memcpy( bits + size, bits_small, size_small * sizeof(unsigned long) ); |
| 953 | size += size_small; |
| 954 | } |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 955 | } |
Alexandre Julliard | 09dc601 | 2010-04-22 14:47:57 +0200 | [diff] [blame] | 956 | HeapFree( GetProcessHeap(), 0, bits_small ); |
Alexandre Julliard | 0d84ccb | 2010-05-20 17:37:28 +0200 | [diff] [blame] | 957 | DeleteObject( ii_small.hbmColor ); |
| 958 | DeleteObject( ii_small.hbmMask ); |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 959 | } |
| 960 | wine_tsx11_lock(); |
| 961 | if (bits) |
| 962 | XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_ICON), |
| 963 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *)bits, size ); |
| 964 | else |
| 965 | XDeleteProperty( display, data->whole_window, x11drv_atom(_NET_WM_ICON) ); |
| 966 | wine_tsx11_unlock(); |
| 967 | HeapFree( GetProcessHeap(), 0, bits ); |
| 968 | |
Alexandre Julliard | 9ff982f | 2010-04-22 14:16:44 +0200 | [diff] [blame] | 969 | hbmOrig = SelectObject(hDC, ii.hbmMask); |
| 970 | InvertRect(hDC, &rcMask); |
| 971 | SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */ |
| 972 | SelectObject(hDC, hbmOrig); |
| 973 | |
| 974 | data->hWMIconBitmap = ii.hbmColor; |
| 975 | data->hWMIconMask = ii.hbmMask; |
| 976 | |
| 977 | hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap); |
| 978 | hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask); |
| 979 | destroy_icon_window( display, data ); |
| 980 | hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint; |
| 981 | |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 982 | DeleteDC(hDC); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
| 986 | |
| 987 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 988 | * set_size_hints |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 989 | * |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 990 | * set the window size hints |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 991 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 992 | 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] | 993 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 994 | XSizeHints* size_hints; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 995 | |
Alexandre Julliard | cf9d3e3 | 2008-04-04 11:28:30 +0200 | [diff] [blame] | 996 | if (!(size_hints = XAllocSizeHints())) return; |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 997 | |
Alexandre Julliard | 6ba06fa | 2008-04-23 15:33:29 +0200 | [diff] [blame] | 998 | size_hints->win_gravity = StaticGravity; |
| 999 | size_hints->flags |= PWinGravity; |
| 1000 | |
Alexandre Julliard | cf9d3e3 | 2008-04-04 11:28:30 +0200 | [diff] [blame] | 1001 | /* don't update size hints if window is not in normal state */ |
| 1002 | if (!(style & (WS_MINIMIZE | WS_MAXIMIZE))) |
| 1003 | { |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 1004 | if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */ |
| 1005 | { |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 1006 | size_hints->x = data->whole_rect.left; |
| 1007 | size_hints->y = data->whole_rect.top; |
Alexandre Julliard | 6ba06fa | 2008-04-23 15:33:29 +0200 | [diff] [blame] | 1008 | size_hints->flags |= PPosition; |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 1009 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1010 | |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 1011 | if (!is_window_resizable( data, style )) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1012 | { |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 1013 | size_hints->max_width = data->whole_rect.right - data->whole_rect.left; |
| 1014 | size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top; |
Alexandre Julliard | 81c4b41 | 2010-05-28 12:13:01 +0200 | [diff] [blame] | 1015 | if (size_hints->max_width <= 0 ||size_hints->max_height <= 0) |
| 1016 | size_hints->max_width = size_hints->max_height = 1; |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 1017 | size_hints->min_width = size_hints->max_width; |
| 1018 | size_hints->min_height = size_hints->max_height; |
| 1019 | size_hints->flags |= PMinSize | PMaxSize; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1020 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1021 | } |
Alexandre Julliard | cf9d3e3 | 2008-04-04 11:28:30 +0200 | [diff] [blame] | 1022 | XSetWMNormalHints( display, data->whole_window, size_hints ); |
| 1023 | XFree( size_hints ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | |
| 1027 | /*********************************************************************** |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 1028 | * get_process_name |
| 1029 | * |
| 1030 | * get the name of the current process for setting class hints |
| 1031 | */ |
| 1032 | static char *get_process_name(void) |
| 1033 | { |
| 1034 | static char *name; |
| 1035 | |
| 1036 | if (!name) |
| 1037 | { |
| 1038 | WCHAR module[MAX_PATH]; |
| 1039 | DWORD len = GetModuleFileNameW( 0, module, MAX_PATH ); |
| 1040 | if (len && len < MAX_PATH) |
| 1041 | { |
| 1042 | char *ptr; |
| 1043 | WCHAR *p, *appname = module; |
| 1044 | |
| 1045 | if ((p = strrchrW( appname, '/' ))) appname = p + 1; |
| 1046 | if ((p = strrchrW( appname, '\\' ))) appname = p + 1; |
| 1047 | len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL ); |
| 1048 | if ((ptr = HeapAlloc( GetProcessHeap(), 0, len ))) |
| 1049 | { |
| 1050 | WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL ); |
| 1051 | name = ptr; |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | return name; |
| 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | /*********************************************************************** |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1060 | * set_initial_wm_hints |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1061 | * |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1062 | * 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] | 1063 | */ |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1064 | 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] | 1065 | { |
Alexandre Julliard | 3bfa90e | 2008-04-07 11:41:54 +0200 | [diff] [blame] | 1066 | long i; |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1067 | Atom protocols[3]; |
Kusanagi Kouichi | 1078914 | 2010-02-20 17:57:07 +0900 | [diff] [blame] | 1068 | Atom dndVersion = WINE_XDND_VERSION; |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1069 | XClassHint *class_hints; |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 1070 | char *process_name = get_process_name(); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1071 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1072 | wine_tsx11_lock(); |
| 1073 | |
| 1074 | /* wm protocols */ |
| 1075 | i = 0; |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 1076 | protocols[i++] = x11drv_atom(WM_DELETE_WINDOW); |
| 1077 | protocols[i++] = x11drv_atom(_NET_WM_PING); |
| 1078 | if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS); |
| 1079 | XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS), |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 1080 | XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1081 | |
| 1082 | /* class hints */ |
| 1083 | if ((class_hints = XAllocClassHint())) |
| 1084 | { |
Andrew Talbot | 55e20a7 | 2006-06-26 20:56:16 +0100 | [diff] [blame] | 1085 | static char wine[] = "Wine"; |
| 1086 | |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 1087 | class_hints->res_name = process_name; |
Andrew Talbot | 55e20a7 | 2006-06-26 20:56:16 +0100 | [diff] [blame] | 1088 | class_hints->res_class = wine; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1089 | XSetClassHint( display, data->whole_window, class_hints ); |
| 1090 | XFree( class_hints ); |
| 1091 | } |
| 1092 | |
Mike Hearn | 34dd455 | 2003-05-04 02:27:20 +0000 | [diff] [blame] | 1093 | /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */ |
| 1094 | XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL); |
| 1095 | /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */ |
| 1096 | i = getpid(); |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 1097 | XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID), |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 1098 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1); |
Ove Kaaven | 77e7fd7 | 2002-01-21 18:41:27 +0000 | [diff] [blame] | 1099 | |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1100 | XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware), |
| 1101 | XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 ); |
| 1102 | |
Alexandre Julliard | dc07b6f | 2008-01-22 10:17:52 +0100 | [diff] [blame] | 1103 | data->wm_hints = XAllocWMHints(); |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1104 | wine_tsx11_unlock(); |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 1105 | |
| 1106 | if (data->wm_hints) |
| 1107 | { |
| 1108 | data->wm_hints->flags = 0; |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 1109 | set_icon_hints( display, data, 0, 0 ); |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 1110 | } |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | /*********************************************************************** |
Alexandre Julliard | 7b3a00c | 2010-02-23 12:33:01 +0100 | [diff] [blame] | 1115 | * get_owner_whole_window |
| 1116 | * |
| 1117 | * Retrieve an owner's window, creating it if necessary. |
| 1118 | */ |
Alexandre Julliard | b6ef8a5 | 2010-03-20 20:16:42 +0100 | [diff] [blame] | 1119 | static Window get_owner_whole_window( HWND owner, BOOL force_managed ) |
Alexandre Julliard | 7b3a00c | 2010-02-23 12:33:01 +0100 | [diff] [blame] | 1120 | { |
| 1121 | struct x11drv_win_data *data; |
| 1122 | |
| 1123 | if (!owner) return 0; |
| 1124 | |
| 1125 | if (!(data = X11DRV_get_win_data( owner ))) |
| 1126 | { |
Alexandre Julliard | 9cd1ce2 | 2010-03-01 17:06:19 +0100 | [diff] [blame] | 1127 | if (GetWindowThreadProcessId( owner, NULL ) != GetCurrentThreadId() || |
| 1128 | !(data = X11DRV_create_win_data( owner ))) |
Alexandre Julliard | 7b3a00c | 2010-02-23 12:33:01 +0100 | [diff] [blame] | 1129 | return (Window)GetPropA( owner, whole_window_prop ); |
| 1130 | } |
Alexandre Julliard | b6ef8a5 | 2010-03-20 20:16:42 +0100 | [diff] [blame] | 1131 | else if (!data->managed && force_managed) /* make it managed */ |
Alexandre Julliard | 913cab1 | 2010-02-23 12:35:10 +0100 | [diff] [blame] | 1132 | { |
| 1133 | SetWindowPos( owner, 0, 0, 0, 0, 0, |
| 1134 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | |
| 1135 | SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED ); |
| 1136 | } |
Alexandre Julliard | 7b3a00c | 2010-02-23 12:33:01 +0100 | [diff] [blame] | 1137 | return data->whole_window; |
| 1138 | } |
| 1139 | |
| 1140 | |
| 1141 | /*********************************************************************** |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1142 | * set_wm_hints |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1143 | * |
| 1144 | * Set the window manager hints for a newly-created window |
| 1145 | */ |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1146 | static void set_wm_hints( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1147 | { |
Alexandre Julliard | 7b3a00c | 2010-02-23 12:33:01 +0100 | [diff] [blame] | 1148 | Window group_leader = data->whole_window; |
| 1149 | Window owner_win = 0; |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1150 | Atom window_type; |
| 1151 | MwmHints mwm_hints; |
Alexandre Julliard | 18f4fb9 | 2008-04-14 13:27:38 +0200 | [diff] [blame] | 1152 | DWORD style, ex_style; |
| 1153 | HWND owner; |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1154 | |
| 1155 | if (data->hwnd == GetDesktopWindow()) |
| 1156 | { |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1157 | /* force some styles for the desktop to get the correct decorations */ |
Alexandre Julliard | 18f4fb9 | 2008-04-14 13:27:38 +0200 | [diff] [blame] | 1158 | style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; |
| 1159 | ex_style = WS_EX_APPWINDOW; |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1160 | owner = 0; |
| 1161 | } |
Alexandre Julliard | 18f4fb9 | 2008-04-14 13:27:38 +0200 | [diff] [blame] | 1162 | else |
| 1163 | { |
| 1164 | style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
| 1165 | ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE ); |
Alexandre Julliard | 61e50e1 | 2010-05-28 12:14:43 +0200 | [diff] [blame] | 1166 | owner = GetWindow( data->hwnd, GW_OWNER ); |
Alexandre Julliard | b6ef8a5 | 2010-03-20 20:16:42 +0100 | [diff] [blame] | 1167 | if ((owner_win = get_owner_whole_window( owner, data->managed ))) group_leader = owner_win; |
Alexandre Julliard | 18f4fb9 | 2008-04-14 13:27:38 +0200 | [diff] [blame] | 1168 | } |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1169 | |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1170 | wine_tsx11_lock(); |
| 1171 | |
Alexandre Julliard | 7b3a00c | 2010-02-23 12:33:01 +0100 | [diff] [blame] | 1172 | if (owner_win) XSetTransientForHint( display, data->whole_window, owner_win ); |
| 1173 | |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1174 | /* size hints */ |
| 1175 | set_size_hints( display, data, style ); |
| 1176 | |
Nickolay V. Shmyrev | 1a1b902 | 2006-10-11 19:32:22 +0400 | [diff] [blame] | 1177 | /* set the WM_WINDOW_TYPE */ |
Dmitry Timoshkov | 751a71a | 2008-04-07 13:37:44 +0900 | [diff] [blame] | 1178 | 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] | 1179 | else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL); |
Alexandre Julliard | 8b84d64 | 2010-05-28 12:12:32 +0200 | [diff] [blame] | 1180 | else if (style & WS_MINIMIZEBOX) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL); |
Nickolay V. Shmyrev | 1a1b902 | 2006-10-11 19:32:22 +0400 | [diff] [blame] | 1181 | else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG); |
| 1182 | 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] | 1183 | 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] | 1184 | #if 0 /* many window managers don't handle utility windows very well */ |
Dmitry Timoshkov | 751a71a | 2008-04-07 13:37:44 +0900 | [diff] [blame] | 1185 | 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] | 1186 | #endif |
Alexandre Julliard | 9bf9c0b | 2008-04-14 13:27:19 +0200 | [diff] [blame] | 1187 | else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL); |
Nickolay V. Shmyrev | 1a1b902 | 2006-10-11 19:32:22 +0400 | [diff] [blame] | 1188 | |
| 1189 | XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE), |
| 1190 | XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1); |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 1191 | |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 1192 | mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; |
Dmitry Timoshkov | 15c0bcb | 2008-04-16 16:50:29 +0900 | [diff] [blame] | 1193 | mwm_hints.decorations = get_mwm_decorations( data, style, ex_style ); |
Dmitry Timoshkov | ac387bb | 2006-10-05 23:16:36 +0900 | [diff] [blame] | 1194 | mwm_hints.functions = MWM_FUNC_MOVE; |
Alexandre Julliard | 4d14adf | 2008-04-04 11:25:48 +0200 | [diff] [blame] | 1195 | if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE; |
Dmitry Timoshkov | e35e75b | 2010-04-07 15:41:01 +0900 | [diff] [blame] | 1196 | if (!(style & WS_DISABLED)) |
| 1197 | { |
| 1198 | if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE; |
| 1199 | if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE; |
| 1200 | if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE; |
| 1201 | } |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 1202 | |
| 1203 | XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS), |
| 1204 | x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace, |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 1205 | (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1206 | |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 1207 | /* wm hints */ |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 1208 | if (data->wm_hints) |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 1209 | { |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 1210 | data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint; |
Alexandre Julliard | e3720c2 | 2009-08-13 18:18:22 +0200 | [diff] [blame] | 1211 | data->wm_hints->input = !use_take_focus && !(style & WS_DISABLED); |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 1212 | data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState; |
| 1213 | data->wm_hints->window_group = group_leader; |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 1214 | XSetWMHints( display, data->whole_window, data->wm_hints ); |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 1215 | } |
Alexandre Julliard | 6a23bd8 | 2008-01-18 14:34:57 +0100 | [diff] [blame] | 1216 | |
| 1217 | wine_tsx11_unlock(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | |
| 1221 | /*********************************************************************** |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1222 | * update_net_wm_states |
| 1223 | */ |
| 1224 | void update_net_wm_states( Display *display, struct x11drv_win_data *data ) |
| 1225 | { |
| 1226 | static const unsigned int state_atoms[NB_NET_WM_STATES] = |
| 1227 | { |
| 1228 | XATOM__NET_WM_STATE_FULLSCREEN, |
| 1229 | XATOM__NET_WM_STATE_ABOVE, |
| 1230 | XATOM__NET_WM_STATE_MAXIMIZED_VERT, |
| 1231 | XATOM__NET_WM_STATE_SKIP_PAGER, |
| 1232 | XATOM__NET_WM_STATE_SKIP_TASKBAR |
| 1233 | }; |
| 1234 | |
| 1235 | DWORD i, style, ex_style, new_state = 0; |
| 1236 | |
| 1237 | if (!data->managed) return; |
| 1238 | if (data->whole_window == root_window) return; |
| 1239 | |
| 1240 | style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
| 1241 | if (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width && |
| 1242 | data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height) |
| 1243 | { |
| 1244 | if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION) |
| 1245 | new_state |= (1 << NET_WM_STATE_MAXIMIZED); |
| 1246 | else if (!(style & WS_MINIMIZE)) |
| 1247 | new_state |= (1 << NET_WM_STATE_FULLSCREEN); |
| 1248 | } |
| 1249 | else if (style & WS_MAXIMIZE) |
| 1250 | new_state |= (1 << NET_WM_STATE_MAXIMIZED); |
| 1251 | |
| 1252 | ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE ); |
| 1253 | if (ex_style & WS_EX_TOPMOST) |
| 1254 | new_state |= (1 << NET_WM_STATE_ABOVE); |
| 1255 | if (ex_style & WS_EX_TOOLWINDOW) |
| 1256 | new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR) | (1 << NET_WM_STATE_SKIP_PAGER); |
Alexandre Julliard | 61e50e1 | 2010-05-28 12:14:43 +0200 | [diff] [blame] | 1257 | if (!(ex_style & WS_EX_APPWINDOW) && GetWindow( data->hwnd, GW_OWNER )) |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1258 | new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR); |
| 1259 | |
| 1260 | if (!data->mapped) /* set the _NET_WM_STATE atom directly */ |
| 1261 | { |
| 1262 | Atom atoms[NB_NET_WM_STATES+1]; |
| 1263 | DWORD count; |
| 1264 | |
| 1265 | for (i = count = 0; i < NB_NET_WM_STATES; i++) |
| 1266 | { |
| 1267 | if (!(new_state & (1 << i))) continue; |
| 1268 | TRACE( "setting wm state %u for unmapped window %p/%lx\n", |
| 1269 | i, data->hwnd, data->whole_window ); |
| 1270 | atoms[count++] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM]; |
| 1271 | if (state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) |
| 1272 | atoms[count++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ); |
| 1273 | } |
| 1274 | wine_tsx11_lock(); |
| 1275 | XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_STATE), XA_ATOM, |
| 1276 | 32, PropModeReplace, (unsigned char *)atoms, count ); |
| 1277 | wine_tsx11_unlock(); |
| 1278 | } |
| 1279 | else /* ask the window manager to do it for us */ |
| 1280 | { |
| 1281 | XEvent xev; |
| 1282 | |
| 1283 | xev.xclient.type = ClientMessage; |
| 1284 | xev.xclient.window = data->whole_window; |
| 1285 | xev.xclient.message_type = x11drv_atom(_NET_WM_STATE); |
| 1286 | xev.xclient.serial = 0; |
| 1287 | xev.xclient.display = display; |
| 1288 | xev.xclient.send_event = True; |
| 1289 | xev.xclient.format = 32; |
| 1290 | xev.xclient.data.l[3] = 1; |
| 1291 | |
| 1292 | for (i = 0; i < NB_NET_WM_STATES; i++) |
| 1293 | { |
| 1294 | if (!((data->net_wm_state ^ new_state) & (1 << i))) continue; /* unchanged */ |
| 1295 | |
| 1296 | TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n", |
| 1297 | i, data->hwnd, data->whole_window, |
| 1298 | (new_state & (1 << i)) != 0, (data->net_wm_state & (1 << i)) != 0 ); |
| 1299 | |
| 1300 | xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; |
| 1301 | xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM]; |
| 1302 | xev.xclient.data.l[2] = ((state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) ? |
| 1303 | x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ) : 0); |
| 1304 | wine_tsx11_lock(); |
| 1305 | XSendEvent( display, root_window, False, |
| 1306 | SubstructureRedirectMask | SubstructureNotifyMask, &xev ); |
| 1307 | wine_tsx11_unlock(); |
| 1308 | } |
| 1309 | } |
| 1310 | data->net_wm_state = new_state; |
| 1311 | } |
| 1312 | |
| 1313 | |
| 1314 | /*********************************************************************** |
| 1315 | * set_xembed_flags |
| 1316 | */ |
| 1317 | static void set_xembed_flags( Display *display, struct x11drv_win_data *data, unsigned long flags ) |
| 1318 | { |
| 1319 | unsigned long info[2]; |
| 1320 | |
| 1321 | info[0] = 0; /* protocol version */ |
| 1322 | info[1] = flags; |
| 1323 | wine_tsx11_lock(); |
| 1324 | XChangeProperty( display, data->whole_window, x11drv_atom(_XEMBED_INFO), |
| 1325 | x11drv_atom(_XEMBED_INFO), 32, PropModeReplace, (unsigned char*)info, 2 ); |
| 1326 | wine_tsx11_unlock(); |
| 1327 | } |
| 1328 | |
| 1329 | |
| 1330 | /*********************************************************************** |
| 1331 | * map_window |
| 1332 | */ |
| 1333 | static void map_window( Display *display, struct x11drv_win_data *data, DWORD new_style ) |
| 1334 | { |
| 1335 | TRACE( "win %p/%lx\n", data->hwnd, data->whole_window ); |
| 1336 | |
Damjan Jovanovic | 3613b15 | 2009-01-06 20:59:07 +0200 | [diff] [blame] | 1337 | remove_startup_notification( display, data->whole_window ); |
| 1338 | |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1339 | wait_for_withdrawn_state( display, data, TRUE ); |
| 1340 | |
| 1341 | if (!data->embedded) |
| 1342 | { |
| 1343 | update_net_wm_states( display, data ); |
| 1344 | sync_window_style( display, data ); |
| 1345 | wine_tsx11_lock(); |
| 1346 | XMapWindow( display, data->whole_window ); |
| 1347 | wine_tsx11_unlock(); |
| 1348 | } |
| 1349 | else set_xembed_flags( display, data, XEMBED_MAPPED ); |
| 1350 | |
| 1351 | data->mapped = TRUE; |
| 1352 | data->iconic = (new_style & WS_MINIMIZE) != 0; |
| 1353 | } |
| 1354 | |
| 1355 | |
| 1356 | /*********************************************************************** |
| 1357 | * unmap_window |
| 1358 | */ |
| 1359 | static void unmap_window( Display *display, struct x11drv_win_data *data ) |
| 1360 | { |
| 1361 | TRACE( "win %p/%lx\n", data->hwnd, data->whole_window ); |
| 1362 | |
| 1363 | if (!data->embedded) |
| 1364 | { |
| 1365 | wait_for_withdrawn_state( display, data, FALSE ); |
| 1366 | wine_tsx11_lock(); |
| 1367 | if (data->managed) XWithdrawWindow( display, data->whole_window, DefaultScreen(display) ); |
| 1368 | else XUnmapWindow( display, data->whole_window ); |
| 1369 | wine_tsx11_unlock(); |
| 1370 | } |
| 1371 | else set_xembed_flags( display, data, 0 ); |
| 1372 | |
| 1373 | data->mapped = FALSE; |
| 1374 | data->net_wm_state = 0; |
| 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | /*********************************************************************** |
| 1379 | * make_window_embedded |
| 1380 | */ |
| 1381 | void make_window_embedded( Display *display, struct x11drv_win_data *data ) |
| 1382 | { |
| 1383 | if (data->mapped) |
| 1384 | { |
| 1385 | /* the window cannot be mapped before being embedded */ |
| 1386 | unmap_window( display, data ); |
| 1387 | data->embedded = TRUE; |
| 1388 | map_window( display, data, 0 ); |
| 1389 | } |
| 1390 | else |
| 1391 | { |
| 1392 | data->embedded = TRUE; |
| 1393 | set_xembed_flags( display, data, 0 ); |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | |
| 1398 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1399 | * X11DRV_window_to_X_rect |
| 1400 | * |
| 1401 | * Convert a rect from client to X window coordinates |
| 1402 | */ |
Andrew Talbot | f63ceec | 2009-01-29 21:40:50 +0000 | [diff] [blame] | 1403 | static 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] | 1404 | { |
Alexandre Julliard | 8cd1f71 | 2001-07-20 18:37:37 +0000 | [diff] [blame] | 1405 | RECT rc; |
| 1406 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1407 | if (!data->managed) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1408 | if (IsRectEmpty( rect )) return; |
| 1409 | |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 1410 | get_x11_rect_offset( data, &rc ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1411 | |
Alexandre Julliard | 8cd1f71 | 2001-07-20 18:37:37 +0000 | [diff] [blame] | 1412 | rect->left -= rc.left; |
| 1413 | rect->right -= rc.right; |
| 1414 | rect->top -= rc.top; |
| 1415 | rect->bottom -= rc.bottom; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1416 | if (rect->top >= rect->bottom) rect->bottom = rect->top + 1; |
| 1417 | if (rect->left >= rect->right) rect->right = rect->left + 1; |
| 1418 | } |
| 1419 | |
| 1420 | |
| 1421 | /*********************************************************************** |
| 1422 | * X11DRV_X_to_window_rect |
| 1423 | * |
| 1424 | * Opposite of X11DRV_window_to_X_rect |
| 1425 | */ |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1426 | 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] | 1427 | { |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 1428 | RECT rc; |
Alexandre Julliard | 74cd76c | 2007-08-29 12:02:57 +0200 | [diff] [blame] | 1429 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1430 | if (!data->managed) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1431 | if (IsRectEmpty( rect )) return; |
| 1432 | |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 1433 | get_x11_rect_offset( data, &rc ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1434 | |
Alexandre Julliard | c4e20e7 | 2007-10-11 12:24:27 +0200 | [diff] [blame] | 1435 | rect->left += rc.left; |
| 1436 | rect->right += rc.right; |
| 1437 | rect->top += rc.top; |
| 1438 | rect->bottom += rc.bottom; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1439 | if (rect->top >= rect->bottom) rect->bottom = rect->top + 1; |
| 1440 | if (rect->left >= rect->right) rect->right = rect->left + 1; |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | /*********************************************************************** |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1445 | * sync_window_position |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1446 | * |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1447 | * Synchronize the X window position with the Windows one |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1448 | */ |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1449 | static void sync_window_position( Display *display, struct x11drv_win_data *data, |
Alexandre Julliard | 08b8325 | 2010-02-08 17:14:01 +0100 | [diff] [blame] | 1450 | UINT swp_flags, const RECT *old_window_rect, |
| 1451 | const RECT *old_whole_rect, const RECT *old_client_rect ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1452 | { |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 1453 | DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1454 | XWindowChanges changes; |
Alexandre Julliard | bbd32aa | 2008-04-23 15:34:07 +0200 | [diff] [blame] | 1455 | unsigned int mask = 0; |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 1456 | |
| 1457 | if (data->managed && data->iconic) return; |
| 1458 | |
Alexandre Julliard | bbd32aa | 2008-04-23 15:34:07 +0200 | [diff] [blame] | 1459 | /* resizing a managed maximized window is not allowed */ |
| 1460 | if (!(style & WS_MAXIMIZE) || !data->managed) |
| 1461 | { |
Alexandre Julliard | 308476e | 2008-09-17 21:11:47 +0200 | [diff] [blame] | 1462 | changes.width = data->whole_rect.right - data->whole_rect.left; |
| 1463 | changes.height = data->whole_rect.bottom - data->whole_rect.top; |
| 1464 | /* if window rect is empty force size to 1x1 */ |
| 1465 | if (changes.width <= 0 || changes.height <= 0) changes.width = changes.height = 1; |
Alexandre Julliard | a4644f1 | 2009-05-05 15:36:25 +0200 | [diff] [blame] | 1466 | if (changes.width > 65535) changes.width = 65535; |
| 1467 | if (changes.height > 65535) changes.height = 65535; |
Alexandre Julliard | bbd32aa | 2008-04-23 15:34:07 +0200 | [diff] [blame] | 1468 | mask |= CWWidth | CWHeight; |
| 1469 | } |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 1470 | |
| 1471 | /* only the size is allowed to change for the desktop window */ |
| 1472 | if (data->whole_window != root_window) |
| 1473 | { |
| 1474 | changes.x = data->whole_rect.left - virtual_screen_rect.left; |
| 1475 | changes.y = data->whole_rect.top - virtual_screen_rect.top; |
| 1476 | mask |= CWX | CWY; |
| 1477 | } |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1478 | |
Alexandre Julliard | ac40efa | 2008-08-29 13:34:55 +0200 | [diff] [blame] | 1479 | if (!(swp_flags & SWP_NOZORDER) || (swp_flags & SWP_SHOWWINDOW)) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1480 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1481 | /* find window that this one must be after */ |
| 1482 | HWND prev = GetWindow( data->hwnd, GW_HWNDPREV ); |
| 1483 | while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE)) |
| 1484 | prev = GetWindow( prev, GW_HWNDPREV ); |
| 1485 | if (!prev) /* top child */ |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1486 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1487 | changes.stack_mode = Above; |
| 1488 | mask |= CWStackMode; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1489 | } |
Alexandre Julliard | 5787c12 | 2008-03-24 15:47:28 +0100 | [diff] [blame] | 1490 | /* should use stack_mode Below but most window managers don't get it right */ |
| 1491 | /* 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] | 1492 | } |
| 1493 | |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 1494 | wine_tsx11_lock(); |
| 1495 | set_size_hints( display, data, style ); |
Alexandre Julliard | 00b06da | 2010-01-04 17:56:32 +0100 | [diff] [blame] | 1496 | data->configure_serial = NextRequest( display ); |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 1497 | XReconfigureWMWindow( display, data->whole_window, |
| 1498 | DefaultScreen(display), mask, &changes ); |
Alexandre Julliard | 4c7b8ca | 2010-02-04 17:27:19 +0100 | [diff] [blame] | 1499 | #ifdef HAVE_LIBXSHAPE |
Alexandre Julliard | 61e50e1 | 2010-05-28 12:14:43 +0200 | [diff] [blame] | 1500 | if (IsRectEmpty( old_window_rect ) != IsRectEmpty( &data->window_rect )) |
| 1501 | sync_window_region( display, data, (HRGN)1 ); |
Alexandre Julliard | 4c7b8ca | 2010-02-04 17:27:19 +0100 | [diff] [blame] | 1502 | if (data->shaped) |
| 1503 | { |
Alexandre Julliard | 08b8325 | 2010-02-08 17:14:01 +0100 | [diff] [blame] | 1504 | int old_x_offset = old_window_rect->left - old_whole_rect->left; |
| 1505 | int old_y_offset = old_window_rect->top - old_whole_rect->top; |
| 1506 | int new_x_offset = data->window_rect.left - data->whole_rect.left; |
| 1507 | int new_y_offset = data->window_rect.top - data->whole_rect.top; |
| 1508 | if (old_x_offset != new_x_offset || old_y_offset != new_y_offset) |
| 1509 | XShapeOffsetShape( display, data->whole_window, ShapeBounding, |
| 1510 | new_x_offset - old_x_offset, new_y_offset - old_y_offset ); |
Alexandre Julliard | 4c7b8ca | 2010-02-04 17:27:19 +0100 | [diff] [blame] | 1511 | } |
| 1512 | #endif |
Alexandre Julliard | cef3bc6 | 2008-04-04 11:20:45 +0200 | [diff] [blame] | 1513 | wine_tsx11_unlock(); |
Alexandre Julliard | 00b06da | 2010-01-04 17:56:32 +0100 | [diff] [blame] | 1514 | |
| 1515 | TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n", |
| 1516 | data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top, |
| 1517 | data->whole_rect.right - data->whole_rect.left, |
| 1518 | data->whole_rect.bottom - data->whole_rect.top, |
| 1519 | changes.sibling, mask, data->configure_serial ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1523 | /*********************************************************************** |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1524 | * sync_client_position |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1525 | * |
| 1526 | * Synchronize the X client window position with the Windows one |
| 1527 | */ |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1528 | static void sync_client_position( Display *display, struct x11drv_win_data *data, |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1529 | UINT swp_flags, const RECT *old_client_rect, |
| 1530 | const RECT *old_whole_rect ) |
| 1531 | { |
| 1532 | int mask; |
| 1533 | XWindowChanges changes; |
| 1534 | RECT old = *old_client_rect; |
| 1535 | RECT new = data->client_rect; |
| 1536 | |
| 1537 | OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top ); |
| 1538 | OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top ); |
| 1539 | if (!(mask = get_window_changes( &changes, &old, &new ))) return; |
| 1540 | |
| 1541 | if (data->client_window) |
| 1542 | { |
| 1543 | TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n", |
| 1544 | data->client_window, new.left, new.top, |
| 1545 | new.right - new.left, new.bottom - new.top, mask ); |
| 1546 | wine_tsx11_lock(); |
| 1547 | XConfigureWindow( display, data->client_window, mask, &changes ); |
| 1548 | wine_tsx11_unlock(); |
| 1549 | } |
| 1550 | |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 1551 | if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( data ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1555 | /*********************************************************************** |
| 1556 | * move_window_bits |
| 1557 | * |
| 1558 | * Move the window bits when a window is moved. |
| 1559 | */ |
| 1560 | static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect, |
| 1561 | const RECT *old_client_rect ) |
| 1562 | { |
| 1563 | RECT src_rect = *old_rect; |
| 1564 | RECT dst_rect = *new_rect; |
| 1565 | HDC hdc_src, hdc_dst; |
| 1566 | INT code; |
| 1567 | HRGN rgn = 0; |
| 1568 | HWND parent = 0; |
| 1569 | |
| 1570 | if (!data->whole_window) |
| 1571 | { |
| 1572 | OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top ); |
| 1573 | parent = GetAncestor( data->hwnd, GA_PARENT ); |
| 1574 | hdc_src = GetDCEx( parent, 0, DCX_CACHE ); |
| 1575 | hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW ); |
| 1576 | } |
| 1577 | else |
| 1578 | { |
| 1579 | OffsetRect( &dst_rect, -data->client_rect.left, -data->client_rect.top ); |
| 1580 | /* make src rect relative to the old position of the window */ |
| 1581 | OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top ); |
| 1582 | if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return; |
| 1583 | hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE ); |
| 1584 | } |
| 1585 | |
| 1586 | code = X11DRV_START_EXPOSURES; |
| 1587 | ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL ); |
| 1588 | |
| 1589 | TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n", |
| 1590 | data->hwnd, data->whole_window, data->client_window, |
| 1591 | wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) ); |
| 1592 | BitBlt( hdc_dst, dst_rect.left, dst_rect.top, |
| 1593 | dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top, |
| 1594 | hdc_src, src_rect.left, src_rect.top, SRCCOPY ); |
| 1595 | |
| 1596 | code = X11DRV_END_EXPOSURES; |
| 1597 | ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn ); |
| 1598 | |
| 1599 | ReleaseDC( data->hwnd, hdc_dst ); |
| 1600 | if (hdc_src != hdc_dst) ReleaseDC( parent, hdc_src ); |
| 1601 | |
| 1602 | if (rgn) |
| 1603 | { |
| 1604 | if (!data->whole_window) |
| 1605 | { |
| 1606 | /* map region to client rect since we are using DCX_WINDOW */ |
| 1607 | OffsetRgn( rgn, data->window_rect.left - data->client_rect.left, |
| 1608 | data->window_rect.top - data->client_rect.top ); |
| 1609 | RedrawWindow( data->hwnd, NULL, rgn, |
| 1610 | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN ); |
| 1611 | } |
| 1612 | else RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN ); |
| 1613 | DeleteObject( rgn ); |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1618 | /********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1619 | * create_whole_window |
| 1620 | * |
| 1621 | * Create the whole X window for a given window |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1622 | */ |
Alexandre Julliard | d147e02 | 2008-01-23 21:39:32 +0100 | [diff] [blame] | 1623 | static Window create_whole_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1624 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1625 | int cx, cy, mask; |
| 1626 | XSetWindowAttributes attr; |
Alexandre Julliard | 3ba2025 | 2008-01-23 16:32:55 +0100 | [diff] [blame] | 1627 | WCHAR text[1024]; |
Alexandre Julliard | be3c3a5 | 2008-09-12 15:54:02 +0200 | [diff] [blame] | 1628 | COLORREF key; |
| 1629 | BYTE alpha; |
| 1630 | DWORD layered_flags; |
Alexandre Julliard | aa47784 | 2010-02-01 22:35:32 +0100 | [diff] [blame] | 1631 | HRGN win_rgn; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1632 | |
Alexandre Julliard | e6dfbcb | 2008-01-25 12:07:11 +0100 | [diff] [blame] | 1633 | if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect )) |
| 1634 | { |
| 1635 | TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window ); |
| 1636 | data->managed = TRUE; |
| 1637 | SetPropA( data->hwnd, managed_prop, (HANDLE)1 ); |
| 1638 | } |
| 1639 | |
Alexandre Julliard | aa47784 | 2010-02-01 22:35:32 +0100 | [diff] [blame] | 1640 | if ((win_rgn = CreateRectRgn( 0, 0, 0, 0 )) && |
| 1641 | GetWindowRgn( data->hwnd, win_rgn ) == ERROR) |
| 1642 | { |
| 1643 | DeleteObject( win_rgn ); |
| 1644 | win_rgn = 0; |
| 1645 | } |
| 1646 | data->shaped = (win_rgn != 0); |
| 1647 | |
Alexandre Julliard | 6bb18e2 | 2006-03-27 15:33:43 +0200 | [diff] [blame] | 1648 | mask = get_window_attributes( display, data, &attr ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1649 | |
Alexandre Julliard | ac98e0c | 2007-08-20 22:06:33 +0200 | [diff] [blame] | 1650 | data->whole_rect = data->window_rect; |
Alexandre Julliard | edebc2b | 2009-06-25 12:10:44 +0200 | [diff] [blame] | 1651 | X11DRV_window_to_X_rect( data, &data->whole_rect ); |
| 1652 | if (!(cx = data->whole_rect.right - data->whole_rect.left)) cx = 1; |
| 1653 | else if (cx > 65535) cx = 65535; |
| 1654 | if (!(cy = data->whole_rect.bottom - data->whole_rect.top)) cy = 1; |
| 1655 | else if (cy > 65535) cy = 65535; |
| 1656 | |
| 1657 | wine_tsx11_lock(); |
Alexandre Julliard | a06aeab | 2006-10-26 12:53:59 +0200 | [diff] [blame] | 1658 | data->whole_window = XCreateWindow( display, root_window, |
Alexandre Julliard | edebc2b | 2009-06-25 12:10:44 +0200 | [diff] [blame] | 1659 | data->whole_rect.left - virtual_screen_rect.left, |
| 1660 | data->whole_rect.top - virtual_screen_rect.top, |
Alexandre Julliard | a06aeab | 2006-10-26 12:53:59 +0200 | [diff] [blame] | 1661 | cx, cy, 0, screen_depth, InputOutput, |
| 1662 | visual, mask, &attr ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1663 | |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 1664 | if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd ); |
| 1665 | wine_tsx11_unlock(); |
| 1666 | |
Alexandre Julliard | aa47784 | 2010-02-01 22:35:32 +0100 | [diff] [blame] | 1667 | if (!data->whole_window) goto done; |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 1668 | |
| 1669 | if (!create_client_window( display, data, NULL )) |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 1670 | { |
Alexandre Julliard | 42ad345 | 2008-02-22 10:40:22 +0100 | [diff] [blame] | 1671 | wine_tsx11_lock(); |
| 1672 | XDeleteContext( display, data->whole_window, winContext ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1673 | XDestroyWindow( display, data->whole_window ); |
| 1674 | data->whole_window = 0; |
| 1675 | wine_tsx11_unlock(); |
Alexandre Julliard | aa47784 | 2010-02-01 22:35:32 +0100 | [diff] [blame] | 1676 | goto done; |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1677 | } |
| 1678 | |
Alexandre Julliard | 7d9739e | 2007-08-20 14:04:36 +0200 | [diff] [blame] | 1679 | set_initial_wm_hints( display, data ); |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1680 | set_wm_hints( display, data ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1681 | |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 1682 | SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window ); |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 1683 | |
Alexandre Julliard | 3ba2025 | 2008-01-23 16:32:55 +0100 | [diff] [blame] | 1684 | /* set the window text */ |
| 1685 | if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0; |
| 1686 | sync_window_text( display, data->whole_window, text ); |
| 1687 | |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 1688 | /* set the window region */ |
Alexandre Julliard | 61e50e1 | 2010-05-28 12:14:43 +0200 | [diff] [blame] | 1689 | if (win_rgn || IsRectEmpty( &data->window_rect )) sync_window_region( display, data, win_rgn ); |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 1690 | |
Alexandre Julliard | be3c3a5 | 2008-09-12 15:54:02 +0200 | [diff] [blame] | 1691 | /* set the window opacity */ |
| 1692 | if (!GetLayeredWindowAttributes( data->hwnd, &key, &alpha, &layered_flags )) layered_flags = 0; |
| 1693 | sync_window_opacity( display, data->whole_window, key, alpha, layered_flags ); |
| 1694 | |
Alexandre Julliard | 731d77f | 2008-04-09 20:24:27 +0200 | [diff] [blame] | 1695 | wine_tsx11_lock(); |
| 1696 | XFlush( display ); /* make sure the window exists before we start painting to it */ |
| 1697 | wine_tsx11_unlock(); |
Alexandre Julliard | 1afd0df | 2010-05-10 12:33:59 +0200 | [diff] [blame] | 1698 | |
| 1699 | sync_window_cursor( data ); |
Alexandre Julliard | aa47784 | 2010-02-01 22:35:32 +0100 | [diff] [blame] | 1700 | done: |
| 1701 | if (win_rgn) DeleteObject( win_rgn ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1702 | return data->whole_window; |
| 1703 | } |
| 1704 | |
| 1705 | |
| 1706 | /********************************************************************** |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1707 | * destroy_whole_window |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1708 | * |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1709 | * Destroy the whole X window for a given window. |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1710 | */ |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1711 | 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] | 1712 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1713 | if (!data->whole_window) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1714 | |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1715 | TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1716 | wine_tsx11_lock(); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1717 | XDeleteContext( display, data->whole_window, winContext ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1718 | XDeleteContext( display, data->client_window, winContext ); |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1719 | if (!already_destroyed) XDestroyWindow( display, data->whole_window ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1720 | data->whole_window = data->client_window = 0; |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1721 | data->wm_state = WithdrawnState; |
| 1722 | data->net_wm_state = 0; |
| 1723 | data->mapped = FALSE; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1724 | if (data->xic) |
| 1725 | { |
| 1726 | XUnsetICFocus( data->xic ); |
| 1727 | XDestroyIC( data->xic ); |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1728 | data->xic = 0; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1729 | } |
Alexandre Julliard | 975f1b2 | 2006-05-09 17:32:40 +0200 | [diff] [blame] | 1730 | /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */ |
| 1731 | XFlush( display ); |
Alexandre Julliard | dc07b6f | 2008-01-22 10:17:52 +0100 | [diff] [blame] | 1732 | XFree( data->wm_hints ); |
| 1733 | data->wm_hints = NULL; |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1734 | wine_tsx11_unlock(); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 1735 | RemovePropA( data->hwnd, whole_window_prop ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1736 | RemovePropA( data->hwnd, client_window_prop ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | |
| 1740 | /***************************************************************** |
| 1741 | * SetWindowText (X11DRV.@) |
| 1742 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 1743 | void CDECL X11DRV_SetWindowText( HWND hwnd, LPCWSTR text ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1744 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1745 | Window win; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1746 | |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 1747 | if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(gdi_display)) |
| 1748 | { |
| 1749 | Display *display = thread_init_display(); |
Alexandre Julliard | 3ba2025 | 2008-01-23 16:32:55 +0100 | [diff] [blame] | 1750 | sync_window_text( display, win, text ); |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 1751 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | |
| 1755 | /*********************************************************************** |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1756 | * SetWindowStyle (X11DRV.@) |
| 1757 | * |
| 1758 | * Update the X state of a window to reflect a style change |
| 1759 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 1760 | void CDECL X11DRV_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style ) |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1761 | { |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1762 | struct x11drv_win_data *data; |
Alexandre Julliard | 2f11213 | 2008-09-12 14:55:07 +0200 | [diff] [blame] | 1763 | DWORD changed; |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1764 | |
| 1765 | if (hwnd == GetDesktopWindow()) return; |
Alexandre Julliard | 2f11213 | 2008-09-12 14:55:07 +0200 | [diff] [blame] | 1766 | changed = style->styleNew ^ style->styleOld; |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1767 | |
Alexandre Julliard | 2f11213 | 2008-09-12 14:55:07 +0200 | [diff] [blame] | 1768 | if (offset == GWL_STYLE && (changed & WS_VISIBLE) && (style->styleNew & WS_VISIBLE)) |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1769 | { |
| 1770 | /* we don't unmap windows, that causes trouble with the window manager */ |
| 1771 | if (!(data = X11DRV_get_win_data( hwnd )) && |
| 1772 | !(data = X11DRV_create_win_data( hwnd ))) return; |
| 1773 | |
| 1774 | if (data->whole_window && is_window_rect_mapped( &data->window_rect )) |
| 1775 | { |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 1776 | Display *display = thread_display(); |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1777 | set_wm_hints( display, data ); |
Alexandre Julliard | 2f11213 | 2008-09-12 14:55:07 +0200 | [diff] [blame] | 1778 | if (!data->mapped) map_window( display, data, style->styleNew ); |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1779 | } |
| 1780 | } |
| 1781 | |
Alexandre Julliard | 2f11213 | 2008-09-12 14:55:07 +0200 | [diff] [blame] | 1782 | if (offset == GWL_STYLE && (changed & WS_DISABLED)) |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1783 | { |
| 1784 | data = X11DRV_get_win_data( hwnd ); |
Dmitry Timoshkov | e35e75b | 2010-04-07 15:41:01 +0900 | [diff] [blame] | 1785 | if (data && data->whole_window) |
| 1786 | set_wm_hints( thread_display(), data ); |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1787 | } |
Alexandre Julliard | be3c3a5 | 2008-09-12 15:54:02 +0200 | [diff] [blame] | 1788 | |
| 1789 | if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED)) |
| 1790 | { |
| 1791 | /* changing WS_EX_LAYERED resets attributes */ |
| 1792 | if ((data = X11DRV_get_win_data( hwnd )) && data->whole_window) |
| 1793 | sync_window_opacity( thread_display(), data->whole_window, 0, 0, 0 ); |
| 1794 | } |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | |
| 1798 | /*********************************************************************** |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1799 | * DestroyWindow (X11DRV.@) |
| 1800 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 1801 | void CDECL X11DRV_DestroyWindow( HWND hwnd ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1802 | { |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 1803 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1804 | struct x11drv_win_data *data; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1805 | |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 1806 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1807 | |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 1808 | if (data->pixmap) |
| 1809 | { |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 1810 | wine_tsx11_lock(); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 1811 | destroy_glxpixmap(gdi_display, data->gl_drawable); |
| 1812 | XFreePixmap(gdi_display, data->pixmap); |
Chris Robinson | 37d835b | 2007-09-26 08:17:13 -0700 | [diff] [blame] | 1813 | wine_tsx11_unlock(); |
| 1814 | } |
| 1815 | else if (data->gl_drawable) |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 1816 | { |
| 1817 | wine_tsx11_lock(); |
Alexandre Julliard | 6e9dea8 | 2008-05-12 19:37:54 +0200 | [diff] [blame] | 1818 | XDestroyWindow(gdi_display, data->gl_drawable); |
Chris Robinson | 00633e3 | 2007-09-25 22:43:38 -0700 | [diff] [blame] | 1819 | wine_tsx11_unlock(); |
| 1820 | } |
| 1821 | |
Alexandre Julliard | 06a1407 | 2008-06-26 15:08:08 +0200 | [diff] [blame] | 1822 | destroy_whole_window( thread_data->display, data, FALSE ); |
| 1823 | destroy_icon_window( thread_data->display, data ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1824 | |
Alexandre Julliard | e9307d0 | 2008-02-21 20:23:32 +0100 | [diff] [blame] | 1825 | if (data->colormap) |
| 1826 | { |
| 1827 | wine_tsx11_lock(); |
Alexandre Julliard | 06a1407 | 2008-06-26 15:08:08 +0200 | [diff] [blame] | 1828 | XFreeColormap( thread_data->display, data->colormap ); |
Alexandre Julliard | e9307d0 | 2008-02-21 20:23:32 +0100 | [diff] [blame] | 1829 | wine_tsx11_unlock(); |
| 1830 | } |
| 1831 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1832 | if (thread_data->last_focus == hwnd) thread_data->last_focus = 0; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1833 | if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap ); |
| 1834 | if (data->hWMIconMask) DeleteObject( data->hWMIconMask); |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1835 | wine_tsx11_lock(); |
Alexandre Julliard | 06a1407 | 2008-06-26 15:08:08 +0200 | [diff] [blame] | 1836 | XDeleteContext( thread_data->display, (XID)hwnd, win_data_context ); |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1837 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1838 | HeapFree( GetProcessHeap(), 0, data ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 1842 | /*********************************************************************** |
| 1843 | * X11DRV_DestroyNotify |
| 1844 | */ |
| 1845 | void X11DRV_DestroyNotify( HWND hwnd, XEvent *event ) |
| 1846 | { |
| 1847 | Display *display = event->xdestroywindow.display; |
| 1848 | struct x11drv_win_data *data; |
| 1849 | |
| 1850 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
| 1851 | |
| 1852 | FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window ); |
| 1853 | destroy_whole_window( display, data, TRUE ); |
| 1854 | } |
| 1855 | |
| 1856 | |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1857 | static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd ) |
| 1858 | { |
| 1859 | struct x11drv_win_data *data; |
| 1860 | |
Alexandre Julliard | 30d84fc | 2008-01-22 10:15:38 +0100 | [diff] [blame] | 1861 | if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data)))) |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1862 | { |
Alexandre Julliard | 30d84fc | 2008-01-22 10:15:38 +0100 | [diff] [blame] | 1863 | data->hwnd = hwnd; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1864 | wine_tsx11_lock(); |
| 1865 | if (!winContext) winContext = XUniqueContext(); |
| 1866 | if (!win_data_context) win_data_context = XUniqueContext(); |
| 1867 | XSaveContext( display, (XID)hwnd, win_data_context, (char *)data ); |
| 1868 | wine_tsx11_unlock(); |
| 1869 | } |
| 1870 | return data; |
| 1871 | } |
| 1872 | |
| 1873 | |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1874 | /* initialize the desktop window id in the desktop manager process */ |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1875 | 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] | 1876 | { |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1877 | struct x11drv_win_data *data; |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 1878 | |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1879 | if (!(data = alloc_win_data( display, hwnd ))) return NULL; |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1880 | data->whole_window = data->client_window = root_window; |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1881 | data->managed = TRUE; |
| 1882 | SetPropA( data->hwnd, managed_prop, (HANDLE)1 ); |
| 1883 | SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window ); |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1884 | SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window ); |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1885 | set_initial_wm_hints( display, data ); |
| 1886 | return data; |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1889 | /********************************************************************** |
| 1890 | * CreateDesktopWindow (X11DRV.@) |
| 1891 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 1892 | BOOL CDECL X11DRV_CreateDesktopWindow( HWND hwnd ) |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1893 | { |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1894 | unsigned int width, height; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1895 | |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1896 | /* retrieve the real size of the desktop */ |
| 1897 | SERVER_START_REQ( get_window_rectangles ) |
| 1898 | { |
Alexandre Julliard | 7fdadbb | 2008-12-08 16:58:20 +0100 | [diff] [blame] | 1899 | req->handle = wine_server_user_handle( hwnd ); |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1900 | wine_server_call( req ); |
| 1901 | width = reply->window.right - reply->window.left; |
| 1902 | height = reply->window.bottom - reply->window.top; |
| 1903 | } |
| 1904 | SERVER_END_REQ; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1905 | |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1906 | if (!width && !height) /* not initialized yet */ |
| 1907 | { |
| 1908 | SERVER_START_REQ( set_window_pos ) |
| 1909 | { |
Alexandre Julliard | 7fdadbb | 2008-12-08 16:58:20 +0100 | [diff] [blame] | 1910 | req->handle = wine_server_user_handle( hwnd ); |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 1911 | req->previous = 0; |
| 1912 | req->flags = SWP_NOZORDER; |
| 1913 | req->window.left = virtual_screen_rect.left; |
| 1914 | req->window.top = virtual_screen_rect.top; |
| 1915 | req->window.right = virtual_screen_rect.right; |
| 1916 | req->window.bottom = virtual_screen_rect.bottom; |
| 1917 | req->client = req->window; |
| 1918 | wine_server_call( req ); |
| 1919 | } |
| 1920 | SERVER_END_REQ; |
| 1921 | } |
| 1922 | else |
| 1923 | { |
| 1924 | Window win = (Window)GetPropA( hwnd, whole_window_prop ); |
| 1925 | if (win && win != root_window) X11DRV_init_desktop( win, width, height ); |
| 1926 | } |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1927 | return TRUE; |
| 1928 | } |
| 1929 | |
| 1930 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1931 | /********************************************************************** |
| 1932 | * CreateWindow (X11DRV.@) |
| 1933 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 1934 | BOOL CDECL X11DRV_CreateWindow( HWND hwnd ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1935 | { |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 1936 | if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( gdi_display )) |
Alexandre Julliard | b6cc7f9 | 2008-01-24 10:20:11 +0100 | [diff] [blame] | 1937 | { |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 1938 | Display *display = thread_init_display(); |
| 1939 | |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1940 | /* the desktop win data can't be created lazily */ |
| 1941 | if (!create_desktop_win_data( display, hwnd )) return FALSE; |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 1942 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1943 | return TRUE; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | |
| 1947 | /*********************************************************************** |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1948 | * X11DRV_get_win_data |
| 1949 | * |
| 1950 | * Return the X11 data structure associated with a window. |
| 1951 | */ |
| 1952 | struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd ) |
| 1953 | { |
Alexandre Julliard | 06a1407 | 2008-06-26 15:08:08 +0200 | [diff] [blame] | 1954 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1955 | char *data; |
Alexandre Julliard | e551555 | 2005-02-09 14:01:40 +0000 | [diff] [blame] | 1956 | |
Alexandre Julliard | 06a1407 | 2008-06-26 15:08:08 +0200 | [diff] [blame] | 1957 | if (!thread_data) return NULL; |
| 1958 | if (!hwnd) return NULL; |
| 1959 | if (XFindContext( thread_data->display, (XID)hwnd, win_data_context, &data )) data = NULL; |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1960 | return (struct x11drv_win_data *)data; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | |
| 1964 | /*********************************************************************** |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1965 | * X11DRV_create_win_data |
| 1966 | * |
| 1967 | * Create an X11 data window structure for an existing window. |
| 1968 | */ |
| 1969 | struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd ) |
| 1970 | { |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 1971 | Display *display; |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1972 | struct x11drv_win_data *data; |
| 1973 | HWND parent; |
| 1974 | |
| 1975 | if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */ |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 1976 | |
Alexandre Julliard | 93a02e7 | 2008-06-26 16:49:09 +0200 | [diff] [blame] | 1977 | /* don't create win data for HWND_MESSAGE windows */ |
| 1978 | if (parent != GetDesktopWindow() && !GetAncestor( parent, GA_PARENT )) return NULL; |
| 1979 | |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 1980 | display = thread_init_display(); |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 1981 | if (!(data = alloc_win_data( display, hwnd ))) return NULL; |
| 1982 | |
| 1983 | GetWindowRect( hwnd, &data->window_rect ); |
| 1984 | MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 ); |
| 1985 | data->whole_rect = data->window_rect; |
| 1986 | GetClientRect( hwnd, &data->client_rect ); |
| 1987 | MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 ); |
| 1988 | |
| 1989 | if (parent == GetDesktopWindow()) |
| 1990 | { |
| 1991 | if (!create_whole_window( display, data )) |
| 1992 | { |
| 1993 | HeapFree( GetProcessHeap(), 0, data ); |
| 1994 | return NULL; |
| 1995 | } |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 1996 | TRACE( "win %p/%lx/%lx window %s whole %s client %s\n", |
| 1997 | 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] | 1998 | wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect )); |
| 1999 | } |
Alexandre Julliard | 026974f | 2008-01-24 10:20:51 +0100 | [diff] [blame] | 2000 | return data; |
| 2001 | } |
| 2002 | |
| 2003 | |
| 2004 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 2005 | * X11DRV_get_whole_window |
| 2006 | * |
| 2007 | * Return the X window associated with the full area of a window |
| 2008 | */ |
| 2009 | Window X11DRV_get_whole_window( HWND hwnd ) |
| 2010 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 2011 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 2012 | |
Alexandre Julliard | c19af91 | 2008-01-17 19:53:59 +0100 | [diff] [blame] | 2013 | if (!data) |
| 2014 | { |
| 2015 | if (hwnd == GetDesktopWindow()) return root_window; |
| 2016 | return (Window)GetPropA( hwnd, whole_window_prop ); |
| 2017 | } |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 2018 | return data->whole_window; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 2022 | /*********************************************************************** |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 2023 | * X11DRV_get_client_window |
| 2024 | * |
| 2025 | * Return the X window associated with the client area of a window |
| 2026 | */ |
Andrew Talbot | f63ceec | 2009-01-29 21:40:50 +0000 | [diff] [blame] | 2027 | static Window X11DRV_get_client_window( HWND hwnd ) |
Alexandre Julliard | 8ee07d4 | 2008-02-21 12:29:36 +0100 | [diff] [blame] | 2028 | { |
| 2029 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
| 2030 | |
| 2031 | if (!data) |
| 2032 | { |
| 2033 | if (hwnd == GetDesktopWindow()) return root_window; |
| 2034 | return (Window)GetPropA( hwnd, client_window_prop ); |
| 2035 | } |
| 2036 | return data->client_window; |
| 2037 | } |
| 2038 | |
| 2039 | |
| 2040 | /*********************************************************************** |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 2041 | * X11DRV_get_ic |
| 2042 | * |
| 2043 | * Return the X input context associated with a window |
| 2044 | */ |
| 2045 | XIC X11DRV_get_ic( HWND hwnd ) |
| 2046 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 2047 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Kusanagi Kouichi | 185157c | 2008-04-04 20:44:36 +0900 | [diff] [blame] | 2048 | XIM xim; |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 2049 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 2050 | if (!data) return 0; |
Kusanagi Kouichi | 185157c | 2008-04-04 20:44:36 +0900 | [diff] [blame] | 2051 | if (data->xic) return data->xic; |
| 2052 | if (!(xim = x11drv_thread_data()->xim)) return 0; |
| 2053 | return X11DRV_CreateIC( xim, data ); |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 2057 | /*********************************************************************** |
| 2058 | * X11DRV_GetDC (X11DRV.@) |
| 2059 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2060 | void CDECL X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect, |
| 2061 | const RECT *top_rect, DWORD flags ) |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 2062 | { |
| 2063 | struct x11drv_escape_set_drawable escape; |
| 2064 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
| 2065 | |
| 2066 | escape.code = X11DRV_SET_DRAWABLE; |
| 2067 | escape.mode = IncludeInferiors; |
| 2068 | escape.fbconfig_id = 0; |
| 2069 | escape.gl_drawable = 0; |
| 2070 | escape.pixmap = 0; |
Alexandre Julliard | 2d9b381 | 2008-05-28 17:52:06 +0200 | [diff] [blame] | 2071 | escape.gl_copy = FALSE; |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 2072 | |
Henri Verbeet | 3255b21 | 2010-04-11 21:47:49 +0200 | [diff] [blame] | 2073 | if (top == hwnd) |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 2074 | { |
Alexandre Julliard | 2d9b381 | 2008-05-28 17:52:06 +0200 | [diff] [blame] | 2075 | escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop ); |
| 2076 | /* GL draws to the client area even for window DCs */ |
| 2077 | escape.gl_drawable = data ? data->client_window : X11DRV_get_client_window( hwnd ); |
Henri Verbeet | 3255b21 | 2010-04-11 21:47:49 +0200 | [diff] [blame] | 2078 | if (data && IsIconic( hwnd ) && data->icon_window) |
| 2079 | { |
| 2080 | escape.drawable = data->icon_window; |
| 2081 | } |
| 2082 | else if (flags & DCX_WINDOW) |
Alexandre Julliard | 2d9b381 | 2008-05-28 17:52:06 +0200 | [diff] [blame] | 2083 | escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd ); |
| 2084 | else |
| 2085 | escape.drawable = escape.gl_drawable; |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 2086 | } |
| 2087 | else |
| 2088 | { |
| 2089 | escape.drawable = X11DRV_get_client_window( top ); |
| 2090 | escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop ); |
| 2091 | escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop ); |
| 2092 | escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop ); |
Alexandre Julliard | 2d9b381 | 2008-05-28 17:52:06 +0200 | [diff] [blame] | 2093 | escape.gl_copy = (escape.gl_drawable != 0); |
Alexandre Julliard | af36910 | 2008-03-18 12:42:25 +0100 | [diff] [blame] | 2094 | if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren; |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | escape.dc_rect.left = win_rect->left - top_rect->left; |
| 2098 | escape.dc_rect.top = win_rect->top - top_rect->top; |
| 2099 | escape.dc_rect.right = win_rect->right - top_rect->left; |
| 2100 | escape.dc_rect.bottom = win_rect->bottom - top_rect->top; |
| 2101 | escape.drawable_rect.left = top_rect->left; |
| 2102 | escape.drawable_rect.top = top_rect->top; |
| 2103 | escape.drawable_rect.right = top_rect->right; |
| 2104 | escape.drawable_rect.bottom = top_rect->bottom; |
| 2105 | |
| 2106 | ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL ); |
| 2107 | } |
| 2108 | |
| 2109 | |
| 2110 | /*********************************************************************** |
| 2111 | * X11DRV_ReleaseDC (X11DRV.@) |
| 2112 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2113 | void CDECL X11DRV_ReleaseDC( HWND hwnd, HDC hdc ) |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 2114 | { |
| 2115 | struct x11drv_escape_set_drawable escape; |
| 2116 | |
| 2117 | escape.code = X11DRV_SET_DRAWABLE; |
| 2118 | escape.drawable = root_window; |
| 2119 | escape.mode = IncludeInferiors; |
| 2120 | escape.drawable_rect = virtual_screen_rect; |
| 2121 | SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left, |
| 2122 | virtual_screen_rect.bottom - virtual_screen_rect.top ); |
Alexandre Julliard | bcf88b5 | 2010-02-16 12:37:42 +0100 | [diff] [blame] | 2123 | OffsetRect( &escape.dc_rect, -escape.drawable_rect.left, -escape.drawable_rect.top ); |
Alexandre Julliard | 1642fbc | 2008-02-25 15:59:19 +0100 | [diff] [blame] | 2124 | escape.fbconfig_id = 0; |
| 2125 | escape.gl_drawable = 0; |
| 2126 | escape.pixmap = 0; |
| 2127 | ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL ); |
| 2128 | } |
| 2129 | |
| 2130 | |
Alexandre Julliard | dc26f27 | 2008-03-12 15:01:24 +0100 | [diff] [blame] | 2131 | /*********************************************************************** |
| 2132 | * SetCapture (X11DRV.@) |
| 2133 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2134 | void CDECL X11DRV_SetCapture( HWND hwnd, UINT flags ) |
Alexandre Julliard | dc26f27 | 2008-03-12 15:01:24 +0100 | [diff] [blame] | 2135 | { |
| 2136 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
| 2137 | |
Alexandre Julliard | 06a1407 | 2008-06-26 15:08:08 +0200 | [diff] [blame] | 2138 | if (!thread_data) return; |
Alexandre Julliard | 78de7e3 | 2008-03-24 17:59:40 +0100 | [diff] [blame] | 2139 | if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return; |
Alexandre Julliard | dc26f27 | 2008-03-12 15:01:24 +0100 | [diff] [blame] | 2140 | |
| 2141 | if (hwnd) |
| 2142 | { |
| 2143 | Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) ); |
| 2144 | |
| 2145 | if (!grab_win) return; |
| 2146 | wine_tsx11_lock(); |
| 2147 | XFlush( gdi_display ); |
| 2148 | XGrabPointer( thread_data->display, grab_win, False, |
| 2149 | PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
Alexandre Julliard | 78de7e3 | 2008-03-24 17:59:40 +0100 | [diff] [blame] | 2150 | GrabModeAsync, GrabModeAsync, None, None, CurrentTime ); |
Alexandre Julliard | dc26f27 | 2008-03-12 15:01:24 +0100 | [diff] [blame] | 2151 | wine_tsx11_unlock(); |
| 2152 | thread_data->grab_window = grab_win; |
| 2153 | } |
| 2154 | else /* release capture */ |
| 2155 | { |
| 2156 | wine_tsx11_lock(); |
| 2157 | XFlush( gdi_display ); |
| 2158 | XUngrabPointer( thread_data->display, CurrentTime ); |
Alexandre Julliard | 95cf00f | 2009-01-26 15:12:55 +0100 | [diff] [blame] | 2159 | XFlush( thread_data->display ); |
Alexandre Julliard | dc26f27 | 2008-03-12 15:01:24 +0100 | [diff] [blame] | 2160 | wine_tsx11_unlock(); |
| 2161 | thread_data->grab_window = None; |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2166 | /***************************************************************** |
| 2167 | * SetParent (X11DRV.@) |
| 2168 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2169 | void CDECL X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2170 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 2171 | Display *display = thread_display(); |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2172 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2173 | |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2174 | if (!data) return; |
| 2175 | if (parent == old_parent) return; |
Alexandre Julliard | fb0ff05 | 2001-10-16 21:58:58 +0000 | [diff] [blame] | 2176 | |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2177 | if (parent != GetDesktopWindow()) /* a child window */ |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 2178 | { |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2179 | if (old_parent == GetDesktopWindow()) |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 2180 | { |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2181 | /* destroy the old X windows */ |
Alexandre Julliard | 3b6f95c | 2008-03-05 16:51:09 +0100 | [diff] [blame] | 2182 | destroy_whole_window( display, data, FALSE ); |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2183 | destroy_icon_window( display, data ); |
| 2184 | if (data->managed) |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 2185 | { |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2186 | data->managed = FALSE; |
| 2187 | RemovePropA( data->hwnd, managed_prop ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 2188 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2189 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2190 | } |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2191 | else /* new top level window */ |
| 2192 | { |
| 2193 | /* FIXME: we ignore errors since we can't really recover anyway */ |
Alexandre Julliard | d147e02 | 2008-01-23 21:39:32 +0100 | [diff] [blame] | 2194 | create_whole_window( display, data ); |
Pierre d'Herbemont | 221b044 | 2006-12-10 23:21:28 +0100 | [diff] [blame] | 2195 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2199 | /***************************************************************** |
| 2200 | * SetFocus (X11DRV.@) |
| 2201 | * |
| 2202 | * Set the X focus. |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2203 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2204 | void CDECL X11DRV_SetFocus( HWND hwnd ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2205 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 2206 | Display *display = thread_display(); |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 2207 | struct x11drv_win_data *data; |
Alexandre Julliard | 125793d | 2008-02-18 17:22:51 +0100 | [diff] [blame] | 2208 | XWindowChanges changes; |
Vincent Povirk | e4a50e1 | 2010-03-17 12:29:23 -0500 | [diff] [blame] | 2209 | DWORD timestamp; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2210 | |
Alexandre Julliard | 9d53a1a | 2008-06-26 16:21:32 +0200 | [diff] [blame] | 2211 | if (!(hwnd = GetAncestor( hwnd, GA_ROOT ))) return; |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 2212 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Todd Mokros | 88ac4b9 | 2005-08-22 09:14:21 +0000 | [diff] [blame] | 2213 | if (data->managed || !data->whole_window) return; |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 2214 | |
Vincent Povirk | e4a50e1 | 2010-03-17 12:29:23 -0500 | [diff] [blame] | 2215 | if (EVENT_x11_time_to_win32_time(0)) |
| 2216 | /* ICCCM says don't use CurrentTime, so try to use last message time if possible */ |
| 2217 | /* FIXME: this is not entirely correct */ |
| 2218 | timestamp = GetMessageTime() - EVENT_x11_time_to_win32_time(0); |
| 2219 | else |
| 2220 | timestamp = CurrentTime; |
| 2221 | |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 2222 | /* Set X focus and install colormap */ |
| 2223 | wine_tsx11_lock(); |
Alexandre Julliard | 125793d | 2008-02-18 17:22:51 +0100 | [diff] [blame] | 2224 | changes.stack_mode = Above; |
| 2225 | XConfigureWindow( display, data->whole_window, CWStackMode, &changes ); |
Vincent Povirk | e4a50e1 | 2010-03-17 12:29:23 -0500 | [diff] [blame] | 2226 | XSetInputFocus( display, data->whole_window, RevertToParent, timestamp ); |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 2227 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2231 | /*********************************************************************** |
Alexandre Julliard | 89a3bd0 | 2008-07-02 15:40:10 +0200 | [diff] [blame] | 2232 | * WindowPosChanging (X11DRV.@) |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2233 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2234 | void CDECL X11DRV_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags, |
| 2235 | const RECT *window_rect, const RECT *client_rect, RECT *visible_rect ) |
Alexandre Julliard | 89a3bd0 | 2008-07-02 15:40:10 +0200 | [diff] [blame] | 2236 | { |
| 2237 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
| 2238 | DWORD style = GetWindowLongW( hwnd, GWL_STYLE ); |
| 2239 | |
| 2240 | if (!data) |
| 2241 | { |
| 2242 | /* create the win data if the window is being made visible */ |
| 2243 | if (!(style & WS_VISIBLE) && !(swp_flags & SWP_SHOWWINDOW)) return; |
| 2244 | if (!(data = X11DRV_create_win_data( hwnd ))) return; |
| 2245 | } |
| 2246 | |
| 2247 | /* check if we need to switch the window to managed */ |
| 2248 | if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, window_rect )) |
| 2249 | { |
| 2250 | TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window ); |
| 2251 | if (data->mapped) unmap_window( thread_display(), data ); |
| 2252 | data->managed = TRUE; |
| 2253 | SetPropA( hwnd, managed_prop, (HANDLE)1 ); |
| 2254 | } |
| 2255 | |
| 2256 | *visible_rect = *window_rect; |
| 2257 | X11DRV_window_to_X_rect( data, visible_rect ); |
| 2258 | } |
| 2259 | |
| 2260 | |
| 2261 | /*********************************************************************** |
| 2262 | * WindowPosChanged (X11DRV.@) |
| 2263 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2264 | void CDECL X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags, |
| 2265 | const RECT *rectWindow, const RECT *rectClient, |
| 2266 | const RECT *visible_rect, const RECT *valid_rects ) |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2267 | { |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 2268 | struct x11drv_thread_data *thread_data; |
| 2269 | Display *display; |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2270 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
| 2271 | DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE ); |
Alexandre Julliard | 08b8325 | 2010-02-08 17:14:01 +0100 | [diff] [blame] | 2272 | RECT old_window_rect, old_whole_rect, old_client_rect; |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2273 | int event_type; |
| 2274 | |
Alexandre Julliard | 89a3bd0 | 2008-07-02 15:40:10 +0200 | [diff] [blame] | 2275 | if (!data) return; |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2276 | |
Alexandre Julliard | e7044cb | 2008-06-26 16:47:42 +0200 | [diff] [blame] | 2277 | thread_data = x11drv_thread_data(); |
| 2278 | display = thread_data->display; |
| 2279 | |
Alexandre Julliard | 08b8325 | 2010-02-08 17:14:01 +0100 | [diff] [blame] | 2280 | old_window_rect = data->window_rect; |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2281 | old_whole_rect = data->whole_rect; |
| 2282 | old_client_rect = data->client_rect; |
| 2283 | data->window_rect = *rectWindow; |
Alexandre Julliard | 89a3bd0 | 2008-07-02 15:40:10 +0200 | [diff] [blame] | 2284 | data->whole_rect = *visible_rect; |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2285 | data->client_rect = *rectClient; |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2286 | |
| 2287 | TRACE( "win %p window %s client %s style %08x flags %08x\n", |
| 2288 | hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags ); |
| 2289 | |
| 2290 | if (!IsRectEmpty( &valid_rects[0] )) |
| 2291 | { |
| 2292 | int x_offset = old_whole_rect.left - data->whole_rect.left; |
| 2293 | int y_offset = old_whole_rect.top - data->whole_rect.top; |
| 2294 | |
| 2295 | /* if all that happened is that the whole window moved, copy everything */ |
| 2296 | if (!(swp_flags & SWP_FRAMECHANGED) && |
| 2297 | old_whole_rect.right - data->whole_rect.right == x_offset && |
| 2298 | old_whole_rect.bottom - data->whole_rect.bottom == y_offset && |
| 2299 | old_client_rect.left - data->client_rect.left == x_offset && |
| 2300 | old_client_rect.right - data->client_rect.right == x_offset && |
| 2301 | old_client_rect.top - data->client_rect.top == y_offset && |
| 2302 | old_client_rect.bottom - data->client_rect.bottom == y_offset && |
| 2303 | !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) )) |
| 2304 | { |
| 2305 | /* if we have an X window the bits will be moved by the X server */ |
| 2306 | if (!data->whole_window) |
| 2307 | move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect ); |
| 2308 | } |
| 2309 | else |
| 2310 | move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect ); |
| 2311 | } |
| 2312 | |
| 2313 | wine_tsx11_lock(); |
| 2314 | XFlush( gdi_display ); /* make sure painting is done before we move the window */ |
| 2315 | wine_tsx11_unlock(); |
| 2316 | |
| 2317 | sync_client_position( display, data, swp_flags, &old_client_rect, &old_whole_rect ); |
| 2318 | |
| 2319 | if (!data->whole_window) return; |
| 2320 | |
| 2321 | /* check if we are currently processing an event relevant to this window */ |
| 2322 | event_type = 0; |
| 2323 | if (thread_data->current_event && thread_data->current_event->xany.window == data->whole_window) |
| 2324 | event_type = thread_data->current_event->type; |
| 2325 | |
| 2326 | if (event_type != ConfigureNotify && event_type != PropertyNotify) |
| 2327 | event_type = 0; /* ignore other events */ |
| 2328 | |
Alexandre Julliard | 6b9517a | 2008-05-01 17:45:17 +0200 | [diff] [blame] | 2329 | if (data->mapped) |
| 2330 | { |
| 2331 | if (((swp_flags & SWP_HIDEWINDOW) && !(new_style & WS_VISIBLE)) || |
Alexandre Julliard | 2db72e9 | 2010-05-28 12:16:17 +0200 | [diff] [blame^] | 2332 | (event_type != ConfigureNotify && |
| 2333 | !is_window_rect_mapped( rectWindow ) && is_window_rect_mapped( &old_window_rect ))) |
Alexandre Julliard | 6b9517a | 2008-05-01 17:45:17 +0200 | [diff] [blame] | 2334 | unmap_window( display, data ); |
| 2335 | } |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2336 | |
| 2337 | /* don't change position if we are about to minimize or maximize a managed window */ |
| 2338 | if (!event_type && |
| 2339 | !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE)))) |
Alexandre Julliard | 08b8325 | 2010-02-08 17:14:01 +0100 | [diff] [blame] | 2340 | sync_window_position( display, data, swp_flags, |
| 2341 | &old_window_rect, &old_whole_rect, &old_client_rect ); |
Alexandre Julliard | 855308f | 2008-04-23 15:32:58 +0200 | [diff] [blame] | 2342 | |
| 2343 | if ((new_style & WS_VISIBLE) && |
| 2344 | ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow ))) |
| 2345 | { |
| 2346 | if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED))) |
| 2347 | set_wm_hints( display, data ); |
| 2348 | |
| 2349 | if (!data->mapped) |
| 2350 | { |
| 2351 | map_window( display, data, new_style ); |
| 2352 | } |
| 2353 | else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE))) |
| 2354 | { |
| 2355 | data->iconic = (new_style & WS_MINIMIZE) != 0; |
| 2356 | TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic ); |
| 2357 | wine_tsx11_lock(); |
| 2358 | if (data->iconic) |
| 2359 | XIconifyWindow( display, data->whole_window, DefaultScreen(display) ); |
| 2360 | else if (is_window_rect_mapped( rectWindow )) |
| 2361 | XMapWindow( display, data->whole_window ); |
| 2362 | wine_tsx11_unlock(); |
| 2363 | update_net_wm_states( display, data ); |
| 2364 | } |
| 2365 | else if (!event_type) |
| 2366 | { |
| 2367 | update_net_wm_states( display, data ); |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | wine_tsx11_lock(); |
| 2372 | XFlush( display ); /* make sure changes are done before we start painting again */ |
| 2373 | wine_tsx11_unlock(); |
| 2374 | } |
| 2375 | |
| 2376 | |
Alexandre Julliard | 31b4061 | 2008-07-31 11:40:49 +0200 | [diff] [blame] | 2377 | /*********************************************************************** |
| 2378 | * ShowWindow (X11DRV.@) |
| 2379 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2380 | UINT CDECL X11DRV_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp ) |
Alexandre Julliard | 31b4061 | 2008-07-31 11:40:49 +0200 | [diff] [blame] | 2381 | { |
| 2382 | int x, y; |
| 2383 | unsigned int width, height, border, depth; |
| 2384 | Window root, top; |
| 2385 | DWORD style = GetWindowLongW( hwnd, GWL_STYLE ); |
| 2386 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
| 2387 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
| 2388 | |
| 2389 | if (!data || !data->whole_window || !data->managed || !data->mapped || data->iconic) return swp; |
| 2390 | if (style & WS_MINIMIZE) return swp; |
Alexandre Julliard | 3cb23d3 | 2008-09-17 21:13:11 +0200 | [diff] [blame] | 2391 | if (IsRectEmpty( rect )) return swp; |
Alexandre Julliard | 31b4061 | 2008-07-31 11:40:49 +0200 | [diff] [blame] | 2392 | |
| 2393 | /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */ |
| 2394 | |
| 2395 | if (!thread_data->current_event || thread_data->current_event->xany.window != data->whole_window) |
| 2396 | return swp; |
| 2397 | |
| 2398 | if (thread_data->current_event->type != ConfigureNotify && |
| 2399 | thread_data->current_event->type != PropertyNotify) |
| 2400 | return swp; |
| 2401 | |
| 2402 | TRACE( "win %p/%lx cmd %d at %s flags %08x\n", |
| 2403 | hwnd, data->whole_window, cmd, wine_dbgstr_rect(rect), swp ); |
| 2404 | |
| 2405 | wine_tsx11_lock(); |
| 2406 | XGetGeometry( thread_data->display, data->whole_window, |
| 2407 | &root, &x, &y, &width, &height, &border, &depth ); |
| 2408 | XTranslateCoordinates( thread_data->display, data->whole_window, root, 0, 0, &x, &y, &top ); |
| 2409 | wine_tsx11_unlock(); |
| 2410 | rect->left = x; |
| 2411 | rect->top = y; |
| 2412 | rect->right = x + width; |
| 2413 | rect->bottom = y + height; |
| 2414 | OffsetRect( rect, virtual_screen_rect.left, virtual_screen_rect.top ); |
| 2415 | X11DRV_X_to_window_rect( data, rect ); |
| 2416 | return swp & ~(SWP_NOMOVE | SWP_NOCLIENTMOVE | SWP_NOSIZE | SWP_NOCLIENTSIZE); |
| 2417 | } |
| 2418 | |
| 2419 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2420 | /********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 2421 | * SetWindowIcon (X11DRV.@) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2422 | * |
| 2423 | * hIcon or hIconSm has changed (or is being initialised for the |
| 2424 | * first time). Complete the X11 driver-specific initialisation |
| 2425 | * and set the window hints. |
| 2426 | * |
| 2427 | * This is not entirely correct, may need to create |
| 2428 | * an icon window and set the pixmap as a background |
| 2429 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2430 | void CDECL X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2431 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 2432 | Display *display = thread_display(); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 2433 | struct x11drv_win_data *data; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2434 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2435 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 2436 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 2437 | if (!data->whole_window) return; |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 2438 | if (!data->managed) return; |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 2439 | |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 2440 | if (data->wm_hints) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2441 | { |
Alexandre Julliard | a551dfe | 2010-04-19 17:51:44 +0200 | [diff] [blame] | 2442 | if (type == ICON_BIG) set_icon_hints( display, data, icon, 0 ); |
| 2443 | else set_icon_hints( display, data, 0, icon ); |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 2444 | wine_tsx11_lock(); |
Alexandre Julliard | bde8957 | 2007-08-16 23:27:37 +0200 | [diff] [blame] | 2445 | XSetWMHints( display, data->whole_window, data->wm_hints ); |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 2446 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2447 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 2448 | } |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 2449 | |
| 2450 | |
| 2451 | /*********************************************************************** |
| 2452 | * SetWindowRgn (X11DRV.@) |
| 2453 | * |
| 2454 | * Assign specified region to window (for non-rectangular windows) |
| 2455 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2456 | int CDECL X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw ) |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 2457 | { |
| 2458 | struct x11drv_win_data *data; |
| 2459 | |
| 2460 | if ((data = X11DRV_get_win_data( hwnd ))) |
| 2461 | { |
| 2462 | sync_window_region( thread_display(), data, hrgn ); |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 2463 | } |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 2464 | else if (X11DRV_get_whole_window( hwnd )) |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 2465 | { |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 2466 | SendMessageW( hwnd, WM_X11DRV_SET_WIN_REGION, 0, 0 ); |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 2467 | } |
Alexandre Julliard | 395928d | 2008-01-23 16:30:18 +0100 | [diff] [blame] | 2468 | return TRUE; |
| 2469 | } |
Alexandre Julliard | 24dbaa0 | 2008-04-17 16:13:34 +0200 | [diff] [blame] | 2470 | |
| 2471 | |
Alexandre Julliard | be3c3a5 | 2008-09-12 15:54:02 +0200 | [diff] [blame] | 2472 | /*********************************************************************** |
| 2473 | * SetLayeredWindowAttributes (X11DRV.@) |
| 2474 | * |
| 2475 | * Set transparency attributes for a layered window. |
| 2476 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2477 | void CDECL X11DRV_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags ) |
Alexandre Julliard | be3c3a5 | 2008-09-12 15:54:02 +0200 | [diff] [blame] | 2478 | { |
Alexandre Julliard | fb84ba5 | 2008-09-22 12:52:53 +0200 | [diff] [blame] | 2479 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Alexandre Julliard | be3c3a5 | 2008-09-12 15:54:02 +0200 | [diff] [blame] | 2480 | |
Alexandre Julliard | fb84ba5 | 2008-09-22 12:52:53 +0200 | [diff] [blame] | 2481 | if (data) |
| 2482 | { |
| 2483 | if (data->whole_window) |
| 2484 | sync_window_opacity( thread_display(), data->whole_window, key, alpha, flags ); |
| 2485 | } |
| 2486 | else |
| 2487 | { |
| 2488 | Window win = X11DRV_get_whole_window( hwnd ); |
| 2489 | if (win) sync_window_opacity( gdi_display, win, key, alpha, flags ); |
| 2490 | } |
Alexandre Julliard | be3c3a5 | 2008-09-12 15:54:02 +0200 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | |
Alexandre Julliard | 370368a | 2008-09-08 15:42:24 +0200 | [diff] [blame] | 2494 | /********************************************************************** |
| 2495 | * X11DRV_WindowMessage (X11DRV.@) |
| 2496 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2497 | LRESULT CDECL X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp ) |
Alexandre Julliard | 370368a | 2008-09-08 15:42:24 +0200 | [diff] [blame] | 2498 | { |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 2499 | struct x11drv_win_data *data; |
| 2500 | |
Alexandre Julliard | 370368a | 2008-09-08 15:42:24 +0200 | [diff] [blame] | 2501 | switch(msg) |
| 2502 | { |
| 2503 | case WM_X11DRV_ACQUIRE_SELECTION: |
| 2504 | return X11DRV_AcquireClipboard( hwnd ); |
Alexandre Julliard | 370368a | 2008-09-08 15:42:24 +0200 | [diff] [blame] | 2505 | case WM_X11DRV_SET_WIN_FORMAT: |
| 2506 | return set_win_format( hwnd, (XID)wp ); |
Alexandre Julliard | 9d45cfd | 2008-09-08 15:51:08 +0200 | [diff] [blame] | 2507 | case WM_X11DRV_SET_WIN_REGION: |
| 2508 | if ((data = X11DRV_get_win_data( hwnd ))) sync_window_region( thread_display(), data, (HRGN)1 ); |
| 2509 | return 0; |
Alexandre Julliard | 370368a | 2008-09-08 15:42:24 +0200 | [diff] [blame] | 2510 | case WM_X11DRV_RESIZE_DESKTOP: |
| 2511 | X11DRV_resize_desktop( LOWORD(lp), HIWORD(lp) ); |
| 2512 | return 0; |
Alexandre Julliard | 6551553 | 2010-04-28 19:23:05 -0500 | [diff] [blame] | 2513 | case WM_X11DRV_SET_CURSOR: |
| 2514 | set_window_cursor( hwnd, (HCURSOR)lp ); |
| 2515 | return 0; |
Alexandre Julliard | 370368a | 2008-09-08 15:42:24 +0200 | [diff] [blame] | 2516 | default: |
| 2517 | FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, wp, lp ); |
| 2518 | return 0; |
| 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | |
Alexandre Julliard | 24dbaa0 | 2008-04-17 16:13:34 +0200 | [diff] [blame] | 2523 | /*********************************************************************** |
| 2524 | * is_netwm_supported |
| 2525 | */ |
| 2526 | static BOOL is_netwm_supported( Display *display, Atom atom ) |
| 2527 | { |
| 2528 | static Atom *net_supported; |
| 2529 | static int net_supported_count = -1; |
| 2530 | int i; |
| 2531 | |
| 2532 | wine_tsx11_lock(); |
| 2533 | if (net_supported_count == -1) |
| 2534 | { |
| 2535 | Atom type; |
| 2536 | int format; |
| 2537 | unsigned long count, remaining; |
| 2538 | |
| 2539 | if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0, |
| 2540 | ~0UL, False, XA_ATOM, &type, &format, &count, |
| 2541 | &remaining, (unsigned char **)&net_supported )) |
| 2542 | net_supported_count = get_property_size( format, count ) / sizeof(Atom); |
| 2543 | else |
| 2544 | net_supported_count = 0; |
| 2545 | } |
| 2546 | wine_tsx11_unlock(); |
| 2547 | |
| 2548 | for (i = 0; i < net_supported_count; i++) |
| 2549 | if (net_supported[i] == atom) return TRUE; |
| 2550 | return FALSE; |
| 2551 | } |
| 2552 | |
| 2553 | |
| 2554 | /*********************************************************************** |
| 2555 | * SysCommand (X11DRV.@) |
| 2556 | * |
| 2557 | * Perform WM_SYSCOMMAND handling. |
| 2558 | */ |
Maarten Lankhorst | 0a64595 | 2008-12-16 15:32:08 +0100 | [diff] [blame] | 2559 | LRESULT CDECL X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam ) |
Alexandre Julliard | 24dbaa0 | 2008-04-17 16:13:34 +0200 | [diff] [blame] | 2560 | { |
| 2561 | WPARAM hittest = wparam & 0x0f; |
| 2562 | DWORD dwPoint; |
| 2563 | int x, y, dir; |
| 2564 | XEvent xev; |
| 2565 | Display *display = thread_display(); |
| 2566 | struct x11drv_win_data *data; |
| 2567 | |
| 2568 | if (!(data = X11DRV_get_win_data( hwnd ))) return -1; |
| 2569 | if (!data->whole_window || !data->managed || !data->mapped) return -1; |
| 2570 | |
| 2571 | switch (wparam & 0xfff0) |
| 2572 | { |
| 2573 | case SC_MOVE: |
| 2574 | if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD; |
| 2575 | else dir = _NET_WM_MOVERESIZE_MOVE; |
| 2576 | break; |
| 2577 | case SC_SIZE: |
| 2578 | /* windows without WS_THICKFRAME are not resizable through the window manager */ |
| 2579 | if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return -1; |
| 2580 | |
| 2581 | switch (hittest) |
| 2582 | { |
| 2583 | case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break; |
| 2584 | case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break; |
| 2585 | case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break; |
| 2586 | case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break; |
| 2587 | case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break; |
| 2588 | case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break; |
| 2589 | case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break; |
| 2590 | case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break; |
| 2591 | default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break; |
| 2592 | } |
| 2593 | break; |
| 2594 | |
| 2595 | case SC_KEYMENU: |
| 2596 | /* prevent a simple ALT press+release from activating the system menu, |
| 2597 | * as that can get confusing on managed windows */ |
| 2598 | if ((WCHAR)lparam) return -1; /* got an explicit char */ |
| 2599 | if (GetMenu( hwnd )) return -1; /* window has a real menu */ |
| 2600 | if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) return -1; /* no system menu */ |
| 2601 | TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam, lparam ); |
| 2602 | return 0; |
| 2603 | |
| 2604 | default: |
| 2605 | return -1; |
| 2606 | } |
| 2607 | |
| 2608 | if (IsZoomed(hwnd)) return -1; |
| 2609 | |
| 2610 | if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) )) |
| 2611 | { |
| 2612 | TRACE( "_NET_WM_MOVERESIZE not supported\n" ); |
| 2613 | return -1; |
| 2614 | } |
| 2615 | |
| 2616 | dwPoint = GetMessagePos(); |
| 2617 | x = (short)LOWORD(dwPoint); |
| 2618 | y = (short)HIWORD(dwPoint); |
| 2619 | |
| 2620 | TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir); |
| 2621 | |
| 2622 | xev.xclient.type = ClientMessage; |
| 2623 | xev.xclient.window = X11DRV_get_whole_window(hwnd); |
| 2624 | xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE); |
| 2625 | xev.xclient.serial = 0; |
| 2626 | xev.xclient.display = display; |
| 2627 | xev.xclient.send_event = True; |
| 2628 | xev.xclient.format = 32; |
Alexandre Julliard | 9fab7b4 | 2008-09-12 11:03:26 +0200 | [diff] [blame] | 2629 | xev.xclient.data.l[0] = x - virtual_screen_rect.left; /* x coord */ |
| 2630 | xev.xclient.data.l[1] = y - virtual_screen_rect.top; /* y coord */ |
Alexandre Julliard | 24dbaa0 | 2008-04-17 16:13:34 +0200 | [diff] [blame] | 2631 | xev.xclient.data.l[2] = dir; /* direction */ |
| 2632 | xev.xclient.data.l[3] = 1; /* button */ |
| 2633 | xev.xclient.data.l[4] = 0; /* unused */ |
| 2634 | |
| 2635 | /* need to ungrab the pointer that may have been automatically grabbed |
| 2636 | * with a ButtonPress event */ |
| 2637 | wine_tsx11_lock(); |
| 2638 | XUngrabPointer( display, CurrentTime ); |
| 2639 | XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev); |
| 2640 | wine_tsx11_unlock(); |
| 2641 | return 0; |
| 2642 | } |