2 * Explorer desktop support
4 * Copyright 2006 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
26 #include <wine/debug.h>
27 #include "explorer_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(explorer
);
31 #define DESKTOP_CLASS_ATOM ((LPCWSTR)MAKEINTATOM(32769))
32 #define DESKTOP_ALL_ACCESS 0x01ff
34 static BOOL using_root
;
36 /* window procedure for the desktop window */
37 static LRESULT WINAPI
desktop_wnd_proc( HWND hwnd
, UINT message
, WPARAM wp
, LPARAM lp
)
39 WINE_TRACE( "got msg %04x wp %lx lp %lx\n", message
, wp
, lp
);
44 if ((wp
& 0xfff0) == SC_CLOSE
) ExitWindows( 0, 0 );
52 return (LRESULT
)SetCursor( LoadCursorA( 0, (LPSTR
)IDC_ARROW
) );
58 if (!using_root
) PaintDesktop( (HDC
)wp
);
64 BeginPaint( hwnd
, &ps
);
65 if (!using_root
&& ps
.fErase
) PaintDesktop( ps
.hdc
);
66 EndPaint( hwnd
, &ps
);
71 return DefWindowProcW( hwnd
, message
, wp
, lp
);
75 /* create the desktop and the associated X11 window, and make it the current desktop */
76 static unsigned long create_desktop( const char *name
, unsigned int width
, unsigned int height
)
78 HMODULE x11drv
= GetModuleHandleA( "winex11.drv" );
80 unsigned long xwin
= 0;
81 unsigned long (*create_desktop_func
)(unsigned int, unsigned int);
83 desktop
= CreateDesktopA( name
, NULL
, NULL
, 0, DESKTOP_ALL_ACCESS
, NULL
);
86 WINE_ERR( "failed to create desktop %s error %d\n", wine_dbgstr_a(name
), GetLastError() );
89 /* magic: desktop "root" means use the X11 root window */
90 if (x11drv
&& strcasecmp( name
, "root" ))
92 create_desktop_func
= (void *)GetProcAddress( x11drv
, "wine_create_desktop" );
93 if (create_desktop_func
) xwin
= create_desktop_func( width
, height
);
95 SetThreadDesktop( desktop
);
99 /* retrieve the default desktop size from the X11 driver config */
100 /* FIXME: this is for backwards compatibility, should probably be changed */
101 static BOOL
get_default_desktop_size( unsigned int *width
, unsigned int *height
)
105 DWORD size
= sizeof(buffer
);
108 /* @@ Wine registry key: HKCU\Software\Wine\X11 Driver */
109 if (RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\X11 Driver", &hkey
)) return FALSE
;
110 if (!RegQueryValueExA( hkey
, "Desktop", 0, NULL
, (LPBYTE
)buffer
, &size
))
111 ret
= (sscanf( buffer
, "%ux%u", width
, height
) == 2);
116 static void initialize_display_settings( HWND desktop
)
118 static const WCHAR display_device_guid_propW
[] = {
119 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
120 'd','e','v','i','c','e','_','g','u','i','d',0 };
127 UuidToStringA( &guid
, &guid_str
);
128 WINE_TRACE( "display guid %s\n", guid_str
);
130 guid_atom
= GlobalAddAtomA( (LPCSTR
)guid_str
);
131 SetPropW( desktop
, display_device_guid_propW
, ULongToHandle(guid_atom
) );
133 RpcStringFreeA( &guid_str
);
135 /* Store current display mode in the registry */
136 if (EnumDisplaySettingsExW( NULL
, ENUM_CURRENT_SETTINGS
, &dmW
, 0 ))
138 WINE_TRACE( "Current display mode %ux%u %u bpp %u Hz\n", dmW
.dmPelsWidth
,
139 dmW
.dmPelsHeight
, dmW
.dmBitsPerPel
, dmW
.dmDisplayFrequency
);
140 ChangeDisplaySettingsExW( NULL
, &dmW
, 0,
141 CDS_GLOBAL
| CDS_NORESET
| CDS_UPDATEREGISTRY
,
146 /* main desktop management function */
147 void manage_desktop( char *arg
)
151 unsigned long xwin
= 0;
152 unsigned int width
, height
;
153 char *cmdline
= NULL
;
155 static const WCHAR desktop_nameW
[] = {'W','i','n','e',' ','d','e','s','k','t','o','p',0};
157 /* get the rest of the command line (if any) */
158 while (*p
&& !isspace(*p
)) p
++;
162 while (*p
&& isspace(*p
)) p
++;
166 /* parse the desktop option */
167 /* the option is of the form /desktop=name[,widthxheight] */
168 if (*arg
== '=' || *arg
== ',')
171 if ((p
= strchr( arg
, ',' ))) *p
++ = 0;
172 if (!p
|| sscanf( p
, "%ux%u", &width
, &height
) != 2)
177 xwin
= create_desktop( arg
, width
, height
);
179 else if (get_default_desktop_size( &width
, &height
))
181 xwin
= create_desktop( "Default", width
, height
);
184 if (!xwin
) using_root
= TRUE
; /* using the root window */
186 /* create the desktop window */
187 hwnd
= CreateWindowExW( 0, DESKTOP_CLASS_ATOM
, NULL
,
188 WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
189 GetSystemMetrics(SM_XVIRTUALSCREEN
), GetSystemMetrics(SM_YVIRTUALSCREEN
),
190 GetSystemMetrics(SM_CXVIRTUALSCREEN
), GetSystemMetrics(SM_CYVIRTUALSCREEN
),
192 if (hwnd
== GetDesktopWindow())
194 SetWindowLongPtrW( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)desktop_wnd_proc
);
195 SendMessageW( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO
)));
196 SetWindowTextW( hwnd
, desktop_nameW
);
197 SystemParametersInfoA( SPI_SETDESKPATTERN
, -1, NULL
, FALSE
);
198 SetDeskWallPaper( (LPSTR
)-1 );
199 initialize_display_settings( hwnd
);
200 initialize_diskarbitration();
202 initialize_systray();
206 DestroyWindow( hwnd
); /* someone beat us to it */
210 /* if we have a command line, execute it */
214 PROCESS_INFORMATION pi
;
216 memset( &si
, 0, sizeof(si
) );
218 WINE_TRACE( "starting %s\n", wine_dbgstr_a(cmdline
) );
219 if (CreateProcessA( NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
221 CloseHandle( pi
.hThread
);
222 CloseHandle( pi
.hProcess
);
226 /* run the desktop message loop */
229 WINE_TRACE( "desktop message loop starting on hwnd %p\n", hwnd
);
230 while (GetMessageW( &msg
, 0, 0, 0 )) DispatchMessageW( &msg
);
231 WINE_TRACE( "desktop message loop exiting for hwnd %p\n", hwnd
);