winex11: control + enter should generate '\n' instead of '\r'.
[wine] / dlls / winex11.drv / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include <X11/cursorfont.h>
23 #include <X11/Xlib.h>
24
25 #include "x11drv.h"
26
27 /* avoid conflict with field names in included win32 headers */
28 #undef Status
29 #include "ddrawi.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, 60);
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, 60);
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, 60);
67     }
68 }
69
70 static int X11DRV_desktop_GetCurrentMode(void)
71 {
72     unsigned int i;
73     DWORD dwBpp = screen_bpp;
74     for (i=0; i<dd_mode_count; i++)
75     {
76         if ( (screen_width == dd_modes[i].dwWidth) &&
77              (screen_height == dd_modes[i].dwHeight) && 
78              (dwBpp == dd_modes[i].dwBPP))
79             return i;
80     }
81     ERR("In unknown mode, returning default\n");
82     return 0;
83 }
84
85 static LONG X11DRV_desktop_SetCurrentMode(int mode)
86 {
87     DWORD dwBpp = screen_bpp;
88     if (dwBpp != dd_modes[mode].dwBPP)
89     {
90         FIXME("Cannot change screen BPP from %d to %d\n", dwBpp, dd_modes[mode].dwBPP);
91         /* Ignore the depth mismatch
92          *
93          * Some (older) applications require a specific bit depth, this will allow them
94          * to run. X11drv performs a color depth conversion if needed.
95          */
96     }
97     TRACE("Resizing Wine desktop window to %dx%d\n", dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
98     X11DRV_resize_desktop(dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
99     return DISP_CHANGE_SUCCESSFUL;
100 }
101
102 /***********************************************************************
103  *              X11DRV_init_desktop
104  *
105  * Setup the desktop when not using the root window.
106  */
107 void X11DRV_init_desktop( Window win, unsigned int width, unsigned int height )
108 {
109     root_window = win;
110     managed_mode = 0;  /* no managed windows in desktop mode */
111     max_width = screen_width;
112     max_height = screen_height;
113     xinerama_init( width, height );
114
115     /* initialize the available resolutions */
116     dd_modes = X11DRV_Settings_SetHandlers("desktop", 
117                                            X11DRV_desktop_GetCurrentMode, 
118                                            X11DRV_desktop_SetCurrentMode, 
119                                            NUM_DESKTOP_MODES+2, 1);
120     make_modes();
121     X11DRV_Settings_AddDepthModes();
122     dd_mode_count = X11DRV_Settings_GetModeCount();
123 }
124
125
126 /***********************************************************************
127  *              X11DRV_create_desktop
128  *
129  * Create the X11 desktop window for the desktop mode.
130  */
131 Window X11DRV_create_desktop( UINT width, UINT height )
132 {
133     XSetWindowAttributes win_attr;
134     Window win;
135     Display *display = thread_display();
136
137     wine_tsx11_lock();
138
139     /* Create window */
140     win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
141                           PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
142     win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
143
144     if (visual != DefaultVisual( display, DefaultScreen(display) ))
145         win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
146                                              visual, AllocNone );
147     else
148         win_attr.colormap = None;
149
150     win = XCreateWindow( display, DefaultRootWindow(display),
151                          0, 0, width, height, 0, screen_depth, InputOutput, visual,
152                          CWEventMask | CWCursor | CWColormap, &win_attr );
153     XFlush( display );
154     wine_tsx11_unlock();
155     if (win != None) X11DRV_init_desktop( win, width, height );
156     return win;
157 }
158
159
160 struct desktop_resize_data
161 {
162     RECT  old_screen_rect;
163     RECT  old_virtual_rect;
164 };
165
166 static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
167 {
168     struct x11drv_win_data *data;
169     Display *display = thread_display();
170     struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
171     int mask = 0;
172
173     if (!(data = X11DRV_get_win_data( hwnd ))) return TRUE;
174
175     /* update the full screen state */
176     update_net_wm_states( display, data );
177
178     if (resize_data->old_virtual_rect.left != virtual_screen_rect.left) mask |= CWX;
179     if (resize_data->old_virtual_rect.top != virtual_screen_rect.top) mask |= CWY;
180     if (mask && data->whole_window)
181     {
182         XWindowChanges changes;
183
184         wine_tsx11_lock();
185         changes.x = data->whole_rect.left - virtual_screen_rect.left;
186         changes.y = data->whole_rect.top - virtual_screen_rect.top;
187         XReconfigureWMWindow( display, data->whole_window,
188                               DefaultScreen(display), mask, &changes );
189         wine_tsx11_unlock();
190     }
191     return TRUE;
192 }
193
194
195 /***********************************************************************
196  *              X11DRV_resize_desktop
197  */
198 void X11DRV_resize_desktop( unsigned int width, unsigned int height )
199 {
200     HWND hwnd = GetDesktopWindow();
201     struct desktop_resize_data resize_data;
202
203     SetRect( &resize_data.old_screen_rect, 0, 0, screen_width, screen_height );
204     resize_data.old_virtual_rect = virtual_screen_rect;
205
206     xinerama_init( width, height );
207
208     if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
209     {
210         SendMessageW( hwnd, WM_X11DRV_RESIZE_DESKTOP, 0, MAKELPARAM( width, height ) );
211     }
212     else
213     {
214         TRACE( "desktop %p change to (%dx%d)\n", hwnd, width, height );
215         SetWindowPos( hwnd, 0, virtual_screen_rect.left, virtual_screen_rect.top,
216                       virtual_screen_rect.right - virtual_screen_rect.left,
217                       virtual_screen_rect.bottom - virtual_screen_rect.top,
218                       SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE );
219         SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_bpp,
220                              MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
221     }
222
223     EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );
224 }