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