Skip to content

Commit

Permalink
Merge pull request #88 from jovanlanik/session-lock
Browse files Browse the repository at this point in the history
ext-session-lock support
  • Loading branch information
jovanlanik authored Apr 18, 2024
2 parents 6732a03 + c614171 commit 30b5389
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 322 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GTK-based lockscreen for Wayland.
![screenshot](https://user-images.githubusercontent.com/21199271/169707623-2ac5f02b-b6ed-461a-b9a3-5d96440843a2.png)
## About
gtklock is a lockscreen based on [gtkgreet](https://git.sr.ht/~kennylevinsen/gtkgreet).
It uses the wlr-layer-shell and wlr-input-inhibitor Wayland protocols.
It uses the ext-session-lock Wayland protocol.
Works on sway and other wlroots-based compositors.

ℹ️ __For documentation, check out the [man page](https://man.voidlinux.org/gtklock) and [wiki](https://github.com/jovanlanik/gtklock/wiki).__
Expand All @@ -31,8 +31,8 @@ $ ninja -C builddir
- PAM
- wayland-client
- gtk+3.0
- gtk-layer-shell
### Install dependencies
- gtk-session-lock
### Installing build dependencies
- Arch: `# pacman -S gcc meson pkgconf scdoc pam wayland gtk3 gtk-layer-shell`
- Fedora: `# dnf install gcc meson pkgconf scdoc pam-devel wayland-devel gtk3-devel gtk-layer-shell-devel`
- Void: `# xbps-install gcc meson pkgconf scdoc pam-devel wayland-devel gtk+3-devel gtk-layer-shell-devel`
Expand Down
5 changes: 3 additions & 2 deletions include/gtklock.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
#pragma once

#include <gtk/gtk.h>
#include <gtk-session-lock.h>

struct Window;

struct GtkLock {
GtkApplication *app;
GtkSessionLockLock *lock;

GArray *windows;
GArray *messages;
GArray *errors;
Expand All @@ -22,8 +25,6 @@ struct GtkLock {
guint draw_clock_source;
guint idle_hide_source;

gboolean use_layer_shell;
gboolean use_input_inhibit;
gboolean use_idle_hide;

char *time;
Expand Down
10 changes: 0 additions & 10 deletions include/input-inhibitor.h

This file was deleted.

2 changes: 0 additions & 2 deletions include/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ struct Window {
GtkWidget *warning_label;
GtkWidget *clock_label;

gulong enter_notify_handler;

void *module_data[];
};

Expand Down
8 changes: 2 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,24 @@ minor_version = version[1]
micro_version = version[2]

gtk = dependency('gtk+-3.0')
gtk_layer_shell = dependency('gtk-layer-shell-0')
gtk_session_lock = dependency('gtk-session-lock-0')
gmodule_export = dependency('gmodule-export-2.0')
pam = dependency('pam')
wayland_client = dependency('wayland-client')

dependencies = [
gtk,
gtk_layer_shell,
gtk_session_lock,
gmodule_export,
pam,
wayland_client,
]

subdir('man')
subdir('res')
subdir('src')
subdir('wayland')

gtklock_set = [
gtklock_sources,
ui_resources,
wayland_sources,
]

executable(
Expand Down
15 changes: 10 additions & 5 deletions src/gtklock.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
#include "window.h"
#include "gtklock.h"
#include "module.h"
#include "input-inhibitor.h"

void gtklock_remove_window(struct GtkLock *gtklock, struct Window *win) {
for(guint idx = 0; idx < gtklock->windows->len; idx++) {
struct Window *ctx = g_array_index(gtklock->windows, struct Window *, idx);
if(ctx == win) {
g_array_remove_index_fast(gtklock->windows, idx);
g_array_remove_index(gtklock->windows, idx);
g_free(ctx);
return;
}
Expand Down Expand Up @@ -99,12 +98,17 @@ struct GtkLock* create_gtklock(void) {
}

void gtklock_activate(struct GtkLock *gtklock) {
g_application_hold(G_APPLICATION(gtklock->app));

if(!gtk_session_lock_is_supported())
report_error_and_exit("Your compositor doesn't support ext-session-lock");
gtklock->lock = gtk_session_lock_prepare_lock();
gtk_session_lock_lock_lock(gtklock->lock);

gtklock->draw_clock_source = g_timeout_add(1000, G_SOURCE_FUNC(gtklock_update_clocks_handler), gtklock);
gtklock_update_clocks(gtklock);
if(gtklock->use_idle_hide) gtklock->idle_hide_source =
g_timeout_add_seconds(gtklock->idle_timeout, G_SOURCE_FUNC(gtklock_idle_handler), gtklock);
if(gtklock->use_layer_shell) g_application_hold(G_APPLICATION(gtklock->app));
if(gtklock->use_input_inhibit) input_inhibitor_get();
}

void gtklock_shutdown(struct GtkLock *gtklock) {
Expand All @@ -116,7 +120,8 @@ void gtklock_shutdown(struct GtkLock *gtklock) {
g_source_remove(gtklock->idle_hide_source);
gtklock->idle_hide_source = 0;
}
if(gtklock->use_input_inhibit) input_inhibitor_destroy();
gtk_session_lock_lock_unlock_and_destroy(gtklock->lock);
gdk_display_sync(gdk_display_get_default());
}

void gtklock_destroy(struct GtkLock *gtklock) {
Expand Down
87 changes: 0 additions & 87 deletions src/input-inhibitor.c

This file was deleted.

1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ gtklock_sources = files([
'auth.c',
'config.c',
'gtklock.c',
'input-inhibitor.c',
'module.c',
'source.c',
'util.c',
Expand Down
9 changes: 4 additions & 5 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ GModule *module_load(const char *name) {
g_warning("%s: module has mismatched minor version (%u), may be incompatible", name, *minor);
}
else {
const gchar *gtklock_version = "v" STR(MAJOR_VERSION) "." STR(MINOR_VERSION) "." STR(MICRO_VERSION);
const gchar *module_version = NULL;
if(g_module_symbol(module, "module_version", (gpointer *)&module_version)) {
if(g_strcmp0(gtklock_version, module_version) != 0)
g_warning("%s: module has mismatched version, may be incompatible", name);
} else g_warning("%s: module has no version info, may be incompatible", name);
if(g_module_symbol(module, "module_version", (gpointer *)&module_version))
report_error_and_exit("%s: module has legacy version info (%s), is incompatible", name, module_version);
else
report_error_and_exit("%s: module has no version info, is incompatible", name);
}

return module;
Expand Down
Loading

0 comments on commit 30b5389

Please sign in to comment.