Skip to content

Commit

Permalink
Inhibit applet: enable keyboard use.
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Villenave committed Oct 8, 2021
1 parent b622e6e commit a723686
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion applets/inhibit/inhibit-applet.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ static void gpm_applet_update_icon (GpmInhibitApplet *applet);
static void gpm_applet_size_allocate_cb (GtkWidget *widget, GdkRectangle *allocation);;
static void gpm_applet_update_tooltip (GpmInhibitApplet *applet);
static gboolean gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event);
static gboolean gpm_applet_key_cb (GpmInhibitApplet *applet, GdkEventKey *event);
static gboolean gpm_applet_switch_cb (GpmInhibitApplet *applet);
static void gpm_applet_dialog_about_cb (GtkAction *action, gpointer data);
static gboolean gpm_applet_cb (MatePanelApplet *_applet, const gchar *iid, gpointer data);
static void gpm_applet_destroy_cb (GtkWidget *widget);
Expand Down Expand Up @@ -237,7 +239,7 @@ gpm_applet_update_tooltip (GpmInhibitApplet *applet)
* gpm_applet_click_cb:
* @applet: Inhibit applet instance
*
* pops and unpops
* toggle switch (through mouse button)
**/
static gboolean
gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event)
Expand All @@ -246,7 +248,44 @@ gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event)
if (event->button != 1) {
return FALSE;
}
gpm_applet_switch_cb (applet);
return TRUE;
}

/**
* gpm_applet_key_cb:
* @applet: Inhibit applet instance
*
* toggle switch (through key press event)
**/
static gboolean
gpm_applet_key_cb (GpmInhibitApplet *applet, GdkEventKey *event)
{
switch (event->keyval) {
case GDK_KEY_KP_Enter:
case GDK_KEY_ISO_Enter:
case GDK_KEY_3270_Enter:
case GDK_KEY_Return:
case GDK_KEY_space:
case GDK_KEY_KP_Space:
gpm_applet_switch_cb (applet);
return TRUE;
default:
return FALSE;
break;
}
return FALSE;
}

/**
* gpm_applet_switch_cb:
* @applet: Inhibit applet instance
*
* pops and unpops
**/
static gboolean
gpm_applet_switch_cb (GpmInhibitApplet *applet)
{
if (applet->cookie > 0) {
g_debug ("uninhibiting %u", applet->cookie);
gpm_applet_uninhibit (applet, applet->cookie);
Expand Down Expand Up @@ -479,6 +518,9 @@ gpm_inhibit_applet_init (GpmInhibitApplet *applet)
g_signal_connect (G_OBJECT(applet), "button-press-event",
G_CALLBACK(gpm_applet_click_cb), NULL);

g_signal_connect (G_OBJECT(applet), "key-press-event",
G_CALLBACK(gpm_applet_key_cb), NULL);

g_signal_connect (G_OBJECT(applet), "size-allocate",
G_CALLBACK(gpm_applet_size_allocate_cb), NULL);

Expand Down

0 comments on commit a723686

Please sign in to comment.