2 * X11DRV desktop window handling
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <X11/cursorfont.h>
27 /* avoid conflict with field names in included win32 headers */
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
33 /* data for resolution changing */
34 static struct x11drv_mode_info
*dd_modes
;
35 static unsigned int dd_mode_count
;
37 static unsigned int max_width
;
38 static unsigned int max_height
;
40 static struct screen_size
{
77 #define _NET_WM_STATE_REMOVE 0
78 #define _NET_WM_STATE_ADD 1
80 /* create the mode structures */
81 static void make_modes(void)
83 RECT primary_rect
= get_primary_monitor_rect();
85 unsigned int screen_width
= primary_rect
.right
- primary_rect
.left
;
86 unsigned int screen_height
= primary_rect
.bottom
- primary_rect
.top
;
88 /* original specified desktop size */
89 X11DRV_Settings_AddOneMode(screen_width
, screen_height
, 0, 60);
90 for (i
=0; i
<ARRAY_SIZE(screen_sizes
); i
++)
92 if ( (screen_sizes
[i
].width
<= max_width
) && (screen_sizes
[i
].height
<= max_height
) )
94 if ( ( (screen_sizes
[i
].width
!= max_width
) || (screen_sizes
[i
].height
!= max_height
) ) &&
95 ( (screen_sizes
[i
].width
!= screen_width
) || (screen_sizes
[i
].height
!= screen_height
) ) )
97 /* only add them if they are smaller than the root window and unique */
98 X11DRV_Settings_AddOneMode(screen_sizes
[i
].width
, screen_sizes
[i
].height
, 0, 60);
102 if ((max_width
!= screen_width
) && (max_height
!= screen_height
))
104 /* root window size (if different from desktop window) */
105 X11DRV_Settings_AddOneMode(max_width
, max_height
, 0, 60);
109 static int X11DRV_desktop_GetCurrentMode(void)
112 DWORD dwBpp
= screen_bpp
;
113 RECT primary_rect
= get_primary_monitor_rect();
115 for (i
=0; i
<dd_mode_count
; i
++)
117 if ( (primary_rect
.right
- primary_rect
.left
== dd_modes
[i
].width
) &&
118 (primary_rect
.bottom
- primary_rect
.top
== dd_modes
[i
].height
) &&
119 (dwBpp
== dd_modes
[i
].bpp
))
122 ERR("In unknown mode, returning default\n");
126 static LONG
X11DRV_desktop_SetCurrentMode(int mode
)
128 DWORD dwBpp
= screen_bpp
;
129 if (dwBpp
!= dd_modes
[mode
].bpp
)
131 FIXME("Cannot change screen BPP from %d to %d\n", dwBpp
, dd_modes
[mode
].bpp
);
132 /* Ignore the depth mismatch
134 * Some (older) applications require a specific bit depth, this will allow them
135 * to run. X11drv performs a color depth conversion if needed.
138 TRACE("Resizing Wine desktop window to %dx%d\n", dd_modes
[mode
].width
, dd_modes
[mode
].height
);
139 X11DRV_resize_desktop(dd_modes
[mode
].width
, dd_modes
[mode
].height
);
140 return DISP_CHANGE_SUCCESSFUL
;
143 /***********************************************************************
144 * X11DRV_init_desktop
146 * Setup the desktop when not using the root window.
148 void X11DRV_init_desktop( Window win
, unsigned int width
, unsigned int height
)
153 managed_mode
= FALSE
; /* no managed windows in desktop mode */
155 xinerama_init( width
, height
);
156 X11DRV_DisplayDevices_Init( TRUE
);
158 primary_rect
= get_primary_monitor_rect();
159 max_width
= primary_rect
.right
- primary_rect
.left
;
160 max_height
= primary_rect
.bottom
- primary_rect
.top
;
162 /* initialize the available resolutions */
163 dd_modes
= X11DRV_Settings_SetHandlers("desktop",
164 X11DRV_desktop_GetCurrentMode
,
165 X11DRV_desktop_SetCurrentMode
,
166 ARRAY_SIZE(screen_sizes
)+2, 1);
168 X11DRV_Settings_AddDepthModes();
169 dd_mode_count
= X11DRV_Settings_GetModeCount();
173 /***********************************************************************
174 * X11DRV_create_desktop
176 * Create the X11 desktop window for the desktop mode.
178 BOOL CDECL
X11DRV_create_desktop( UINT width
, UINT height
)
180 static const WCHAR rootW
[] = {'r','o','o','t',0};
181 XSetWindowAttributes win_attr
;
183 Display
*display
= thread_init_display();
185 WCHAR name
[MAX_PATH
];
187 if (!GetUserObjectInformationW( GetThreadDesktop( GetCurrentThreadId() ),
188 UOI_NAME
, name
, sizeof(name
), NULL
))
191 TRACE( "%s %ux%u\n", debugstr_w(name
), width
, height
);
193 /* magic: desktop "root" means use the root window */
194 if (!lstrcmpiW( name
, rootW
)) return FALSE
;
197 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
| EnterWindowMask
|
198 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
| FocusChangeMask
;
199 win_attr
.cursor
= XCreateFontCursor( display
, XC_top_left_arrow
);
201 if (default_visual
.visual
!= DefaultVisual( display
, DefaultScreen(display
) ))
202 win_attr
.colormap
= XCreateColormap( display
, DefaultRootWindow(display
),
203 default_visual
.visual
, AllocNone
);
205 win_attr
.colormap
= None
;
207 win
= XCreateWindow( display
, DefaultRootWindow(display
),
208 0, 0, width
, height
, 0, default_visual
.depth
, InputOutput
, default_visual
.visual
,
209 CWEventMask
| CWCursor
| CWColormap
, &win_attr
);
210 if (!win
) return FALSE
;
212 SetRect( &rect
, 0, 0, width
, height
);
213 if (is_window_rect_fullscreen( &rect
))
215 TRACE("setting desktop to fullscreen\n");
216 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
, 32,
217 PropModeReplace
, (unsigned char*)&x11drv_atom(_NET_WM_STATE_FULLSCREEN
),
220 if (!create_desktop_win_data( win
)) return FALSE
;
222 X11DRV_init_desktop( win
, width
, height
);
227 struct desktop_resize_data
229 RECT old_virtual_rect
;
230 RECT new_virtual_rect
;
233 static BOOL CALLBACK
update_windows_on_desktop_resize( HWND hwnd
, LPARAM lparam
)
235 struct x11drv_win_data
*data
;
236 struct desktop_resize_data
*resize_data
= (struct desktop_resize_data
*)lparam
;
239 if (!(data
= get_win_data( hwnd
))) return TRUE
;
241 /* update the full screen state */
242 update_net_wm_states( data
);
244 if (resize_data
->old_virtual_rect
.left
!= resize_data
->new_virtual_rect
.left
) mask
|= CWX
;
245 if (resize_data
->old_virtual_rect
.top
!= resize_data
->new_virtual_rect
.top
) mask
|= CWY
;
246 if (mask
&& data
->whole_window
)
248 POINT pos
= virtual_screen_to_root( data
->whole_rect
.left
, data
->whole_rect
.top
);
249 XWindowChanges changes
;
252 XReconfigureWMWindow( data
->display
, data
->whole_window
, data
->vis
.screen
, mask
, &changes
);
254 release_win_data( data
);
255 if (hwnd
== GetForegroundWindow()) clip_fullscreen_window( hwnd
, TRUE
);
259 BOOL
is_desktop_fullscreen(void)
261 RECT primary_rect
= get_primary_monitor_rect();
262 return (primary_rect
.right
- primary_rect
.left
== max_width
&&
263 primary_rect
.bottom
- primary_rect
.top
== max_height
);
266 static void update_desktop_fullscreen( unsigned int width
, unsigned int height
)
268 Display
*display
= thread_display();
271 if (!display
|| root_window
== DefaultRootWindow( display
)) return;
273 xev
.xclient
.type
= ClientMessage
;
274 xev
.xclient
.window
= root_window
;
275 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
276 xev
.xclient
.serial
= 0;
277 xev
.xclient
.display
= display
;
278 xev
.xclient
.send_event
= True
;
279 xev
.xclient
.format
= 32;
280 if (width
== max_width
&& height
== max_height
)
281 xev
.xclient
.data
.l
[0] = _NET_WM_STATE_ADD
;
283 xev
.xclient
.data
.l
[0] = _NET_WM_STATE_REMOVE
;
284 xev
.xclient
.data
.l
[1] = x11drv_atom(_NET_WM_STATE_FULLSCREEN
);
285 xev
.xclient
.data
.l
[2] = 0;
286 xev
.xclient
.data
.l
[3] = 1;
288 TRACE("action=%li\n", xev
.xclient
.data
.l
[0]);
290 XSendEvent( display
, DefaultRootWindow(display
), False
,
291 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
293 xev
.xclient
.data
.l
[1] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_VERT
);
294 xev
.xclient
.data
.l
[2] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
295 XSendEvent( display
, DefaultRootWindow(display
), False
,
296 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
299 /***********************************************************************
300 * X11DRV_resize_desktop
302 void X11DRV_resize_desktop( unsigned int width
, unsigned int height
)
304 HWND hwnd
= GetDesktopWindow();
305 struct desktop_resize_data resize_data
;
307 resize_data
.old_virtual_rect
= get_virtual_screen_rect();
309 xinerama_init( width
, height
);
310 X11DRV_DisplayDevices_Init( TRUE
);
311 resize_data
.new_virtual_rect
= get_virtual_screen_rect();
313 if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
315 SendMessageW( hwnd
, WM_X11DRV_RESIZE_DESKTOP
, 0, MAKELPARAM( width
, height
) );
319 TRACE( "desktop %p change to (%dx%d)\n", hwnd
, width
, height
);
320 update_desktop_fullscreen( width
, height
);
321 SetWindowPos( hwnd
, 0, resize_data
.new_virtual_rect
.left
, resize_data
.new_virtual_rect
.top
,
322 resize_data
.new_virtual_rect
.right
- resize_data
.new_virtual_rect
.left
,
323 resize_data
.new_virtual_rect
.bottom
- resize_data
.new_virtual_rect
.top
,
324 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_DEFERERASE
);
325 ungrab_clipping_window();
326 SendMessageTimeoutW( HWND_BROADCAST
, WM_DISPLAYCHANGE
, screen_bpp
,
327 MAKELPARAM( width
, height
), SMTO_ABORTIFHUNG
, 2000, NULL
);
330 EnumWindows( update_windows_on_desktop_resize
, (LPARAM
)&resize_data
);