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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <X11/cursorfont.h>
26 #include "wine/winuser16.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
36 /* desktop window procedure */
37 static LRESULT WINAPI desktop_winproc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
42 SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
43 SetDeskWallPaper( (LPSTR)-1 );
47 PaintDesktop( (HDC)wParam );
48 ValidateRect( hwnd, NULL );
52 if ((wParam & 0xfff0) == SC_CLOSE) ExitWindows( 0, 0 );
56 return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)IDC_ARROW ) );
65 /* desktop window manager thread */
66 static DWORD CALLBACK desktop_thread( LPVOID driver_data )
72 Atom atom = x11drv_atom(WM_DELETE_WINDOW);
74 NtCurrentTeb()->driver_data = driver_data;
75 display = thread_display();
76 hwnd = GetDesktopWindow();
78 /* patch the desktop window queue to point to our queue */
79 win = WIN_GetPtr( hwnd );
80 win->tid = GetCurrentThreadId();
81 X11DRV_register_window( display, hwnd, win->pDriverData );
82 WIN_ReleasePtr( win );
84 SetWindowLongW( hwnd, GWL_WNDPROC, (LONG)desktop_winproc );
86 XChangeProperty ( display, root_window, x11drv_atom(WM_PROTOCOLS),
87 XA_ATOM, 32, PropModeReplace, (char *)&atom, 1 );
88 XMapWindow( display, root_window );
91 SendMessageW( hwnd, WM_NCCREATE, 0, 0 /* should be CREATESTRUCT */ );
93 while (GetMessageW( &msg, hwnd, 0, 0 )) DispatchMessageW( &msg );
98 /***********************************************************************
99 * X11DRV_create_desktop_thread
101 * Create the thread that manages the desktop window
103 void X11DRV_create_desktop_thread(void)
105 HANDLE handle = CreateThread( NULL, 0, desktop_thread, NtCurrentTeb()->driver_data,
109 MESSAGE( "Could not create desktop thread\n" );
112 /* we transferred our driver data to the new thread */
113 NtCurrentTeb()->driver_data = NULL;
114 CloseHandle( handle );
118 /* data for resolution changing */
119 static LPDDHALMODEINFO dd_modes;
120 static unsigned int dd_mode_count;
122 static unsigned int max_width;
123 static unsigned int max_height;
125 static const unsigned int widths[] = {320, 512, 640, 800, 1024, 1152, 1280, 1600};
126 static const unsigned int heights[] = {200, 384, 480, 600, 768, 864, 1024, 1200};
127 #define NUM_DESKTOP_MODES (8)
129 /* create the mode structures */
130 static void make_modes(void)
133 /* original specified desktop size */
134 X11DRV_Settings_AddOneMode(screen_width, screen_height, 0, 0);
135 for (i=0; i<NUM_DESKTOP_MODES; i++)
137 if ( (widths[i] <= max_width) && (heights[i] <= max_height) )
139 if ( ( (widths[i] != max_width) || (heights[i] != max_height) ) &&
140 ( (widths[i] != screen_width) || (heights[i] != screen_height) ) )
142 /* only add them if they are smaller than the root window and unique */
143 X11DRV_Settings_AddOneMode(widths[i], heights[i], 0, 0);
147 if ((max_width != screen_width) && (max_height != screen_height))
149 /* root window size (if different from desktop window) */
150 X11DRV_Settings_AddOneMode(max_width, max_height, 0, 0);
154 /***********************************************************************
155 * X11DRV_resize_desktop
157 * Reset the desktop window size and WM hints
159 int X11DRV_resize_desktop( unsigned int width, unsigned int height )
161 XSizeHints *size_hints;
162 Display *display = thread_display();
163 Window w = root_window;
166 size_hints = XAllocSizeHints();
169 ERR("Not enough memory for window manager hints.\n" );
173 size_hints->min_width = size_hints->max_width = width;
174 size_hints->min_height = size_hints->max_height = height;
175 size_hints->flags = PMinSize | PMaxSize | PSize;
178 XSetWMNormalHints( display, w, size_hints );
179 XResizeWindow( display, w, width, height );
180 screen_width = width;
181 screen_height = height;
183 SYSMETRICS_Set( SM_CXSCREEN, width );
184 SYSMETRICS_Set( SM_CYSCREEN, height );
186 FIXME("Need to update SYSMETRICS after resizing display (now %dx%d)\n",
197 int X11DRV_desktop_GetCurrentMode(void)
200 DWORD dwBpp = screen_depth;
201 if (dwBpp == 24) dwBpp = 32;
202 for (i=0; i<dd_mode_count; i++)
204 if ( (screen_width == dd_modes[i].dwWidth) &&
205 (screen_height == dd_modes[i].dwHeight) &&
206 (dwBpp == dd_modes[i].dwBPP))
209 ERR("In unknown mode, returning default\n");
213 void X11DRV_desktop_SetCurrentMode(int mode)
215 DWORD dwBpp = screen_depth;
216 if (dwBpp == 24) dwBpp = 32;
217 TRACE("Resizing Wine desktop window to %ldx%ld\n", dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
218 X11DRV_resize_desktop(dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
219 if (dwBpp != dd_modes[mode].dwBPP)
221 FIXME("Cannot change screen BPP from %ld to %ld\n", dwBpp, dd_modes[mode].dwBPP);
225 /***********************************************************************
226 * X11DRV_create_desktop
228 * Create the X11 desktop window for the desktop mode.
230 Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry )
232 int x = 0, y = 0, flags;
233 unsigned int width = 640, height = 480; /* Default size = 640x480 */
234 char *name = GetCommandLineA();
235 XSizeHints *size_hints;
237 XClassHint *class_hints;
238 XSetWindowAttributes win_attr;
239 XTextProperty window_name;
241 Display *display = thread_display();
244 flags = XParseGeometry( geometry, &x, &y, &width, &height );
245 max_width = screen_width;
246 max_height = screen_height;
247 screen_width = width;
248 screen_height = height;
251 win_attr.background_pixel = BlackPixel(display, 0);
252 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
253 PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
254 win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
257 win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
260 win_attr.colormap = None;
262 win = XCreateWindow( display, DefaultRootWindow(display),
263 x, y, width, height, 0, screen_depth, InputOutput, visual,
264 CWBackPixel | CWEventMask | CWCursor | CWColormap, &win_attr );
266 /* Set window manager properties */
267 size_hints = XAllocSizeHints();
268 wm_hints = XAllocWMHints();
269 class_hints = XAllocClassHint();
270 if (!size_hints || !wm_hints || !class_hints)
272 MESSAGE("Not enough memory for window manager hints.\n" );
275 size_hints->min_width = size_hints->max_width = width;
276 size_hints->min_height = size_hints->max_height = height;
277 size_hints->flags = PMinSize | PMaxSize;
278 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
279 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
280 else size_hints->flags |= PSize;
282 wm_hints->flags = InputHint | StateHint;
283 wm_hints->input = True;
284 wm_hints->initial_state = NormalState;
285 class_hints->res_name = "wine";
286 class_hints->res_class = "Wine";
288 XStringListToTextProperty( &name, 1, &window_name );
289 XSetWMProperties( display, win, &window_name, &window_name,
290 NULL, 0, size_hints, wm_hints, class_hints );
293 XFree( class_hints );
296 /* initialize the available resolutions */
297 dd_modes = X11DRV_Settings_SetHandlers("desktop",
298 X11DRV_desktop_GetCurrentMode,
299 X11DRV_desktop_SetCurrentMode,
300 NUM_DESKTOP_MODES+2, 1);
302 X11DRV_Settings_AddDepthModes();
303 dd_mode_count = X11DRV_Settings_GetModeCount();
304 X11DRV_Settings_SetDefaultMode(0);