2 * Explorer desktop support
4 * Copyright 2006 Alexandre Julliard
5 * Copyright 2013 Hans Leidekker for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
35 #include "explorer_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(explorer
);
39 #define DESKTOP_CLASS_ATOM ((LPCWSTR)MAKEINTATOM(32769))
40 #define DESKTOP_ALL_ACCESS 0x01ff
43 static const WCHAR default_driver
[] = {'m','a','c',',','x','1','1',0};
45 static const WCHAR default_driver
[] = {'x','1','1',0};
48 static BOOL using_root
;
57 static WCHAR
*desktop_folder
;
58 static WCHAR
*desktop_folder_public
;
60 static int icon_cx
, icon_cy
, icon_offset_cx
, icon_offset_cy
;
61 static int title_cx
, title_cy
, title_offset_cx
, title_offset_cy
;
62 static int desktop_width
, launcher_size
, launchers_per_row
;
64 static struct launcher
**launchers
;
65 static unsigned int nb_launchers
, nb_allocated
;
67 static RECT
get_icon_rect( unsigned int index
)
70 unsigned int row
= index
/ launchers_per_row
;
71 unsigned int col
= index
% launchers_per_row
;
73 rect
.left
= col
* launcher_size
+ icon_offset_cx
;
74 rect
.right
= rect
.left
+ icon_cx
;
75 rect
.top
= row
* launcher_size
+ icon_offset_cy
;
76 rect
.bottom
= rect
.top
+ icon_cy
;
80 static RECT
get_title_rect( unsigned int index
)
83 unsigned int row
= index
/ launchers_per_row
;
84 unsigned int col
= index
% launchers_per_row
;
86 rect
.left
= col
* launcher_size
+ title_offset_cx
;
87 rect
.right
= rect
.left
+ title_cx
;
88 rect
.top
= row
* launcher_size
+ title_offset_cy
;
89 rect
.bottom
= rect
.top
+ title_cy
;
93 static const struct launcher
*launcher_from_point( int x
, int y
)
98 if (!nb_launchers
) return NULL
;
99 index
= x
/ launcher_size
+ (y
/ launcher_size
) * launchers_per_row
;
100 if (index
>= nb_launchers
) return NULL
;
102 icon
= get_icon_rect( index
);
103 title
= get_title_rect( index
);
104 if ((x
< icon
.left
|| x
> icon
.right
|| y
< icon
.top
|| y
> icon
.bottom
) &&
105 (x
< title
.left
|| x
> title
.right
|| y
< title
.top
|| y
> title
.bottom
)) return NULL
;
106 return launchers
[index
];
109 static void draw_launchers( HDC hdc
, RECT update_rect
)
111 COLORREF color
= SetTextColor( hdc
, RGB(255,255,255) ); /* FIXME: depends on background color */
112 int mode
= SetBkMode( hdc
, TRANSPARENT
);
117 SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0 );
118 font
= SelectObject( hdc
, CreateFontIndirectW( &lf
) );
120 for (i
= 0; i
< nb_launchers
; i
++)
122 RECT dummy
, icon
= get_icon_rect( i
), title
= get_title_rect( i
);
124 if (IntersectRect( &dummy
, &icon
, &update_rect
))
125 DrawIconEx( hdc
, icon
.left
, icon
.top
, launchers
[i
]->icon
, icon_cx
, icon_cy
,
126 0, 0, DI_DEFAULTSIZE
|DI_NORMAL
);
128 if (IntersectRect( &dummy
, &title
, &update_rect
))
129 DrawTextW( hdc
, launchers
[i
]->title
, -1, &title
,
130 DT_CENTER
|DT_WORDBREAK
|DT_EDITCONTROL
|DT_END_ELLIPSIS
);
133 SelectObject( hdc
, font
);
134 SetTextColor( hdc
, color
);
135 SetBkMode( hdc
, mode
);
138 static void do_launch( const struct launcher
*launcher
)
140 static const WCHAR openW
[] = {'o','p','e','n',0};
141 ShellExecuteW( NULL
, openW
, launcher
->path
, NULL
, NULL
, 0 );
144 static WCHAR
*append_path( const WCHAR
*path
, const WCHAR
*filename
, int len_filename
)
146 int len_path
= strlenW( path
);
149 if (len_filename
== -1) len_filename
= strlenW( filename
);
150 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, (len_path
+ len_filename
+ 2) * sizeof(WCHAR
) )))
152 memcpy( ret
, path
, len_path
* sizeof(WCHAR
) );
153 ret
[len_path
] = '\\';
154 memcpy( ret
+ len_path
+ 1, filename
, len_filename
* sizeof(WCHAR
) );
155 ret
[len_path
+ 1 + len_filename
] = 0;
159 static IShellLinkW
*load_shelllink( const WCHAR
*path
)
165 hr
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLinkW
,
167 if (FAILED( hr
)) return NULL
;
169 hr
= IShellLinkW_QueryInterface( link
, &IID_IPersistFile
, (void **)&file
);
172 IShellLinkW_Release( link
);
175 hr
= IPersistFile_Load( file
, path
, 0 );
176 IPersistFile_Release( file
);
179 IShellLinkW_Release( link
);
185 static HICON
extract_icon( IShellLinkW
*link
)
187 WCHAR tmp_path
[MAX_PATH
], icon_path
[MAX_PATH
], target_path
[MAX_PATH
];
192 IShellLinkW_GetIconLocation( link
, tmp_path
, MAX_PATH
, &index
);
193 ExpandEnvironmentStringsW( tmp_path
, icon_path
, MAX_PATH
);
195 if (icon_path
[0]) ExtractIconExW( icon_path
, index
, &icon
, NULL
, 1 );
199 IShellLinkW_GetPath( link
, tmp_path
, MAX_PATH
, NULL
, SLGP_RAWPATH
);
200 ExpandEnvironmentStringsW( tmp_path
, target_path
, MAX_PATH
);
201 ExtractIconExW( target_path
, index
, &icon
, NULL
, 1 );
206 static WCHAR
*build_title( const WCHAR
*filename
, int len
)
211 if (len
== -1) len
= strlenW( filename
);
212 for (p
= filename
+ len
- 1; p
>= filename
; p
--)
220 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
221 memcpy( ret
, filename
, len
* sizeof(WCHAR
) );
226 static BOOL
add_launcher( const WCHAR
*folder
, const WCHAR
*filename
, int len_filename
)
228 struct launcher
*launcher
;
231 if (nb_launchers
== nb_allocated
)
233 unsigned int count
= nb_allocated
* 2;
234 struct launcher
**tmp
= HeapReAlloc( GetProcessHeap(), 0, launchers
, count
* sizeof(*tmp
) );
235 if (!tmp
) return FALSE
;
237 nb_allocated
= count
;
240 if (!(launcher
= HeapAlloc( GetProcessHeap(), 0, sizeof(*launcher
) ))) return FALSE
;
241 if (!(launcher
->path
= append_path( folder
, filename
, len_filename
))) goto error
;
242 if (!(link
= load_shelllink( launcher
->path
))) goto error
;
244 launcher
->icon
= extract_icon( link
);
245 launcher
->title
= build_title( filename
, len_filename
);
246 IShellLinkW_Release( link
);
247 if (launcher
->icon
&& launcher
->title
)
249 launchers
[nb_launchers
++] = launcher
;
252 HeapFree( GetProcessHeap(), 0, launcher
->title
);
253 DestroyIcon( launcher
->icon
);
256 HeapFree( GetProcessHeap(), 0, launcher
->path
);
257 HeapFree( GetProcessHeap(), 0, launcher
);
261 static void free_launcher( struct launcher
*launcher
)
263 DestroyIcon( launcher
->icon
);
264 HeapFree( GetProcessHeap(), 0, launcher
->path
);
265 HeapFree( GetProcessHeap(), 0, launcher
->title
);
266 HeapFree( GetProcessHeap(), 0, launcher
);
269 static BOOL
remove_launcher( const WCHAR
*folder
, const WCHAR
*filename
, int len_filename
)
275 if (!(path
= append_path( folder
, filename
, len_filename
))) return FALSE
;
276 for (i
= 0; i
< nb_launchers
; i
++)
278 if (!strcmpiW( launchers
[i
]->path
, path
))
280 free_launcher( launchers
[i
] );
282 memmove( &launchers
[i
], &launchers
[i
+ 1], sizeof(launchers
[i
]) * (nb_launchers
- i
) );
287 HeapFree( GetProcessHeap(), 0, path
);
291 static BOOL
get_icon_text_metrics( HWND hwnd
, TEXTMETRICW
*tm
)
299 SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0 );
300 hfont
= SelectObject( hdc
, CreateFontIndirectW( &lf
) );
301 ret
= GetTextMetricsW( hdc
, tm
);
302 SelectObject( hdc
, hfont
);
303 ReleaseDC( hwnd
, hdc
);
307 static BOOL
process_changes( const WCHAR
*folder
, char *buf
)
309 FILE_NOTIFY_INFORMATION
*info
= (FILE_NOTIFY_INFORMATION
*)buf
;
314 switch (info
->Action
)
316 case FILE_ACTION_ADDED
:
317 case FILE_ACTION_RENAMED_NEW_NAME
:
318 if (add_launcher( folder
, info
->FileName
, info
->FileNameLength
/ sizeof(WCHAR
) ))
322 case FILE_ACTION_REMOVED
:
323 case FILE_ACTION_RENAMED_OLD_NAME
:
324 if (remove_launcher( folder
, info
->FileName
, info
->FileNameLength
/ sizeof(WCHAR
) ))
329 WARN( "unexpected action %u\n", info
->Action
);
332 if (!info
->NextEntryOffset
) break;
333 info
= (FILE_NOTIFY_INFORMATION
*)((char *)info
+ info
->NextEntryOffset
);
338 static DWORD CALLBACK
watch_desktop_folders( LPVOID param
)
341 HRESULT init
= CoInitialize( NULL
);
342 HANDLE dir0
, dir1
, events
[2];
343 OVERLAPPED ovl0
, ovl1
;
344 char *buf0
= NULL
, *buf1
= NULL
;
345 DWORD count
, size
= 4096, error
= ERROR_OUTOFMEMORY
;
348 dir0
= CreateFileW( desktop_folder
, FILE_LIST_DIRECTORY
|SYNCHRONIZE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
349 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
|FILE_FLAG_OVERLAPPED
, NULL
);
350 if (dir0
== INVALID_HANDLE_VALUE
) return GetLastError();
351 dir1
= CreateFileW( desktop_folder_public
, FILE_LIST_DIRECTORY
|SYNCHRONIZE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
352 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
|FILE_FLAG_OVERLAPPED
, NULL
);
353 if (dir1
== INVALID_HANDLE_VALUE
)
356 return GetLastError();
358 if (!(ovl0
.hEvent
= events
[0] = CreateEventW( NULL
, FALSE
, FALSE
, NULL
))) goto error
;
359 if (!(ovl1
.hEvent
= events
[1] = CreateEventW( NULL
, FALSE
, FALSE
, NULL
))) goto error
;
360 if (!(buf0
= HeapAlloc( GetProcessHeap(), 0, size
))) goto error
;
361 if (!(buf1
= HeapAlloc( GetProcessHeap(), 0, size
))) goto error
;
365 ret
= ReadDirectoryChangesW( dir0
, buf0
, size
, FALSE
, FILE_NOTIFY_CHANGE_FILE_NAME
, NULL
, &ovl0
, NULL
);
368 error
= GetLastError();
371 ret
= ReadDirectoryChangesW( dir1
, buf1
, size
, FALSE
, FILE_NOTIFY_CHANGE_FILE_NAME
, NULL
, &ovl1
, NULL
);
374 error
= GetLastError();
379 switch ((error
= WaitForMultipleObjects( 2, events
, FALSE
, INFINITE
)))
382 if (!GetOverlappedResult( dir0
, &ovl0
, &count
, FALSE
) || !count
) break;
383 if (process_changes( desktop_folder
, buf0
)) redraw
= TRUE
;
386 case WAIT_OBJECT_0
+ 1:
387 if (!GetOverlappedResult( dir1
, &ovl1
, &count
, FALSE
) || !count
) break;
388 if (process_changes( desktop_folder_public
, buf1
)) redraw
= TRUE
;
394 if (redraw
) InvalidateRect( hwnd
, NULL
, TRUE
);
400 CloseHandle( events
[0] );
401 CloseHandle( events
[1] );
402 HeapFree( GetProcessHeap(), 0, buf0
);
403 HeapFree( GetProcessHeap(), 0, buf1
);
404 if (SUCCEEDED( init
)) CoUninitialize();
408 static void add_folder( const WCHAR
*folder
)
410 static const WCHAR lnkW
[] = {'\\','*','.','l','n','k',0};
411 int len
= strlenW( folder
) + strlenW( lnkW
);
412 WIN32_FIND_DATAW data
;
416 if (!(glob
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return;
417 strcpyW( glob
, folder
);
418 strcatW( glob
, lnkW
);
420 if ((handle
= FindFirstFileW( glob
, &data
)) != INVALID_HANDLE_VALUE
)
422 do { add_launcher( folder
, data
.cFileName
, -1 ); } while (FindNextFileW( handle
, &data
));
425 HeapFree( GetProcessHeap(), 0, glob
);
428 #define BORDER_SIZE 4
429 #define PADDING_SIZE 4
430 #define TITLE_CHARS 14
432 static void initialize_launchers( HWND hwnd
)
438 if (!(get_icon_text_metrics( hwnd
, &tm
))) return;
440 icon_cx
= GetSystemMetrics( SM_CXICON
);
441 icon_cy
= GetSystemMetrics( SM_CYICON
);
442 icon_size
= max( icon_cx
, icon_cy
);
443 title_cy
= tm
.tmHeight
* 2;
444 title_cx
= max( tm
.tmAveCharWidth
* TITLE_CHARS
, icon_size
+ PADDING_SIZE
+ title_cy
);
445 launcher_size
= BORDER_SIZE
+ title_cx
+ BORDER_SIZE
;
446 icon_offset_cx
= (launcher_size
- icon_cx
) / 2;
447 icon_offset_cy
= BORDER_SIZE
+ (icon_size
- icon_cy
) / 2;
448 title_offset_cx
= BORDER_SIZE
;
449 title_offset_cy
= BORDER_SIZE
+ icon_size
+ PADDING_SIZE
;
450 desktop_width
= GetSystemMetrics( SM_CXSCREEN
);
451 launchers_per_row
= desktop_width
/ launcher_size
;
453 hr
= SHGetKnownFolderPath( &FOLDERID_Desktop
, KF_FLAG_CREATE
, NULL
, &desktop_folder
);
456 WINE_ERR("Could not get user desktop folder\n");
459 hr
= SHGetKnownFolderPath( &FOLDERID_PublicDesktop
, KF_FLAG_CREATE
, NULL
, &desktop_folder_public
);
462 WINE_ERR("Could not get public desktop folder\n");
463 CoTaskMemFree( desktop_folder
);
466 if ((launchers
= HeapAlloc( GetProcessHeap(), 0, 2 * sizeof(launchers
[0]) )))
470 init
= CoInitialize( NULL
);
471 add_folder( desktop_folder
);
472 add_folder( desktop_folder_public
);
473 if (SUCCEEDED( init
)) CoUninitialize();
475 CreateThread( NULL
, 0, watch_desktop_folders
, hwnd
, 0, NULL
);
479 /* screen saver handler */
480 static BOOL
start_screensaver( void )
484 const char *argv
[3] = { "xdg-screensaver", "activate", NULL
};
485 int pid
= _spawnvp( _P_DETACH
, argv
[0], argv
);
488 WINE_TRACE( "started process %d\n", pid
);
495 /* window procedure for the desktop window */
496 static LRESULT WINAPI
desktop_wnd_proc( HWND hwnd
, UINT message
, WPARAM wp
, LPARAM lp
)
498 WINE_TRACE( "got msg %04x wp %lx lp %lx\n", message
, wp
, lp
);
509 return start_screensaver();
518 return (LRESULT
)SetCursor( LoadCursorA( 0, (LPSTR
)IDC_ARROW
) );
524 if (!using_root
) PaintDesktop( (HDC
)wp
);
527 case WM_SETTINGCHANGE
:
528 if (wp
== SPI_SETDESKWALLPAPER
)
529 SystemParametersInfoW( SPI_SETDESKWALLPAPER
, 0, NULL
, FALSE
);
532 case WM_LBUTTONDBLCLK
:
535 const struct launcher
*launcher
= launcher_from_point( (short)LOWORD(lp
), (short)HIWORD(lp
) );
536 if (launcher
) do_launch( launcher
);
543 BeginPaint( hwnd
, &ps
);
546 if (ps
.fErase
) PaintDesktop( ps
.hdc
);
547 draw_launchers( ps
.hdc
, ps
.rcPaint
);
549 EndPaint( hwnd
, &ps
);
554 return DefWindowProcW( hwnd
, message
, wp
, lp
);
558 /* create the desktop and the associated driver window, and make it the current desktop */
559 static BOOL
create_desktop( HMODULE driver
, const WCHAR
*name
, unsigned int width
, unsigned int height
)
561 static const WCHAR rootW
[] = {'r','o','o','t',0};
563 BOOL (CDECL
*create_desktop_func
)(unsigned int, unsigned int);
565 /* magic: desktop "root" means use the root window */
566 if (driver
&& strcmpiW( name
, rootW
))
568 create_desktop_func
= (void *)GetProcAddress( driver
, "wine_create_desktop" );
569 if (create_desktop_func
) ret
= create_desktop_func( width
, height
);
574 /* parse the desktop size specification */
575 static BOOL
parse_size( const WCHAR
*size
, unsigned int *width
, unsigned int *height
)
579 *width
= strtoulW( size
, &end
, 10 );
580 if (end
== size
) return FALSE
;
581 if (*end
!= 'x') return FALSE
;
583 *height
= strtoulW( size
, &end
, 10 );
587 /* retrieve the desktop name to use if not specified on the command line */
588 static const WCHAR
*get_default_desktop_name(void)
590 static const WCHAR desktopW
[] = {'D','e','s','k','t','o','p',0};
591 static const WCHAR defaultW
[] = {'D','e','f','a','u','l','t',0};
592 static const WCHAR explorer_keyW
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
593 'E','x','p','l','o','r','e','r',0};
594 static WCHAR buffer
[MAX_PATH
];
595 DWORD size
= sizeof(buffer
);
596 HDESK desk
= GetThreadDesktop( GetCurrentThreadId() );
600 if (desk
&& GetUserObjectInformationW( desk
, UOI_NAME
, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
602 if (strcmpiW( buffer
, defaultW
)) return buffer
;
605 /* @@ Wine registry key: HKCU\Software\Wine\Explorer */
606 if (!RegOpenKeyW( HKEY_CURRENT_USER
, explorer_keyW
, &hkey
))
608 if (!RegQueryValueExW( hkey
, desktopW
, 0, NULL
, (LPBYTE
)buffer
, &size
)) ret
= buffer
;
614 /* retrieve the default desktop size from the registry */
615 static BOOL
get_default_desktop_size( const WCHAR
*name
, unsigned int *width
, unsigned int *height
)
617 static const WCHAR desktop_keyW
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
618 'E','x','p','l','o','r','e','r','\\',
619 'D','e','s','k','t','o','p','s',0};
622 DWORD size
= sizeof(buffer
);
628 /* @@ Wine registry key: HKCU\Software\Wine\Explorer\Desktops */
629 if (!RegOpenKeyW( HKEY_CURRENT_USER
, desktop_keyW
, &hkey
))
631 if (!RegQueryValueExW( hkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
))
634 if (!parse_size( buffer
, width
, height
)) *width
= *height
= 0;
641 static HMODULE
load_graphics_driver( const WCHAR
*driver
, const GUID
*guid
)
643 static const WCHAR device_keyW
[] = {
644 'S','y','s','t','e','m','\\',
645 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
646 'C','o','n','t','r','o','l','\\',
647 'V','i','d','e','o','\\',
648 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
649 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2','x',
650 '%','0','2','x','%','0','2','x','%','0','2','x','}','\\','0','0','0','0',0};
651 static const WCHAR graphics_driverW
[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
652 static const WCHAR driversW
[] = {'S','o','f','t','w','a','r','e','\\',
653 'W','i','n','e','\\','D','r','i','v','e','r','s',0};
654 static const WCHAR graphicsW
[] = {'G','r','a','p','h','i','c','s',0};
655 static const WCHAR drv_formatW
[] = {'w','i','n','e','%','s','.','d','r','v',0};
657 WCHAR buffer
[MAX_PATH
], libname
[32], *name
, *next
;
658 WCHAR key
[sizeof(device_keyW
)/sizeof(WCHAR
) + 39];
665 strcpyW( buffer
, default_driver
);
667 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
668 if (!RegOpenKeyW( HKEY_CURRENT_USER
, driversW
, &hkey
))
670 DWORD count
= sizeof(buffer
);
671 RegQueryValueExW( hkey
, graphicsW
, 0, NULL
, (LPBYTE
)buffer
, &count
);
675 else lstrcpynW( buffer
, driver
, sizeof(buffer
)/sizeof(WCHAR
) );
680 next
= strchrW( name
, ',' );
681 if (next
) *next
++ = 0;
683 snprintfW( libname
, sizeof(libname
)/sizeof(WCHAR
), drv_formatW
, name
);
684 if ((module
= LoadLibraryW( libname
)) != 0) break;
685 switch (GetLastError())
687 case ERROR_MOD_NOT_FOUND
:
688 strcpy( error
, "The graphics driver is missing. Check your build!" );
690 case ERROR_DLL_INIT_FAILED
:
691 strcpy( error
, "Make sure that your X server is running and that $DISPLAY is set correctly." );
694 sprintf( error
, "Unknown error (%u).", GetLastError() );
702 GetModuleFileNameW( module
, buffer
, MAX_PATH
);
703 TRACE( "display %s driver %s\n", debugstr_guid(guid
), debugstr_w(buffer
) );
706 sprintfW( key
, device_keyW
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
707 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
708 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
710 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE
, key
, 0, NULL
,
711 REG_OPTION_VOLATILE
, KEY_SET_VALUE
, NULL
, &hkey
, NULL
))
714 RegSetValueExW( hkey
, graphics_driverW
, 0, REG_SZ
,
715 (BYTE
*)buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
717 RegSetValueExA( hkey
, "DriverError", 0, REG_SZ
, (BYTE
*)error
, strlen(error
) + 1 );
724 static void initialize_display_settings(void)
728 /* Store current display mode in the registry */
729 if (EnumDisplaySettingsExW( NULL
, ENUM_CURRENT_SETTINGS
, &dmW
, 0 ))
731 WINE_TRACE( "Current display mode %ux%u %u bpp %u Hz\n", dmW
.dmPelsWidth
,
732 dmW
.dmPelsHeight
, dmW
.dmBitsPerPel
, dmW
.dmDisplayFrequency
);
733 ChangeDisplaySettingsExW( NULL
, &dmW
, 0,
734 CDS_GLOBAL
| CDS_NORESET
| CDS_UPDATEREGISTRY
,
739 static void set_desktop_window_title( HWND hwnd
, const WCHAR
*name
)
741 static const WCHAR desktop_nameW
[] = {'W','i','n','e',' ','d','e','s','k','t','o','p',0};
742 static const WCHAR desktop_name_separatorW
[] = {' ', '-', ' ', 0};
743 WCHAR
*window_titleW
= NULL
;
744 int window_title_len
;
748 SetWindowTextW( hwnd
, desktop_nameW
);
752 window_title_len
= strlenW(name
) * sizeof(WCHAR
)
753 + sizeof(desktop_name_separatorW
)
754 + sizeof(desktop_nameW
);
755 window_titleW
= HeapAlloc( GetProcessHeap(), 0, window_title_len
);
758 SetWindowTextW( hwnd
, desktop_nameW
);
762 strcpyW( window_titleW
, name
);
763 strcatW( window_titleW
, desktop_name_separatorW
);
764 strcatW( window_titleW
, desktop_nameW
);
766 SetWindowTextW( hwnd
, window_titleW
);
767 HeapFree( GetProcessHeap(), 0, window_titleW
);
770 /* main desktop management function */
771 void manage_desktop( WCHAR
*arg
)
773 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
778 HMODULE graphics_driver
;
779 unsigned int width
, height
;
780 WCHAR
*cmdline
= NULL
, *driver
= NULL
;
782 const WCHAR
*name
= NULL
;
784 /* get the rest of the command line (if any) */
785 while (*p
&& !isspace(*p
)) p
++;
789 while (*p
&& isspace(*p
)) p
++;
793 /* parse the desktop option */
794 /* the option is of the form /desktop=name[,widthxheight[,driver]] */
795 if (*arg
== '=' || *arg
== ',')
799 if ((p
= strchrW( arg
, ',' )))
802 if ((driver
= strchrW( p
, ',' ))) *driver
++ = 0;
804 if (!p
|| !parse_size( p
, &width
, &height
))
805 get_default_desktop_size( name
, &width
, &height
);
807 else if ((name
= get_default_desktop_name()))
809 if (!get_default_desktop_size( name
, &width
, &height
)) width
= height
= 0;
812 if (name
&& width
&& height
)
814 if (!(desktop
= CreateDesktopW( name
, NULL
, NULL
, 0, DESKTOP_ALL_ACCESS
, NULL
)))
816 WINE_ERR( "failed to create desktop %s error %d\n", wine_dbgstr_w(name
), GetLastError() );
819 SetThreadDesktop( desktop
);
823 TRACE( "display guid %s\n", debugstr_guid(&guid
) );
824 graphics_driver
= load_graphics_driver( driver
, &guid
);
826 /* create the desktop window */
827 hwnd
= CreateWindowExW( 0, DESKTOP_CLASS_ATOM
, NULL
,
828 WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 0, 0, 0, 0, 0, &guid
);
830 /* create the HWND_MESSAGE parent */
831 msg_hwnd
= CreateWindowExW( 0, messageW
, NULL
, WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
832 0, 0, 100, 100, 0, 0, 0, NULL
);
834 if (hwnd
== GetDesktopWindow())
836 using_root
= !desktop
|| !create_desktop( graphics_driver
, name
, width
, height
);
837 SetWindowLongPtrW( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)desktop_wnd_proc
);
838 SendMessageW( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO
)));
839 if (name
) set_desktop_window_title( hwnd
, name
);
840 SetWindowPos( hwnd
, 0, GetSystemMetrics(SM_XVIRTUALSCREEN
), GetSystemMetrics(SM_YVIRTUALSCREEN
),
841 GetSystemMetrics(SM_CXVIRTUALSCREEN
), GetSystemMetrics(SM_CYVIRTUALSCREEN
),
843 SystemParametersInfoW( SPI_SETDESKWALLPAPER
, 0, NULL
, FALSE
);
845 initialize_display_settings();
851 void (WINAPI
*pShellDDEInit
)( BOOL
);
853 initialize_systray( graphics_driver
, using_root
);
854 if (!using_root
) initialize_launchers( hwnd
);
856 if ((shell32
= LoadLibraryA( "shell32.dll" )) &&
857 (pShellDDEInit
= (void *)GetProcAddress( shell32
, (LPCSTR
)188)))
859 pShellDDEInit( TRUE
);
865 DestroyWindow( hwnd
); /* someone beat us to it */
869 if (GetAncestor( msg_hwnd
, GA_PARENT
)) DestroyWindow( msg_hwnd
); /* someone beat us to it */
871 /* if we have a command line, execute it */
875 PROCESS_INFORMATION pi
;
877 memset( &si
, 0, sizeof(si
) );
879 WINE_TRACE( "starting %s\n", wine_dbgstr_w(cmdline
) );
880 if (CreateProcessW( NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
882 CloseHandle( pi
.hThread
);
883 CloseHandle( pi
.hProcess
);
887 /* run the desktop message loop */
890 WINE_TRACE( "desktop message loop starting on hwnd %p\n", hwnd
);
891 while (GetMessageW( &msg
, 0, 0, 0 )) DispatchMessageW( &msg
);
892 WINE_TRACE( "desktop message loop exiting for hwnd %p\n", hwnd
);