[Xfce4-commits] [panel-plugins/xfce4-time-out-plugin] 01/01: Add lock button to break dialog (Bug #16317)
noreply at xfce.org
noreply at xfce.org
Tue Feb 11 04:33:00 CET 2020
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 f62ea6c46175c32d69ffba51d5f71cfcd3f8f397
Author: Joshua Cogliati <jjcogliati-r1 at yahoo.com>
Date: Tue Feb 11 00:28:34 2020 -0300
Add lock button to break dialog (Bug #16317)
---
panel-plugin/time-out-lock-screen.c | 70 +++++++++++++++++++++++++++++++++++--
panel-plugin/time-out-lock-screen.h | 4 +++
panel-plugin/time-out.c | 33 +++++++++++++++++
3 files changed, 105 insertions(+), 2 deletions(-)
diff --git a/panel-plugin/time-out-lock-screen.c b/panel-plugin/time-out-lock-screen.c
index c7ea91a..e3be77f 100644
--- a/panel-plugin/time-out-lock-screen.c
+++ b/panel-plugin/time-out-lock-screen.c
@@ -36,6 +36,8 @@ static void time_out_lock_screen_init (TimeOutLockScreen *lock_sc
static void time_out_lock_screen_finalize (GObject *object);
static void time_out_lock_screen_postpone (GtkButton *button,
TimeOutLockScreen *lock_screen);
+static void time_out_lock_screen_lock (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,
@@ -49,10 +51,12 @@ struct _TimeOutLockScreenClass
/* Signals */
void (*postpone) (TimeOutLockScreen *lock_screen);
+ void (*lock) (TimeOutLockScreen *lock_screen);
void (*resume) (TimeOutLockScreen *lock_screen);
/* Signal identifiers */
guint postpone_signal_id;
+ guint lock_signal_id;
guint resume_signal_id;
};
@@ -82,6 +86,7 @@ struct _TimeOutLockScreen
GtkWidget *window;
GtkWidget *time_label;
GtkWidget *postpone_button;
+ GtkWidget *lock_button;
GtkWidget *resume_button;
GtkWidget *progress;
@@ -149,6 +154,17 @@ time_out_lock_screen_class_init (TimeOutLockScreenClass *klass)
G_TYPE_NONE,
0);
+ /* Register 'lock' signal */
+ klass->lock_signal_id = g_signal_new ("lock",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ G_STRUCT_OFFSET (TimeOutLockScreenClass, lock),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
/* Register 'resume' signal */
klass->resume_signal_id = g_signal_new ("resume",
G_TYPE_FROM_CLASS (gobject_class),
@@ -168,6 +184,7 @@ time_out_lock_screen_init (TimeOutLockScreen *lock_screen)
{
GdkPixbuf *pixbuf;
GtkWidget *vbox;
+ GtkWidget *button_box;
GtkWidget *image;
GtkCssProvider *provider;
@@ -221,15 +238,27 @@ time_out_lock_screen_init (TimeOutLockScreen *lock_screen)
gtk_box_pack_start (GTK_BOX (vbox), lock_screen->progress, FALSE, FALSE, 0);
gtk_widget_show (lock_screen->progress);
+ /* Create box for buttons */
+ button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_box_set_homogeneous (GTK_BOX (button_box), TRUE);
+ gtk_box_pack_start (GTK_BOX (vbox), button_box, TRUE, TRUE, 0);
+ gtk_widget_show (button_box);
+
/* Create postpone button */
lock_screen->postpone_button = gtk_button_new_with_mnemonic (_("_Postpone"));
- gtk_box_pack_start (GTK_BOX (vbox), lock_screen->postpone_button, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (button_box), lock_screen->postpone_button, TRUE, TRUE, 0);
g_signal_connect (G_OBJECT (lock_screen->postpone_button), "clicked", G_CALLBACK (time_out_lock_screen_postpone), lock_screen);
gtk_widget_show (lock_screen->postpone_button);
+ /* Create lock button */
+ lock_screen->lock_button = gtk_button_new_with_mnemonic (_("_Lock"));
+ gtk_box_pack_end (GTK_BOX (button_box), lock_screen->lock_button, TRUE, TRUE, 0);
+ g_signal_connect (G_OBJECT (lock_screen->lock_button), "clicked", G_CALLBACK (time_out_lock_screen_lock), lock_screen);
+ gtk_widget_show (lock_screen->lock_button);
+
/* Create resume button */
lock_screen->resume_button = gtk_button_new_with_mnemonic (_("_Resume"));
- gtk_box_pack_start (GTK_BOX (vbox), lock_screen->resume_button, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (button_box), lock_screen->resume_button, TRUE, TRUE, 0);
g_signal_connect (G_OBJECT (lock_screen->resume_button), "clicked", G_CALLBACK (time_out_lock_screen_resume), lock_screen);
}
@@ -372,6 +401,18 @@ time_out_lock_screen_set_allow_postpone (TimeOutLockScreen *lock_screen,
void
+time_out_lock_screen_set_allow_lock (TimeOutLockScreen *lock_screen,
+ gboolean allow_lock)
+{
+ if (G_LIKELY (allow_lock))
+ gtk_widget_show (lock_screen->lock_button);
+ else
+ gtk_widget_hide (lock_screen->lock_button);
+}
+
+
+
+void
time_out_lock_screen_show_resume (TimeOutLockScreen *lock_screen,
gboolean show)
{
@@ -413,6 +454,22 @@ time_out_lock_screen_set_display_hours (TimeOutLockScreen *lock_screen,
+void
+time_out_lock_screen_grab (TimeOutLockScreen *lock_screen)
+{
+ time_out_lock_screen_grab_seat (lock_screen->seat, lock_screen->window);
+}
+
+
+
+void
+time_out_lock_screen_ungrab (TimeOutLockScreen *lock_screen)
+{
+ gdk_seat_ungrab (lock_screen->seat);
+}
+
+
+
static void
time_out_lock_screen_postpone (GtkButton *button,
TimeOutLockScreen *lock_screen)
@@ -424,7 +481,16 @@ time_out_lock_screen_postpone (GtkButton *button,
g_signal_emit_by_name (lock_screen, "postpone", NULL);
}
+static void
+time_out_lock_screen_lock (GtkButton *button,
+ TimeOutLockScreen *lock_screen)
+{
+ g_return_if_fail (GTK_IS_BUTTON (button));
+ g_return_if_fail (IS_TIME_OUT_LOCK_SCREEN (lock_screen));
+ /* Emit postpone signal */
+ g_signal_emit_by_name (lock_screen, "lock", NULL);
+}
static void
time_out_lock_screen_resume (GtkButton *button,
diff --git a/panel-plugin/time-out-lock-screen.h b/panel-plugin/time-out-lock-screen.h
index 35641ca..2447994 100644
--- a/panel-plugin/time-out-lock-screen.h
+++ b/panel-plugin/time-out-lock-screen.h
@@ -50,8 +50,12 @@ void time_out_lock_screen_set_display_hours (TimeOutLockScreen *
gboolean display_hours);
void time_out_lock_screen_set_allow_postpone (TimeOutLockScreen *lock_screen,
gboolean allow_postpone);
+void time_out_lock_screen_set_allow_lock (TimeOutLockScreen *lock_screen,
+ gboolean allow_lock);
void time_out_lock_screen_show_resume (TimeOutLockScreen *lock_screen,
gboolean auto_resume);
+void time_out_lock_screen_grab (TimeOutLockScreen *lock_screen);
+void time_out_lock_screen_ungrab (TimeOutLockScreen *lock_screen);
G_END_DECLS;
diff --git a/panel-plugin/time-out.c b/panel-plugin/time-out.c
index 5ebc5bc..388b3e6 100644
--- a/panel-plugin/time-out.c
+++ b/panel-plugin/time-out.c
@@ -135,6 +135,8 @@ static void time_out_start_lock_countdown (TimeOutPlugin
static void time_out_stop_lock_countdown (TimeOutPlugin *time_out);
static void time_out_postpone (TimeOutLockScreen *lock_screen,
TimeOutPlugin *time_out);
+static void time_out_lock (TimeOutLockScreen *lock_screen,
+ TimeOutPlugin *time_out);
static void time_out_resume (TimeOutLockScreen *lock_screen,
TimeOutPlugin *time_out);
static void time_out_break_countdown_update (TimeOutCountdown *countdown,
@@ -173,6 +175,9 @@ time_out_new (XfcePanelPlugin *plugin)
/* Connect to 'postpone' signal of the lock screen */
g_signal_connect (G_OBJECT (time_out->lock_screen), "postpone", G_CALLBACK (time_out_postpone), time_out);
+ /* Connect to 'lock' signal of the lock screen */
+ g_signal_connect (G_OBJECT (time_out->lock_screen), "lock", G_CALLBACK (time_out_lock), time_out);
+
/* Connect to 'resume' signal of the lock screen */
g_signal_connect (G_OBJECT (time_out->lock_screen), "resume", G_CALLBACK (time_out_resume), time_out);
@@ -999,6 +1004,9 @@ time_out_start_lock_countdown (TimeOutPlugin *time_out)
/* Set whether to allow postpone or not */
time_out_lock_screen_set_allow_postpone (time_out->lock_screen, time_out->allow_postpone);
+ /* Enable button to lock screen */
+ time_out_lock_screen_set_allow_lock (time_out->lock_screen, TRUE);
+
/* Hide the resume button initially */
time_out_lock_screen_show_resume (time_out->lock_screen, FALSE);
@@ -1049,6 +1057,30 @@ time_out_postpone (TimeOutLockScreen *lock_screen,
time_out_start_break_countdown (time_out, time_out->postpone_countdown_seconds);
}
+static void
+time_out_lock (TimeOutLockScreen *lock_screen,
+ TimeOutPlugin *time_out)
+{
+ GError *error = NULL;
+ gboolean succeed = FALSE;
+ gint exit_status;
+
+ g_return_if_fail (IS_TIME_OUT_LOCK_SCREEN (lock_screen));
+ g_return_if_fail (time_out != NULL);
+
+ /* ungrab seat so lock screen can start */
+ time_out_lock_screen_ungrab (time_out->lock_screen);
+
+ /* Lock screen and check for errors */
+ succeed = g_spawn_command_line_sync ("xflock4", NULL, NULL, &exit_status , &error);
+
+ if (!succeed)
+ xfce_dialog_show_error (NULL, error, _("Failed to lock screen"));
+
+ /* regrab seat */
+ time_out_lock_screen_grab (time_out->lock_screen);
+}
+
static void
@@ -1151,5 +1183,6 @@ time_out_lock_countdown_finish (TimeOutCountdown *countdown,
time_out_lock_screen_set_remaining (time_out->lock_screen, 0);
time_out_lock_screen_set_allow_postpone (time_out->lock_screen, FALSE);
time_out_lock_screen_show_resume (time_out->lock_screen, TRUE);
+ time_out_lock_screen_set_allow_lock (time_out->lock_screen, FALSE);
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list