From dd195a679b7fb679c4613711acd5b299d380884b Mon Sep 17 00:00:00 2001 From: Valentin Villenave Date: Fri, 8 Oct 2021 11:18:26 +0200 Subject: [PATCH 1/3] Brightness applet: add Accessible object & keyboard navigation. --- applets/brightness/brightness-applet.c | 68 ++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/applets/brightness/brightness-applet.c b/applets/brightness/brightness-applet.c index 28e6f459..94d3d218 100644 --- a/applets/brightness/brightness-applet.c +++ b/applets/brightness/brightness-applet.c @@ -96,7 +96,9 @@ static gboolean gpm_applet_key_press_cb (GtkWidget *popup, GdkEventKey static gboolean gpm_applet_scroll_cb (GpmBrightnessApplet *applet, GdkEventScroll *event); static gboolean gpm_applet_slide_cb (GtkWidget *w, GpmBrightnessApplet *applet); static void gpm_applet_create_popup (GpmBrightnessApplet *applet); -static gboolean gpm_applet_popup_cb (GpmBrightnessApplet *applet, GdkEventButton *event); +static gboolean gpm_applet_popup_click_cb (GpmBrightnessApplet *applet, GdkEventButton *event); +static gboolean gpm_applet_popup_key_cb (GpmBrightnessApplet *applet, GdkEventKey *event); +static gboolean gpm_applet_popup_cb (GpmBrightnessApplet *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); @@ -375,6 +377,10 @@ gpm_applet_update_tooltip (GpmBrightnessApplet *applet) buf = g_strdup_printf (_("LCD brightness : %d%%"), applet->level); } gtk_widget_set_tooltip_text (GTK_WIDGET(applet), buf); + + AtkObject *atk_obj = gtk_widget_get_accessible (GTK_WIDGET (applet)); + if (GTK_IS_ACCESSIBLE (atk_obj)) + atk_object_set_description (atk_obj, buf); } else { gtk_widget_set_tooltip_text (GTK_WIDGET(applet), NULL); } @@ -673,6 +679,48 @@ gpm_applet_create_popup (GpmBrightnessApplet *applet) GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(toplevel)); GdkVisual *visual = gdk_screen_get_rgba_visual(screen); gtk_widget_set_visual(GTK_WIDGET(toplevel), visual); + gtk_widget_grab_focus (applet->popup); +} + +/** + * gpm_applet_popup_click_cb: + * @applet: Brightness applet instance + * + * pops and unpops (through mouse button) + **/ +gboolean +gpm_applet_popup_click_cb (GpmBrightnessApplet *applet, GdkEventButton *event) +{ + /* react only to left mouse button */ + if (event->button != 1) { + return FALSE; + } + return gpm_applet_popup_cb (applet); +} + +/** + * gpm_applet_popup_cb: + * @applet: Brightness applet instance + * + * shows the popup (through key press event) + **/ +gboolean +gpm_applet_popup_key_cb (GpmBrightnessApplet *applet, GdkEventKey *event) +{ + /* More or less the same keys accepted in the popup itself, + * except that we don’t want Escape to open the popup. */ + 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: + return gpm_applet_popup_cb (applet); + default: + break; + } + return FALSE; } /** @@ -682,7 +730,7 @@ gpm_applet_create_popup (GpmBrightnessApplet *applet) * pops and unpops **/ static gboolean -gpm_applet_popup_cb (GpmBrightnessApplet *applet, GdkEventButton *event) +gpm_applet_popup_cb (GpmBrightnessApplet *applet) { GtkAllocation allocation, popup_allocation; gint orientation, x, y; @@ -690,11 +738,6 @@ gpm_applet_popup_cb (GpmBrightnessApplet *applet, GdkEventButton *event) GdkDisplay *display; GdkSeat *seat; - /* react only to left mouse button */ - if (event->button != 1) { - return FALSE; - } - /* if yet popped, release focus and hide */ if (applet->popped) { gtk_widget_hide (applet->popup); @@ -775,7 +818,7 @@ gpm_applet_popup_cb (GpmBrightnessApplet *applet, GdkEventButton *event) /** * gpm_applet_theme_change_cb: * - * Updtes icon when theme changes + * Updates icon when theme changes **/ static void gpm_applet_theme_change_cb (GtkIconTheme *icon_theme, gpointer data) @@ -1035,11 +1078,14 @@ gpm_brightness_applet_init (GpmBrightnessApplet *applet) /* connect */ g_signal_connect (G_OBJECT(applet), "button-press-event", - G_CALLBACK(gpm_applet_popup_cb), NULL); + G_CALLBACK(gpm_applet_popup_click_cb), NULL); g_signal_connect (G_OBJECT(applet), "scroll-event", G_CALLBACK(gpm_applet_scroll_cb), NULL); + g_signal_connect (G_OBJECT(applet), "key-press-event", + G_CALLBACK(gpm_applet_popup_key_cb), NULL); + /* We use g_signal_connect_after because letting the panel draw * the background is the only way to have the correct * background when a theme defines a background picture. */ @@ -1076,6 +1122,7 @@ gpm_applet_cb (MatePanelApplet *_applet, const gchar *iid, gpointer data) { GpmBrightnessApplet *applet = GPM_BRIGHTNESS_APPLET(_applet); GtkActionGroup *action_group; + AtkObject *atk_obj; static const GtkActionEntry menu_actions [] = { { "About", "help-about", N_("_About"), @@ -1100,6 +1147,9 @@ gpm_applet_cb (MatePanelApplet *_applet, const gchar *iid, gpointer data) BRIGHTNESS_MENU_UI_DIR "/brightness-applet-menu.xml", action_group); g_object_unref (action_group); + atk_obj = gtk_widget_get_accessible (GTK_WIDGET (applet)); + if (GTK_IS_ACCESSIBLE (atk_obj)) + atk_object_set_name (atk_obj, _("Brightness Applet")); gpm_applet_draw_cb (applet); return TRUE; From 2c178fb52901fbe026523062c289ffeab9f8babb Mon Sep 17 00:00:00 2001 From: Valentin Villenave Date: Fri, 8 Oct 2021 11:28:23 +0200 Subject: [PATCH 2/3] Inhibit applet: enable keyboard use. --- applets/inhibit/inhibit-applet.c | 41 +++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/applets/inhibit/inhibit-applet.c b/applets/inhibit/inhibit-applet.c index 1b689211..fd079b85 100644 --- a/applets/inhibit/inhibit-applet.c +++ b/applets/inhibit/inhibit-applet.c @@ -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); @@ -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) @@ -246,7 +248,41 @@ gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event) if (event->button != 1) { return FALSE; } + return gpm_applet_switch_cb (applet); +} +/** + * 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: + return gpm_applet_switch_cb (applet); + default: + 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); @@ -479,6 +515,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); From f88d5d18bdd3fdb75eabc5a5c71bbd6be64c3e7e Mon Sep 17 00:00:00 2001 From: Valentin Villenave Date: Wed, 27 Oct 2021 12:22:20 +0200 Subject: [PATCH 3/3] Use gdk_event_triggers_context_menu () --- applets/brightness/brightness-applet.c | 8 +++----- applets/inhibit/inhibit-applet.c | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/applets/brightness/brightness-applet.c b/applets/brightness/brightness-applet.c index 94d3d218..121ce07a 100644 --- a/applets/brightness/brightness-applet.c +++ b/applets/brightness/brightness-applet.c @@ -691,11 +691,9 @@ gpm_applet_create_popup (GpmBrightnessApplet *applet) gboolean gpm_applet_popup_click_cb (GpmBrightnessApplet *applet, GdkEventButton *event) { - /* react only to left mouse button */ - if (event->button != 1) { - return FALSE; - } - return gpm_applet_popup_cb (applet); + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) + return gpm_applet_popup_cb (applet); + return FALSE; } /** diff --git a/applets/inhibit/inhibit-applet.c b/applets/inhibit/inhibit-applet.c index fd079b85..1988cbf5 100644 --- a/applets/inhibit/inhibit-applet.c +++ b/applets/inhibit/inhibit-applet.c @@ -244,11 +244,9 @@ gpm_applet_update_tooltip (GpmInhibitApplet *applet) static gboolean gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event) { - /* react only to left mouse button */ - if (event->button != 1) { - return FALSE; - } - return gpm_applet_switch_cb (applet); + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) + return gpm_applet_switch_cb (applet); + return FALSE; } /**