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_PARENTNOTIFY
:
533 if (LOWORD(wp
) == WM_DESTROY
) cleanup_systray_window( (HWND
)lp
);
536 case WM_LBUTTONDBLCLK
:
539 const struct launcher
*launcher
= launcher_from_point( (short)LOWORD(lp
), (short)HIWORD(lp
) );
540 if (launcher
) do_launch( launcher
);
547 BeginPaint( hwnd
, &ps
);
550 if (ps
.fErase
) PaintDesktop( ps
.hdc
);
551 draw_launchers( ps
.hdc
, ps
.rcPaint
);
553 EndPaint( hwnd
, &ps
);
558 return DefWindowProcW( hwnd
, message
, wp
, lp
);
562 /* create the desktop and the associated driver window, and make it the current desktop */
563 static BOOL
create_desktop( HMODULE driver
, const WCHAR
*name
, unsigned int width
, unsigned int height
)
565 static const WCHAR rootW
[] = {'r','o','o','t',0};
567 BOOL (CDECL
*create_desktop_func
)(unsigned int, unsigned int);
569 /* magic: desktop "root" means use the root window */
570 if (driver
&& strcmpiW( name
, rootW
))
572 create_desktop_func
= (void *)GetProcAddress( driver
, "wine_create_desktop" );
573 if (create_desktop_func
) ret
= create_desktop_func( width
, height
);
578 /* parse the desktop size specification */
579 static BOOL
parse_size( const WCHAR
*size
, unsigned int *width
, unsigned int *height
)
583 *width
= strtoulW( size
, &end
, 10 );
584 if (end
== size
) return FALSE
;
585 if (*end
!= 'x') return FALSE
;
587 *height
= strtoulW( size
, &end
, 10 );
591 /* retrieve the desktop name to use if not specified on the command line */
592 static const WCHAR
*get_default_desktop_name(void)
594 static const WCHAR desktopW
[] = {'D','e','s','k','t','o','p',0};
595 static const WCHAR defaultW
[] = {'D','e','f','a','u','l','t',0};
596 static const WCHAR explorer_keyW
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
597 'E','x','p','l','o','r','e','r',0};
598 static WCHAR buffer
[MAX_PATH
];
599 DWORD size
= sizeof(buffer
);
600 HDESK desk
= GetThreadDesktop( GetCurrentThreadId() );
604 if (desk
&& GetUserObjectInformationW( desk
, UOI_NAME
, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
606 if (strcmpiW( buffer
, defaultW
)) return buffer
;
609 /* @@ Wine registry key: HKCU\Software\Wine\Explorer */
610 if (!RegOpenKeyW( HKEY_CURRENT_USER
, explorer_keyW
, &hkey
))
612 if (!RegQueryValueExW( hkey
, desktopW
, 0, NULL
, (LPBYTE
)buffer
, &size
)) ret
= buffer
;
618 /* retrieve the default desktop size from the registry */
619 static BOOL
get_default_desktop_size( const WCHAR
*name
, unsigned int *width
, unsigned int *height
)
621 static const WCHAR desktop_keyW
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
622 'E','x','p','l','o','r','e','r','\\',
623 'D','e','s','k','t','o','p','s',0};
626 DWORD size
= sizeof(buffer
);
632 /* @@ Wine registry key: HKCU\Software\Wine\Explorer\Desktops */
633 if (!RegOpenKeyW( HKEY_CURRENT_USER
, desktop_keyW
, &hkey
))
635 if (!RegQueryValueExW( hkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
))
638 if (!parse_size( buffer
, width
, height
)) *width
= *height
= 0;
645 static BOOL
get_default_enable_shell( const WCHAR
*name
)
647 static const WCHAR desktop_keyW
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
648 'E','x','p','l','o','r','e','r','\\',
649 'D','e','s','k','t','o','p','s',0};
650 static const WCHAR enable_shellW
[] = {'E','n','a','b','l','e','S','h','e','l','l',0};
651 static const WCHAR shellW
[] = {'s','h','e','l','l',0};
655 DWORD size
= sizeof(result
);
657 /* @@ Wine registry key: HKCU\Software\Wine\Explorer\Desktops */
658 if (!RegOpenKeyW( HKEY_CURRENT_USER
, desktop_keyW
, &hkey
))
660 if (!RegGetValueW( hkey
, name
, enable_shellW
, RRF_RT_REG_DWORD
, NULL
, &result
, &size
))
664 /* Default off, except for the magic desktop name "shell" */
666 result
= (lstrcmpiW( name
, shellW
) == 0);
670 static HMODULE
load_graphics_driver( const WCHAR
*driver
, const GUID
*guid
)
672 static const WCHAR device_keyW
[] = {
673 'S','y','s','t','e','m','\\',
674 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
675 'C','o','n','t','r','o','l','\\',
676 'V','i','d','e','o','\\',
677 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
678 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2','x',
679 '%','0','2','x','%','0','2','x','%','0','2','x','}','\\','0','0','0','0',0};
680 static const WCHAR graphics_driverW
[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
681 static const WCHAR driversW
[] = {'S','o','f','t','w','a','r','e','\\',
682 'W','i','n','e','\\','D','r','i','v','e','r','s',0};
683 static const WCHAR graphicsW
[] = {'G','r','a','p','h','i','c','s',0};
684 static const WCHAR drv_formatW
[] = {'w','i','n','e','%','s','.','d','r','v',0};
686 WCHAR buffer
[MAX_PATH
], libname
[32], *name
, *next
;
687 WCHAR key
[sizeof(device_keyW
)/sizeof(WCHAR
) + 39];
694 strcpyW( buffer
, default_driver
);
696 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
697 if (!RegOpenKeyW( HKEY_CURRENT_USER
, driversW
, &hkey
))
699 DWORD count
= sizeof(buffer
);
700 RegQueryValueExW( hkey
, graphicsW
, 0, NULL
, (LPBYTE
)buffer
, &count
);
704 else lstrcpynW( buffer
, driver
, sizeof(buffer
)/sizeof(WCHAR
) );
709 next
= strchrW( name
, ',' );
710 if (next
) *next
++ = 0;
712 snprintfW( libname
, sizeof(libname
)/sizeof(WCHAR
), drv_formatW
, name
);
713 if ((module
= LoadLibraryW( libname
)) != 0) break;
714 switch (GetLastError())
716 case ERROR_MOD_NOT_FOUND
:
717 strcpy( error
, "The graphics driver is missing. Check your build!" );
719 case ERROR_DLL_INIT_FAILED
:
720 strcpy( error
, "Make sure that your X server is running and that $DISPLAY is set correctly." );
723 sprintf( error
, "Unknown error (%u).", GetLastError() );
731 GetModuleFileNameW( module
, buffer
, MAX_PATH
);
732 TRACE( "display %s driver %s\n", debugstr_guid(guid
), debugstr_w(buffer
) );
735 sprintfW( key
, device_keyW
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
736 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
737 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
739 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE
, key
, 0, NULL
,
740 REG_OPTION_VOLATILE
, KEY_SET_VALUE
, NULL
, &hkey
, NULL
))
743 RegSetValueExW( hkey
, graphics_driverW
, 0, REG_SZ
,
744 (BYTE
*)buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
746 RegSetValueExA( hkey
, "DriverError", 0, REG_SZ
, (BYTE
*)error
, strlen(error
) + 1 );
753 static void initialize_display_settings(void)
757 /* Store current display mode in the registry */
758 if (EnumDisplaySettingsExW( NULL
, ENUM_CURRENT_SETTINGS
, &dmW
, 0 ))
760 WINE_TRACE( "Current display mode %ux%u %u bpp %u Hz\n", dmW
.dmPelsWidth
,
761 dmW
.dmPelsHeight
, dmW
.dmBitsPerPel
, dmW
.dmDisplayFrequency
);
762 ChangeDisplaySettingsExW( NULL
, &dmW
, 0,
763 CDS_GLOBAL
| CDS_NORESET
| CDS_UPDATEREGISTRY
,
768 static void set_desktop_window_title( HWND hwnd
, const WCHAR
*name
)
770 static const WCHAR desktop_nameW
[] = {'W','i','n','e',' ','d','e','s','k','t','o','p',0};
771 static const WCHAR desktop_name_separatorW
[] = {' ', '-', ' ', 0};
772 WCHAR
*window_titleW
= NULL
;
773 int window_title_len
;
777 SetWindowTextW( hwnd
, desktop_nameW
);
781 window_title_len
= strlenW(name
) * sizeof(WCHAR
)
782 + sizeof(desktop_name_separatorW
)
783 + sizeof(desktop_nameW
);
784 window_titleW
= HeapAlloc( GetProcessHeap(), 0, window_title_len
);
787 SetWindowTextW( hwnd
, desktop_nameW
);
791 strcpyW( window_titleW
, name
);
792 strcatW( window_titleW
, desktop_name_separatorW
);
793 strcatW( window_titleW
, desktop_nameW
);
795 SetWindowTextW( hwnd
, window_titleW
);
796 HeapFree( GetProcessHeap(), 0, window_titleW
);
799 /* main desktop management function */
800 void manage_desktop( WCHAR
*arg
)
802 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
807 HMODULE graphics_driver
;
808 unsigned int width
, height
;
809 WCHAR
*cmdline
= NULL
, *driver
= NULL
;
811 const WCHAR
*name
= NULL
;
812 BOOL enable_shell
= FALSE
;
814 /* get the rest of the command line (if any) */
815 while (*p
&& !isspace(*p
)) p
++;
819 while (*p
&& isspace(*p
)) p
++;
823 /* parse the desktop option */
824 /* the option is of the form /desktop=name[,widthxheight[,driver]] */
825 if (*arg
== '=' || *arg
== ',')
829 if ((p
= strchrW( arg
, ',' )))
832 if ((driver
= strchrW( p
, ',' ))) *driver
++ = 0;
834 if (!p
|| !parse_size( p
, &width
, &height
))
835 get_default_desktop_size( name
, &width
, &height
);
837 else if ((name
= get_default_desktop_name()))
839 if (!get_default_desktop_size( name
, &width
, &height
)) width
= height
= 0;
843 enable_shell
= get_default_enable_shell( name
);
845 if (name
&& width
&& height
)
847 if (!(desktop
= CreateDesktopW( name
, NULL
, NULL
, 0, DESKTOP_ALL_ACCESS
, NULL
)))
849 WINE_ERR( "failed to create desktop %s error %d\n", wine_dbgstr_w(name
), GetLastError() );
852 SetThreadDesktop( desktop
);
856 TRACE( "display guid %s\n", debugstr_guid(&guid
) );
857 graphics_driver
= load_graphics_driver( driver
, &guid
);
859 /* create the desktop window */
860 hwnd
= CreateWindowExW( 0, DESKTOP_CLASS_ATOM
, NULL
,
861 WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 0, 0, 0, 0, 0, &guid
);
865 /* create the HWND_MESSAGE parent */
866 CreateWindowExW( 0, messageW
, NULL
, WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
867 0, 0, 100, 100, 0, 0, 0, NULL
);
869 using_root
= !desktop
|| !create_desktop( graphics_driver
, name
, width
, height
);
870 SetWindowLongPtrW( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)desktop_wnd_proc
);
871 SendMessageW( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO
)));
872 if (name
) set_desktop_window_title( hwnd
, name
);
873 SetWindowPos( hwnd
, 0, GetSystemMetrics(SM_XVIRTUALSCREEN
), GetSystemMetrics(SM_YVIRTUALSCREEN
),
874 GetSystemMetrics(SM_CXVIRTUALSCREEN
), GetSystemMetrics(SM_CYVIRTUALSCREEN
),
876 SystemParametersInfoW( SPI_SETDESKWALLPAPER
, 0, NULL
, FALSE
);
878 initialize_display_settings();
884 void (WINAPI
*pShellDDEInit
)( BOOL
);
886 if (using_root
) enable_shell
= FALSE
;
888 initialize_systray( graphics_driver
, using_root
, enable_shell
);
889 if (!using_root
) initialize_launchers( hwnd
);
891 if ((shell32
= LoadLibraryA( "shell32.dll" )) &&
892 (pShellDDEInit
= (void *)GetProcAddress( shell32
, (LPCSTR
)188)))
894 pShellDDEInit( TRUE
);
899 /* if we have a command line, execute it */
903 PROCESS_INFORMATION pi
;
905 memset( &si
, 0, sizeof(si
) );
907 WINE_TRACE( "starting %s\n", wine_dbgstr_w(cmdline
) );
908 if (CreateProcessW( NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
910 CloseHandle( pi
.hThread
);
911 CloseHandle( pi
.hProcess
);
915 /* run the desktop message loop */
918 WINE_TRACE( "desktop message loop starting on hwnd %p\n", hwnd
);
919 while (GetMessageW( &msg
, 0, 0, 0 )) DispatchMessageW( &msg
);
920 WINE_TRACE( "desktop message loop exiting for hwnd %p\n", hwnd
);