Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility improvements: labelling and keyboard navigation #365

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 57 additions & 9 deletions applets/brightness/brightness-applet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -673,6 +679,46 @@ 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)
{
if (gdk_event_triggers_context_menu ((GdkEvent *) event))
return gpm_applet_popup_cb (applet);
return FALSE;
}

/**
* 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;
}

/**
Expand All @@ -682,19 +728,14 @@ 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;
GdkWindow *window;
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);
Expand Down Expand Up @@ -775,7 +816,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)
Expand Down Expand Up @@ -1035,11 +1076,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. */
Expand Down Expand Up @@ -1076,6 +1120,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"),
Expand All @@ -1100,6 +1145,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;
Expand Down
45 changes: 41 additions & 4 deletions 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,16 +239,48 @@ 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)
{
/* react only to left mouse button */
if (event->button != 1) {
return FALSE;
if (gdk_event_triggers_context_menu ((GdkEvent *) event))
return gpm_applet_switch_cb (applet);
return FALSE;
}

/**
* 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);
Expand Down Expand Up @@ -479,6 +513,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