-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kotontrion/docs/examples
add examples
- Loading branch information
Showing
5 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
executable( | ||
'simple-example-c', | ||
files('simple-example.c'), | ||
build_by_default: get_option('examples'), | ||
dependencies: [gtk, gtk_session_lock], | ||
install: false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#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 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(); | ||
|
||
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(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)); | ||
} | ||
} | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import gi | ||
gi.require_version('Gtk', '3.0') | ||
gi.require_version('GtkSessionLock', '0.1') | ||
from gi.repository import Gtk, Gdk, GtkSessionLock | ||
|
||
if(not GtkSessionLock.is_supported()): | ||
quit() | ||
|
||
lock = GtkSessionLock.prepare_lock() | ||
display = Gdk.Display.get_default() | ||
|
||
def unlock(widget): | ||
lock.unlock_and_destroy() | ||
display.sync() | ||
quit() | ||
|
||
def create_lock_window(): | ||
window = Gtk.Window() | ||
entry = Gtk.Entry(visibility=False, | ||
valign=Gtk.Align.CENTER, | ||
halign=Gtk.Align.CENTER) | ||
entry.connect("activate", unlock) | ||
window.add(entry) | ||
return window | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters