Skip to content

Commit

Permalink
fix: repair examples and fix instructions again
Browse files Browse the repository at this point in the history
  • Loading branch information
Cu3PO42 committed Apr 10, 2024
1 parent e1a913f commit cc35a32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ The operations in this library need to be performed in a specific order to guara
2. To lock the session, first prepare a lock via `gtk_session_lock_prepare_lock()`. The purpose of the prepare operation is to perform additional setup before actually performing the lock.
3. You MUST connect to the lock's `locked` signal. You SHOULD connect to its `finished` signal.
4. After correcting to signals, call the `gtk_session_lock_lock_lock(lock)` method.
5. Proceed only once you receive a signal.
6. If you receive the `finished` signal, the session could not be locked. You SHOULD call `gtk_session_lock_lock_destroy(lock)` to dispose of the Wayland objects and avoid memory leaks.
7. If you receive the `locked` signal, your session is now locked. You SHOULD now create windows to be shown on your monitors.
8. For every monitor:
7. For every monitor:
1. Create a Gtk Window, but do not yet show it.
2. You MUST call `gtk_session_lock_lock_new_surface(lock, window, monitor)` to prepare the window for display on the given monitor before it is realized.
3. You SHOULD show (i.e. realize and map) the window as soon as possible. If you do not, the compositor will display a solid color.
4. You MUST NOT create two windows on the same monitor.
8. If you receive the `locked` signal, your session is now locked. Your compositor will not be showing any information other than your lockscreen or solid colors.
9. You SHOULD listen to monitor connection and disconnection events and create new windows on demand.
10. Before calling `hide` on the window, you MUST call `gtk_session_lock_unmap_lock_window(window)` on it. You MUST NOT call this method before `destroy`. This additional step is necessary to maintain compatibility with gtk-layer-shell.
11. Once you wish to unlock the session, e.g. after you have authenticated the user, you SHOULD first call `gtk_session_lock_lock_unlock_and_destroy(lock)`.
Expand Down
20 changes: 11 additions & 9 deletions examples/simple-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ static void on_finished(GtkSessionLockLock *lock, void *_data) {
}

static void on_locked(GtkSessionLockLock *lock, void *_data) {
GdkDisplay *display = gdk_display_get_default();
for (int i = 0; i < gdk_display_get_n_monitors(display); ++i) {
GdkMonitor *monitor = gdk_display_get_monitor(gdk_display_get_default(), i);

GtkWindow *window = create_lock_window();
gtk_session_lock_lock_new_surface(lock, window, monitor);

gtk_widget_show_all(GTK_WIDGET(window));
}
printf("Your session is now locked.\n");
}

static void activate (GtkApplication* app, void *_data) {
Expand All @@ -56,6 +48,16 @@ static void activate (GtkApplication* app, void *_data) {
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) {
Expand Down
13 changes: 7 additions & 6 deletions examples/simple-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ def create_lock_window():
return window

def on_locked():
for i in range(display.get_n_monitors()):
window = create_lock_window()
monitor = display.get_monitor(i)
lock.new_surface(window, monitor)
window.show_all()
print("Your session is now locked.")

def on_finished():
print("Finished event received. Session could not be locked.")
quit()

lock.connect("locked", on_locked)
lock.connect("finished", on_finished)

lock.lock_lock()


for i in range(display.get_n_monitors()):
window = create_lock_window()
monitor = display.get_monitor(i)
lock.new_surface(window, monitor)
window.show_all()

Gtk.main()

0 comments on commit cc35a32

Please sign in to comment.