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
{
76 #define NUM_DESKTOP_MODES (sizeof(screen_sizes) / sizeof(struct screen_size))
78 #define _NET_WM_STATE_REMOVE 0
79 #define _NET_WM_STATE_ADD 1
81 /* create the mode structures */
82 static void make_modes(void)
84 RECT primary_rect
= get_primary_monitor_rect();
86 unsigned int screen_width
= primary_rect
.right
- primary_rect
.left
;
87 unsigned int screen_height
= primary_rect
.bottom
- primary_rect
.top
;
89 /* original specified desktop size */
90 X11DRV_Settings_AddOneMode(screen_width
, screen_height
, 0, 60);
91 for (i
=0; i
<NUM_DESKTOP_MODES
; i
++)
93 if ( (screen_sizes
[i
].width
<= max_width
) && (screen_sizes
[i
].height
<= max_height
) )
95 if ( ( (screen_sizes
[i
].width
!= max_width
) || (screen_sizes
[i
].height
!= max_height
) ) &&
96 ( (screen_sizes
[i
].width
!= screen_width
) || (screen_sizes
[i
].height
!= screen_height
) ) )
98 /* only add them if they are smaller than the root window and unique */
99 X11DRV_Settings_AddOneMode(screen_sizes
[i
].width
, screen_sizes
[i
].height
, 0, 60);
103 if ((max_width
!= screen_width
) && (max_height
!= screen_height
))
105 /* root window size (if different from desktop window) */
106 X11DRV_Settings_AddOneMode(max_width
, max_height
, 0, 60);
110 static int X11DRV_desktop_GetCurrentMode(void)
113 DWORD dwBpp
= screen_bpp
;
114 RECT primary_rect
= get_primary_monitor_rect();
116 for (i
=0; i
<dd_mode_count
; i
++)
118 if ( (primary_rect
.right
- primary_rect
.left
== dd_modes
[i
].width
) &&
119 (primary_rect
.bottom
- primary_rect
.top
== dd_modes
[i
].height
) &&
120 (dwBpp
== dd_modes
[i
].bpp
))
123 ERR("In unknown mode, returning default\n");
127 static LONG
X11DRV_desktop_SetCurrentMode(int mode
)
129 DWORD dwBpp
= screen_bpp
;
130 if (dwBpp
!= dd_modes
[mode
].bpp
)
132 FIXME("Cannot change screen BPP from %d to %d\n", dwBpp
, dd_modes
[mode
].bpp
);
133 /* Ignore the depth mismatch
135 * Some (older) applications require a specific bit depth, this will allow them
136 * to run. X11drv performs a color depth conversion if needed.
139 TRACE("Resizing Wine desktop window to %dx%d\n", dd_modes
[mode
].width
, dd_modes
[mode
].height
);
140 X11DRV_resize_desktop(dd_modes
[mode
].width
, dd_modes
[mode
].height
);
141 return DISP_CHANGE_SUCCESSFUL
;
144 /***********************************************************************
145 * X11DRV_init_desktop
147 * Setup the desktop when not using the root window.
149 void X11DRV_init_desktop( Window win
, unsigned int width
, unsigned int height
)
151 RECT primary_rect
= get_primary_monitor_rect();
154 managed_mode
= FALSE
; /* no managed windows in desktop mode */
155 max_width
= primary_rect
.right
- primary_rect
.left
;
156 max_height
= primary_rect
.bottom
- primary_rect
.top
;
157 xinerama_init( width
, height
);
159 /* initialize the available resolutions */
160 dd_modes
= X11DRV_Settings_SetHandlers("desktop",
161 X11DRV_desktop_GetCurrentMode
,
162 X11DRV_desktop_SetCurrentMode
,
163 NUM_DESKTOP_MODES
+2, 1);
165 X11DRV_Settings_AddDepthModes();
166 dd_mode_count
= X11DRV_Settings_GetModeCount();
170 /***********************************************************************
171 * X11DRV_create_desktop
173 * Create the X11 desktop window for the desktop mode.
175 BOOL CDECL
X11DRV_create_desktop( UINT width
, UINT height
)
177 XSetWindowAttributes win_attr
;
179 Display
*display
= thread_init_display();
182 TRACE( "%u x %u\n", width
, height
);
185 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
| EnterWindowMask
|
186 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
| FocusChangeMask
;
187 win_attr
.cursor
= XCreateFontCursor( display
, XC_top_left_arrow
);
189 if (default_visual
.visual
!= DefaultVisual( display
, DefaultScreen(display
) ))
190 win_attr
.colormap
= XCreateColormap( display
, DefaultRootWindow(display
),
191 default_visual
.visual
, AllocNone
);
193 win_attr
.colormap
= None
;
195 win
= XCreateWindow( display
, DefaultRootWindow(display
),
196 0, 0, width
, height
, 0, default_visual
.depth
, InputOutput
, default_visual
.visual
,
197 CWEventMask
| CWCursor
| CWColormap
, &win_attr
);
198 if (!win
) return FALSE
;
200 SetRect( &rect
, 0, 0, width
, height
);
201 if (is_window_rect_fullscreen( &rect
))
203 TRACE("setting desktop to fullscreen\n");
204 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
, 32,
205 PropModeReplace
, (unsigned char*)&x11drv_atom(_NET_WM_STATE_FULLSCREEN
),
208 if (!create_desktop_win_data( win
)) return FALSE
;
210 X11DRV_init_desktop( win
, width
, height
);
215 struct desktop_resize_data
217 RECT old_virtual_rect
;
218 RECT new_virtual_rect
;
221 static BOOL CALLBACK
update_windows_on_desktop_resize( HWND hwnd
, LPARAM lparam
)
223 struct x11drv_win_data
*data
;
224 struct desktop_resize_data
*resize_data
= (struct desktop_resize_data
*)lparam
;
227 if (!(data
= get_win_data( hwnd
))) return TRUE
;
229 /* update the full screen state */
230 update_net_wm_states( data
);
232 if (resize_data
->old_virtual_rect
.left
!= resize_data
->new_virtual_rect
.left
) mask
|= CWX
;
233 if (resize_data
->old_virtual_rect
.top
!= resize_data
->new_virtual_rect
.top
) mask
|= CWY
;
234 if (mask
&& data
->whole_window
)
236 POINT pos
= virtual_screen_to_root( data
->whole_rect
.left
, data
->whole_rect
.top
);
237 XWindowChanges changes
;
240 XReconfigureWMWindow( data
->display
, data
->whole_window
, data
->vis
.screen
, mask
, &changes
);
242 release_win_data( data
);
243 if (hwnd
== GetForegroundWindow()) clip_fullscreen_window( hwnd
, TRUE
);
247 BOOL
is_desktop_fullscreen(void)
249 RECT primary_rect
= get_primary_monitor_rect();
250 return (primary_rect
.right
- primary_rect
.left
== max_width
&&
251 primary_rect
.bottom
- primary_rect
.top
== max_height
);
254 static void update_desktop_fullscreen( unsigned int width
, unsigned int height
)
256 Display
*display
= thread_display();
259 if (!display
|| root_window
== DefaultRootWindow( display
)) return;
261 xev
.xclient
.type
= ClientMessage
;
262 xev
.xclient
.window
= root_window
;
263 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
264 xev
.xclient
.serial
= 0;
265 xev
.xclient
.display
= display
;
266 xev
.xclient
.send_event
= True
;
267 xev
.xclient
.format
= 32;
268 if (width
== max_width
&& height
== max_height
)
269 xev
.xclient
.data
.l
[0] = _NET_WM_STATE_ADD
;
271 xev
.xclient
.data
.l
[0] = _NET_WM_STATE_REMOVE
;
272 xev
.xclient
.data
.l
[1] = x11drv_atom(_NET_WM_STATE_FULLSCREEN
);
273 xev
.xclient
.data
.l
[2] = 0;
274 xev
.xclient
.data
.l
[3] = 1;
276 TRACE("action=%li\n", xev
.xclient
.data
.l
[0]);
278 XSendEvent( display
, DefaultRootWindow(display
), False
,
279 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
281 xev
.xclient
.data
.l
[1] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_VERT
);
282 xev
.xclient
.data
.l
[2] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
283 XSendEvent( display
, DefaultRootWindow(display
), False
,
284 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
287 /***********************************************************************
288 * X11DRV_resize_desktop
290 void X11DRV_resize_desktop( unsigned int width
, unsigned int height
)
292 HWND hwnd
= GetDesktopWindow();
293 struct desktop_resize_data resize_data
;
295 resize_data
.old_virtual_rect
= get_virtual_screen_rect();
297 xinerama_init( width
, height
);
298 resize_data
.new_virtual_rect
= get_virtual_screen_rect();
300 if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
302 SendMessageW( hwnd
, WM_X11DRV_RESIZE_DESKTOP
, 0, MAKELPARAM( width
, height
) );
306 TRACE( "desktop %p change to (%dx%d)\n", hwnd
, width
, height
);
307 update_desktop_fullscreen( width
, height
);
308 SetWindowPos( hwnd
, 0, resize_data
.new_virtual_rect
.left
, resize_data
.new_virtual_rect
.top
,
309 resize_data
.new_virtual_rect
.right
- resize_data
.new_virtual_rect
.left
,
310 resize_data
.new_virtual_rect
.bottom
- resize_data
.new_virtual_rect
.top
,
311 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_DEFERERASE
);
312 ungrab_clipping_window();
313 SendMessageTimeoutW( HWND_BROADCAST
, WM_DISPLAYCHANGE
, screen_bpp
,
314 MAKELPARAM( width
, height
), SMTO_ABORTIFHUNG
, 2000, NULL
);
317 EnumWindows( update_windows_on_desktop_resize
, (LPARAM
)&resize_data
);