wbemprox: Don't fail if there are less objects than asked for in IEnumWbemClassObject...
[wine.git] / dlls / winex11.drv / desktop.c
blob8d9de205874f1011743f1b068f3220b1031e4987
1 /*
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
21 #include "config.h"
22 #include <X11/cursorfont.h>
23 #include <X11/Xlib.h>
25 #include "x11drv.h"
27 /* avoid conflict with field names in included win32 headers */
28 #undef Status
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 const unsigned int widths[] = {320, 400, 512, 640, 800, 1024, 1152, 1280, 1400, 1600};
41 static const unsigned int heights[] = {200, 300, 384, 480, 600, 768, 864, 1024, 1050, 1200};
42 #define NUM_DESKTOP_MODES (sizeof(widths) / sizeof(widths[0]))
44 #define _NET_WM_STATE_REMOVE 0
45 #define _NET_WM_STATE_ADD 1
47 /* create the mode structures */
48 static void make_modes(void)
50 unsigned int i;
51 /* original specified desktop size */
52 X11DRV_Settings_AddOneMode(screen_width, screen_height, 0, 60);
53 for (i=0; i<NUM_DESKTOP_MODES; i++)
55 if ( (widths[i] <= max_width) && (heights[i] <= max_height) )
57 if ( ( (widths[i] != max_width) || (heights[i] != max_height) ) &&
58 ( (widths[i] != screen_width) || (heights[i] != screen_height) ) )
60 /* only add them if they are smaller than the root window and unique */
61 X11DRV_Settings_AddOneMode(widths[i], heights[i], 0, 60);
65 if ((max_width != screen_width) && (max_height != screen_height))
67 /* root window size (if different from desktop window) */
68 X11DRV_Settings_AddOneMode(max_width, max_height, 0, 60);
72 static int X11DRV_desktop_GetCurrentMode(void)
74 unsigned int i;
75 DWORD dwBpp = screen_bpp;
76 for (i=0; i<dd_mode_count; i++)
78 if ( (screen_width == dd_modes[i].width) &&
79 (screen_height == dd_modes[i].height) &&
80 (dwBpp == dd_modes[i].bpp))
81 return i;
83 ERR("In unknown mode, returning default\n");
84 return 0;
87 static LONG X11DRV_desktop_SetCurrentMode(int mode)
89 DWORD dwBpp = screen_bpp;
90 if (dwBpp != dd_modes[mode].bpp)
92 FIXME("Cannot change screen BPP from %d to %d\n", dwBpp, dd_modes[mode].bpp);
93 /* Ignore the depth mismatch
95 * Some (older) applications require a specific bit depth, this will allow them
96 * to run. X11drv performs a color depth conversion if needed.
99 TRACE("Resizing Wine desktop window to %dx%d\n", dd_modes[mode].width, dd_modes[mode].height);
100 X11DRV_resize_desktop(dd_modes[mode].width, dd_modes[mode].height);
101 return DISP_CHANGE_SUCCESSFUL;
104 /***********************************************************************
105 * X11DRV_init_desktop
107 * Setup the desktop when not using the root window.
109 void X11DRV_init_desktop( Window win, unsigned int width, unsigned int height )
111 root_window = win;
112 managed_mode = 0; /* no managed windows in desktop mode */
113 max_width = screen_width;
114 max_height = screen_height;
115 xinerama_init( width, height );
117 /* initialize the available resolutions */
118 dd_modes = X11DRV_Settings_SetHandlers("desktop",
119 X11DRV_desktop_GetCurrentMode,
120 X11DRV_desktop_SetCurrentMode,
121 NUM_DESKTOP_MODES+2, 1);
122 make_modes();
123 X11DRV_Settings_AddDepthModes();
124 dd_mode_count = X11DRV_Settings_GetModeCount();
128 /***********************************************************************
129 * X11DRV_create_desktop
131 * Create the X11 desktop window for the desktop mode.
133 Window CDECL X11DRV_create_desktop( UINT width, UINT height )
135 XSetWindowAttributes win_attr;
136 Window win;
137 Display *display = thread_init_display();
139 TRACE( "%u x %u\n", width, height );
141 /* Create window */
142 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | EnterWindowMask |
143 PointerMotionMask | ButtonPressMask | ButtonReleaseMask | FocusChangeMask;
144 win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
146 if (default_visual.visual != DefaultVisual( display, DefaultScreen(display) ))
147 win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
148 default_visual.visual, AllocNone );
149 else
150 win_attr.colormap = None;
152 win = XCreateWindow( display, DefaultRootWindow(display),
153 0, 0, width, height, 0, default_visual.depth, InputOutput, default_visual.visual,
154 CWEventMask | CWCursor | CWColormap, &win_attr );
155 if (win != None && width == screen_width && height == screen_height)
157 TRACE("setting desktop to fullscreen\n");
158 XChangeProperty( display, win, x11drv_atom(_NET_WM_STATE), XA_ATOM, 32,
159 PropModeReplace, (unsigned char*)&x11drv_atom(_NET_WM_STATE_FULLSCREEN),
162 XFlush( display );
163 if (win != None) X11DRV_init_desktop( win, width, height );
164 return win;
168 struct desktop_resize_data
170 RECT old_screen_rect;
171 RECT old_virtual_rect;
174 static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
176 struct x11drv_win_data *data;
177 struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
178 int mask = 0;
180 if (!(data = get_win_data( hwnd ))) return TRUE;
182 /* update the full screen state */
183 update_net_wm_states( data );
185 if (resize_data->old_virtual_rect.left != virtual_screen_rect.left) mask |= CWX;
186 if (resize_data->old_virtual_rect.top != virtual_screen_rect.top) mask |= CWY;
187 if (mask && data->whole_window)
189 XWindowChanges changes;
191 changes.x = data->whole_rect.left - virtual_screen_rect.left;
192 changes.y = data->whole_rect.top - virtual_screen_rect.top;
193 XReconfigureWMWindow( data->display, data->whole_window, data->vis.screen, mask, &changes );
195 release_win_data( data );
196 if (hwnd == GetForegroundWindow()) clip_fullscreen_window( hwnd, TRUE );
197 return TRUE;
200 BOOL is_desktop_fullscreen(void)
202 return screen_width == max_width && screen_height == max_height;
205 static void update_desktop_fullscreen( unsigned int width, unsigned int height)
207 Display *display = thread_display();
208 XEvent xev;
210 if (!display || root_window == DefaultRootWindow( display )) return;
212 xev.xclient.type = ClientMessage;
213 xev.xclient.window = root_window;
214 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
215 xev.xclient.serial = 0;
216 xev.xclient.display = display;
217 xev.xclient.send_event = True;
218 xev.xclient.format = 32;
219 if (width == max_width && height == max_height)
220 xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
221 else
222 xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE;
223 xev.xclient.data.l[1] = x11drv_atom(_NET_WM_STATE_FULLSCREEN);
224 xev.xclient.data.l[2] = 0;
225 xev.xclient.data.l[3] = 1;
227 TRACE("action=%li\n", xev.xclient.data.l[0]);
229 XSendEvent( display, DefaultRootWindow(display), False,
230 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
232 xev.xclient.data.l[1] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_VERT);
233 xev.xclient.data.l[2] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ);
234 XSendEvent( display, DefaultRootWindow(display), False,
235 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
238 /***********************************************************************
239 * X11DRV_resize_desktop
241 void X11DRV_resize_desktop( unsigned int width, unsigned int height )
243 HWND hwnd = GetDesktopWindow();
244 struct desktop_resize_data resize_data;
246 SetRect( &resize_data.old_screen_rect, 0, 0, screen_width, screen_height );
247 resize_data.old_virtual_rect = virtual_screen_rect;
249 xinerama_init( width, height );
251 if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
253 SendMessageW( hwnd, WM_X11DRV_RESIZE_DESKTOP, 0, MAKELPARAM( width, height ) );
255 else
257 TRACE( "desktop %p change to (%dx%d)\n", hwnd, width, height );
258 update_desktop_fullscreen( width, height );
259 SetWindowPos( hwnd, 0, virtual_screen_rect.left, virtual_screen_rect.top,
260 virtual_screen_rect.right - virtual_screen_rect.left,
261 virtual_screen_rect.bottom - virtual_screen_rect.top,
262 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE );
263 ungrab_clipping_window();
264 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_bpp,
265 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
268 EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );