[Xfce4-commits] [panel-plugins/xfce4-time-out-plugin] 15/15: Grab keyboard for lock screen
noreply at xfce.org
noreply at xfce.org
Fri Oct 4 05:13:50 CEST 2019
This is an automated email from the git hooks/post-receive script.
a n d r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-time-out-plugin.
commit 8bab67d75a88c1b68ed2d6af929975a75fb2bd0d
Author: Andre Miranda <andreldm at xfce.org>
Date: Sat Sep 28 20:03:23 2019 -0300
Grab keyboard for lock screen
---
panel-plugin/time-out-lock-screen.c | 38 +++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/panel-plugin/time-out-lock-screen.c b/panel-plugin/time-out-lock-screen.c
index 5ca5c31..c7ea91a 100644
--- a/panel-plugin/time-out-lock-screen.c
+++ b/panel-plugin/time-out-lock-screen.c
@@ -38,6 +38,8 @@ static void time_out_lock_screen_postpone (GtkButton *button,
TimeOutLockScreen *lock_screen);
static void time_out_lock_screen_resume (GtkButton *button,
TimeOutLockScreen *lock_screen);
+static void time_out_lock_screen_grab_seat (GdkSeat *seat,
+ GtkWidget *window);
@@ -83,6 +85,9 @@ struct _TimeOutLockScreen
GtkWidget *resume_button;
GtkWidget *progress;
+ /* Seat */
+ GdkSeat *seat;
+
/* Fade out */
TimeOutFadeout *fadeout;
};
@@ -239,6 +244,9 @@ time_out_lock_screen_finalize (GObject *object)
if (G_UNLIKELY (lock_screen->fadeout != NULL))
time_out_fadeout_destroy (lock_screen->fadeout);
+ /* Release keyboard */
+ gdk_seat_ungrab (lock_screen->seat);
+
/* Destroy information window */
gtk_widget_destroy (lock_screen->window);
}
@@ -284,6 +292,10 @@ time_out_lock_screen_show (TimeOutLockScreen *lock_screen, gint max_sec)
/* Display information window */
gtk_widget_show_now (lock_screen->window);
gtk_widget_grab_focus (lock_screen->window);
+
+ /* Grab keyboard */
+ lock_screen->seat = gdk_display_get_default_seat (display);
+ time_out_lock_screen_grab_seat (lock_screen->seat, lock_screen->window);
}
@@ -297,6 +309,9 @@ time_out_lock_screen_hide (TimeOutLockScreen *lock_screen)
time_out_fadeout_destroy (lock_screen->fadeout);
lock_screen->fadeout = NULL;
+ /* Release keyboard */
+ gdk_seat_ungrab (lock_screen->seat);
+
/* Push out changes */
gdk_display_flush (gdk_display_get_default ());
@@ -421,3 +436,26 @@ time_out_lock_screen_resume (GtkButton *button,
/* Emit resume signal */
g_signal_emit_by_name (lock_screen, "resume", NULL);
}
+
+static void
+time_out_lock_screen_grab_seat (GdkSeat *seat, GtkWidget *window)
+{
+ GdkGrabStatus status;
+ gint attempts = 0;
+
+ while (TRUE)
+ {
+ status = gdk_seat_grab (seat, gtk_widget_get_window (window),
+ GDK_SEAT_CAPABILITY_KEYBOARD, FALSE, NULL, NULL,
+ NULL, NULL);
+
+ if (++attempts > 5 || status == GDK_GRAB_SUCCESS)
+ break;
+
+ /* Wait 100ms before trying again */
+ g_usleep (100000);
+ }
+
+ if (status != GDK_GRAB_SUCCESS)
+ g_warning ("Failed to grab seat");
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list