Skip to content
Snippets Groups Projects
Commit b28d987e authored by Brian Tarricone's avatar Brian Tarricone Committed by Gaël Bonithon
Browse files

Ungrab brightness keys when not handling them

Closes #33

(cherry picked from commit 488d3471)
parent d4003ff1
No related branches found
No related tags found
No related merge requests found
......@@ -281,6 +281,20 @@ xfpm_backlight_button_pressed_cb (XfpmButton *button, XfpmButtonKey type, XfpmBa
xfpm_backlight_show (backlight, level);
}
static void
xfpm_backlight_handle_brightness_keys_changed (XfpmBacklight *backlight)
{
gboolean handle_keys = FALSE;
g_object_get (G_OBJECT (backlight->priv->conf),
HANDLE_BRIGHTNESS_KEYS, &handle_keys,
NULL);
XFPM_DEBUG ("handle_brightness_keys changed to %s", handle_keys ? "TRUE" : "FALSE");
xfpm_button_set_handle_brightness_keys (backlight->priv->button, handle_keys);
}
static void
xfpm_backlight_brightness_on_ac_settings_changed (XfpmBacklight *backlight)
{
......@@ -438,6 +452,9 @@ xfpm_backlight_init (XfpmBacklight *backlight)
BRIGHTNESS_SWITCH,
backlight->priv->brightness_switch,
NULL);
xfpm_button_set_handle_brightness_keys (backlight->priv->button, handle_keys);
g_signal_connect_object (backlight->priv->conf, "notify::" HANDLE_BRIGHTNESS_KEYS,
G_CALLBACK (xfpm_backlight_handle_brightness_keys_changed), backlight, G_CONNECT_SWAPPED);
g_signal_connect_object (backlight->priv->idle, "alarm-expired",
G_CALLBACK (xfpm_backlight_alarm_timeout_cb), backlight, 0);
......
......@@ -64,6 +64,7 @@ struct XfpmButtonPrivate
{
GdkScreen *screen;
GdkWindow *window;
gboolean handle_brightness_keys;
guint16 mapped_buttons;
};
......@@ -182,6 +183,39 @@ xfpm_button_xevent_key (XfpmButton *button, guint keysym , XfpmButtonKey key)
return TRUE;
}
static void
xfpm_button_ungrab (XfpmButton *button, guint keysym, XfpmButtonKey key)
{
Display *display;
GdkDisplay *gdisplay;
guint modmask = AnyModifier;
guint keycode = XKeysymToKeycode (gdk_x11_get_default_xdisplay(), keysym);
if (keycode == 0)
{
XFPM_DEBUG ("could not map keysym %x to keycode\n", keysym);
return;
}
display = gdk_x11_get_default_xdisplay ();
gdisplay = gdk_display_get_default ();
gdk_x11_display_error_trap_push (gdisplay);
XUngrabKey (display, keycode, modmask,
GDK_WINDOW_XID (button->priv->window));
XUngrabKey (display, keycode, LockMask | modmask,
GDK_WINDOW_XID (button->priv->window));
gdk_display_flush (gdisplay);
gdk_x11_display_error_trap_pop_ignored (gdisplay);
XFPM_DEBUG_ENUM (key, XFPM_TYPE_BUTTON_KEY, "Ungrabbed key %li ", (long int) keycode);
xfpm_key_map [key].key_code = 0;
xfpm_key_map [key].key = 0;
}
static void
xfpm_button_setup (XfpmButton *button)
{
......@@ -204,11 +238,14 @@ xfpm_button_setup (XfpmButton *button)
if ( xfpm_button_xevent_key (button, XF86XK_Sleep, BUTTON_SLEEP) )
button->priv->mapped_buttons |= SLEEP_KEY;
if ( xfpm_button_xevent_key (button, XF86XK_MonBrightnessUp, BUTTON_MON_BRIGHTNESS_UP) )
button->priv->mapped_buttons |= BRIGHTNESS_KEY_UP;
if (button->priv->handle_brightness_keys)
{
if ( xfpm_button_xevent_key (button, XF86XK_MonBrightnessUp, BUTTON_MON_BRIGHTNESS_UP) )
button->priv->mapped_buttons |= BRIGHTNESS_KEY_UP;
if (xfpm_button_xevent_key (button, XF86XK_MonBrightnessDown, BUTTON_MON_BRIGHTNESS_DOWN) )
button->priv->mapped_buttons |= BRIGHTNESS_KEY_DOWN;
if (xfpm_button_xevent_key (button, XF86XK_MonBrightnessDown, BUTTON_MON_BRIGHTNESS_DOWN) )
button->priv->mapped_buttons |= BRIGHTNESS_KEY_DOWN;
}
if (xfpm_button_xevent_key (button, XF86XK_Battery, BUTTON_BATTERY))
button->priv->mapped_buttons |= BATTERY_KEY;
......@@ -244,6 +281,7 @@ xfpm_button_init (XfpmButton *button)
{
button->priv = xfpm_button_get_instance_private (button);
button->priv->handle_brightness_keys = FALSE;
button->priv->mapped_buttons = 0;
button->priv->screen = NULL;
button->priv->window = NULL;
......@@ -282,3 +320,38 @@ xfpm_button_get_mapped (XfpmButton *button)
return button->priv->mapped_buttons;
}
void
xfpm_button_set_handle_brightness_keys (XfpmButton *button,
gboolean handle_brightness_keys)
{
g_return_if_fail (XFPM_IS_BUTTON (button));
if (button->priv->handle_brightness_keys != handle_brightness_keys)
{
button->priv->handle_brightness_keys = handle_brightness_keys;
if (handle_brightness_keys)
{
if (xfpm_button_xevent_key (button, XF86XK_MonBrightnessUp, BUTTON_MON_BRIGHTNESS_UP))
button->priv->mapped_buttons |= BRIGHTNESS_KEY_UP;
if (xfpm_button_xevent_key (button, XF86XK_MonBrightnessDown, BUTTON_MON_BRIGHTNESS_DOWN))
button->priv->mapped_buttons |= BRIGHTNESS_KEY_DOWN;
}
else
{
if ((button->priv->mapped_buttons & BRIGHTNESS_KEY_UP) != 0)
{
xfpm_button_ungrab (button, XF86XK_MonBrightnessUp, BUTTON_MON_BRIGHTNESS_UP);
button->priv->mapped_buttons &= ~(BRIGHTNESS_KEY_UP);
}
if ((button->priv->mapped_buttons & BRIGHTNESS_KEY_DOWN) != 0)
{
xfpm_button_ungrab (button, XF86XK_MonBrightnessDown, BUTTON_MON_BRIGHTNESS_DOWN);
button->priv->mapped_buttons &= ~(BRIGHTNESS_KEY_DOWN);
}
}
}
}
......@@ -50,6 +50,9 @@ GType xfpm_button_get_type (void) G_GNUC_CONST;
XfpmButton *xfpm_button_new (void);
guint16 xfpm_button_get_mapped (XfpmButton *button) G_GNUC_PURE;
void xfpm_button_set_handle_brightness_keys (XfpmButton *button,
gboolean handle_brightness_keys);
G_END_DECLS
#endif /* __XFPM_BUTTON_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment