2006-03-07 11:41:52 +01:00
|
|
|
/*
|
|
|
|
* Explorer desktop support
|
|
|
|
*
|
|
|
|
* Copyright 2006 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-03-07 11:41:52 +01:00
|
|
|
*/
|
|
|
|
|
2006-03-27 22:43:03 +02:00
|
|
|
#include <stdio.h>
|
2008-02-13 14:43:17 +01:00
|
|
|
#include "wine/unicode.h"
|
2006-11-07 00:52:01 +01:00
|
|
|
|
|
|
|
#define OEMRESOURCE
|
|
|
|
|
2006-03-07 11:41:52 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#include <wine/debug.h>
|
|
|
|
#include "explorer_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(explorer);
|
|
|
|
|
2006-11-08 01:19:02 +01:00
|
|
|
#define DESKTOP_CLASS_ATOM ((LPCWSTR)MAKEINTATOM(32769))
|
2006-03-27 22:43:03 +02:00
|
|
|
#define DESKTOP_ALL_ACCESS 0x01ff
|
2006-03-07 11:41:52 +01:00
|
|
|
|
2006-08-09 11:21:41 +02:00
|
|
|
static BOOL using_root;
|
|
|
|
|
2006-03-27 22:43:03 +02:00
|
|
|
/* window procedure for the desktop window */
|
2006-03-07 11:41:52 +01:00
|
|
|
static LRESULT WINAPI desktop_wnd_proc( HWND hwnd, UINT message, WPARAM wp, LPARAM lp )
|
|
|
|
{
|
2007-12-03 15:14:35 +01:00
|
|
|
WINE_TRACE( "got msg %04x wp %lx lp %lx\n", message, wp, lp );
|
2006-03-07 11:41:52 +01:00
|
|
|
|
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
if ((wp & 0xfff0) == SC_CLOSE) ExitWindows( 0, 0 );
|
2006-03-27 22:43:03 +02:00
|
|
|
return 0;
|
2006-03-07 11:41:52 +01:00
|
|
|
|
2006-04-07 20:26:47 +02:00
|
|
|
case WM_CLOSE:
|
|
|
|
PostQuitMessage(0);
|
|
|
|
return 0;
|
|
|
|
|
2006-03-07 11:41:52 +01:00
|
|
|
case WM_SETCURSOR:
|
|
|
|
return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)IDC_ARROW ) );
|
|
|
|
|
|
|
|
case WM_NCHITTEST:
|
|
|
|
return HTCLIENT;
|
|
|
|
|
|
|
|
case WM_ERASEBKGND:
|
2006-08-09 11:21:41 +02:00
|
|
|
if (!using_root) PaintDesktop( (HDC)wp );
|
2006-03-07 11:41:52 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
BeginPaint( hwnd, &ps );
|
2006-08-09 11:21:41 +02:00
|
|
|
if (!using_root && ps.fErase) PaintDesktop( ps.hdc );
|
2006-03-07 11:41:52 +01:00
|
|
|
EndPaint( hwnd, &ps );
|
|
|
|
}
|
|
|
|
return 0;
|
2006-03-27 22:43:03 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProcW( hwnd, message, wp, lp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the desktop and the associated X11 window, and make it the current desktop */
|
2008-04-23 18:04:43 +02:00
|
|
|
static unsigned long create_desktop( const WCHAR *name, unsigned int width, unsigned int height )
|
2006-03-27 22:43:03 +02:00
|
|
|
{
|
2008-04-23 18:04:43 +02:00
|
|
|
static const WCHAR rootW[] = {'r','o','o','t',0};
|
2006-03-27 22:43:03 +02:00
|
|
|
HMODULE x11drv = GetModuleHandleA( "winex11.drv" );
|
|
|
|
HDESK desktop;
|
|
|
|
unsigned long xwin = 0;
|
|
|
|
unsigned long (*create_desktop_func)(unsigned int, unsigned int);
|
|
|
|
|
2008-04-23 18:04:43 +02:00
|
|
|
desktop = CreateDesktopW( name, NULL, NULL, 0, DESKTOP_ALL_ACCESS, NULL );
|
2006-03-27 22:43:03 +02:00
|
|
|
if (!desktop)
|
|
|
|
{
|
2008-04-23 18:04:43 +02:00
|
|
|
WINE_ERR( "failed to create desktop %s error %d\n", wine_dbgstr_w(name), GetLastError() );
|
2006-03-27 22:43:03 +02:00
|
|
|
ExitProcess( 1 );
|
|
|
|
}
|
|
|
|
/* magic: desktop "root" means use the X11 root window */
|
2008-04-23 18:04:43 +02:00
|
|
|
if (x11drv && strcmpiW( name, rootW ))
|
2006-03-27 22:43:03 +02:00
|
|
|
{
|
|
|
|
create_desktop_func = (void *)GetProcAddress( x11drv, "wine_create_desktop" );
|
|
|
|
if (create_desktop_func) xwin = create_desktop_func( width, height );
|
2006-03-07 11:41:52 +01:00
|
|
|
}
|
2006-03-27 22:43:03 +02:00
|
|
|
SetThreadDesktop( desktop );
|
|
|
|
return xwin;
|
2006-03-07 11:41:52 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 18:04:43 +02:00
|
|
|
/* parse the desktop size specification */
|
|
|
|
static BOOL parse_size( const WCHAR *size, unsigned int *width, unsigned int *height )
|
|
|
|
{
|
|
|
|
WCHAR *end;
|
|
|
|
|
|
|
|
*width = strtoulW( size, &end, 10 );
|
|
|
|
if (end == size) return FALSE;
|
|
|
|
if (*end != 'x') return FALSE;
|
|
|
|
size = end + 1;
|
|
|
|
*height = strtoulW( size, &end, 10 );
|
|
|
|
return !*end;
|
|
|
|
}
|
|
|
|
|
2008-04-24 16:27:50 +02:00
|
|
|
/* retrieve the desktop name to use if not specified on the command line */
|
|
|
|
static const WCHAR *get_default_desktop_name(void)
|
|
|
|
{
|
|
|
|
static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
|
|
|
|
static const WCHAR defaultW[] = {'D','e','f','a','u','l','t',0};
|
|
|
|
static const WCHAR explorer_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
|
|
|
|
'E','x','p','l','o','r','e','r',0};
|
|
|
|
static WCHAR buffer[MAX_PATH];
|
|
|
|
DWORD size = sizeof(buffer);
|
|
|
|
HDESK desk = GetThreadDesktop( GetCurrentThreadId() );
|
|
|
|
WCHAR *ret = NULL;
|
|
|
|
HKEY hkey;
|
|
|
|
|
|
|
|
if (desk && GetUserObjectInformationW( desk, UOI_NAME, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
|
|
|
|
{
|
|
|
|
if (strcmpiW( buffer, defaultW )) return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\Explorer */
|
|
|
|
if (!RegOpenKeyW( HKEY_CURRENT_USER, explorer_keyW, &hkey ))
|
|
|
|
{
|
|
|
|
if (!RegQueryValueExW( hkey, desktopW, 0, NULL, (LPBYTE)buffer, &size )) ret = buffer;
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-24 16:24:46 +02:00
|
|
|
/* retrieve the default desktop size from the registry */
|
|
|
|
static BOOL get_default_desktop_size( const WCHAR *name, unsigned int *width, unsigned int *height )
|
2006-03-27 22:43:03 +02:00
|
|
|
{
|
2008-04-24 16:24:46 +02:00
|
|
|
static const WCHAR desktop_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
|
|
|
|
'E','x','p','l','o','r','e','r','\\',
|
|
|
|
'D','e','s','k','t','o','p','s',0};
|
2006-03-27 22:43:03 +02:00
|
|
|
HKEY hkey;
|
2008-04-23 18:04:43 +02:00
|
|
|
WCHAR buffer[64];
|
2006-03-27 22:43:03 +02:00
|
|
|
DWORD size = sizeof(buffer);
|
2008-04-24 16:24:46 +02:00
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
*width = 800;
|
|
|
|
*height = 600;
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\Explorer\Desktops */
|
|
|
|
if (!RegOpenKeyW( HKEY_CURRENT_USER, desktop_keyW, &hkey ))
|
|
|
|
{
|
|
|
|
if (!RegQueryValueExW( hkey, name, 0, NULL, (LPBYTE)buffer, &size ))
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
if (!parse_size( buffer, width, height )) *width = *height = 0;
|
|
|
|
}
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
|
|
|
return found;
|
2006-03-27 22:43:03 +02:00
|
|
|
}
|
|
|
|
|
2007-11-16 12:39:08 +01:00
|
|
|
static void initialize_display_settings( HWND desktop )
|
|
|
|
{
|
|
|
|
static const WCHAR display_device_guid_propW[] = {
|
|
|
|
'_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
|
|
|
|
'd','e','v','i','c','e','_','g','u','i','d',0 };
|
|
|
|
GUID guid;
|
2007-12-05 06:03:10 +01:00
|
|
|
RPC_CSTR guid_str;
|
2007-11-16 12:39:08 +01:00
|
|
|
ATOM guid_atom;
|
2007-12-03 15:14:35 +01:00
|
|
|
DEVMODEW dmW;
|
2007-11-16 12:39:08 +01:00
|
|
|
|
|
|
|
UuidCreate( &guid );
|
2007-12-05 06:03:10 +01:00
|
|
|
UuidToStringA( &guid, &guid_str );
|
|
|
|
WINE_TRACE( "display guid %s\n", guid_str );
|
2007-11-16 12:39:08 +01:00
|
|
|
|
2007-12-05 06:03:10 +01:00
|
|
|
guid_atom = GlobalAddAtomA( (LPCSTR)guid_str );
|
2007-11-16 12:39:08 +01:00
|
|
|
SetPropW( desktop, display_device_guid_propW, ULongToHandle(guid_atom) );
|
|
|
|
|
2007-12-05 06:03:10 +01:00
|
|
|
RpcStringFreeA( &guid_str );
|
2007-12-03 15:14:35 +01:00
|
|
|
|
|
|
|
/* Store current display mode in the registry */
|
|
|
|
if (EnumDisplaySettingsExW( NULL, ENUM_CURRENT_SETTINGS, &dmW, 0 ))
|
|
|
|
{
|
|
|
|
WINE_TRACE( "Current display mode %ux%u %u bpp %u Hz\n", dmW.dmPelsWidth,
|
|
|
|
dmW.dmPelsHeight, dmW.dmBitsPerPel, dmW.dmDisplayFrequency );
|
|
|
|
ChangeDisplaySettingsExW( NULL, &dmW, 0,
|
|
|
|
CDS_GLOBAL | CDS_NORESET | CDS_UPDATEREGISTRY,
|
|
|
|
NULL );
|
|
|
|
}
|
2007-11-16 12:39:08 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 18:04:43 +02:00
|
|
|
static void set_desktop_window_title( HWND hwnd, const WCHAR *name )
|
2008-02-13 14:43:17 +01:00
|
|
|
{
|
|
|
|
static const WCHAR desktop_nameW[] = {'W','i','n','e',' ','d','e','s','k','t','o','p',0};
|
|
|
|
static const WCHAR desktop_name_separatorW[] = {' ', '-', ' ', 0};
|
|
|
|
WCHAR *window_titleW = NULL;
|
|
|
|
int window_title_len;
|
|
|
|
|
|
|
|
if (!name[0])
|
|
|
|
{
|
|
|
|
SetWindowTextW( hwnd, desktop_nameW );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-23 18:04:43 +02:00
|
|
|
window_title_len = strlenW(name) * sizeof(WCHAR)
|
2008-02-13 14:43:17 +01:00
|
|
|
+ sizeof(desktop_name_separatorW)
|
|
|
|
+ sizeof(desktop_nameW);
|
|
|
|
window_titleW = HeapAlloc( GetProcessHeap(), 0, window_title_len );
|
|
|
|
if (!window_titleW)
|
|
|
|
{
|
|
|
|
SetWindowTextW( hwnd, desktop_nameW );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-23 18:04:43 +02:00
|
|
|
strcpyW( window_titleW, name );
|
2008-02-13 14:43:17 +01:00
|
|
|
strcatW( window_titleW, desktop_name_separatorW );
|
|
|
|
strcatW( window_titleW, desktop_nameW );
|
|
|
|
|
|
|
|
SetWindowTextW( hwnd, window_titleW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, window_titleW );
|
|
|
|
}
|
|
|
|
|
2006-03-27 22:43:03 +02:00
|
|
|
/* main desktop management function */
|
2008-04-23 18:04:43 +02:00
|
|
|
void manage_desktop( WCHAR *arg )
|
2006-03-07 11:41:52 +01:00
|
|
|
{
|
2008-04-23 18:04:43 +02:00
|
|
|
static const WCHAR defaultW[] = {'D','e','f','a','u','l','t',0};
|
2008-06-25 14:49:33 +02:00
|
|
|
static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
|
2006-03-07 11:41:52 +01:00
|
|
|
MSG msg;
|
2008-06-25 14:49:33 +02:00
|
|
|
HWND hwnd, msg_hwnd;
|
2006-03-27 22:43:03 +02:00
|
|
|
unsigned long xwin = 0;
|
|
|
|
unsigned int width, height;
|
2008-04-23 18:04:43 +02:00
|
|
|
WCHAR *cmdline = NULL;
|
|
|
|
WCHAR *p = arg;
|
|
|
|
const WCHAR *name = NULL;
|
2006-03-07 11:41:52 +01:00
|
|
|
|
2006-03-27 22:43:03 +02:00
|
|
|
/* get the rest of the command line (if any) */
|
|
|
|
while (*p && !isspace(*p)) p++;
|
|
|
|
if (*p)
|
|
|
|
{
|
|
|
|
*p++ = 0;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (*p) cmdline = p;
|
|
|
|
}
|
2006-03-07 11:50:05 +01:00
|
|
|
|
2006-03-27 22:43:03 +02:00
|
|
|
/* parse the desktop option */
|
|
|
|
/* the option is of the form /desktop=name[,widthxheight] */
|
|
|
|
if (*arg == '=' || *arg == ',')
|
|
|
|
{
|
|
|
|
arg++;
|
2008-04-24 16:24:46 +02:00
|
|
|
name = arg;
|
2008-04-23 18:04:43 +02:00
|
|
|
if ((p = strchrW( arg, ',' ))) *p++ = 0;
|
|
|
|
if (!p || !parse_size( p, &width, &height ))
|
2008-04-24 16:24:46 +02:00
|
|
|
get_default_desktop_size( name, &width, &height );
|
2006-03-27 22:43:03 +02:00
|
|
|
}
|
2008-04-24 16:27:50 +02:00
|
|
|
else if ((name = get_default_desktop_name()))
|
|
|
|
{
|
|
|
|
if (!get_default_desktop_size( name, &width, &height )) width = height = 0;
|
|
|
|
}
|
2008-04-24 16:24:46 +02:00
|
|
|
else /* check for the X11 driver key for backwards compatibility (to be removed) */
|
2006-03-27 22:43:03 +02:00
|
|
|
{
|
2008-04-24 16:24:46 +02:00
|
|
|
static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
|
|
|
|
static const WCHAR x11_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
|
|
|
|
'X','1','1',' ','D','r','i','v','e','r',0};
|
|
|
|
HKEY hkey;
|
|
|
|
WCHAR buffer[64];
|
|
|
|
DWORD size = sizeof(buffer);
|
|
|
|
|
|
|
|
width = height = 0;
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\X11 Driver */
|
|
|
|
if (!RegOpenKeyW( HKEY_CURRENT_USER, x11_keyW, &hkey ))
|
|
|
|
{
|
|
|
|
if (!RegQueryValueExW( hkey, desktopW, 0, NULL, (LPBYTE)buffer, &size ))
|
|
|
|
{
|
|
|
|
name = defaultW;
|
|
|
|
if (!parse_size( buffer, &width, &height )) width = height = 0;
|
|
|
|
}
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
2006-03-27 22:43:03 +02:00
|
|
|
}
|
|
|
|
|
2008-04-24 16:24:46 +02:00
|
|
|
if (name && width && height) xwin = create_desktop( name, width, height );
|
|
|
|
|
2008-01-23 11:31:07 +01:00
|
|
|
if (!xwin) using_root = TRUE; /* using the root window */
|
2006-03-27 22:43:03 +02:00
|
|
|
|
|
|
|
/* create the desktop window */
|
|
|
|
hwnd = CreateWindowExW( 0, DESKTOP_CLASS_ATOM, NULL,
|
|
|
|
WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
|
2008-01-23 11:31:07 +01:00
|
|
|
GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN),
|
|
|
|
GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN),
|
|
|
|
0, 0, 0, NULL );
|
2008-06-25 14:49:33 +02:00
|
|
|
|
|
|
|
/* create the HWND_MESSAGE parent */
|
|
|
|
msg_hwnd = CreateWindowExW( 0, messageW, NULL, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
|
|
|
|
0, 0, 100, 100, 0, 0, 0, NULL );
|
|
|
|
|
2006-03-27 22:43:03 +02:00
|
|
|
if (hwnd == GetDesktopWindow())
|
|
|
|
{
|
|
|
|
SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)desktop_wnd_proc );
|
|
|
|
SendMessageW( hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO)));
|
2008-02-13 14:43:17 +01:00
|
|
|
if (name) set_desktop_window_title( hwnd, name );
|
2006-03-27 22:43:03 +02:00
|
|
|
SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
|
|
|
|
SetDeskWallPaper( (LPSTR)-1 );
|
2007-11-16 12:39:08 +01:00
|
|
|
initialize_display_settings( hwnd );
|
2008-09-02 20:58:01 +02:00
|
|
|
initialize_appbar();
|
2006-03-27 22:43:03 +02:00
|
|
|
initialize_systray();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DestroyWindow( hwnd ); /* someone beat us to it */
|
|
|
|
hwnd = 0;
|
|
|
|
}
|
|
|
|
|
2008-06-25 14:49:33 +02:00
|
|
|
if (GetAncestor( msg_hwnd, GA_PARENT )) DestroyWindow( msg_hwnd ); /* someone beat us to it */
|
|
|
|
|
2006-03-27 22:43:03 +02:00
|
|
|
/* if we have a command line, execute it */
|
|
|
|
if (cmdline)
|
|
|
|
{
|
2008-04-23 18:04:43 +02:00
|
|
|
STARTUPINFOW si;
|
2006-03-27 22:43:03 +02:00
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
|
|
|
memset( &si, 0, sizeof(si) );
|
|
|
|
si.cb = sizeof(si);
|
2008-04-23 18:04:43 +02:00
|
|
|
WINE_TRACE( "starting %s\n", wine_dbgstr_w(cmdline) );
|
|
|
|
if (CreateProcessW( NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
|
2006-03-27 22:43:03 +02:00
|
|
|
{
|
|
|
|
CloseHandle( pi.hThread );
|
|
|
|
CloseHandle( pi.hProcess );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* run the desktop message loop */
|
|
|
|
if (hwnd)
|
|
|
|
{
|
|
|
|
WINE_TRACE( "desktop message loop starting on hwnd %p\n", hwnd );
|
|
|
|
while (GetMessageW( &msg, 0, 0, 0 )) DispatchMessageW( &msg );
|
|
|
|
WINE_TRACE( "desktop message loop exiting for hwnd %p\n", hwnd );
|
|
|
|
}
|
2006-03-07 11:50:05 +01:00
|
|
|
|
2006-03-27 22:43:03 +02:00
|
|
|
ExitProcess( 0 );
|
2006-03-07 11:41:52 +01:00
|
|
|
}
|