-
Notifications
You must be signed in to change notification settings - Fork 3
/
simple-example.c
70 lines (51 loc) · 2.2 KB
/
simple-example.c
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
#include "gtk-session-lock.h"
#include <gtk/gtk.h>
#include <stdio.h>
GtkSessionLockLock *lock;
GtkApplication *app;
static void unlock( GtkWidget *widget, gpointer data) {
gtk_session_lock_lock_unlock_and_destroy(lock);
gdk_display_sync(gdk_display_get_default());
g_application_quit(G_APPLICATION(app));
}
static GtkWindow* create_lock_window() {
GtkWindow *window = GTK_WINDOW (gtk_application_window_new(app));
GtkWidget *entry = gtk_entry_new();
gtk_entry_set_visibility(GTK_ENTRY(entry),FALSE);
gtk_widget_set_valign(entry, GTK_ALIGN_CENTER);
gtk_widget_set_halign(entry, GTK_ALIGN_CENTER);
gtk_container_add(GTK_CONTAINER(window), entry);
g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(unlock), NULL);
return window;
}
static void on_finished(GtkSessionLockLock *lock, void *_data) {
printf("Finished event received. Session could not be locked.\n");
g_application_quit(G_APPLICATION(app));
}
static void on_locked(GtkSessionLockLock *lock, void *_data) {
printf("Your session is now locked.\n");
}
static void activate (GtkApplication* app, void *_data) {
if (!gtk_session_lock_is_supported()) {
printf("Your Wayland compositor does not support the ext-session-lock protocol\n");
g_application_quit(G_APPLICATION(app));
}
lock = gtk_session_lock_prepare_lock();
g_signal_connect(lock, "locked", G_CALLBACK (on_locked), NULL);
g_signal_connect(lock, "finished", G_CALLBACK (on_finished), NULL);
gtk_session_lock_lock_lock(lock);
GdkDisplay *display = gdk_display_get_default();
for (int i = 0; i < gdk_display_get_n_monitors(display); ++i) {
GdkMonitor *monitor = gdk_display_get_monitor(display, i);
GtkWindow *window = create_lock_window();
gtk_session_lock_lock_new_surface(lock, window, monitor);
gtk_widget_show_all(GTK_WIDGET(window));
}
}
int main (int argc, char **argv) {
app = gtk_application_new ("Cu3PO42.gtk-session-lock-example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}