summaryrefslogtreecommitdiff
path: root/community/lxsession/lxsession-0.4.6.1-logind-support.patch
blob: 978223207c9f61fabcb04d97707a100144165607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
--- lxsession-0.4.6.1/lxsession-logout/dbus-interface.c	2011-07-27 21:26:36.000000000 +0200
+++ lxsession-0.4.6.1/lxsession-logout-logind/dbus-interface.c	2012-11-13 17:26:30.807070976 +0100
@@ -51,13 +51,20 @@
 char * dbus_HAL_Reboot(void);
 char * dbus_HAL_Suspend(void);
 char * dbus_HAL_Hibernate(void);
+gboolean dbus_logind_CanPowerOff(void);
+gboolean dbus_logind_CanReboot(void);
+gboolean dbus_logind_CanSuspend(void);
+gboolean dbus_logind_CanHibernate(void);
+char * dbus_logind_PowerOff(void);
+char * dbus_logind_Reboot(void);
+char * dbus_logind_Suspend(void);
+char * dbus_logind_Hibernate(void);
+char * dbus_LXDE_Logout(void);
 /* End FORWARDS */
 
 /* Connect to the system bus.  Once a connection is made, it is saved for reuse. */
-static DBusConnection * dbus_connect(void)
+static DBusConnection * dbus_connect_system(void)
 {
-    if ((dbus_context.connection == NULL) && ( ! dbus_context.connection_tried))
-    {
         DBusError error;
         dbus_error_init(&error);
         dbus_context.connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
@@ -67,16 +74,57 @@
             dbus_error_free(&error);
         }
         dbus_context.connection_tried = TRUE;
-    }
 
     return dbus_context.connection;
 }
 
+static DBusConnection * dbus_connect_session(void)
+{
+        DBusError error;
+        dbus_error_init(&error);
+        dbus_context.connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
+        if (dbus_context.connection == NULL)
+        {
+            g_warning(G_STRLOC ": Failed to connect to the session message bus: %s", error.message);
+            dbus_error_free(&error);
+        }
+        dbus_context.connection_tried = TRUE;
+
+    return dbus_context.connection;
+}
+
+
 /* Send a message. */
-static DBusMessage * dbus_send_message(DBusMessage * message, char * * error_text)
+static DBusMessage * dbus_send_message_system(DBusMessage * message, char * * error_text)
 {
     /* Get a connection handle. */
-    DBusConnection * connection = dbus_connect();
+    DBusConnection * connection = dbus_connect_system();
+    if (connection == NULL)
+        return FALSE;
+
+    /* Send the message. */
+    DBusError error;
+    dbus_error_init(&error);
+    DBusMessage * reply = dbus_connection_send_with_reply_and_block(connection, message, DBUS_TIMEOUT, &error);
+    dbus_message_unref(message);
+    if (reply == NULL)
+    {
+        if ((error.name == NULL) || (strcmp(error.name, DBUS_ERROR_NO_REPLY) != 0))
+        {
+            if (error_text != NULL)
+                *error_text = g_strdup(error.message);
+            g_warning(G_STRLOC ": DBUS: %s", error.message);
+        }
+        dbus_error_free(&error);
+    }
+    return reply;
+}
+
+/* Send a message. */
+static DBusMessage * dbus_send_message_session(DBusMessage * message, char * * error_text)
+{
+    /* Get a connection handle. */
+    DBusConnection * connection = dbus_connect_session();
     if (connection == NULL)
         return FALSE;
 
@@ -132,6 +180,36 @@
     }
     return result;
 }
+
+/* Read a result for a method that returns a string encoded boolean. */
+static gboolean dbus_read_result_sboolean(DBusMessage * reply)
+{
+    gboolean result = FALSE;
+    char* string_result;
+    if (reply != NULL)
+    {
+        /* Get the string result. */
+        DBusError error;
+        dbus_error_init(&error);
+        dbus_bool_t status = dbus_message_get_args(
+            reply,
+            &error,
+            DBUS_TYPE_STRING, &string_result,
+            DBUS_TYPE_INVALID);
+        if ( ! status)
+        {
+            g_warning(G_STRLOC ": DBUS: %s", error.message);
+            dbus_error_free(&error);
+        }
+        else
+        {
+            if (!strcmp(string_result, "yes"))
+                result = TRUE;
+        }
+        dbus_message_unref(reply);
+    }
+    return result;
+}
 #endif
 
 /*** ConsoleKit mechanism ***/
@@ -152,7 +230,7 @@
 static gboolean dbus_ConsoleKit_query(const char * const query)
 {
 #ifdef HAVE_DBUS
-    return dbus_read_result_boolean(dbus_send_message(dbus_ConsoleKit_formulate_message(query), NULL));
+    return dbus_read_result_boolean(dbus_send_message_system(dbus_ConsoleKit_formulate_message(query), NULL));
 #else
     return FALSE;
 #endif
@@ -163,7 +241,7 @@
 {
 #ifdef HAVE_DBUS
     char * error = NULL;
-    dbus_read_result_void(dbus_send_message(dbus_ConsoleKit_formulate_message(command), &error));
+    dbus_read_result_void(dbus_send_message_system(dbus_ConsoleKit_formulate_message(command), &error));
     return error;
 #else
     return NULL;
@@ -225,7 +303,7 @@
         DBUS_TYPE_INVALID);
 
     /* Send the message. */
-    DBusMessage * reply = dbus_send_message(message, NULL);
+    DBusMessage * reply = dbus_send_message_system(message, NULL);
     if (reply == NULL)
 	return FALSE;
 
@@ -252,7 +330,7 @@
 {
 #ifdef HAVE_DBUS
     char * error = NULL;
-    dbus_read_result_void(dbus_send_message(dbus_UPower_formulate_command(command), &error));
+    dbus_read_result_void(dbus_send_message_system(dbus_UPower_formulate_command(command), &error));
     return error;
 #else
     return NULL;
@@ -329,7 +407,7 @@
     DBusMessage * message = dbus_HAL_formulate_string_property_query(property);
     if (message == NULL)
         return FALSE;
-    DBusMessage * reply = dbus_send_message(message, NULL);
+    DBusMessage * reply = dbus_send_message_system(message, NULL);
     if (reply == NULL)
 	return FALSE;
     dbus_message_unref(reply);
@@ -343,7 +421,7 @@
 static gboolean dbus_HAL_boolean_query(const char * const property)
 {
 #ifdef HAVE_DBUS
-    return dbus_read_result_boolean(dbus_send_message(dbus_HAL_formulate_boolean_property_query(property), NULL));
+    return dbus_read_result_boolean(dbus_send_message_system(dbus_HAL_formulate_boolean_property_query(property), NULL));
 #else
     return FALSE;
 #endif
@@ -367,7 +445,7 @@
 
     /* Send the message and wait for a reply. */
     char * error = NULL;
-    dbus_read_result_void(dbus_send_message(message, &error));
+    dbus_read_result_void(dbus_send_message_system(message, &error));
     return error;
 #else
     return NULL;
@@ -421,3 +499,185 @@
 {
     return dbus_HAL_command("Hibernate");
 }
+
+/*** logind mechanism ***/
+
+#ifdef HAVE_DBUS
+/* Formulate a message to the logind Manager interface to query a property. */
+static DBusMessage * dbus_logind_formulate_query(const char * const query)
+{
+    return dbus_message_new_method_call(
+	"org.freedesktop.login1",
+        "/org/freedesktop/login1",
+        "org.freedesktop.login1.Manager",
+        query);
+}
+
+/* Formulate a message to the logind Manager interface. */
+static DBusMessage * dbus_logind_formulate_message(const char * const method)
+{
+    static dbus_bool_t interactive = FALSE;
+    DBusMessage * message = dbus_message_new_method_call(
+	"org.freedesktop.login1",
+        "/org/freedesktop/login1",
+        "org.freedesktop.login1.Manager",
+        method);
+    if (message != NULL)
+        dbus_message_append_args(message, DBUS_TYPE_BOOLEAN, &interactive, DBUS_TYPE_INVALID);
+    return message;
+}
+#endif
+
+/* Send a specified query to the logind interface and process a boolean result. */
+static gboolean dbus_logind_query(const char * const query)
+{
+#ifdef HAVE_DBUS
+    return dbus_read_result_sboolean(dbus_send_message_system(dbus_logind_formulate_query(query), NULL));
+#else
+    return FALSE;
+#endif
+}
+
+/* Send a specified command to the logind interface and process a void result. */
+static char * dbus_logind_command(const char * const command)
+{
+#ifdef HAVE_DBUS
+    char * error = NULL;
+    dbus_read_result_void(dbus_send_message_system(dbus_logind_formulate_message(command), &error));
+    return error;
+#else
+    return NULL;
+#endif
+}
+
+/* Read the can-poweroff property of logind. */
+gboolean dbus_logind_CanPowerOff(void)
+{
+    return dbus_logind_query("CanPowerOff");
+}
+
+/* Read the can-reboot property of logind. */
+gboolean dbus_logind_CanReboot(void)
+{
+    return dbus_logind_query("CanReboot");
+}
+
+/* Read the can-suspend property of logind. */
+gboolean dbus_logind_CanSuspend(void)
+{
+    return dbus_logind_query("CanSuspend");
+}
+
+/* Read the can-hibernate property of logind. */
+gboolean dbus_logind_CanHibernate(void)
+{
+    return dbus_logind_query("CanHibernate");
+}
+
+/* Invoke the PowerOff method on logind. */
+char * dbus_logind_PowerOff(void)
+{
+    return dbus_logind_command("PowerOff");
+}
+
+/* Invoke the Reboot method on logind. */
+char * dbus_logind_Reboot(void)
+{
+    return dbus_logind_command("Reboot");
+}
+
+/* Invoke the Suspend method on logind. */
+char * dbus_logind_Suspend(void)
+{
+    return dbus_logind_command("Suspend");
+}
+
+/* Invoke the Hibernate method on logind. */
+char * dbus_logind_Hibernate(void)
+{
+    return dbus_logind_command("Hibernate");
+}
+
+/*** LXDE mechanism ***/
+
+#ifdef HAVE_DBUS
+/* Formulate a message to the LXDE Session Manager interface. */
+static DBusMessage * dbus_LXDE_formulate_message(const char * const query)
+{
+    return dbus_message_new_method_call(
+        "org.lxde.SessionManager",
+        "/org/lxde/SessionManager",
+        "org.lxde.SessionManager",
+        query);
+}
+#endif
+
+/* Send a specified message to the LXDE interface and process a boolean result. */
+static gboolean dbus_LXDE_query(const char * const query)
+{
+#ifdef HAVE_DBUS
+    return dbus_read_result_boolean(dbus_send_message_session(dbus_LXDE_formulate_message(query), NULL));
+#else
+    return FALSE;
+#endif
+}
+
+/* Send a specified message to the LXDE interface and process a void result. */
+static char * dbus_LXDE_command(const char * const command)
+{
+#ifdef HAVE_DBUS
+    char * error = NULL;
+    dbus_read_result_void(dbus_send_message_session(dbus_LXDE_formulate_message(command), &error));
+    return error;
+#else
+    return NULL;
+#endif
+}
+
+/* Invoke the Logout method on LXDE. */
+char * dbus_LXDE_Logout(void)
+{
+    return dbus_LXDE_command("Logout");
+}
+
+/*** Lightdm mechanism ***/
+
+#ifdef HAVE_DBUS
+/* Formulate a message to the Lightdm interface. */
+static DBusMessage * dbus_Lightdm_formulate_message(const char * const query)
+{
+    return dbus_message_new_method_call(
+                "org.freedesktop.DisplayManager",
+                g_getenv ("XDG_SEAT_PATH"),
+                "org.freedesktop.DisplayManager.Seat",
+                query);
+}
+#endif
+
+/* Send a specified message to the Lightdm interface and process a boolean result. */
+static gboolean dbus_Lightdm_query(const char * const query)
+{
+#ifdef HAVE_DBUS
+    return dbus_read_result_boolean(dbus_send_message_session(dbus_Lightdm_formulate_message(query), NULL));
+#else
+    return FALSE;
+#endif
+}
+
+/* Send a specified message to the Lightdm interface and process a void result. */
+static char * dbus_Lightdm_command(const char * const command)
+{
+#ifdef HAVE_DBUS
+    char * error = NULL;
+    dbus_read_result_void(dbus_send_message_session(dbus_Lightdm_formulate_message(command), &error));
+    return error;
+#else
+    return NULL;
+#endif
+}
+
+/* Invoke the Logout method on LXDE. */
+char * dbus_Lightdm_SwitchToGreeter(void)
+{
+    return dbus_Lightdm_command("SwitchToGreeter");
+}
--- lxsession-0.4.6.1/lxsession-logout/dbus-interface.h	2011-07-27 21:26:36.000000000 +0200
+++ lxsession-0.4.6.1/lxsession-logout-logind/dbus-interface.h	2012-11-13 17:26:30.807070976 +0100
@@ -44,4 +44,18 @@
 extern char * dbus_HAL_Suspend(void);
 extern char * dbus_HAL_Hibernate(void);
 
+/* Interface to logind for shutdown, reboot, suspend, and hibernate. */
+extern gboolean dbus_logind_CanPowerOff(void);
+extern gboolean dbus_logind_CanRestart(void);
+extern char * dbus_logind_PowerOff(void);
+extern char * dbus_logind_Restart(void);
+extern gboolean dbus_logind_CanSuspend(void);
+extern gboolean dbus_logind_CanHibernate(void);
+extern char * dbus_logind_Suspend(void);
+extern char * dbus_logind_Hibernate(void);
+
+extern char * dbus_LXDE_Logout(void);
+
+extern char * dbus_Lightdm_SwitchToGreeter();
+
 #endif
--- lxsession-0.4.6.1/lxsession-logout/lxsession-logout.c	2011-07-27 21:26:36.000000000 +0200
+++ lxsession-0.4.6.1/lxsession-logout-logind/lxsession-logout.c	2012-11-13 17:26:30.807070976 +0100
@@ -69,12 +69,21 @@
     int reboot_HAL : 1;			/* Reboot is available via HAL */
     int suspend_HAL : 1;		/* Suspend is available via HAL */
     int hibernate_HAL : 1;		/* Hibernate is available via HAL */
+    int shutdown_logind : 1;		/* Shutdown is available via logind */
+    int reboot_logind : 1;		/* Reboot is available via logind */
+    int suspend_logind : 1;		/* Suspend is available via logind */
+    int hibernate_logind : 1;		/* Hibernate is available via logind */
     int switch_user_GDM : 1;		/* Switch User is available via GDM */
-    int switch_user_KDM : 1;		/* Switch User is available via KDM */
+    int switch_user_LIGHTDM : 1;	/* Switch User is available via GDM */
+    int switch_user_KDM : 1;		/* Switch User is available via LIGHTDM */
     int ltsp : 1;			/* Shutdown and reboot is accomplished via LTSP */
+
+    int lock_screen : 1;                /* Lock screen available */
+
 } HandlerContext;
 
 static gboolean lock_screen(void);
+static const gchar* determine_lock_screen(void);
 static gboolean verify_running(const char * display_manager, const char * executable);
 static void logout_clicked(GtkButton * button, HandlerContext * handler_context);
 static void change_root_property(GtkWidget* w, const char* prop_name, const char* value);
@@ -93,13 +102,32 @@
  */
 static gboolean lock_screen(void)
 {
-    if (!g_spawn_command_line_async("lxlock", NULL))
+    const gchar* program = determine_lock_screen();
+
+    if (program)
     {
+        g_spawn_command_line_async(program, NULL);
         return TRUE;
     }
     return FALSE;
 }
 
+static const gchar* determine_lock_screen(void)
+{
+    const gchar* program = NULL;
+
+    if (g_find_program_in_path("lxlock"))
+    {
+        program = "lxlock";
+    }
+    else if (g_find_program_in_path("xdg-screensaver"))
+    {
+        program = "xdg-screensaver lock";
+    }
+    return program;
+}
+
+
 /* Verify that a program is running and that an executable is available. */
 static gboolean verify_running(const char * display_manager, const char * executable)
 {
@@ -187,6 +215,8 @@
         error_result = dbus_ConsoleKit_Stop();
     else if (handler_context->shutdown_HAL)
         error_result = dbus_HAL_Shutdown();
+    else if (handler_context->shutdown_logind)
+        error_result = dbus_logind_PowerOff();
 
     if (error_result != NULL)
         gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
@@ -208,6 +238,8 @@
         error_result = dbus_ConsoleKit_Restart();
     else if (handler_context->reboot_HAL)
         error_result = dbus_HAL_Reboot();
+    else if (handler_context->reboot_logind)
+        error_result = dbus_logind_Reboot();
 
     if (error_result != NULL)
         gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
@@ -225,6 +257,8 @@
         error_result = dbus_UPower_Suspend();
     else if (handler_context->suspend_HAL)
         error_result = dbus_HAL_Suspend();
+    else if (handler_context->suspend_logind)
+        error_result = dbus_logind_Suspend();
 
     if (error_result != NULL)
         gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
@@ -242,6 +276,8 @@
         error_result = dbus_UPower_Hibernate();
     else if (handler_context->hibernate_HAL)
         error_result = dbus_HAL_Hibernate();
+    else if (handler_context->hibernate_logind)
+        error_result = dbus_logind_Hibernate();
 
     if (error_result != NULL)
         gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
@@ -258,6 +294,17 @@
         g_spawn_command_line_sync("gdmflexiserver --startnew", NULL, NULL, NULL, NULL);
     else if (handler_context->switch_user_KDM)
         g_spawn_command_line_sync("kdmctl reserve", NULL, NULL, NULL, NULL);
+    else if (handler_context->switch_user_LIGHTDM)
+        dbus_Lightdm_SwitchToGreeter();
+    gtk_main_quit();
+}
+
+/* Handler for "clicked" signal on Lock button. */
+static void lock_screen_clicked(GtkButton * button, HandlerContext * handler_context)
+{
+    gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
+
+    lock_screen();
     gtk_main_quit();
 }
 
@@ -435,6 +482,28 @@
         handler_context.hibernate_HAL = TRUE;
     }
 
+    /* Initialize capabilities of the logind mechanism. */
+    if (!handler_context.shutdown_available && dbus_logind_CanPowerOff())
+    {
+        handler_context.shutdown_available = TRUE;
+        handler_context.shutdown_logind = TRUE;
+    }
+    if (!handler_context.reboot_available && dbus_logind_CanReboot())
+    {
+        handler_context.reboot_available = TRUE;
+        handler_context.reboot_logind = TRUE;
+    }
+    if (!handler_context.suspend_available && dbus_logind_CanSuspend())
+    {
+        handler_context.suspend_available = TRUE;
+        handler_context.suspend_logind = TRUE;
+    }
+    if (!handler_context.hibernate_available && dbus_logind_CanHibernate())
+    {
+        handler_context.hibernate_available = TRUE;
+        handler_context.hibernate_logind = TRUE;
+    }
+
     /* If we are under GDM, its "Switch User" is available. */
     if (verify_running("gdm", "gdmflexiserver"))
     {
@@ -442,6 +511,34 @@
         handler_context.switch_user_GDM = TRUE;
     }
 
+    /* If we are under GDM3, its "Switch User" is available. */
+    if (verify_running("gdm3", "gdmflexiserver"))
+    {
+        handler_context.switch_user_available = TRUE;
+        handler_context.switch_user_GDM = TRUE;
+    }
+
+    /* lightdm also use gdmflexiserver */
+    if (verify_running("lightdm", "gdmflexiserver"))
+    {
+        handler_context.switch_user_available = TRUE;
+        handler_context.switch_user_GDM = TRUE;
+    }
+
+    /* lightdm also use gdmflexiserver */
+    if (verify_running("lightdm", "gdmflexiserver"))
+    {
+        handler_context.switch_user_available = TRUE;
+        handler_context.switch_user_GDM = TRUE;
+    }
+
+    /* lightdm can also be find by the env */
+    if (g_getenv("XDG_SEAT_PATH"))
+    {
+        handler_context.switch_user_available = TRUE;
+        handler_context.switch_user_LIGHTDM = TRUE;
+    }
+
     /* If we are under KDM, its "Switch User" is available. */
     if (verify_running("kdm", "kdmctl"))
     {
@@ -451,7 +548,18 @@
 
     /* LTSP support */
     if (g_getenv("LTSP_CLIENT"))
+    {
         handler_context.ltsp = TRUE;
+        handler_context.shutdown_available = TRUE;
+        handler_context.reboot_available = TRUE;
+    }
+
+    /* Lock screen */
+    const gchar* very_lock_screen = determine_lock_screen();
+    if (very_lock_screen)
+    {
+        handler_context.lock_screen = TRUE;
+    }
 
     /* Make the button images accessible. */
     gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), PACKAGE_DATA_DIR "/lxsession/images");
@@ -596,6 +704,17 @@
         gtk_box_pack_start(GTK_BOX(controls), switch_user_button, FALSE, FALSE, 4);
     }
 
+    /* Create the Lock Screen button. */
+    if (handler_context.lock_screen && !handler_context.ltsp)
+    {
+        GtkWidget * lock_screen_button = gtk_button_new_with_mnemonic(_("L_ock Screen"));
+        GtkWidget * image = gtk_image_new_from_icon_name("system-lock-screen", GTK_ICON_SIZE_BUTTON);
+        gtk_button_set_image(GTK_BUTTON(lock_screen_button), image);
+        gtk_button_set_alignment(GTK_BUTTON(lock_screen_button), 0.0, 0.5);
+        g_signal_connect(G_OBJECT(lock_screen_button), "clicked", G_CALLBACK(lock_screen_clicked), &handler_context);
+        gtk_box_pack_start(GTK_BOX(controls), lock_screen_button, FALSE, FALSE, 4);
+    }
+
     /* Create the Logout button. */
     GtkWidget * logout_button = gtk_button_new_with_mnemonic(_("_Logout"));
     GtkWidget * image = gtk_image_new_from_icon_name("system-log-out", GTK_ICON_SIZE_BUTTON);