PATCH - implement LockWorkStation using xdg-screensaver on Linux

Steven Edwards winehacker at gmail.com
Tue Jun 19 13:08:50 CDT 2007


Patch by Hans Leidekker

This could be expanded for other platforms that use xdg stuff by
changing the #ifdef. I added the #ifdef to also deal with the MacOS
case.

-- 
Steven Edwards

"There is one thing stronger than all the armies in the world, and
that is an idea whose time has come." - Victor Hugo
-------------- next part --------------
From 8c445e4ef1490d56ef07f438e5f710c6e292d412 Mon Sep 17 00:00:00 2001
From: Steven Edwards <winehacker at gmail.com>
Date: Tue, 19 Jun 2007 13:53:49 -0400
Subject: [PATCH] Implement LockWorkStation
Hans Leidekker <hans at it.vu.nl>
---
 dlls/user32/user32.spec      |    2 +-
 dlls/user32/user_main.c      |   27 +++++++++++++++++++++++++++
 programs/wineboot/wineboot.c |   24 ++++++++++++++++++++++--
 3 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec
index 7e4ce33..f97afd6 100644
--- a/dlls/user32/user32.spec
+++ b/dlls/user32/user32.spec
@@ -475,7 +475,7 @@ # @ stub LoadKeyboardLayoutEx
 @ stdcall LockSetForegroundWindow (long)
 @ stub LockWindowStation
 @ stdcall LockWindowUpdate(long)
-@ stub LockWorkStation
+@ stdcall LockWorkStation()
 @ stdcall LookupIconIdFromDirectory(ptr long)
 @ stdcall LookupIconIdFromDirectoryEx(ptr long long long long)
 @ stub MBToWCSEx
diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c
index e572220..6e6e219 100644
--- a/dlls/user32/user_main.c
+++ b/dlls/user32/user_main.c
@@ -318,3 +318,30 @@ BOOL WINAPI ExitWindowsEx( UINT flags, D
     CloseHandle( pi.hThread );
     return TRUE;
 }
+
+/***********************************************************************
+ *		LockWorkStation (USER32.@)
+ */
+BOOL WINAPI LockWorkStation( void )
+{
+    static const WCHAR cmdW[] =
+        { '\\','w','i','n','e','b','o','o','t','.','e','x','e',' ','-','-','l','o','c','k',0 };
+
+    WCHAR cmdline[MAX_PATH + 64];
+    PROCESS_INFORMATION pi;
+    STARTUPINFOW si;
+
+    GetSystemDirectoryW( cmdline, MAX_PATH );
+    lstrcatW( cmdline, cmdW );
+
+    memset( &si, 0, sizeof si );
+    si.cb = sizeof si;
+    if (!CreateProcessW( NULL, cmdline, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi ))
+    {
+        ERR( "Failed to run %s\n", debugstr_w(cmdline) );
+        return FALSE;
+    }
+    CloseHandle( pi.hProcess );
+    CloseHandle( pi.hThread );
+    return TRUE;
+}
diff --git a/programs/wineboot/wineboot.c b/programs/wineboot/wineboot.c
index 27babc7..27347b6 100644
--- a/programs/wineboot/wineboot.c
+++ b/programs/wineboot/wineboot.c
@@ -704,6 +704,21 @@ done:
     return ret;
 }
 
+static int lock_workstation( void )
+{
+#ifdef linux
+    const char *argv[3];
+
+    argv[0] = "xdg-screensaver";
+    argv[1] = "lock";
+    argv[2] = NULL;
+    execvp( "xdg-screensaver", (char **)argv );
+#else
+    WINE_FIXME( "This platform does not support locking the workstation" );
+#endif
+    return 0;
+}
+
 static void usage(void)
 {
     WINE_MESSAGE( "Usage: wineboot [options]\n" );
@@ -712,11 +727,12 @@ static void usage(void)
     WINE_MESSAGE( "    -e,--end-session  End the current session cleanly\n" );
     WINE_MESSAGE( "    -f,--force        Force exit for processes that don't exit cleanly\n" );
     WINE_MESSAGE( "    -k,--kill         Kill running processes without any cleanup\n" );
+    WINE_MESSAGE( "    -l,--lock         Lock the current session\n" );
     WINE_MESSAGE( "    -r,--restart      Restart only, don't do normal startup operations\n" );
     WINE_MESSAGE( "    -s,--shutdown     Shutdown only, don't reboot\n" );
 }
 
-static const char short_options[] = "efhkrs";
+static const char short_options[] = "efhklrs";
 
 static const struct option long_options[] =
 {
@@ -724,6 +740,7 @@ static const struct option long_options[
     { "end-session", 0, 0, 'e' },
     { "force",       0, 0, 'f' },
     { "kill",        0, 0, 'k' },
+    { "lock",        0, 0, 'l' },
     { "restart",     0, 0, 'r' },
     { "shutdown",    0, 0, 's' },
     { NULL,          0, 0, 0 }
@@ -748,7 +765,7 @@ int main( int argc, char *argv[] )
     TCHAR gen_path[MAX_PATH];
     DWORD res;
     int optc;
-    int end_session = 0, force = 0, kill = 0, restart = 0, shutdown = 0;
+    int end_session = 0, force = 0, kill = 0, lock = 0, restart = 0, shutdown = 0;
 
     res=GetWindowsDirectory( gen_path, sizeof(gen_path) );
     
@@ -782,6 +799,7 @@ int main( int argc, char *argv[] )
         case 'e': end_session = 1; break;
         case 'f': force = 1; break;
         case 'k': kill = 1; break;
+        case 'l': lock = 1; break;
         case 'r': restart = 1; break;
         case 's': shutdown = 1; break;
         case 'h': usage(); return 0;
@@ -800,6 +818,8 @@ int main( int argc, char *argv[] )
 
     if (restart) ops = SETUP;
 
+    if (lock) return lock_workstation();
+
     /* Perform the ops by order, stopping if one fails, skipping if necessary */
     /* Shachar: Sorry for the perl syntax */
     res=(ops.ntonly || !ops.preboot || wininit())&&
-- 
1.4.0


More information about the wine-patches mailing list