dmusic: Assign to structs instead of using memcpy.
[wine.git] / dlls / winex11.drv / desktop.c
blob96d050abdc17ccb42846a6381bb5fb39cdd37a11
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 "win.h"
26 #include "x11drv.h"
28 /* avoid conflict with field names in included win32 headers */
29 #undef Status
30 #include "ddrawi.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
35 /* data for resolution changing */
36 static LPDDHALMODEINFO dd_modes;
37 static unsigned int dd_mode_count;
39 static unsigned int max_width;
40 static unsigned int max_height;
42 static const unsigned int widths[] = {320, 400, 512, 640, 800, 1024, 1152, 1280, 1400, 1600};
43 static const unsigned int heights[] = {200, 300, 384, 480, 600, 768, 864, 1024, 1050, 1200};
44 #define NUM_DESKTOP_MODES (sizeof(widths) / sizeof(widths[0]))
46 /* create the mode structures */
47 static void make_modes(void)
49 int i;
50 /* original specified desktop size */
51 X11DRV_Settings_AddOneMode(screen_width, screen_height, 0, 60);
52 for (i=0; i<NUM_DESKTOP_MODES; i++)
54 if ( (widths[i] <= max_width) && (heights[i] <= max_height) )
56 if ( ( (widths[i] != max_width) || (heights[i] != max_height) ) &&
57 ( (widths[i] != screen_width) || (heights[i] != screen_height) ) )
59 /* only add them if they are smaller than the root window and unique */
60 X11DRV_Settings_AddOneMode(widths[i], heights[i], 0, 60);
64 if ((max_width != screen_width) && (max_height != screen_height))
66 /* root window size (if different from desktop window) */
67 X11DRV_Settings_AddOneMode(max_width, max_height, 0, 60);
71 static int X11DRV_desktop_GetCurrentMode(void)
73 unsigned int i;
74 DWORD dwBpp = screen_bpp;
75 for (i=0; i<dd_mode_count; i++)
77 if ( (screen_width == dd_modes[i].dwWidth) &&
78 (screen_height == dd_modes[i].dwHeight) &&
79 (dwBpp == dd_modes[i].dwBPP))
80 return i;
82 ERR("In unknown mode, returning default\n");
83 return 0;
86 static LONG X11DRV_desktop_SetCurrentMode(int mode)
88 DWORD dwBpp = screen_bpp;
89 if (dwBpp != dd_modes[mode].dwBPP)
91 FIXME("Cannot change screen BPP from %d to %d\n", dwBpp, dd_modes[mode].dwBPP);
92 /* Ignore the depth mismatch
94 * Some (older) applications require a specific bit depth, this will allow them
95 * to run. X11drv performs a color depth conversion if needed.
98 TRACE("Resizing Wine desktop window to %dx%d\n", dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
99 X11DRV_resize_desktop(dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
100 return DISP_CHANGE_SUCCESSFUL;
103 /***********************************************************************
104 * X11DRV_init_desktop
106 * Setup the desktop when not using the root window.
108 void X11DRV_init_desktop( Window win, unsigned int width, unsigned int height )
110 root_window = win;
111 managed_mode = 0; /* no managed windows in desktop mode */
112 max_width = screen_width;
113 max_height = screen_height;
114 xinerama_init( width, height );
116 /* initialize the available resolutions */
117 dd_modes = X11DRV_Settings_SetHandlers("desktop",
118 X11DRV_desktop_GetCurrentMode,
119 X11DRV_desktop_SetCurrentMode,
120 NUM_DESKTOP_MODES+2, 1);
121 make_modes();
122 X11DRV_Settings_AddDepthModes();
123 dd_mode_count = X11DRV_Settings_GetModeCount();
127 /***********************************************************************
128 * X11DRV_create_desktop
130 * Create the X11 desktop window for the desktop mode.
132 Window X11DRV_create_desktop( UINT width, UINT height )
134 XSetWindowAttributes win_attr;
135 Window win;
136 Display *display = thread_display();
138 wine_tsx11_lock();
140 /* Create window */
141 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
142 PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
143 win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
145 if (visual != DefaultVisual( display, DefaultScreen(display) ))
146 win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
147 visual, AllocNone );
148 else
149 win_attr.colormap = None;
151 win = XCreateWindow( display, DefaultRootWindow(display),
152 0, 0, width, height, 0, screen_depth, InputOutput, visual,
153 CWEventMask | CWCursor | CWColormap, &win_attr );
154 XFlush( display );
155 wine_tsx11_unlock();
156 if (win != None) X11DRV_init_desktop( win, width, height );
157 return win;