2 * Window related functions
4 * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
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.
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.
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
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include <X11/Xresource.h>
34 #include <X11/Xutil.h>
36 #include <X11/extensions/shape.h>
37 #endif /* HAVE_LIBXSHAPE */
43 #include "wine/unicode.h"
46 #include "wine/debug.h"
47 #include "wine/server.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
52 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
53 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
54 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
55 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
56 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
57 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
58 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
59 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
60 #define _NET_WM_MOVERESIZE_MOVE 8
61 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9
62 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10
64 #define _NET_WM_STATE_REMOVE 0
65 #define _NET_WM_STATE_ADD 1
66 #define _NET_WM_STATE_TOGGLE 2
68 static const unsigned int net_wm_state_atoms
[NB_NET_WM_STATES
] =
70 XATOM__NET_WM_STATE_FULLSCREEN
,
71 XATOM__NET_WM_STATE_ABOVE
,
72 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
73 XATOM__NET_WM_STATE_SKIP_PAGER
,
74 XATOM__NET_WM_STATE_SKIP_TASKBAR
77 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
79 /* is cursor clipping active? */
80 BOOL clipping_cursor
= FALSE
;
82 /* X context to associate a hwnd to an X window */
83 XContext winContext
= 0;
85 /* X context to associate a struct x11drv_win_data to an hwnd */
86 XContext win_data_context
= 0;
88 /* time of last user event and window where it's stored */
89 static Time last_user_time
;
90 static Window user_time_window
;
92 static const char foreign_window_prop
[] = "__wine_x11_foreign_window";
93 static const char whole_window_prop
[] = "__wine_x11_whole_window";
94 static const char clip_window_prop
[] = "__wine_x11_clip_window";
96 static CRITICAL_SECTION win_data_section
;
97 static CRITICAL_SECTION_DEBUG critsect_debug
=
99 0, 0, &win_data_section
,
100 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
101 0, 0, { (DWORD_PTR
)(__FILE__
": win_data_section") }
103 static CRITICAL_SECTION win_data_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
106 /***********************************************************************
107 * http://standards.freedesktop.org/startup-notification-spec
109 static void remove_startup_notification(Display
*display
, Window window
)
111 static LONG startup_notification_removed
= 0;
120 if (InterlockedCompareExchange(&startup_notification_removed
, 1, 0) != 0)
123 if (GetEnvironmentVariableA("DESKTOP_STARTUP_ID", id
, sizeof(id
)) == 0)
125 SetEnvironmentVariableA("DESKTOP_STARTUP_ID", NULL
);
127 if ((src
= strstr( id
, "_TIME" ))) update_user_time( atol( src
+ 5 ));
129 pos
= snprintf(message
, sizeof(message
), "remove: ID=");
130 message
[pos
++] = '"';
131 for (i
= 0; id
[i
] && pos
< sizeof(message
) - 3; i
++)
133 if (id
[i
] == '"' || id
[i
] == '\\')
134 message
[pos
++] = '\\';
135 message
[pos
++] = id
[i
];
137 message
[pos
++] = '"';
138 message
[pos
++] = '\0';
140 xevent
.xclient
.type
= ClientMessage
;
141 xevent
.xclient
.message_type
= x11drv_atom(_NET_STARTUP_INFO_BEGIN
);
142 xevent
.xclient
.display
= display
;
143 xevent
.xclient
.window
= window
;
144 xevent
.xclient
.format
= 8;
147 srclen
= strlen(src
) + 1;
154 memset(&xevent
.xclient
.data
.b
[0], 0, 20);
155 memcpy(&xevent
.xclient
.data
.b
[0], src
, msglen
);
159 XSendEvent( display
, DefaultRootWindow( display
), False
, PropertyChangeMask
, &xevent
);
160 xevent
.xclient
.message_type
= x11drv_atom(_NET_STARTUP_INFO
);
165 struct has_popup_result
171 static BOOL
is_managed( HWND hwnd
)
173 struct x11drv_win_data
*data
= get_win_data( hwnd
);
174 BOOL ret
= data
&& data
->managed
;
175 release_win_data( data
);
179 static BOOL CALLBACK
has_managed_popup( HWND hwnd
, LPARAM lparam
)
181 struct has_popup_result
*result
= (struct has_popup_result
*)lparam
;
183 if (hwnd
== result
->hwnd
) return FALSE
; /* popups are always above owner */
184 if (GetWindow( hwnd
, GW_OWNER
) != result
->hwnd
) return TRUE
;
185 result
->found
= is_managed( hwnd
);
186 return !result
->found
;
189 static BOOL
has_owned_popups( HWND hwnd
)
191 struct has_popup_result result
;
194 result
.found
= FALSE
;
195 EnumWindows( has_managed_popup
, (LPARAM
)&result
);
199 /***********************************************************************
202 * Check if a given window should be managed
204 static BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
206 DWORD style
, ex_style
;
208 if (!managed_mode
) return FALSE
;
210 /* child windows are not managed */
211 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
212 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
213 /* activated windows are managed */
214 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
215 if (hwnd
== GetActiveWindow()) return TRUE
;
216 /* windows with caption are managed */
217 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
218 /* windows with thick frame are managed */
219 if (style
& WS_THICKFRAME
) return TRUE
;
220 if (style
& WS_POPUP
)
225 /* popup with sysmenu == caption are managed */
226 if (style
& WS_SYSMENU
) return TRUE
;
227 /* full-screen popup windows are managed */
228 hmon
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
);
229 mi
.cbSize
= sizeof( mi
);
230 GetMonitorInfoW( hmon
, &mi
);
231 if (window_rect
->left
<= mi
.rcWork
.left
&& window_rect
->right
>= mi
.rcWork
.right
&&
232 window_rect
->top
<= mi
.rcWork
.top
&& window_rect
->bottom
>= mi
.rcWork
.bottom
)
235 /* application windows are managed */
236 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
237 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
238 /* windows that own popups are managed */
239 if (has_owned_popups( hwnd
)) return TRUE
;
240 /* default: not managed */
245 /***********************************************************************
246 * is_window_resizable
248 * Check if window should be made resizable by the window manager
250 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
252 if (style
& WS_THICKFRAME
) return TRUE
;
253 /* Metacity needs the window to be resizable to make it fullscreen */
254 return is_window_rect_fullscreen( &data
->whole_rect
);
258 /***********************************************************************
259 * get_mwm_decorations
261 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
262 DWORD style
, DWORD ex_style
)
264 unsigned long ret
= 0;
266 if (!decorated_mode
) return 0;
268 if (IsRectEmpty( &data
->window_rect
)) return 0;
269 if (data
->shaped
) return 0;
271 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
272 if (ex_style
& WS_EX_LAYERED
) return 0;
274 if ((style
& WS_CAPTION
) == WS_CAPTION
)
276 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
277 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
278 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
279 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
281 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
282 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
283 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
288 /***********************************************************************
289 * get_x11_rect_offset
291 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
293 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
295 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
298 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
300 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
301 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
302 decor
= get_mwm_decorations( data
, style
, ex_style
);
304 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
305 if (decor
& MWM_DECOR_BORDER
)
307 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
308 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
311 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
315 /***********************************************************************
316 * get_window_attributes
318 * Fill the window attributes structure for an X window.
320 static int get_window_attributes( struct x11drv_win_data
*data
, XSetWindowAttributes
*attr
)
322 attr
->override_redirect
= !data
->managed
;
323 attr
->colormap
= data
->colormap
? data
->colormap
: default_colormap
;
324 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
325 attr
->bit_gravity
= NorthWestGravity
;
326 attr
->backing_store
= NotUseful
;
327 attr
->border_pixel
= 0;
328 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
329 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
330 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
|
331 KeymapStateMask
| StructureNotifyMask
);
332 if (data
->managed
) attr
->event_mask
|= PropertyChangeMask
;
334 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWBorderPixel
|
335 CWEventMask
| CWBitGravity
| CWBackingStore
);
339 /***********************************************************************
342 * Change the X window attributes when the window style has changed.
344 static void sync_window_style( struct x11drv_win_data
*data
)
346 if (data
->whole_window
!= root_window
)
348 XSetWindowAttributes attr
;
349 int mask
= get_window_attributes( data
, &attr
);
351 XChangeWindowAttributes( data
->display
, data
->whole_window
, mask
, &attr
);
356 /***********************************************************************
359 * Update the X11 window region.
361 static void sync_window_region( struct x11drv_win_data
*data
, HRGN win_region
)
363 #ifdef HAVE_LIBXSHAPE
364 HRGN hrgn
= win_region
;
366 if (!data
->whole_window
) return;
367 data
->shaped
= FALSE
;
369 if (IsRectEmpty( &data
->window_rect
)) /* set an empty shape */
371 static XRectangle empty_rect
;
372 XShapeCombineRectangles( data
->display
, data
->whole_window
, ShapeBounding
, 0, 0,
373 &empty_rect
, 1, ShapeSet
, YXBanded
);
377 if (hrgn
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
379 if (!(hrgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
380 if (GetWindowRgn( data
->hwnd
, hrgn
) == ERROR
)
382 DeleteObject( hrgn
);
389 XShapeCombineMask( data
->display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
393 RGNDATA
*pRegionData
;
395 if (GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) MirrorRgn( data
->hwnd
, hrgn
);
396 if ((pRegionData
= X11DRV_GetRegionData( hrgn
, 0 )))
398 XShapeCombineRectangles( data
->display
, data
->whole_window
, ShapeBounding
,
399 data
->window_rect
.left
- data
->whole_rect
.left
,
400 data
->window_rect
.top
- data
->whole_rect
.top
,
401 (XRectangle
*)pRegionData
->Buffer
,
402 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
403 HeapFree(GetProcessHeap(), 0, pRegionData
);
407 if (hrgn
&& hrgn
!= win_region
) DeleteObject( hrgn
);
408 #endif /* HAVE_LIBXSHAPE */
412 /***********************************************************************
413 * sync_window_opacity
415 static void sync_window_opacity( Display
*display
, Window win
,
416 COLORREF key
, BYTE alpha
, DWORD flags
)
418 unsigned long opacity
= 0xffffffff;
420 if (flags
& LWA_ALPHA
) opacity
= (0xffffffff / 0xff) * alpha
;
422 if (opacity
== 0xffffffff)
423 XDeleteProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
) );
425 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
),
426 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&opacity
, 1 );
430 /***********************************************************************
433 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
436 char *buffer
, *utf8_buffer
;
439 /* allocate new buffer for window text */
440 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
441 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
442 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
444 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
445 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
447 HeapFree( GetProcessHeap(), 0, buffer
);
450 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
452 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
454 XSetWMName( display
, win
, &prop
);
455 XSetWMIconName( display
, win
, &prop
);
459 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
460 according to the standard
461 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
463 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
464 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
466 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
467 HeapFree( GetProcessHeap(), 0, buffer
);
471 /***********************************************************************
474 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
476 static unsigned long *get_bitmap_argb( HDC hdc
, HBITMAP color
, HBITMAP mask
, unsigned int *size
)
478 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
479 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
481 unsigned int *ptr
, *bits
= NULL
;
482 unsigned char *mask_bits
= NULL
;
484 BOOL has_alpha
= FALSE
;
486 if (!GetObjectW( color
, sizeof(bm
), &bm
)) return NULL
;
487 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
488 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
489 info
->bmiHeader
.biHeight
= -bm
.bmHeight
;
490 info
->bmiHeader
.biPlanes
= 1;
491 info
->bmiHeader
.biBitCount
= 32;
492 info
->bmiHeader
.biCompression
= BI_RGB
;
493 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
494 info
->bmiHeader
.biXPelsPerMeter
= 0;
495 info
->bmiHeader
.biYPelsPerMeter
= 0;
496 info
->bmiHeader
.biClrUsed
= 0;
497 info
->bmiHeader
.biClrImportant
= 0;
498 *size
= bm
.bmWidth
* bm
.bmHeight
+ 2;
499 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, *size
* sizeof(long) ))) goto failed
;
500 if (!GetDIBits( hdc
, color
, 0, bm
.bmHeight
, bits
+ 2, info
, DIB_RGB_COLORS
)) goto failed
;
502 bits
[0] = bm
.bmWidth
;
503 bits
[1] = bm
.bmHeight
;
505 for (i
= 0; i
< bm
.bmWidth
* bm
.bmHeight
; i
++)
506 if ((has_alpha
= (bits
[i
+ 2] & 0xff000000) != 0)) break;
510 unsigned int width_bytes
= (bm
.bmWidth
+ 31) / 32 * 4;
511 /* generate alpha channel from the mask */
512 info
->bmiHeader
.biBitCount
= 1;
513 info
->bmiHeader
.biSizeImage
= width_bytes
* bm
.bmHeight
;
514 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
515 if (!GetDIBits( hdc
, mask
, 0, bm
.bmHeight
, mask_bits
, info
, DIB_RGB_COLORS
)) goto failed
;
517 for (i
= 0; i
< bm
.bmHeight
; i
++)
518 for (j
= 0; j
< bm
.bmWidth
; j
++, ptr
++)
519 if (!((mask_bits
[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80)) *ptr
|= 0xff000000;
520 HeapFree( GetProcessHeap(), 0, mask_bits
);
523 /* convert to array of longs */
524 if (bits
&& sizeof(long) > sizeof(int))
525 for (i
= *size
- 1; i
>= 0; i
--) ((unsigned long *)bits
)[i
] = bits
[i
];
527 return (unsigned long *)bits
;
530 HeapFree( GetProcessHeap(), 0, bits
);
531 HeapFree( GetProcessHeap(), 0, mask_bits
);
536 /***********************************************************************
537 * create_icon_pixmaps
539 static BOOL
create_icon_pixmaps( HDC hdc
, const ICONINFO
*icon
, Pixmap
*icon_ret
, Pixmap
*mask_ret
)
541 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
542 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
543 XVisualInfo vis
= default_visual
;
544 struct gdi_image_bits bits
;
545 Pixmap color_pixmap
= 0, mask_pixmap
= 0;
553 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
554 info
->bmiHeader
.biBitCount
= 0;
555 if (!(lines
= GetDIBits( hdc
, icon
->hbmColor
, 0, 0, NULL
, info
, DIB_RGB_COLORS
))) goto failed
;
556 if (!(bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
557 if (!GetDIBits( hdc
, icon
->hbmColor
, 0, lines
, bits
.ptr
, info
, DIB_RGB_COLORS
)) goto failed
;
559 color_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
);
560 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
562 if (!color_pixmap
) goto failed
;
564 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
565 info
->bmiHeader
.biBitCount
= 0;
566 if (!(lines
= GetDIBits( hdc
, icon
->hbmMask
, 0, 0, NULL
, info
, DIB_RGB_COLORS
))) goto failed
;
567 if (!(bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
568 if (!GetDIBits( hdc
, icon
->hbmMask
, 0, lines
, bits
.ptr
, info
, DIB_RGB_COLORS
)) goto failed
;
570 /* invert the mask */
571 for (i
= 0; i
< info
->bmiHeader
.biSizeImage
/ sizeof(DWORD
); i
++) ((DWORD
*)bits
.ptr
)[i
] ^= ~0u;
574 mask_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
);
575 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
577 if (!mask_pixmap
) goto failed
;
579 *icon_ret
= color_pixmap
;
580 *mask_ret
= mask_pixmap
;
584 if (color_pixmap
) XFreePixmap( gdi_display
, color_pixmap
);
585 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
590 /***********************************************************************
593 static void fetch_icon_data( HWND hwnd
, HICON icon_big
, HICON icon_small
)
595 struct x11drv_win_data
*data
;
596 ICONINFO ii
, ii_small
;
600 Pixmap icon_pixmap
, mask_pixmap
;
604 icon_big
= (HICON
)SendMessageW( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
605 if (!icon_big
) icon_big
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
606 if (!icon_big
) icon_big
= LoadIconW( 0, (LPWSTR
)IDI_WINLOGO
);
610 icon_small
= (HICON
)SendMessageW( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
611 if (!icon_small
) icon_small
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICONSM
);
614 if (!GetIconInfo(icon_big
, &ii
)) return;
616 hDC
= CreateCompatibleDC(0);
617 bits
= get_bitmap_argb( hDC
, ii
.hbmColor
, ii
.hbmMask
, &size
);
618 if (bits
&& GetIconInfo( icon_small
, &ii_small
))
620 unsigned int size_small
;
621 unsigned long *bits_small
, *new;
623 if ((bits_small
= get_bitmap_argb( hDC
, ii_small
.hbmColor
, ii_small
.hbmMask
, &size_small
)) &&
624 (bits_small
[0] != bits
[0] || bits_small
[1] != bits
[1])) /* size must be different */
626 if ((new = HeapReAlloc( GetProcessHeap(), 0, bits
,
627 (size
+ size_small
) * sizeof(unsigned long) )))
630 memcpy( bits
+ size
, bits_small
, size_small
* sizeof(unsigned long) );
634 HeapFree( GetProcessHeap(), 0, bits_small
);
635 DeleteObject( ii_small
.hbmColor
);
636 DeleteObject( ii_small
.hbmMask
);
639 if (!create_icon_pixmaps( hDC
, &ii
, &icon_pixmap
, &mask_pixmap
)) icon_pixmap
= mask_pixmap
= 0;
641 DeleteObject( ii
.hbmColor
);
642 DeleteObject( ii
.hbmMask
);
645 if ((data
= get_win_data( hwnd
)))
647 if (data
->icon_pixmap
) XFreePixmap( gdi_display
, data
->icon_pixmap
);
648 if (data
->icon_mask
) XFreePixmap( gdi_display
, data
->icon_mask
);
649 HeapFree( GetProcessHeap(), 0, data
->icon_bits
);
650 data
->icon_pixmap
= icon_pixmap
;
651 data
->icon_mask
= mask_pixmap
;
652 data
->icon_bits
= bits
;
653 data
->icon_size
= size
;
654 release_win_data( data
);
658 if (icon_pixmap
) XFreePixmap( gdi_display
, icon_pixmap
);
659 if (mask_pixmap
) XFreePixmap( gdi_display
, mask_pixmap
);
660 HeapFree( GetProcessHeap(), 0, bits
);
665 /***********************************************************************
668 * set the window size hints
670 static void set_size_hints( struct x11drv_win_data
*data
, DWORD style
)
672 XSizeHints
* size_hints
;
674 if (!(size_hints
= XAllocSizeHints())) return;
676 size_hints
->win_gravity
= StaticGravity
;
677 size_hints
->flags
|= PWinGravity
;
679 /* don't update size hints if window is not in normal state */
680 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
682 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
684 size_hints
->x
= data
->whole_rect
.left
;
685 size_hints
->y
= data
->whole_rect
.top
;
686 size_hints
->flags
|= PPosition
;
688 else size_hints
->win_gravity
= NorthWestGravity
;
690 if (!is_window_resizable( data
, style
))
692 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
693 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
694 if (size_hints
->max_width
<= 0 ||size_hints
->max_height
<= 0)
695 size_hints
->max_width
= size_hints
->max_height
= 1;
696 size_hints
->min_width
= size_hints
->max_width
;
697 size_hints
->min_height
= size_hints
->max_height
;
698 size_hints
->flags
|= PMinSize
| PMaxSize
;
701 XSetWMNormalHints( data
->display
, data
->whole_window
, size_hints
);
706 /***********************************************************************
709 static void set_mwm_hints( struct x11drv_win_data
*data
, DWORD style
, DWORD ex_style
)
713 if (data
->hwnd
== GetDesktopWindow())
715 if (is_desktop_fullscreen()) mwm_hints
.decorations
= 0;
716 else mwm_hints
.decorations
= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
| MWM_DECOR_MENU
| MWM_DECOR_MINIMIZE
;
717 mwm_hints
.functions
= MWM_FUNC_MOVE
| MWM_FUNC_MINIMIZE
| MWM_FUNC_CLOSE
;
721 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
722 mwm_hints
.functions
= MWM_FUNC_MOVE
;
723 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
724 if (!(style
& WS_DISABLED
))
726 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
727 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
728 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
732 TRACE( "%p setting mwm hints to %lx,%lx (style %x exstyle %x)\n",
733 data
->hwnd
, mwm_hints
.decorations
, mwm_hints
.functions
, style
, ex_style
);
735 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
736 mwm_hints
.input_mode
= 0;
737 mwm_hints
.status
= 0;
738 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
739 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
740 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
744 /***********************************************************************
747 static void set_style_hints( struct x11drv_win_data
*data
, DWORD style
, DWORD ex_style
)
749 Window group_leader
= data
->whole_window
;
750 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
751 Window owner_win
= 0;
757 owner
= GetAncestor( owner
, GA_ROOT
);
758 owner_win
= X11DRV_get_whole_window( owner
);
763 XSetTransientForHint( data
->display
, data
->whole_window
, owner_win
);
764 group_leader
= owner_win
;
767 /* Only use dialog type for owned popups. Metacity allows making fullscreen
768 * only normal windows, and doesn't handle correctly TRANSIENT_FOR hint for
769 * dialogs owned by fullscreen windows.
771 if (((style
& WS_POPUP
) || (ex_style
& WS_EX_DLGMODALFRAME
)) && owner
)
772 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
774 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
776 XChangeProperty(data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
777 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
779 if ((wm_hints
= XAllocWMHints()))
781 wm_hints
->flags
= InputHint
| StateHint
| WindowGroupHint
;
782 wm_hints
->input
= !use_take_focus
&& !(style
& WS_DISABLED
);
783 wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
784 wm_hints
->window_group
= group_leader
;
785 if (data
->icon_pixmap
)
787 wm_hints
->icon_pixmap
= data
->icon_pixmap
;
788 wm_hints
->icon_mask
= data
->icon_mask
;
789 wm_hints
->flags
|= IconPixmapHint
| IconMaskHint
;
791 XSetWMHints( data
->display
, data
->whole_window
, wm_hints
);
796 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
),
797 XA_CARDINAL
, 32, PropModeReplace
,
798 (unsigned char *)data
->icon_bits
, data
->icon_size
);
800 XDeleteProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
) );
805 /***********************************************************************
808 * get the name of the current process for setting class hints
810 static char *get_process_name(void)
816 WCHAR module
[MAX_PATH
];
817 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
818 if (len
&& len
< MAX_PATH
)
821 WCHAR
*p
, *appname
= module
;
823 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
824 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
825 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
826 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
828 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
837 /***********************************************************************
838 * set_initial_wm_hints
840 * Set the window manager hints that don't change over the lifetime of a window.
842 static void set_initial_wm_hints( Display
*display
, Window window
)
846 Atom dndVersion
= WINE_XDND_VERSION
;
847 XClassHint
*class_hints
;
848 char *process_name
= get_process_name();
852 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
853 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
854 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
855 XChangeProperty( display
, window
, x11drv_atom(WM_PROTOCOLS
),
856 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
859 if ((class_hints
= XAllocClassHint()))
861 static char wine
[] = "Wine";
863 class_hints
->res_name
= process_name
;
864 class_hints
->res_class
= wine
;
865 XSetClassHint( display
, window
, class_hints
);
866 XFree( class_hints
);
869 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
870 XSetWMProperties(display
, window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
871 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
873 XChangeProperty(display
, window
, x11drv_atom(_NET_WM_PID
),
874 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
876 XChangeProperty( display
, window
, x11drv_atom(XdndAware
),
877 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
879 update_user_time( 0 ); /* make sure that the user time window exists */
880 if (user_time_window
)
881 XChangeProperty( display
, window
, x11drv_atom(_NET_WM_USER_TIME_WINDOW
),
882 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&user_time_window
, 1 );
886 /***********************************************************************
889 * If the window is managed, make sure its owner window is too.
891 static void make_owner_managed( HWND hwnd
)
895 if (!(owner
= GetWindow( hwnd
, GW_OWNER
))) return;
896 if (is_managed( owner
)) return;
897 if (!is_managed( hwnd
)) return;
899 SetWindowPos( owner
, 0, 0, 0, 0, 0,
900 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
901 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
905 /***********************************************************************
908 * Set all the window manager hints for a window.
910 static void set_wm_hints( struct x11drv_win_data
*data
)
912 DWORD style
, ex_style
;
914 if (data
->hwnd
== GetDesktopWindow())
916 /* force some styles for the desktop to get the correct decorations */
917 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
918 ex_style
= WS_EX_APPWINDOW
;
922 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
923 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
926 set_size_hints( data
, style
);
927 set_mwm_hints( data
, style
, ex_style
);
928 set_style_hints( data
, style
, ex_style
);
932 /***********************************************************************
935 Window
init_clip_window(void)
937 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
939 if (!data
->clip_window
&&
940 (data
->clip_window
= (Window
)GetPropA( GetDesktopWindow(), clip_window_prop
)))
942 XSelectInput( data
->display
, data
->clip_window
, StructureNotifyMask
);
944 return data
->clip_window
;
948 /***********************************************************************
951 void update_user_time( Time time
)
953 if (!user_time_window
)
955 Window win
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, CopyFromParent
,
956 InputOnly
, CopyFromParent
, 0, NULL
);
957 if (InterlockedCompareExchangePointer( (void **)&user_time_window
, (void *)win
, 0 ))
958 XDestroyWindow( gdi_display
, win
);
959 TRACE( "user time window %lx\n", user_time_window
);
963 XLockDisplay( gdi_display
);
964 if (!last_user_time
|| (long)(time
- last_user_time
) > 0)
966 last_user_time
= time
;
967 XChangeProperty( gdi_display
, user_time_window
, x11drv_atom(_NET_WM_USER_TIME
),
968 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&time
, 1 );
970 XUnlockDisplay( gdi_display
);
973 /***********************************************************************
974 * update_net_wm_states
976 void update_net_wm_states( struct x11drv_win_data
*data
)
978 DWORD i
, style
, ex_style
, new_state
= 0;
980 if (!data
->managed
) return;
981 if (data
->whole_window
== root_window
) return;
983 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
984 if (style
& WS_MINIMIZE
)
985 new_state
|= data
->net_wm_state
& ((1 << NET_WM_STATE_FULLSCREEN
)|(1 << NET_WM_STATE_MAXIMIZED
));
986 if (is_window_rect_fullscreen( &data
->whole_rect
))
988 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
989 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
990 else if (!(style
& WS_MINIMIZE
))
991 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
993 else if (style
& WS_MAXIMIZE
)
994 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
996 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
997 if (ex_style
& WS_EX_TOPMOST
)
998 new_state
|= (1 << NET_WM_STATE_ABOVE
);
999 if (ex_style
& (WS_EX_TOOLWINDOW
| WS_EX_NOACTIVATE
))
1000 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
1001 if (!(ex_style
& WS_EX_APPWINDOW
) && GetWindow( data
->hwnd
, GW_OWNER
))
1002 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
1004 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
1006 Atom atoms
[NB_NET_WM_STATES
+1];
1009 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
1011 if (!(new_state
& (1 << i
))) continue;
1012 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1013 i
, data
->hwnd
, data
->whole_window
);
1014 atoms
[count
++] = X11DRV_Atoms
[net_wm_state_atoms
[i
] - FIRST_XATOM
];
1015 if (net_wm_state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
1016 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
1018 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
1019 32, PropModeReplace
, (unsigned char *)atoms
, count
);
1021 else /* ask the window manager to do it for us */
1025 xev
.xclient
.type
= ClientMessage
;
1026 xev
.xclient
.window
= data
->whole_window
;
1027 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
1028 xev
.xclient
.serial
= 0;
1029 xev
.xclient
.display
= data
->display
;
1030 xev
.xclient
.send_event
= True
;
1031 xev
.xclient
.format
= 32;
1032 xev
.xclient
.data
.l
[3] = 1;
1033 xev
.xclient
.data
.l
[4] = 0;
1035 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
1037 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1039 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1040 i
, data
->hwnd
, data
->whole_window
,
1041 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1043 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1044 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[net_wm_state_atoms
[i
] - FIRST_XATOM
];
1045 xev
.xclient
.data
.l
[2] = ((net_wm_state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1046 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1047 XSendEvent( data
->display
, root_window
, False
,
1048 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1051 data
->net_wm_state
= new_state
;
1054 /***********************************************************************
1055 * read_net_wm_states
1057 void read_net_wm_states( Display
* display
, struct x11drv_win_data
*data
)
1061 unsigned long i
, j
, count
, remaining
;
1062 DWORD new_state
= 0;
1063 BOOL maximized_horz
= FALSE
;
1065 if (!data
->whole_window
) return;
1067 if (!XGetWindowProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), 0,
1068 65536/sizeof(CARD32
), False
, XA_ATOM
, &type
, &format
, &count
,
1069 &remaining
, (unsigned char **)&state
))
1071 if (type
== XA_ATOM
&& format
== 32)
1073 for (i
= 0; i
< count
; i
++)
1075 if (state
[i
] == x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
))
1076 maximized_horz
= TRUE
;
1077 for (j
=0; j
< NB_NET_WM_STATES
; j
++)
1079 if (state
[i
] == X11DRV_Atoms
[net_wm_state_atoms
[j
] - FIRST_XATOM
])
1081 new_state
|= 1 << j
;
1089 if (!maximized_horz
)
1090 new_state
&= ~(1 << NET_WM_STATE_MAXIMIZED
);
1092 data
->net_wm_state
= new_state
;
1096 /***********************************************************************
1099 static void set_xembed_flags( struct x11drv_win_data
*data
, unsigned long flags
)
1101 unsigned long info
[2];
1103 if (!data
->whole_window
) return;
1105 info
[0] = 0; /* protocol version */
1107 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1108 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1112 /***********************************************************************
1115 static void map_window( HWND hwnd
, DWORD new_style
)
1117 struct x11drv_win_data
*data
;
1119 make_owner_managed( hwnd
);
1120 wait_for_withdrawn_state( hwnd
, TRUE
);
1122 if (!(data
= get_win_data( hwnd
))) return;
1124 if (data
->whole_window
&& !data
->mapped
)
1126 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1128 remove_startup_notification( data
->display
, data
->whole_window
);
1129 set_wm_hints( data
);
1131 if (!data
->embedded
)
1133 update_net_wm_states( data
);
1134 sync_window_style( data
);
1135 XMapWindow( data
->display
, data
->whole_window
);
1136 XFlush( data
->display
);
1137 if (data
->surface
&& data
->vis
.visualid
!= default_visual
.visualid
)
1138 data
->surface
->funcs
->flush( data
->surface
);
1140 else set_xembed_flags( data
, XEMBED_MAPPED
);
1142 data
->mapped
= TRUE
;
1143 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1145 release_win_data( data
);
1149 /***********************************************************************
1152 static void unmap_window( HWND hwnd
)
1154 struct x11drv_win_data
*data
;
1156 wait_for_withdrawn_state( hwnd
, FALSE
);
1158 if (!(data
= get_win_data( hwnd
))) return;
1162 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1164 if (data
->embedded
) set_xembed_flags( data
, 0 );
1165 else if (!data
->managed
) XUnmapWindow( data
->display
, data
->whole_window
);
1166 else XWithdrawWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
1168 data
->mapped
= FALSE
;
1169 data
->net_wm_state
= 0;
1171 release_win_data( data
);
1175 /***********************************************************************
1176 * make_window_embedded
1178 void make_window_embedded( struct x11drv_win_data
*data
)
1180 /* the window cannot be mapped before being embedded */
1183 if (!data
->managed
) XUnmapWindow( data
->display
, data
->whole_window
);
1184 else XWithdrawWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
1185 data
->net_wm_state
= 0;
1187 data
->embedded
= TRUE
;
1188 data
->managed
= TRUE
;
1189 sync_window_style( data
);
1190 set_xembed_flags( data
, (data
->mapped
|| data
->embedder
) ? XEMBED_MAPPED
: 0 );
1194 /***********************************************************************
1195 * X11DRV_window_to_X_rect
1197 * Convert a rect from client to X window coordinates
1199 static void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1203 if (!data
->managed
) return;
1204 if (IsRectEmpty( rect
)) return;
1206 get_x11_rect_offset( data
, &rc
);
1208 rect
->left
-= rc
.left
;
1209 rect
->right
-= rc
.right
;
1210 rect
->top
-= rc
.top
;
1211 rect
->bottom
-= rc
.bottom
;
1212 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1213 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1217 /***********************************************************************
1218 * X11DRV_X_to_window_rect
1220 * Opposite of X11DRV_window_to_X_rect
1222 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1226 if (!data
->managed
) return;
1227 if (IsRectEmpty( rect
)) return;
1229 get_x11_rect_offset( data
, &rc
);
1231 rect
->left
+= rc
.left
;
1232 rect
->right
+= rc
.right
;
1233 rect
->top
+= rc
.top
;
1234 rect
->bottom
+= rc
.bottom
;
1235 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1236 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1240 /***********************************************************************
1241 * sync_window_position
1243 * Synchronize the X window position with the Windows one
1245 static void sync_window_position( struct x11drv_win_data
*data
,
1246 UINT swp_flags
, const RECT
*old_window_rect
,
1247 const RECT
*old_whole_rect
, const RECT
*old_client_rect
)
1249 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1250 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1251 XWindowChanges changes
;
1252 unsigned int mask
= 0;
1254 if (data
->managed
&& data
->iconic
) return;
1256 /* resizing a managed maximized window is not allowed */
1257 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1259 changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
1260 changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
1261 /* if window rect is empty force size to 1x1 */
1262 if (changes
.width
<= 0 || changes
.height
<= 0) changes
.width
= changes
.height
= 1;
1263 if (changes
.width
> 65535) changes
.width
= 65535;
1264 if (changes
.height
> 65535) changes
.height
= 65535;
1265 mask
|= CWWidth
| CWHeight
;
1268 /* only the size is allowed to change for the desktop window */
1269 if (data
->whole_window
!= root_window
)
1271 POINT pt
= virtual_screen_to_root( data
->whole_rect
.left
, data
->whole_rect
.top
);
1277 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1279 /* find window that this one must be after */
1280 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1281 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1282 prev
= GetWindow( prev
, GW_HWNDPREV
);
1283 if (!prev
) /* top child */
1285 changes
.stack_mode
= Above
;
1286 mask
|= CWStackMode
;
1288 /* should use stack_mode Below but most window managers don't get it right */
1289 /* and Above with a sibling doesn't work so well either, so we ignore it */
1292 set_size_hints( data
, style
);
1293 set_mwm_hints( data
, style
, ex_style
);
1294 data
->configure_serial
= NextRequest( data
->display
);
1295 XReconfigureWMWindow( data
->display
, data
->whole_window
, data
->vis
.screen
, mask
, &changes
);
1296 #ifdef HAVE_LIBXSHAPE
1297 if (IsRectEmpty( old_window_rect
) != IsRectEmpty( &data
->window_rect
))
1298 sync_window_region( data
, (HRGN
)1 );
1301 int old_x_offset
= old_window_rect
->left
- old_whole_rect
->left
;
1302 int old_y_offset
= old_window_rect
->top
- old_whole_rect
->top
;
1303 int new_x_offset
= data
->window_rect
.left
- data
->whole_rect
.left
;
1304 int new_y_offset
= data
->window_rect
.top
- data
->whole_rect
.top
;
1305 if (old_x_offset
!= new_x_offset
|| old_y_offset
!= new_y_offset
)
1306 XShapeOffsetShape( data
->display
, data
->whole_window
, ShapeBounding
,
1307 new_x_offset
- old_x_offset
, new_y_offset
- old_y_offset
);
1311 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1312 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1313 data
->whole_rect
.right
- data
->whole_rect
.left
,
1314 data
->whole_rect
.bottom
- data
->whole_rect
.top
,
1315 changes
.sibling
, mask
, data
->configure_serial
);
1319 /***********************************************************************
1320 * sync_client_position
1322 * Synchronize the X client window position with the Windows one
1324 static void sync_client_position( struct x11drv_win_data
*data
,
1325 const RECT
*old_client_rect
, const RECT
*old_whole_rect
)
1328 XWindowChanges changes
;
1330 if (!data
->client_window
) return;
1332 changes
.x
= data
->client_rect
.left
- data
->whole_rect
.left
;
1333 changes
.y
= data
->client_rect
.top
- data
->whole_rect
.top
;
1334 changes
.width
= min( max( 1, data
->client_rect
.right
- data
->client_rect
.left
), 65535 );
1335 changes
.height
= min( max( 1, data
->client_rect
.bottom
- data
->client_rect
.top
), 65535 );
1337 if (changes
.x
!= old_client_rect
->left
- old_whole_rect
->left
) mask
|= CWX
;
1338 if (changes
.y
!= old_client_rect
->top
- old_whole_rect
->top
) mask
|= CWY
;
1339 if (changes
.width
!= old_client_rect
->right
- old_client_rect
->left
) mask
|= CWWidth
;
1340 if (changes
.height
!= old_client_rect
->bottom
- old_client_rect
->top
) mask
|= CWHeight
;
1344 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1345 data
->client_window
, changes
.x
, changes
.y
, changes
.width
, changes
.height
, mask
);
1346 XConfigureWindow( data
->display
, data
->client_window
, mask
, &changes
);
1351 /***********************************************************************
1354 * Move the window bits when a window is moved.
1356 static void move_window_bits( HWND hwnd
, Window window
, const RECT
*old_rect
, const RECT
*new_rect
,
1357 const RECT
*old_client_rect
, const RECT
*new_client_rect
,
1358 const RECT
*new_window_rect
)
1360 RECT src_rect
= *old_rect
;
1361 RECT dst_rect
= *new_rect
;
1362 HDC hdc_src
, hdc_dst
;
1369 OffsetRect( &dst_rect
, -new_window_rect
->left
, -new_window_rect
->top
);
1370 parent
= GetAncestor( hwnd
, GA_PARENT
);
1371 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1372 hdc_dst
= GetDCEx( hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1376 OffsetRect( &dst_rect
, -new_client_rect
->left
, -new_client_rect
->top
);
1377 /* make src rect relative to the old position of the window */
1378 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1379 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1380 hdc_src
= hdc_dst
= GetDCEx( hwnd
, 0, DCX_CACHE
);
1383 rgn
= CreateRectRgnIndirect( &dst_rect
);
1384 SelectClipRgn( hdc_dst
, rgn
);
1385 DeleteObject( rgn
);
1386 /* WS_CLIPCHILDREN doesn't exclude children from the window update
1387 * region, and ExcludeUpdateRgn call may inappropriately clip valid
1388 * child window contents from the copied parent window bits, but we
1389 * still want to avoid copying invalid window bits when possible.
1391 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CLIPCHILDREN
))
1392 ExcludeUpdateRgn( hdc_dst
, hwnd
);
1394 code
= X11DRV_START_EXPOSURES
;
1395 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1397 TRACE( "copying bits for win %p/%lx %s -> %s\n",
1398 hwnd
, window
, wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1399 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1400 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1401 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1404 code
= X11DRV_END_EXPOSURES
;
1405 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1407 ReleaseDC( hwnd
, hdc_dst
);
1408 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1414 /* map region to client rect since we are using DCX_WINDOW */
1415 OffsetRgn( rgn
, new_window_rect
->left
- new_client_rect
->left
,
1416 new_window_rect
->top
- new_client_rect
->top
);
1417 RedrawWindow( hwnd
, NULL
, rgn
,
1418 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1420 else RedrawWindow( hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1421 DeleteObject( rgn
);
1426 /**********************************************************************
1427 * create_client_window
1429 Window
create_client_window( struct x11drv_win_data
*data
, const XVisualInfo
*visual
)
1431 XSetWindowAttributes attr
;
1432 int x
= data
->client_rect
.left
- data
->whole_rect
.left
;
1433 int y
= data
->client_rect
.top
- data
->whole_rect
.top
;
1434 int cx
= min( max( 1, data
->client_rect
.right
- data
->client_rect
.left
), 65535 );
1435 int cy
= min( max( 1, data
->client_rect
.bottom
- data
->client_rect
.top
), 65535 );
1437 if (data
->client_window
)
1439 XDeleteContext( data
->display
, data
->client_window
, winContext
);
1440 XDestroyWindow( data
->display
, data
->client_window
);
1443 if (data
->colormap
) XFreeColormap( data
->display
, data
->colormap
);
1444 data
->colormap
= XCreateColormap( data
->display
, root_window
, visual
->visual
,
1445 (visual
->class == PseudoColor
||
1446 visual
->class == GrayScale
||
1447 visual
->class == DirectColor
) ? AllocAll
: AllocNone
);
1448 attr
.colormap
= data
->colormap
;
1449 attr
.bit_gravity
= NorthWestGravity
;
1450 attr
.win_gravity
= NorthWestGravity
;
1451 attr
.backing_store
= NotUseful
;
1452 attr
.event_mask
= ExposureMask
;
1453 attr
.border_pixel
= 0;
1455 data
->client_window
= XCreateWindow( data
->display
, data
->whole_window
, x
, y
, cx
, cy
,
1456 0, default_visual
.depth
, InputOutput
, visual
->visual
,
1457 CWBitGravity
| CWWinGravity
| CWBackingStore
|
1458 CWColormap
| CWEventMask
| CWBorderPixel
, &attr
);
1459 if (!data
->client_window
) return 0;
1461 XSaveContext( data
->display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
1462 XMapWindow( data
->display
, data
->client_window
);
1463 XSync( data
->display
, False
);
1464 return data
->client_window
;
1468 /**********************************************************************
1469 * create_whole_window
1471 * Create the whole X window for a given window
1473 static void create_whole_window( struct x11drv_win_data
*data
)
1476 XSetWindowAttributes attr
;
1480 DWORD layered_flags
;
1484 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1486 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1487 data
->managed
= TRUE
;
1490 if ((win_rgn
= CreateRectRgn( 0, 0, 0, 0 )) && GetWindowRgn( data
->hwnd
, win_rgn
) == ERROR
)
1492 DeleteObject( win_rgn
);
1495 data
->shaped
= (win_rgn
!= 0);
1497 if (data
->vis
.visualid
!= default_visual
.visualid
)
1498 data
->colormap
= XCreateColormap( data
->display
, root_window
, data
->vis
.visual
, AllocNone
);
1500 mask
= get_window_attributes( data
, &attr
);
1502 data
->whole_rect
= data
->window_rect
;
1503 X11DRV_window_to_X_rect( data
, &data
->whole_rect
);
1504 if (!(cx
= data
->whole_rect
.right
- data
->whole_rect
.left
)) cx
= 1;
1505 else if (cx
> 65535) cx
= 65535;
1506 if (!(cy
= data
->whole_rect
.bottom
- data
->whole_rect
.top
)) cy
= 1;
1507 else if (cy
> 65535) cy
= 65535;
1509 pos
= virtual_screen_to_root( data
->whole_rect
.left
, data
->whole_rect
.top
);
1510 data
->whole_window
= XCreateWindow( data
->display
, root_window
, pos
.x
, pos
.y
,
1511 cx
, cy
, 0, data
->vis
.depth
, InputOutput
,
1512 data
->vis
.visual
, mask
, &attr
);
1513 if (!data
->whole_window
) goto done
;
1515 set_initial_wm_hints( data
->display
, data
->whole_window
);
1516 set_wm_hints( data
);
1518 XSaveContext( data
->display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1519 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1521 /* set the window text */
1522 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1523 sync_window_text( data
->display
, data
->whole_window
, text
);
1525 /* set the window region */
1526 if (win_rgn
|| IsRectEmpty( &data
->window_rect
)) sync_window_region( data
, win_rgn
);
1528 /* set the window opacity */
1529 if (!GetLayeredWindowAttributes( data
->hwnd
, &key
, &alpha
, &layered_flags
)) layered_flags
= 0;
1530 sync_window_opacity( data
->display
, data
->whole_window
, key
, alpha
, layered_flags
);
1532 XFlush( data
->display
); /* make sure the window exists before we start painting to it */
1534 sync_window_cursor( data
->whole_window
);
1537 if (win_rgn
) DeleteObject( win_rgn
);
1541 /**********************************************************************
1542 * destroy_whole_window
1544 * Destroy the whole X window for a given window.
1546 static void destroy_whole_window( struct x11drv_win_data
*data
, BOOL already_destroyed
)
1548 if (!data
->whole_window
)
1552 Window xwin
= (Window
)GetPropA( data
->hwnd
, foreign_window_prop
);
1555 if (!already_destroyed
) XSelectInput( data
->display
, xwin
, 0 );
1556 XDeleteContext( data
->display
, xwin
, winContext
);
1557 RemovePropA( data
->hwnd
, foreign_window_prop
);
1564 TRACE( "win %p xwin %lx\n", data
->hwnd
, data
->whole_window
);
1565 XDeleteContext( data
->display
, data
->whole_window
, winContext
);
1566 if (data
->client_window
) XDeleteContext( data
->display
, data
->client_window
, winContext
);
1567 if (!already_destroyed
) XDestroyWindow( data
->display
, data
->whole_window
);
1568 if (data
->colormap
) XFreeColormap( data
->display
, data
->colormap
);
1569 data
->whole_window
= data
->client_window
= 0;
1571 data
->wm_state
= WithdrawnState
;
1572 data
->net_wm_state
= 0;
1573 data
->mapped
= FALSE
;
1576 XUnsetICFocus( data
->xic
);
1577 XDestroyIC( data
->xic
);
1580 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1581 XFlush( data
->display
);
1582 if (data
->surface
) window_surface_release( data
->surface
);
1583 data
->surface
= NULL
;
1584 RemovePropA( data
->hwnd
, whole_window_prop
);
1588 /**********************************************************************
1591 * Change the visual by destroying and recreating the X window if needed.
1593 void set_window_visual( struct x11drv_win_data
*data
, const XVisualInfo
*vis
)
1595 Window client_window
= data
->client_window
;
1596 Window whole_window
= data
->whole_window
;
1598 if (data
->vis
.visualid
== vis
->visualid
) return;
1599 data
->client_window
= 0;
1600 destroy_whole_window( data
, client_window
!= 0 /* don't destroy whole_window until reparented */ );
1601 if (data
->surface
) window_surface_release( data
->surface
);
1602 data
->surface
= NULL
;
1604 create_whole_window( data
);
1605 if (!client_window
) return;
1606 /* move the client to the new parent */
1607 XReparentWindow( data
->display
, client_window
, data
->whole_window
,
1608 data
->client_rect
.left
- data
->whole_rect
.left
,
1609 data
->client_rect
.top
- data
->whole_rect
.top
);
1610 data
->client_window
= client_window
;
1611 XDestroyWindow( data
->display
, whole_window
);
1615 /*****************************************************************
1616 * SetWindowText (X11DRV.@)
1618 void CDECL
X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1622 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1624 Display
*display
= thread_init_display();
1625 sync_window_text( display
, win
, text
);
1630 /***********************************************************************
1631 * SetWindowStyle (X11DRV.@)
1633 * Update the X state of a window to reflect a style change
1635 void CDECL
X11DRV_SetWindowStyle( HWND hwnd
, INT offset
, STYLESTRUCT
*style
)
1637 struct x11drv_win_data
*data
;
1638 DWORD changed
= style
->styleNew
^ style
->styleOld
;
1640 if (hwnd
== GetDesktopWindow()) return;
1641 if (!(data
= get_win_data( hwnd
))) return;
1642 if (!data
->whole_window
) goto done
;
1644 if (offset
== GWL_STYLE
&& (changed
& WS_DISABLED
)) set_wm_hints( data
);
1646 if (offset
== GWL_EXSTYLE
&& (changed
& WS_EX_LAYERED
)) /* changing WS_EX_LAYERED resets attributes */
1648 data
->layered
= FALSE
;
1649 set_window_visual( data
, &default_visual
);
1650 sync_window_opacity( data
->display
, data
->whole_window
, 0, 0, 0 );
1651 if (data
->surface
) set_surface_color_key( data
->surface
, CLR_INVALID
);
1654 release_win_data( data
);
1658 /***********************************************************************
1659 * DestroyWindow (X11DRV.@)
1661 void CDECL
X11DRV_DestroyWindow( HWND hwnd
)
1663 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1664 struct x11drv_win_data
*data
;
1666 destroy_gl_drawable( hwnd
);
1668 if (!(data
= get_win_data( hwnd
))) return;
1670 destroy_whole_window( data
, FALSE
);
1671 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1672 if (thread_data
->last_xic_hwnd
== hwnd
) thread_data
->last_xic_hwnd
= 0;
1673 if (data
->icon_pixmap
) XFreePixmap( gdi_display
, data
->icon_pixmap
);
1674 if (data
->icon_mask
) XFreePixmap( gdi_display
, data
->icon_mask
);
1675 HeapFree( GetProcessHeap(), 0, data
->icon_bits
);
1676 XDeleteContext( gdi_display
, (XID
)hwnd
, win_data_context
);
1677 release_win_data( data
);
1678 HeapFree( GetProcessHeap(), 0, data
);
1682 /***********************************************************************
1683 * X11DRV_DestroyNotify
1685 BOOL
X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1687 struct x11drv_win_data
*data
;
1690 if (!(data
= get_win_data( hwnd
))) return FALSE
;
1691 embedded
= data
->embedded
;
1692 if (!embedded
) FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1694 destroy_whole_window( data
, TRUE
);
1695 release_win_data( data
);
1696 if (embedded
) SendMessageW( hwnd
, WM_CLOSE
, 0, 0 );
1701 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1703 struct x11drv_win_data
*data
;
1705 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1707 data
->display
= display
;
1708 data
->vis
= default_visual
;
1710 EnterCriticalSection( &win_data_section
);
1711 XSaveContext( gdi_display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1717 /* initialize the desktop window id in the desktop manager process */
1718 BOOL
create_desktop_win_data( Window win
)
1720 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1721 Display
*display
= thread_data
->display
;
1722 struct x11drv_win_data
*data
;
1724 if (!(data
= alloc_win_data( display
, GetDesktopWindow() ))) return FALSE
;
1725 data
->whole_window
= win
;
1726 data
->managed
= TRUE
;
1727 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)win
);
1728 set_initial_wm_hints( display
, win
);
1729 release_win_data( data
);
1730 if (thread_data
->clip_window
) XReparentWindow( display
, thread_data
->clip_window
, win
, 0, 0 );
1734 /**********************************************************************
1735 * CreateDesktopWindow (X11DRV.@)
1737 BOOL CDECL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1739 unsigned int width
, height
;
1741 /* retrieve the real size of the desktop */
1742 SERVER_START_REQ( get_window_rectangles
)
1744 req
->handle
= wine_server_user_handle( hwnd
);
1745 req
->relative
= COORDS_CLIENT
;
1746 wine_server_call( req
);
1747 width
= reply
->window
.right
;
1748 height
= reply
->window
.bottom
;
1752 if (!width
&& !height
) /* not initialized yet */
1754 RECT rect
= get_virtual_screen_rect();
1756 SERVER_START_REQ( set_window_pos
)
1758 req
->handle
= wine_server_user_handle( hwnd
);
1760 req
->swp_flags
= SWP_NOZORDER
;
1761 req
->window
.left
= rect
.left
;
1762 req
->window
.top
= rect
.top
;
1763 req
->window
.right
= rect
.right
;
1764 req
->window
.bottom
= rect
.bottom
;
1765 req
->client
= req
->window
;
1766 wine_server_call( req
);
1772 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1773 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1779 /**********************************************************************
1780 * CreateWindow (X11DRV.@)
1782 BOOL CDECL
X11DRV_CreateWindow( HWND hwnd
)
1784 if (hwnd
== GetDesktopWindow())
1786 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
1787 XSetWindowAttributes attr
;
1789 /* create the cursor clipping window */
1790 attr
.override_redirect
= TRUE
;
1791 attr
.event_mask
= StructureNotifyMask
| FocusChangeMask
;
1792 data
->clip_window
= XCreateWindow( data
->display
, root_window
, 0, 0, 1, 1, 0, 0,
1793 InputOnly
, default_visual
.visual
,
1794 CWOverrideRedirect
| CWEventMask
, &attr
);
1795 XFlush( data
->display
);
1796 SetPropA( hwnd
, clip_window_prop
, (HANDLE
)data
->clip_window
);
1797 X11DRV_InitClipboard();
1803 /***********************************************************************
1806 * Lock and return the X11 data structure associated with a window.
1808 struct x11drv_win_data
*get_win_data( HWND hwnd
)
1812 if (!hwnd
) return NULL
;
1813 EnterCriticalSection( &win_data_section
);
1814 if (!XFindContext( gdi_display
, (XID
)hwnd
, win_data_context
, &data
))
1815 return (struct x11drv_win_data
*)data
;
1816 LeaveCriticalSection( &win_data_section
);
1821 /***********************************************************************
1824 * Release the data returned by get_win_data.
1826 void release_win_data( struct x11drv_win_data
*data
)
1828 if (data
) LeaveCriticalSection( &win_data_section
);
1832 /***********************************************************************
1833 * X11DRV_create_win_data
1835 * Create an X11 data window structure for an existing window.
1837 static struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
, const RECT
*window_rect
,
1838 const RECT
*client_rect
)
1841 struct x11drv_win_data
*data
;
1844 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1846 /* don't create win data for HWND_MESSAGE windows */
1847 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
1849 if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId()) return NULL
;
1851 display
= thread_init_display();
1852 init_clip_window(); /* make sure the clip window is initialized in this thread */
1854 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1856 data
->whole_rect
= data
->window_rect
= *window_rect
;
1857 data
->client_rect
= *client_rect
;
1858 if (parent
== GetDesktopWindow())
1860 create_whole_window( data
);
1861 TRACE( "win %p/%lx window %s whole %s client %s\n",
1862 hwnd
, data
->whole_window
, wine_dbgstr_rect( &data
->window_rect
),
1863 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1869 /* window procedure for foreign windows */
1870 static LRESULT WINAPI
foreign_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1874 case WM_WINDOWPOSCHANGED
:
1875 update_systray_balloon_position();
1877 case WM_PARENTNOTIFY
:
1878 if (LOWORD(wparam
) == WM_DESTROY
)
1880 TRACE( "%p: got parent notify destroy for win %lx\n", hwnd
, lparam
);
1881 PostMessageW( hwnd
, WM_CLOSE
, 0, 0 ); /* so that we come back here once the child is gone */
1885 if (GetWindow( hwnd
, GW_CHILD
)) return 0; /* refuse to die if we still have children */
1888 return DefWindowProcW( hwnd
, msg
, wparam
, lparam
);
1892 /***********************************************************************
1893 * create_foreign_window
1895 * Create a foreign window for the specified X window and its ancestors
1897 HWND
create_foreign_window( Display
*display
, Window xwin
)
1899 static const WCHAR classW
[] = {'_','_','w','i','n','e','_','x','1','1','_','f','o','r','e','i','g','n','_','w','i','n','d','o','w',0};
1900 static BOOL class_registered
;
1901 struct x11drv_win_data
*data
;
1904 Window xparent
, xroot
;
1906 unsigned int nchildren
;
1907 XWindowAttributes attr
;
1908 DWORD style
= WS_CLIPCHILDREN
;
1910 if (!class_registered
)
1914 memset( &class, 0, sizeof(class) );
1915 class.cbSize
= sizeof(class);
1916 class.lpfnWndProc
= foreign_window_proc
;
1917 class.lpszClassName
= classW
;
1918 if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS
)
1920 ERR( "Could not register foreign window class\n" );
1923 class_registered
= TRUE
;
1926 if (XFindContext( display
, xwin
, winContext
, (char **)&hwnd
)) hwnd
= 0;
1927 if (hwnd
) return hwnd
; /* already created */
1929 XSelectInput( display
, xwin
, StructureNotifyMask
);
1930 if (!XGetWindowAttributes( display
, xwin
, &attr
) ||
1931 !XQueryTree( display
, xwin
, &xroot
, &xparent
, &xchildren
, &nchildren
))
1933 XSelectInput( display
, xwin
, 0 );
1938 if (xparent
== xroot
)
1940 parent
= GetDesktopWindow();
1942 pos
= root_to_virtual_screen( attr
.x
, attr
.y
);
1946 parent
= create_foreign_window( display
, xparent
);
1952 hwnd
= CreateWindowW( classW
, NULL
, style
, pos
.x
, pos
.y
, attr
.width
, attr
.height
,
1953 parent
, 0, 0, NULL
);
1955 if (!(data
= alloc_win_data( display
, hwnd
)))
1957 DestroyWindow( hwnd
);
1960 SetRect( &data
->window_rect
, pos
.x
, pos
.y
, pos
.x
+ attr
.width
, pos
.y
+ attr
.height
);
1961 data
->whole_rect
= data
->client_rect
= data
->window_rect
;
1962 data
->whole_window
= data
->client_window
= 0;
1963 data
->embedded
= TRUE
;
1964 data
->mapped
= TRUE
;
1966 SetPropA( hwnd
, foreign_window_prop
, (HANDLE
)xwin
);
1967 XSaveContext( display
, xwin
, winContext
, (char *)data
->hwnd
);
1969 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
1970 xwin
, parent
, style
, wine_dbgstr_rect(&data
->window_rect
), hwnd
);
1972 release_win_data( data
);
1974 ShowWindow( hwnd
, SW_SHOW
);
1979 /***********************************************************************
1980 * X11DRV_get_whole_window
1982 * Return the X window associated with the full area of a window
1984 Window
X11DRV_get_whole_window( HWND hwnd
)
1986 struct x11drv_win_data
*data
= get_win_data( hwnd
);
1991 if (hwnd
== GetDesktopWindow()) return root_window
;
1992 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1994 ret
= data
->whole_window
;
1995 release_win_data( data
);
2000 /***********************************************************************
2003 * Return the X input context associated with a window
2005 XIC
X11DRV_get_ic( HWND hwnd
)
2007 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2013 x11drv_thread_data()->last_xic_hwnd
= hwnd
;
2015 if (!ret
&& (xim
= x11drv_thread_data()->xim
)) ret
= X11DRV_CreateIC( xim
, data
);
2016 release_win_data( data
);
2022 /***********************************************************************
2023 * X11DRV_GetDC (X11DRV.@)
2025 void CDECL
X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
2026 const RECT
*top_rect
, DWORD flags
)
2028 struct x11drv_escape_set_drawable escape
;
2031 escape
.code
= X11DRV_SET_DRAWABLE
;
2032 escape
.mode
= IncludeInferiors
;
2034 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
2035 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
2036 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
2037 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
2041 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2043 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
2045 /* special case: when repainting the root window, clip out top-level windows */
2046 if (data
&& data
->whole_window
== root_window
) escape
.mode
= ClipByChildren
;
2047 release_win_data( data
);
2051 /* find the first ancestor that has a drawable */
2052 for (parent
= hwnd
; parent
&& parent
!= top
; parent
= GetAncestor( parent
, GA_PARENT
))
2053 if ((escape
.drawable
= X11DRV_get_whole_window( parent
))) break;
2055 if (escape
.drawable
)
2057 POINT pt
= { 0, 0 };
2058 MapWindowPoints( 0, parent
, &pt
, 1 );
2059 escape
.dc_rect
= *win_rect
;
2060 OffsetRect( &escape
.dc_rect
, pt
.x
, pt
.y
);
2061 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
2063 else escape
.drawable
= X11DRV_get_whole_window( top
);
2066 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2070 /***********************************************************************
2071 * X11DRV_ReleaseDC (X11DRV.@)
2073 void CDECL
X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
2075 struct x11drv_escape_set_drawable escape
;
2077 escape
.code
= X11DRV_SET_DRAWABLE
;
2078 escape
.drawable
= root_window
;
2079 escape
.mode
= IncludeInferiors
;
2080 escape
.dc_rect
= get_virtual_screen_rect();
2081 OffsetRect( &escape
.dc_rect
, -2 * escape
.dc_rect
.left
, -2 * escape
.dc_rect
.top
);
2082 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2086 /*************************************************************************
2087 * ScrollDC (X11DRV.@)
2089 BOOL CDECL
X11DRV_ScrollDC( HDC hdc
, INT dx
, INT dy
, HRGN update
)
2093 HRGN expose_rgn
= 0;
2095 GetClipBox( hdc
, &rect
);
2099 INT code
= X11DRV_START_EXPOSURES
;
2100 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2102 ret
= BitBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2103 hdc
, rect
.left
- dx
, rect
.top
- dy
, SRCCOPY
);
2105 code
= X11DRV_END_EXPOSURES
;
2106 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
,
2107 sizeof(expose_rgn
), (LPSTR
)&expose_rgn
);
2110 CombineRgn( update
, update
, expose_rgn
, RGN_OR
);
2111 DeleteObject( expose_rgn
);
2114 else ret
= BitBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2115 hdc
, rect
.left
- dx
, rect
.top
- dy
, SRCCOPY
);
2121 /***********************************************************************
2122 * SetCapture (X11DRV.@)
2124 void CDECL
X11DRV_SetCapture( HWND hwnd
, UINT flags
)
2126 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2127 struct x11drv_win_data
*data
;
2129 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
2133 if (!(data
= get_win_data( GetAncestor( hwnd
, GA_ROOT
)))) return;
2134 if (data
->whole_window
)
2136 XFlush( gdi_display
);
2137 XGrabPointer( data
->display
, data
->whole_window
, False
,
2138 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
2139 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
2140 thread_data
->grab_hwnd
= data
->hwnd
;
2142 release_win_data( data
);
2144 else /* release capture */
2146 if (!(data
= get_win_data( thread_data
->grab_hwnd
))) return;
2147 XFlush( gdi_display
);
2148 XUngrabPointer( data
->display
, CurrentTime
);
2149 XFlush( data
->display
);
2150 thread_data
->grab_hwnd
= NULL
;
2151 release_win_data( data
);
2156 /*****************************************************************
2157 * SetParent (X11DRV.@)
2159 void CDECL
X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
2161 struct x11drv_win_data
*data
;
2163 if (parent
== old_parent
) return;
2164 if (!(data
= get_win_data( hwnd
))) return;
2165 if (data
->embedded
) goto done
;
2167 if (parent
!= GetDesktopWindow()) /* a child window */
2169 if (old_parent
== GetDesktopWindow())
2171 /* destroy the old X windows */
2172 destroy_whole_window( data
, FALSE
);
2173 data
->managed
= FALSE
;
2176 else /* new top level window */
2178 create_whole_window( data
);
2181 release_win_data( data
);
2182 set_gl_drawable_parent( hwnd
, parent
);
2183 fetch_icon_data( hwnd
, 0, 0 );
2187 static inline RECT
get_surface_rect( const RECT
*visible_rect
)
2189 RECT rect
= get_virtual_screen_rect();
2191 IntersectRect( &rect
, &rect
, visible_rect
);
2192 OffsetRect( &rect
, -visible_rect
->left
, -visible_rect
->top
);
2195 rect
.right
= max( rect
.left
+ 32, (rect
.right
+ 31) & ~31 );
2196 rect
.bottom
= max( rect
.top
+ 32, (rect
.bottom
+ 31) & ~31 );
2201 /***********************************************************************
2202 * WindowPosChanging (X11DRV.@)
2204 void CDECL
X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2205 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
,
2206 struct window_surface
**surface
)
2208 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2212 BOOL layered
= GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
;
2214 if (!data
&& !(data
= X11DRV_create_win_data( hwnd
, window_rect
, client_rect
))) return;
2216 /* check if we need to switch the window to managed */
2217 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
2219 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
2220 release_win_data( data
);
2221 unmap_window( hwnd
);
2222 if (!(data
= get_win_data( hwnd
))) return;
2223 data
->managed
= TRUE
;
2226 *visible_rect
= *window_rect
;
2227 X11DRV_window_to_X_rect( data
, visible_rect
);
2229 /* create the window surface if necessary */
2231 if (!data
->whole_window
&& !data
->embedded
) goto done
;
2232 if (swp_flags
& SWP_HIDEWINDOW
) goto done
;
2233 if (data
->vis
.visualid
!= default_visual
.visualid
) goto done
;
2235 if (*surface
) window_surface_release( *surface
);
2236 *surface
= NULL
; /* indicate that we want to draw directly to the window */
2238 if (data
->embedded
) goto done
;
2239 if (data
->whole_window
== root_window
) goto done
;
2240 if (data
->client_window
) goto done
;
2241 if (!client_side_graphics
&& !layered
) goto done
;
2243 surface_rect
= get_surface_rect( visible_rect
);
2246 if (EqualRect( &data
->surface
->rect
, &surface_rect
))
2248 /* existing surface is good enough */
2249 window_surface_add_ref( data
->surface
);
2250 *surface
= data
->surface
;
2254 else if (!(swp_flags
& SWP_SHOWWINDOW
) && !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) goto done
;
2256 if (!layered
|| !GetLayeredWindowAttributes( hwnd
, &key
, NULL
, &flags
) || !(flags
& LWA_COLORKEY
))
2259 *surface
= create_surface( data
->whole_window
, &data
->vis
, &surface_rect
, key
, FALSE
);
2262 release_win_data( data
);
2266 /***********************************************************************
2267 * WindowPosChanged (X11DRV.@)
2269 void CDECL
X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2270 const RECT
*rectWindow
, const RECT
*rectClient
,
2271 const RECT
*visible_rect
, const RECT
*valid_rects
,
2272 struct window_surface
*surface
)
2274 struct x11drv_thread_data
*thread_data
;
2275 struct x11drv_win_data
*data
;
2276 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2277 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
2280 if (!(data
= get_win_data( hwnd
))) return;
2282 thread_data
= x11drv_thread_data();
2284 old_window_rect
= data
->window_rect
;
2285 old_whole_rect
= data
->whole_rect
;
2286 old_client_rect
= data
->client_rect
;
2287 data
->window_rect
= *rectWindow
;
2288 data
->whole_rect
= *visible_rect
;
2289 data
->client_rect
= *rectClient
;
2290 if (data
->vis
.visualid
== default_visual
.visualid
)
2292 if (surface
) window_surface_add_ref( surface
);
2293 if (data
->surface
) window_surface_release( data
->surface
);
2294 data
->surface
= surface
;
2297 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2298 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
2300 if (!IsRectEmpty( &valid_rects
[0] ))
2302 Window window
= data
->whole_window
;
2303 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
2304 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
2306 /* if all that happened is that the whole window moved, copy everything */
2307 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2308 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
2309 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
2310 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
2311 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
2312 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
2313 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
2314 EqualRect( &valid_rects
[0], &data
->client_rect
))
2316 /* if we have an X window the bits will be moved by the X server */
2317 if (!window
&& (x_offset
!= 0 || y_offset
!= 0))
2319 release_win_data( data
);
2320 move_window_bits( hwnd
, window
, &old_whole_rect
, visible_rect
,
2321 &old_client_rect
, rectClient
, rectWindow
);
2322 if (!(data
= get_win_data( hwnd
))) return;
2327 release_win_data( data
);
2328 move_window_bits( hwnd
, window
, &valid_rects
[1], &valid_rects
[0],
2329 &old_client_rect
, rectClient
, rectWindow
);
2330 if (!(data
= get_win_data( hwnd
))) return;
2334 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2336 sync_client_position( data
, &old_client_rect
, &old_whole_rect
);
2338 if (!data
->whole_window
)
2340 release_win_data( data
);
2341 sync_gl_drawable( hwnd
, visible_rect
, rectClient
);
2345 /* check if we are currently processing an event relevant to this window */
2348 thread_data
->current_event
&&
2349 thread_data
->current_event
->xany
.window
== data
->whole_window
)
2351 event_type
= thread_data
->current_event
->type
;
2352 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
&&
2353 event_type
!= GravityNotify
&& event_type
!= ReparentNotify
)
2354 event_type
= 0; /* ignore other events */
2357 if (data
->mapped
&& event_type
!= ReparentNotify
)
2359 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2360 (!event_type
&& !(new_style
& WS_MINIMIZE
) &&
2361 !is_window_rect_mapped( rectWindow
) && is_window_rect_mapped( &old_window_rect
)))
2363 release_win_data( data
);
2364 unmap_window( hwnd
);
2365 if (is_window_rect_fullscreen( &old_window_rect
)) reset_clipping_window();
2366 if (!(data
= get_win_data( hwnd
))) return;
2370 /* don't change position if we are about to minimize or maximize a managed window */
2372 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2373 sync_window_position( data
, swp_flags
, &old_window_rect
, &old_whole_rect
, &old_client_rect
);
2375 if ((new_style
& WS_VISIBLE
) &&
2376 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2380 BOOL needs_icon
= !data
->icon_pixmap
;
2381 BOOL needs_map
= TRUE
;
2383 /* layered windows are mapped only once their attributes are set */
2384 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
) needs_map
= data
->layered
;
2385 release_win_data( data
);
2386 if (needs_icon
) fetch_icon_data( hwnd
, 0, 0 );
2387 if (needs_map
) map_window( hwnd
, new_style
);
2390 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2392 set_wm_hints( data
);
2393 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2394 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2396 XIconifyWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
2397 else if (is_window_rect_mapped( rectWindow
))
2398 XMapWindow( data
->display
, data
->whole_window
);
2399 update_net_wm_states( data
);
2403 if (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)) set_wm_hints( data
);
2404 if (!event_type
) update_net_wm_states( data
);
2408 XFlush( data
->display
); /* make sure changes are done before we start painting again */
2409 if (data
->surface
&& data
->vis
.visualid
!= default_visual
.visualid
)
2410 data
->surface
->funcs
->flush( data
->surface
);
2412 release_win_data( data
);
2415 /* check if the window icon should be hidden (i.e. moved off-screen) */
2416 static BOOL
hide_icon( struct x11drv_win_data
*data
)
2418 static const WCHAR trayW
[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
2420 if (data
->managed
) return TRUE
;
2421 /* hide icons in desktop mode when the taskbar is active */
2422 if (root_window
== DefaultRootWindow( gdi_display
)) return FALSE
;
2423 return IsWindowVisible( FindWindowW( trayW
, NULL
));
2426 /***********************************************************************
2427 * ShowWindow (X11DRV.@)
2429 UINT CDECL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2432 unsigned int width
, height
, border
, depth
;
2435 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2436 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2437 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2439 if (!data
|| !data
->whole_window
) goto done
;
2440 if (IsRectEmpty( rect
)) goto done
;
2441 if (style
& WS_MINIMIZE
)
2443 if (((rect
->left
!= -32000 || rect
->top
!= -32000)) && hide_icon( data
))
2445 OffsetRect( rect
, -32000 - rect
->left
, -32000 - rect
->top
);
2446 swp
&= ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
);
2450 if (!data
->managed
|| !data
->mapped
|| data
->iconic
) goto done
;
2452 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2454 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2457 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2458 thread_data
->current_event
->type
!= PropertyNotify
)
2461 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2462 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2464 XGetGeometry( thread_data
->display
, data
->whole_window
,
2465 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2466 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2467 pos
= root_to_virtual_screen( x
, y
);
2470 rect
->right
= pos
.x
+ width
;
2471 rect
->bottom
= pos
.y
+ height
;
2472 X11DRV_X_to_window_rect( data
, rect
);
2473 swp
&= ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2476 release_win_data( data
);
2481 /**********************************************************************
2482 * SetWindowIcon (X11DRV.@)
2484 * hIcon or hIconSm has changed (or is being initialised for the
2485 * first time). Complete the X11 driver-specific initialisation
2486 * and set the window hints.
2488 void CDECL
X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2490 struct x11drv_win_data
*data
;
2492 if (!(data
= get_win_data( hwnd
))) return;
2493 if (!data
->whole_window
) goto done
;
2494 release_win_data( data
); /* release the lock, fetching the icon requires sending messages */
2496 if (type
== ICON_BIG
) fetch_icon_data( hwnd
, icon
, 0 );
2497 else fetch_icon_data( hwnd
, 0, icon
);
2499 if (!(data
= get_win_data( hwnd
))) return;
2500 set_wm_hints( data
);
2502 release_win_data( data
);
2506 /***********************************************************************
2507 * SetWindowRgn (X11DRV.@)
2509 * Assign specified region to window (for non-rectangular windows)
2511 void CDECL
X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2513 struct x11drv_win_data
*data
;
2515 if ((data
= get_win_data( hwnd
)))
2517 sync_window_region( data
, hrgn
);
2518 release_win_data( data
);
2520 else if (X11DRV_get_whole_window( hwnd
))
2522 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2527 /***********************************************************************
2528 * SetLayeredWindowAttributes (X11DRV.@)
2530 * Set transparency attributes for a layered window.
2532 void CDECL
X11DRV_SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
2534 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2538 if (data
->whole_window
)
2539 sync_window_opacity( data
->display
, data
->whole_window
, key
, alpha
, flags
);
2541 set_surface_color_key( data
->surface
, (flags
& LWA_COLORKEY
) ? key
: CLR_INVALID
);
2543 data
->layered
= TRUE
;
2544 if (!data
->mapped
) /* mapping is delayed until attributes are set */
2546 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
2548 if ((style
& WS_VISIBLE
) &&
2549 ((style
& WS_MINIMIZE
) || is_window_rect_mapped( &data
->window_rect
)))
2551 release_win_data( data
);
2552 map_window( hwnd
, style
);
2556 release_win_data( data
);
2560 Window win
= X11DRV_get_whole_window( hwnd
);
2563 sync_window_opacity( gdi_display
, win
, key
, alpha
, flags
);
2564 if (flags
& LWA_COLORKEY
)
2565 FIXME( "LWA_COLORKEY not supported on foreign process window %p\n", hwnd
);
2571 /*****************************************************************************
2572 * UpdateLayeredWindow (X11DRV.@)
2574 BOOL CDECL
X11DRV_UpdateLayeredWindow( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
,
2575 const RECT
*window_rect
)
2577 struct window_surface
*surface
;
2578 struct x11drv_win_data
*data
;
2579 BLENDFUNCTION blend
= { AC_SRC_OVER
, 0, 255, 0 };
2580 COLORREF color_key
= (info
->dwFlags
& ULW_COLORKEY
) ? info
->crKey
: CLR_INVALID
;
2581 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
2582 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
2583 void *src_bits
, *dst_bits
;
2589 if (!(data
= get_win_data( hwnd
))) return FALSE
;
2591 data
->layered
= TRUE
;
2592 if (!data
->embedded
&& argb_visual
.visualid
) set_window_visual( data
, &argb_visual
);
2594 rect
= *window_rect
;
2595 OffsetRect( &rect
, -window_rect
->left
, -window_rect
->top
);
2597 surface
= data
->surface
;
2598 if (!surface
|| !EqualRect( &surface
->rect
, &rect
))
2600 data
->surface
= create_surface( data
->whole_window
, &data
->vis
, &rect
,
2601 color_key
, !data
->embedded
);
2602 if (surface
) window_surface_release( surface
);
2603 surface
= data
->surface
;
2605 else set_surface_color_key( surface
, color_key
);
2607 if (surface
) window_surface_add_ref( surface
);
2608 release_win_data( data
);
2610 if (!surface
) return FALSE
;
2613 window_surface_release( surface
);
2617 dst_bits
= surface
->funcs
->get_info( surface
, bmi
);
2619 if (!(dib
= CreateDIBSection( info
->hdcDst
, bmi
, DIB_RGB_COLORS
, &src_bits
, NULL
, 0 ))) goto done
;
2620 if (!(hdc
= CreateCompatibleDC( 0 ))) goto done
;
2622 SelectObject( hdc
, dib
);
2624 surface
->funcs
->lock( surface
);
2628 IntersectRect( &rect
, &rect
, info
->prcDirty
);
2629 memcpy( src_bits
, dst_bits
, bmi
->bmiHeader
.biSizeImage
);
2630 PatBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, BLACKNESS
);
2632 ret
= GdiAlphaBlend( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2634 rect
.left
+ (info
->pptSrc
? info
->pptSrc
->x
: 0),
2635 rect
.top
+ (info
->pptSrc
? info
->pptSrc
->y
: 0),
2636 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2637 (info
->dwFlags
& ULW_ALPHA
) ? *info
->pblend
: blend
);
2640 memcpy( dst_bits
, src_bits
, bmi
->bmiHeader
.biSizeImage
);
2641 add_bounds_rect( surface
->funcs
->get_bounds( surface
), &rect
);
2644 surface
->funcs
->unlock( surface
);
2645 surface
->funcs
->flush( surface
);
2648 window_surface_release( surface
);
2649 if (hdc
) DeleteDC( hdc
);
2650 if (dib
) DeleteObject( dib
);
2655 /**********************************************************************
2656 * X11DRV_WindowMessage (X11DRV.@)
2658 LRESULT CDECL
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2660 struct x11drv_win_data
*data
;
2664 case WM_X11DRV_UPDATE_CLIPBOARD
:
2665 return update_clipboard( hwnd
);
2666 case WM_X11DRV_SET_WIN_REGION
:
2667 if ((data
= get_win_data( hwnd
)))
2669 sync_window_region( data
, (HRGN
)1 );
2670 release_win_data( data
);
2673 case WM_X11DRV_RESIZE_DESKTOP
:
2674 X11DRV_resize_desktop( LOWORD(lp
), HIWORD(lp
) );
2676 case WM_X11DRV_SET_CURSOR
:
2677 if ((data
= get_win_data( hwnd
)))
2679 if (data
->whole_window
) set_window_cursor( data
->whole_window
, (HCURSOR
)lp
);
2680 release_win_data( data
);
2682 else if (hwnd
== x11drv_thread_data()->clip_hwnd
)
2683 set_window_cursor( x11drv_thread_data()->clip_window
, (HCURSOR
)lp
);
2685 case WM_X11DRV_CLIP_CURSOR
:
2686 return clip_cursor_notify( hwnd
, (HWND
)lp
);
2688 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2694 /***********************************************************************
2695 * is_netwm_supported
2697 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2699 static Atom
*net_supported
;
2700 static int net_supported_count
= -1;
2703 if (net_supported_count
== -1)
2707 unsigned long count
, remaining
;
2709 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2710 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2711 &remaining
, (unsigned char **)&net_supported
))
2712 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2714 net_supported_count
= 0;
2717 for (i
= 0; i
< net_supported_count
; i
++)
2718 if (net_supported
[i
] == atom
) return TRUE
;
2723 /***********************************************************************
2724 * SysCommand (X11DRV.@)
2726 * Perform WM_SYSCOMMAND handling.
2728 LRESULT CDECL
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2730 WPARAM hittest
= wparam
& 0x0f;
2732 struct x11drv_win_data
*data
;
2734 if (!(data
= get_win_data( hwnd
))) return -1;
2735 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) goto failed
;
2737 switch (wparam
& 0xfff0)
2740 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2741 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2744 /* windows without WS_THICKFRAME are not resizable through the window manager */
2745 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) goto failed
;
2749 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2750 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2751 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2752 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2753 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2754 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2755 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2756 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2757 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2762 /* prevent a simple ALT press+release from activating the system menu,
2763 * as that can get confusing on managed windows */
2764 if ((WCHAR
)lparam
) goto failed
; /* got an explicit char */
2765 if (GetMenu( hwnd
)) goto failed
; /* window has a real menu */
2766 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) goto failed
; /* no system menu */
2767 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2768 release_win_data( data
);
2775 if (IsZoomed(hwnd
)) goto failed
;
2777 if (!is_netwm_supported( data
->display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2779 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2783 release_win_data( data
);
2784 move_resize_window( hwnd
, dir
);
2788 release_win_data( data
);
2792 void CDECL
X11DRV_FlashWindowEx( PFLASHWINFO pfinfo
)
2794 struct x11drv_win_data
*data
= get_win_data( pfinfo
->hwnd
);
2802 xev
.type
= ClientMessage
;
2803 xev
.xclient
.window
= data
->whole_window
;
2804 xev
.xclient
.message_type
= x11drv_atom( _NET_WM_STATE
);
2805 xev
.xclient
.serial
= 0;
2806 xev
.xclient
.display
= data
->display
;
2807 xev
.xclient
.send_event
= True
;
2808 xev
.xclient
.format
= 32;
2809 xev
.xclient
.data
.l
[0] = pfinfo
->dwFlags
? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
2810 xev
.xclient
.data
.l
[1] = x11drv_atom( _NET_WM_STATE_DEMANDS_ATTENTION
);
2811 xev
.xclient
.data
.l
[2] = 0;
2812 xev
.xclient
.data
.l
[3] = 1;
2813 xev
.xclient
.data
.l
[4] = 0;
2815 XSendEvent( data
->display
, DefaultRootWindow( data
->display
), False
,
2816 SubstructureNotifyMask
, &xev
);
2818 release_win_data( data
);