Index: src/gpm-brightness-xrandr.c =================================================================== --- src/gpm-brightness-xrandr.c (révision 3036) +++ src/gpm-brightness-xrandr.c (révision 3044) @@ -551,7 +551,9 @@ gpm_brightness_xrandr_filter_xevents (GdkXEvent *xevent, GdkEvent *event, gpointer data) { GpmBrightnessXRandR *brightness = GPM_BRIGHTNESS_XRANDR (data); - egg_warning ("Event0 %p", brightness); + if (event->type == GDK_NOTHING) + return GDK_FILTER_CONTINUE; + egg_warning ("Type %i", event->type); if (FALSE) { gpm_brightness_xrandr_may_have_changed (brightness); } Index: src/gpm-button.c =================================================================== --- src/gpm-button.c (révision 3036) +++ src/gpm-button.c (révision 3044) @@ -49,6 +49,9 @@ { GdkScreen *screen; GdkWindow *window; + GHashTable *keysym_to_name_hash; + gchar *last_button; + GTimer *timer; GHashTable *hash_to_hal; gboolean lid_is_closed; HalGManager *hal_manager; /* remove when input events is in the kernel */ @@ -65,26 +68,55 @@ G_DEFINE_TYPE (GpmButton, gpm_button, G_TYPE_OBJECT) +#define GPM_BUTTON_DUPLICATE_TIMEOUT 0.25f + +/** + * gpm_button_emit_type: + **/ +gboolean +gpm_button_emit_type (GpmButton *button, const gchar *type) +{ + g_return_val_if_fail (button != NULL, FALSE); + g_return_val_if_fail (GPM_IS_BUTTON (button), FALSE); + + /* did we just have this button before the timeout? */ + if (g_strcmp0 (type, button->priv->last_button) == 0 && + g_timer_elapsed (button->priv->timer, NULL) < GPM_BUTTON_DUPLICATE_TIMEOUT) { + egg_debug ("ignoring duplicate button %s", type); + return FALSE; + } + + egg_debug ("emitting button-pressed : %s", type); + g_signal_emit (button, signals [BUTTON_PRESSED], 0, type); + + /* save type and last size */ + g_free (button->priv->last_button); + button->priv->last_button = g_strdup (type); + g_timer_reset (button->priv->timer); + + return TRUE; +} + +/** + * gpm_button_filter_x_events: + **/ static GdkFilterReturn -gpm_button_filter_x_events (GdkXEvent *xevent, - GdkEvent *event, - gpointer data) +gpm_button_filter_x_events (GdkXEvent *xevent, GdkEvent *event, gpointer data) { GpmButton *button = (GpmButton *) data; XEvent *xev = (XEvent *) xevent; guint keycode; - gchar *key; + const gchar *key; gchar *keycode_str; - if (xev->type != KeyPress) { + if (xev->type != KeyPress) return GDK_FILTER_CONTINUE; - } keycode = xev->xkey.keycode; /* is the key string already in our DB? */ keycode_str = g_strdup_printf ("0x%x", keycode); - key = g_hash_table_lookup (button->priv->hash_to_hal, (gpointer) keycode_str); + key = g_hash_table_lookup (button->priv->keysym_to_name_hash, (gpointer) keycode_str); g_free (keycode_str); /* found anything? */ @@ -94,8 +126,8 @@ return GDK_FILTER_CONTINUE; } - egg_debug ("Key %i mapped to HAL key %s", keycode, key); - g_signal_emit (button, signals [BUTTON_PRESSED], 0, key); + egg_debug ("Key %i mapped to key %s", keycode, key); + gpm_button_emit_type (button, key); return GDK_FILTER_REMOVE; } @@ -182,7 +214,7 @@ /* is the key string already in our DB? */ keycode_str = g_strdup_printf ("0x%x", keycode); - key = g_hash_table_lookup (button->priv->hash_to_hal, (gpointer) keycode_str); + key = g_hash_table_lookup (button->priv->keysym_to_name_hash, (gpointer) keycode_str); if (key != NULL) { egg_warning ("found in hash %i", keycode); g_free (keycode_str); @@ -198,7 +230,7 @@ } /* add to hash table */ - g_hash_table_insert (button->priv->hash_to_hal, (gpointer) keycode_str, (gpointer) g_strdup (hal_key)); + g_hash_table_insert (button->priv->keysym_to_name_hash, (gpointer) keycode_str, (gpointer) g_strdup (hal_key)); /* the key is freed in the hash function unref */ return TRUE; @@ -220,8 +252,7 @@ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GpmButtonClass, button_pressed), - NULL, - NULL, + NULL,NULL, gpm_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); } @@ -260,7 +291,7 @@ { gchar *type = NULL; gboolean state; - const char *atype; + const gchar *atype; g_return_if_fail (device != NULL); g_return_if_fail (details != NULL); @@ -272,7 +303,7 @@ /* hal may no longer be there */ if (type == NULL) { egg_warning ("cannot get button type for %s", hal_gdevice_get_udi (device)); - return; + goto out; } } else { type = g_strdup (details); @@ -316,10 +347,9 @@ atype = GPM_BUTTON_BRIGHT_DOWN; } - /* we now emit all buttons, even the ones we don't know */ - egg_debug ("emitting button-pressed : %s", atype); - g_signal_emit (button, signals [BUTTON_PRESSED], 0, atype); - + /* we emit all buttons, even the ones we don't know */ + gpm_button_emit_type (button, atype); +out: g_free (type); } @@ -346,9 +376,8 @@ key, is_added, is_removed, finally); /* do not process keys that have been removed */ - if (is_removed) { + if (is_removed) return; - } /* only match button* values */ if (strncmp (key, "button", 6) == 0) { @@ -375,9 +404,8 @@ { egg_debug ("condition=%s, details=%s", condition, details); - if (strcmp (condition, "ButtonPressed") == 0) { + if (strcmp (condition, "ButtonPressed") == 0) emit_button_pressed (button, device, details); - } } /** @@ -479,7 +507,9 @@ button->priv->screen = gdk_screen_get_default (); button->priv->window = gdk_screen_get_root_window (button->priv->screen); - button->priv->hash_to_hal = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + button->priv->keysym_to_name_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + button->priv->last_button = NULL; + button->priv->timer = g_timer_new (); button->priv->lid_is_closed = FALSE; @@ -489,7 +519,6 @@ if (have_xevents) { /* register the brightness keys */ -// gpm_button_xevent_key (button, XF86XK_Execute, GPM_BUTTON_POWER); gpm_button_xevent_key (button, XF86XK_PowerOff, GPM_BUTTON_POWER); // gpm_button_xevent_key (button, XF86XK_Suspend, GPM_BUTTON_SUSPEND); gpm_button_xevent_key (button, XF86XK_Sleep, GPM_BUTTON_SUSPEND); /* should be configurable */ @@ -534,9 +563,11 @@ button->priv = GPM_BUTTON_GET_PRIVATE (button); g_object_unref (button->priv->hal_manager); g_object_unref (button->priv->hal_devicestore); + g_free (button->priv->last_button); + g_timer_destroy (button->priv->timer); - g_hash_table_unref (button->priv->hash_to_hal); + g_hash_table_unref (button->priv->keysym_to_name_hash); G_OBJECT_CLASS (gpm_button_parent_class)->finalize (object); }