GTK4 Session Lock

GTK4 Session Lock — GTK4 support for the Session Lock Wayland protocol

Functions

Signals

void failed Run First
void locked Run First
void unlocked Run First

Types and Values

Object Hierarchy

    GObject
    ╰── GtkSessionLockInstance

Description

Session Lock is a Wayland protocol for lock screens. Use it to lock the compositor and display the lock screen. This library and the underlying Wayland protocol do not handle authentication.

Note on popups

Popups (such as menus and tooltips) do not currently display while the screen is locked. Please use alternatives, such as GtkPopover (which is backed by a subsurface instead of a popup).


Note On Linking

If you link against libwayland you must link this library before libwayland. See linking.md for details.

Functions

gtk_session_lock_is_supported ()

gboolean
gtk_session_lock_is_supported ();

May block for a Wayland roundtrip the first time it's called.

Returns

TRUE if the platform is Wayland and Wayland compositor supports the Session Lock protocol.


gtk_session_lock_instance_new ()

GtkSessionLockInstance *
gtk_session_lock_instance_new ();

Returns

new session lock instance


gtk_session_lock_instance_lock ()

gboolean
gtk_session_lock_instance_lock (GtkSessionLockInstance *self);

Lock the screen. This should be called before assigning any windows to monitors. If this function fails the ::failed signal is emitted, if it succeeds the ::locked signal is emitted. The ::failed signal may be emitted before the function returns (for example, if another GtkSessionLockInstance holds a lock) or later (if another process holds a lock). The only case where neither signal is triggered is if the instance is already locked.

Parameters

self

the instance to lock

 

Returns

false on immediate fail, true if lock acquisition was successfully started


gtk_session_lock_instance_unlock ()

void
gtk_session_lock_instance_unlock (GtkSessionLockInstance *self);

If the screen is locked by this instance unlocks it and fires ::unlocked. Otherwise has no effect

Parameters

self

the instance to unlock

 

gtk_session_lock_instance_is_locked ()

gboolean
gtk_session_lock_instance_is_locked (GtkSessionLockInstance *self);

Returns if this instance currently holds a lock.

Parameters

self

the instance

 

gtk_session_lock_instance_assign_window_to_monitor ()

void
gtk_session_lock_instance_assign_window_to_monitor
                               (GtkSessionLockInstance *self,
                                GtkWindow *window,
                                GdkMonitor *monitor);

This should be called with a different window once for each monitor immediately after calling gtk_session_lock_lock(). Hiding a window that is active on a monitor or not letting a window be resized by the library may result in a Wayland protocol error.

Parameters

self

the instance to use

 

window

The GTK Window to use as a lock surface

 

monitor

The monitor to show it on

 

Types and Values

GtkSessionLockInstance

typedef struct _GtkSessionLockInstance GtkSessionLockInstance;

An instance of the object used to control locking the screen. Multiple instances can exist at once, but only one can be locked at a time.

Signal Details

The “failed” signal

void
user_function (GtkSessionLockInstance *sessionlockinstance,
               gpointer                user_data)

The ::failed signal is fired when the lock could not be acquired.

Parameters

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “locked” signal

void
user_function (GtkSessionLockInstance *sessionlockinstance,
               gpointer                user_data)

The ::locked signal is fired when the screen is successfully locked.

Parameters

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “unlocked” signal

void
user_function (GtkSessionLockInstance *sessionlockinstance,
               gpointer                user_data)

The ::unlocked signal is fired when the session is unlocked, which may have been caused by a call to gtk_session_lock_instance_unlock() or by the compositor.

Parameters

user_data

user data set when the signal handler was connected.

 

Flags: Run First