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