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
23 #include <wine/debug.h>
24 #include "explorer_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(explorer
);
28 #define DESKTOP_CLASS_ATOM MAKEINTATOMW(32769)
29 #define DESKTOP_ALL_ACCESS 0x01ff
31 static BOOL using_root
;
33 /* window procedure for the desktop window */
34 static LRESULT WINAPI
desktop_wnd_proc( HWND hwnd
, UINT message
, WPARAM wp
, LPARAM lp
)
36 WINE_TRACE( "got msg %x wp %x lp %lx\n", message
, wp
, lp
);
41 if ((wp
& 0xfff0) == SC_CLOSE
) ExitWindows( 0, 0 );
49 return (LRESULT
)SetCursor( LoadCursorA( 0, (LPSTR
)IDC_ARROW
) );
55 if (!using_root
) PaintDesktop( (HDC
)wp
);
61 BeginPaint( hwnd
, &ps
);
62 if (!using_root
&& ps
.fErase
) PaintDesktop( ps
.hdc
);
63 EndPaint( hwnd
, &ps
);
67 /* simple check to prevent applications accidentally triggering the
68 * ExitWindowsEx code if they send random messages to the desktop window */
70 if (HIWORD(wp
) == 0xbabe)
71 return ExitWindowsEx( LOWORD(wp
), lp
);
72 return DefWindowProcW( hwnd
, message
, wp
, lp
);
75 return DefWindowProcW( hwnd
, message
, wp
, lp
);
79 /* create the desktop and the associated X11 window, and make it the current desktop */
80 static unsigned long create_desktop( const char *name
, unsigned int width
, unsigned int height
)
82 HMODULE x11drv
= GetModuleHandleA( "winex11.drv" );
84 unsigned long xwin
= 0;
85 unsigned long (*create_desktop_func
)(unsigned int, unsigned int);
87 desktop
= CreateDesktopA( name
, NULL
, NULL
, 0, DESKTOP_ALL_ACCESS
, NULL
);
90 WINE_ERR( "failed to create desktop %s error %ld\n", wine_dbgstr_a(name
), GetLastError() );
93 /* magic: desktop "root" means use the X11 root window */
94 if (x11drv
&& strcasecmp( name
, "root" ))
96 create_desktop_func
= (void *)GetProcAddress( x11drv
, "wine_create_desktop" );
97 if (create_desktop_func
) xwin
= create_desktop_func( width
, height
);
99 SetThreadDesktop( desktop
);
103 /* retrieve the default desktop size from the X11 driver config */
104 /* FIXME: this is for backwards compatibility, should probably be changed */
105 static BOOL
get_default_desktop_size( unsigned int *width
, unsigned int *height
)
109 DWORD size
= sizeof(buffer
);
112 /* @@ Wine registry key: HKCU\Software\Wine\X11 Driver */
113 if (RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\X11 Driver", &hkey
)) return FALSE
;
114 if (!RegQueryValueExA( hkey
, "Desktop", 0, NULL
, (LPBYTE
)buffer
, &size
))
115 ret
= (sscanf( buffer
, "%ux%u", width
, height
) == 2);
120 /* main desktop management function */
121 void manage_desktop( char *arg
)
125 unsigned long xwin
= 0;
126 unsigned int width
, height
;
127 char *cmdline
= NULL
;
129 static const WCHAR desktop_nameW
[] = {'W','i','n','e',' ','d','e','s','k','t','o','p',0};
131 /* get the rest of the command line (if any) */
132 while (*p
&& !isspace(*p
)) p
++;
136 while (*p
&& isspace(*p
)) p
++;
140 /* parse the desktop option */
141 /* the option is of the form /desktop=name[,widthxheight] */
142 if (*arg
== '=' || *arg
== ',')
145 if ((p
= strchr( arg
, ',' ))) *p
++ = 0;
146 if (!p
|| sscanf( p
, "%ux%u", &width
, &height
) != 2)
151 xwin
= create_desktop( arg
, width
, height
);
153 else if (get_default_desktop_size( &width
, &height
))
155 xwin
= create_desktop( "Default", width
, height
);
158 if (!xwin
) /* using the root window */
161 width
= GetSystemMetrics(SM_CXSCREEN
);
162 height
= GetSystemMetrics(SM_CYSCREEN
);
165 /* create the desktop window */
166 hwnd
= CreateWindowExW( 0, DESKTOP_CLASS_ATOM
, NULL
,
167 WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
168 0, 0, width
, height
, 0, 0, 0, NULL
);
169 if (hwnd
== GetDesktopWindow())
171 SetWindowLongPtrW( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)desktop_wnd_proc
);
172 SendMessageW( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO
)));
173 SetWindowTextW( hwnd
, desktop_nameW
);
174 SystemParametersInfoA( SPI_SETDESKPATTERN
, -1, NULL
, FALSE
);
175 SetDeskWallPaper( (LPSTR
)-1 );
177 initialize_systray();
181 DestroyWindow( hwnd
); /* someone beat us to it */
185 /* if we have a command line, execute it */
189 PROCESS_INFORMATION pi
;
191 memset( &si
, 0, sizeof(si
) );
193 WINE_TRACE( "starting %s\n", wine_dbgstr_a(cmdline
) );
194 if (CreateProcessA( NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
196 CloseHandle( pi
.hThread
);
197 CloseHandle( pi
.hProcess
);
201 /* run the desktop message loop */
204 WINE_TRACE( "desktop message loop starting on hwnd %p\n", hwnd
);
205 while (GetMessageW( &msg
, 0, 0, 0 )) DispatchMessageW( &msg
);
206 WINE_TRACE( "desktop message loop exiting for hwnd %p\n", hwnd
);