advapi32: Fixed building TRUSTEEs with objects.
[wine] / dlls / x11drv / desktop.c
1 /*
2  * X11DRV desktop window handling
3  *
4  * Copyright 2001 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include <X11/cursorfont.h>
23 #include <X11/Xlib.h>
24
25 #include "wine/winuser16.h"
26 #include "win.h"
27 #include "ddrawi.h"
28 #include "x11drv.h"
29 #include "x11ddraw.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
33
34 /* data for resolution changing */
35 static LPDDHALMODEINFO dd_modes;
36 static unsigned int dd_mode_count;
37
38 static unsigned int max_width;
39 static unsigned int max_height;
40
41 static const unsigned int widths[]  = {320, 400, 512, 640, 800, 1024, 1152, 1280, 1400, 1600};
42 static const unsigned int heights[] = {200, 300, 384, 480, 600,  768,  864, 1024, 1050, 1200};
43 #define NUM_DESKTOP_MODES (sizeof(widths) / sizeof(widths[0]))
44
45 /* create the mode structures */
46 static void make_modes(void)
47 {
48     int i;
49     /* original specified desktop size */
50     X11DRV_Settings_AddOneMode(screen_width, screen_height, 0, 0);
51     for (i=0; i<NUM_DESKTOP_MODES; i++)
52     {
53         if ( (widths[i] <= max_width) && (heights[i] <= max_height) )
54         {
55             if ( ( (widths[i] != max_width) || (heights[i] != max_height) ) &&
56                  ( (widths[i] != screen_width) || (heights[i] != screen_height) ) )
57             {
58                 /* only add them if they are smaller than the root window and unique */
59                 X11DRV_Settings_AddOneMode(widths[i], heights[i], 0, 0);
60             }
61         }
62     }
63     if ((max_width != screen_width) && (max_height != screen_height))
64     {
65         /* root window size (if different from desktop window) */
66         X11DRV_Settings_AddOneMode(max_width, max_height, 0, 0);
67     }
68 }
69
70 /***********************************************************************
71  *              X11DRV_resize_desktop
72  *
73  * Reset the desktop window size and WM hints
74  */
75 static int X11DRV_resize_desktop( unsigned int width, unsigned int height )
76 {
77     XSizeHints *size_hints;
78     Display *display = thread_display();
79     Window w = root_window;
80     /* set up */
81     wine_tsx11_lock();
82     size_hints  = XAllocSizeHints();
83     if (!size_hints)
84     {
85         ERR("Not enough memory for window manager hints.\n" );
86         wine_tsx11_unlock();
87         return 0;
88     }
89     size_hints->min_width = size_hints->max_width = width;
90     size_hints->min_height = size_hints->max_height = height;
91     size_hints->flags = PMinSize | PMaxSize | PSize;
92
93     /* do the work */
94     XSetWMNormalHints( display, w, size_hints );
95     XResizeWindow( display, w, width, height );
96
97     /* clean up */
98     XFree( size_hints );
99     XFlush( display );
100     wine_tsx11_unlock();
101     X11DRV_handle_desktop_resize( width, height );
102     return 1;
103 }
104
105 static int X11DRV_desktop_GetCurrentMode(void)
106 {
107     unsigned int i;
108     DWORD dwBpp = screen_depth;
109     if (dwBpp == 24) dwBpp = 32;
110     for (i=0; i<dd_mode_count; i++)
111     {
112         if ( (screen_width == dd_modes[i].dwWidth) &&
113              (screen_height == dd_modes[i].dwHeight) && 
114              (dwBpp == dd_modes[i].dwBPP))
115             return i;
116     }
117     ERR("In unknown mode, returning default\n");
118     return 0;
119 }
120
121 static void X11DRV_desktop_SetCurrentMode(int mode)
122 {
123     DWORD dwBpp = screen_depth;
124     if (dwBpp == 24) dwBpp = 32;
125     TRACE("Resizing Wine desktop window to %ldx%ld\n", dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
126     X11DRV_resize_desktop(dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
127     if (dwBpp != dd_modes[mode].dwBPP)
128     {
129         FIXME("Cannot change screen BPP from %ld to %ld\n", dwBpp, dd_modes[mode].dwBPP);
130     }
131 }
132
133 /***********************************************************************
134  *              X11DRV_create_desktop
135  *
136  * Create the X11 desktop window for the desktop mode.
137  */
138 Window X11DRV_create_desktop( UINT width, UINT height )
139 {
140     XSetWindowAttributes win_attr;
141     Window win;
142     Display *display = thread_display();
143
144     wine_tsx11_lock();
145     max_width = screen_width;
146     max_height = screen_height;
147     screen_width  = width;
148     screen_height = height;
149
150     /* Create window */
151     win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
152                           PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
153     win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
154
155     if (visual != DefaultVisual( display, DefaultScreen(display) ))
156         win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
157                                              visual, AllocNone );
158     else
159         win_attr.colormap = None;
160
161     win = XCreateWindow( display, DefaultRootWindow(display),
162                          0, 0, width, height, 0, screen_depth, InputOutput, visual,
163                          CWEventMask | CWCursor | CWColormap, &win_attr );
164     XFlush( display );
165     wine_tsx11_unlock();
166     if (win == None) return None;
167
168     /* initialize the available resolutions */
169     dd_modes = X11DRV_Settings_SetHandlers("desktop", 
170                                            X11DRV_desktop_GetCurrentMode, 
171                                            X11DRV_desktop_SetCurrentMode, 
172                                            NUM_DESKTOP_MODES+2, 1);
173     make_modes();
174     X11DRV_Settings_AddDepthModes();
175     dd_mode_count = X11DRV_Settings_GetModeCount();
176     X11DRV_Settings_SetDefaultMode(0);
177     root_window = win;
178     return win;
179 }