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
24 #include <X11/cursorfont.h>
30 /* avoid conflict with field names in included win32 headers */
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
38 /* data for resolution changing */
39 static LPDDHALMODEINFO dd_modes
;
40 static unsigned int dd_mode_count
;
42 static unsigned int max_width
;
43 static unsigned int max_height
;
45 static const unsigned int widths
[] = {320, 400, 512, 640, 800, 1024, 1152, 1280, 1400, 1600};
46 static const unsigned int heights
[] = {200, 300, 384, 480, 600, 768, 864, 1024, 1050, 1200};
47 #define NUM_DESKTOP_MODES (sizeof(widths) / sizeof(widths[0]))
49 /* create the mode structures */
50 static void make_modes(char * refresh_rates
)
53 unsigned int refresh_rate
;
56 for(; ( elem
= strsep(&refresh_rates
, ",") ) && *elem
&& 0 <= ( refresh_rate
= strtol(elem
, NULL
, 0) ); ) {
57 /* original specified desktop size */
58 X11DRV_Settings_AddOneMode(screen_width
, screen_height
, 0, refresh_rate
);
59 for (i
=0; i
<NUM_DESKTOP_MODES
; i
++)
61 if ( (widths
[i
] <= max_width
) && (heights
[i
] <= max_height
) )
63 if ( ( (widths
[i
] != max_width
) || (heights
[i
] != max_height
) ) &&
64 ( (widths
[i
] != screen_width
) || (heights
[i
] != screen_height
) ) )
66 /* only add them if they are smaller than the root window and unique */
67 X11DRV_Settings_AddOneMode(widths
[i
], heights
[i
], 0, refresh_rate
);
71 if ((max_width
!= screen_width
) && (max_height
!= screen_height
))
73 /* root window size (if different from desktop window) */
74 X11DRV_Settings_AddOneMode(max_width
, max_height
, 0, refresh_rate
);
79 static int X11DRV_desktop_GetCurrentMode(void)
82 DWORD dwBpp
= screen_bpp
;
83 for (i
=0; i
<dd_mode_count
; i
++)
85 if ( (screen_width
== dd_modes
[i
].dwWidth
) &&
86 (screen_height
== dd_modes
[i
].dwHeight
) &&
87 (dwBpp
== dd_modes
[i
].dwBPP
))
90 ERR("In unknown mode, returning default\n");
94 static LONG
X11DRV_desktop_SetCurrentMode(int mode
)
96 DWORD dwBpp
= screen_bpp
;
97 if (dwBpp
!= dd_modes
[mode
].dwBPP
)
99 FIXME("Cannot change screen BPP from %d to %d\n", dwBpp
, dd_modes
[mode
].dwBPP
);
100 /* Ignore the depth mismatch
102 * Some (older) applications require a specific bit depth, this will allow them
103 * to run. X11drv performs a color depth conversion if needed.
106 TRACE("Resizing Wine desktop window to %dx%d\n", dd_modes
[mode
].dwWidth
, dd_modes
[mode
].dwHeight
);
107 X11DRV_resize_desktop(dd_modes
[mode
].dwWidth
, dd_modes
[mode
].dwHeight
);
108 return DISP_CHANGE_SUCCESSFUL
;
111 /***********************************************************************
112 * X11DRV_init_desktop
114 * Setup the desktop when not using the root window.
116 void X11DRV_init_desktop( Window win
, unsigned int width
, unsigned int height
)
119 char buffer
[64] = "60\0";
120 char buffer_copy
[64];
121 int refresh_count
= 0;
122 char *elem
, *bufferp
= buffer_copy
;
124 managed_mode
= 0; /* no managed windows in desktop mode */
125 max_width
= screen_width
;
126 max_height
= screen_height
;
127 xinerama_init( width
, height
);
129 /* @@ Wine registry key: HKCU\Software\Wine\X11 Driver */
130 if ( !RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\X11 Driver", &hkey
) ) {
131 DWORD count
= sizeof(buffer
);
132 RegQueryValueExA(hkey
, "FakeRefreshRate", 0, NULL
, (LPBYTE
)buffer
, &count
);
135 strcpy(buffer_copy
, buffer
);
136 for(; ( elem
= strsep(&bufferp
, ",") ) && *elem
&& 0 <= strtol(elem
, NULL
, 0); )
139 /* initialize the available resolutions */
140 dd_modes
= X11DRV_Settings_SetHandlers("desktop",
141 X11DRV_desktop_GetCurrentMode
,
142 X11DRV_desktop_SetCurrentMode
,
143 (NUM_DESKTOP_MODES
+2)*refresh_count
, 1);
145 X11DRV_Settings_AddDepthModes();
146 dd_mode_count
= X11DRV_Settings_GetModeCount();
150 /***********************************************************************
151 * X11DRV_create_desktop
153 * Create the X11 desktop window for the desktop mode.
155 Window
X11DRV_create_desktop( UINT width
, UINT height
)
157 XSetWindowAttributes win_attr
;
159 Display
*display
= thread_display();
164 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
|
165 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
;
166 win_attr
.cursor
= XCreateFontCursor( display
, XC_top_left_arrow
);
168 if (visual
!= DefaultVisual( display
, DefaultScreen(display
) ))
169 win_attr
.colormap
= XCreateColormap( display
, DefaultRootWindow(display
),
172 win_attr
.colormap
= None
;
174 win
= XCreateWindow( display
, DefaultRootWindow(display
),
175 0, 0, width
, height
, 0, screen_depth
, InputOutput
, visual
,
176 CWEventMask
| CWCursor
| CWColormap
, &win_attr
);
179 if (win
!= None
) X11DRV_init_desktop( win
, width
, height
);