gnome-power-manager r3037 - in trunk: . libhal-glib src test
- From: rhughes svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-power-manager r3037 - in trunk: . libhal-glib src test
- Date: Thu, 23 Oct 2008 10:19:36 +0000 (UTC)
Author: rhughes
Date: Thu Oct 23 10:19:36 2008
New Revision: 3037
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=3037&view=rev
Log:
2008-10-23 Richard Hughes <richard hughsie com>
* libhal-glib/hal-device-store.c: (hal_device_store_index_udi),
(hal_device_store_index), (hal_device_store_find_udi),
(hal_device_store_present), (hal_device_store_insert),
(hal_device_store_remove), (hal_device_store_print),
(hal_device_store_class_init), (hal_device_store_init),
(hal_device_store_finalize), (hal_device_store_new):
* libhal-glib/hal-device-store.h:
* src/gpm-button.c: (gpm_button_filter_x_events),
(gpm_button_xevent_key), (gpm_button_class_init),
(emit_button_pressed), (hal_device_property_modified_cb),
(hal_device_condition_cb), (watch_add_button),
(hal_daemon_start_cb), (hal_daemon_stop_cb), (gpm_button_init),
(gpm_button_finalize):
* test/gpm-st-hal-devicestore.c: (egg_test_hal_device_store):
Don't do policy actions twice when we get an event with HAL and
and event from X. Prefer the event from X and blacklist that key from
the HAL code.
Modified:
trunk/ChangeLog
trunk/libhal-glib/hal-device-store.c
trunk/libhal-glib/hal-device-store.h
trunk/src/gpm-button.c
trunk/test/gpm-st-hal-devicestore.c
Modified: trunk/libhal-glib/hal-device-store.c
==============================================================================
--- trunk/libhal-glib/hal-device-store.c (original)
+++ trunk/libhal-glib/hal-device-store.c Thu Oct 23 10:19:36 2008
@@ -33,13 +33,13 @@
#include "hal-device.h"
#include "hal-device-store.h"
-static void hal_device_store_class_init (HalDevicestoreClass *klass);
-static void hal_device_store_init (HalDevicestore *device_store);
+static void hal_device_store_class_init (HalDeviceStoreClass *klass);
+static void hal_device_store_init (HalDeviceStore *device_store);
static void hal_device_store_finalize (GObject *object);
-#define HAL_DEVICE_STORE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), HAL_TYPE_DEVICE_STORE, HalDevicestorePrivate))
+#define HAL_DEVICE_STORE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), HAL_TYPE_DEVICE_STORE, HalDeviceStorePrivate))
-struct HalDevicestorePrivate
+struct HalDeviceStorePrivate
{
GPtrArray *array; /* the device array */
};
@@ -51,7 +51,7 @@
static guint signals [LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (HalDevicestore, hal_device_store, G_TYPE_OBJECT)
+G_DEFINE_TYPE (HalDeviceStore, hal_device_store, G_TYPE_OBJECT)
/**
* hal_device_store_index_udi:
@@ -62,7 +62,7 @@
* @device: The device
*/
static gint
-hal_device_store_index_udi (HalDevicestore *device_store, const gchar *udi)
+hal_device_store_index_udi (HalDeviceStore *device_store, const gchar *udi)
{
gint i;
guint length;
@@ -87,7 +87,7 @@
* @device: The device
*/
static gint
-hal_device_store_index (HalDevicestore *device_store, HalDevice *device)
+hal_device_store_index (HalDeviceStore *device_store, HalDevice *device)
{
HalDevice *d;
gint i;
@@ -121,7 +121,7 @@
* @device: The device
*/
HalDevice *
-hal_device_store_find_udi (HalDevicestore *device_store, const gchar *udi)
+hal_device_store_find_udi (HalDeviceStore *device_store, const gchar *udi)
{
gint index;
@@ -144,7 +144,7 @@
* @device: The device
*/
gboolean
-hal_device_store_present (HalDevicestore *device_store, HalDevice *device)
+hal_device_store_present (HalDeviceStore *device_store, HalDevice *device)
{
g_return_val_if_fail (HAL_IS_DEVICE_STORE (device_store), FALSE);
g_return_val_if_fail (HAL_IS_DEVICE (device), FALSE);
@@ -163,7 +163,7 @@
* @device: The device
*/
gboolean
-hal_device_store_insert (HalDevicestore *device_store, HalDevice *device)
+hal_device_store_insert (HalDeviceStore *device_store, HalDevice *device)
{
g_return_val_if_fail (HAL_IS_DEVICE_STORE (device_store), FALSE);
g_return_val_if_fail (HAL_IS_DEVICE (device), FALSE);
@@ -183,7 +183,7 @@
* @device: The device
*/
gboolean
-hal_device_store_remove (HalDevicestore *device_store, HalDevice *device)
+hal_device_store_remove (HalDeviceStore *device_store, HalDevice *device)
{
gint index;
HalDevice *d;
@@ -212,7 +212,7 @@
* @device_store: This store instance
*/
gboolean
-hal_device_store_print (HalDevicestore *device_store)
+hal_device_store_print (HalDeviceStore *device_store)
{
HalDevice *d;
guint i;
@@ -235,17 +235,17 @@
* @klass: This class instance
**/
static void
-hal_device_store_class_init (HalDevicestoreClass *klass)
+hal_device_store_class_init (HalDeviceStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = hal_device_store_finalize;
- g_type_class_add_private (klass, sizeof (HalDevicestorePrivate));
+ g_type_class_add_private (klass, sizeof (HalDeviceStorePrivate));
signals [DEVICE_REMOVED] =
g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (HalDevicestoreClass, device_removed),
+ G_STRUCT_OFFSET (HalDeviceStoreClass, device_removed),
NULL,
NULL,
hal_marshal_VOID__STRING_STRING,
@@ -259,7 +259,7 @@
* @hal_device_store: This class instance
**/
static void
-hal_device_store_init (HalDevicestore *device_store)
+hal_device_store_init (HalDeviceStore *device_store)
{
device_store->priv = HAL_DEVICE_STORE_GET_PRIVATE (device_store);
@@ -273,7 +273,7 @@
static void
hal_device_store_finalize (GObject *object)
{
- HalDevicestore *device_store;
+ HalDeviceStore *device_store;
HalDevice *d;
gint i;
guint length;
@@ -298,12 +298,12 @@
/**
* hal_device_store_new:
- * Return value: new HalDevicestore instance.
+ * Return value: new HalDeviceStore instance.
**/
-HalDevicestore *
+HalDeviceStore *
hal_device_store_new (void)
{
- HalDevicestore *device_store = g_object_new (HAL_TYPE_DEVICE_STORE, NULL);
+ HalDeviceStore *device_store = g_object_new (HAL_TYPE_DEVICE_STORE, NULL);
return HAL_DEVICE_STORE (device_store);
}
Modified: trunk/libhal-glib/hal-device-store.h
==============================================================================
--- trunk/libhal-glib/hal-device-store.h (original)
+++ trunk/libhal-glib/hal-device-store.h Thu Oct 23 10:19:36 2008
@@ -28,39 +28,39 @@
G_BEGIN_DECLS
#define HAL_TYPE_DEVICE_STORE (hal_device_store_get_type ())
-#define HAL_DEVICE_STORE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), HAL_TYPE_DEVICE_STORE, HalDevicestore))
-#define HAL_DEVICE_STORE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), HAL_TYPE_DEVICE_STORE, HalDevicestoreClass))
+#define HAL_DEVICE_STORE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), HAL_TYPE_DEVICE_STORE, HalDeviceStore))
+#define HAL_DEVICE_STORE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), HAL_TYPE_DEVICE_STORE, HalDeviceStoreClass))
#define HAL_IS_DEVICE_STORE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), HAL_TYPE_DEVICE_STORE))
#define HAL_IS_DEVICE_STORE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), HAL_TYPE_DEVICE_STORE))
-#define HAL_DEVICE_STORE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), HAL_TYPE_DEVICE_STORE, HalDevicestoreClass))
+#define HAL_DEVICE_STORE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), HAL_TYPE_DEVICE_STORE, HalDeviceStoreClass))
-typedef struct HalDevicestorePrivate HalDevicestorePrivate;
+typedef struct HalDeviceStorePrivate HalDeviceStorePrivate;
typedef struct
{
GObject parent;
- HalDevicestorePrivate *priv;
-} HalDevicestore;
+ HalDeviceStorePrivate *priv;
+} HalDeviceStore;
typedef struct
{
GObjectClass parent_class;
- void (* device_removed) (HalDevicestore *device_store,
+ void (* device_removed) (HalDeviceStore *device_store,
HalDevice *device);
-} HalDevicestoreClass;
+} HalDeviceStoreClass;
GType hal_device_store_get_type (void);
-HalDevicestore *hal_device_store_new (void);
+HalDeviceStore *hal_device_store_new (void);
-HalDevice *hal_device_store_find_udi (HalDevicestore *device_store,
+HalDevice *hal_device_store_find_udi (HalDeviceStore *device_store,
const gchar *udi);
-gboolean hal_device_store_insert (HalDevicestore *device_store,
+gboolean hal_device_store_insert (HalDeviceStore *device_store,
HalDevice *device);
-gboolean hal_device_store_present (HalDevicestore *device_store,
+gboolean hal_device_store_present (HalDeviceStore *device_store,
HalDevice *device);
-gboolean hal_device_store_remove (HalDevicestore *device_store,
+gboolean hal_device_store_remove (HalDeviceStore *device_store,
HalDevice *device);
-gboolean hal_device_store_print (HalDevicestore *device_store);
+gboolean hal_device_store_print (HalDeviceStore *device_store);
G_END_DECLS
Modified: trunk/src/gpm-button.c
==============================================================================
--- trunk/src/gpm-button.c (original)
+++ trunk/src/gpm-button.c Thu Oct 23 10:19:36 2008
@@ -49,10 +49,11 @@
{
GdkScreen *screen;
GdkWindow *window;
- GHashTable *hash_to_hal;
+ GHashTable *keysym_to_name_hash;
+ GHashTable *emit_x_hash;
gboolean lid_is_closed;
HalManager *hal_manager; /* remove when input events is in the kernel */
- HalDevicestore *hal_devicestore;
+ HalDeviceStore *hal_device_store;
};
enum {
@@ -65,26 +66,27 @@
G_DEFINE_TYPE (GpmButton, gpm_button, G_TYPE_OBJECT)
+/**
+ * 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;
gchar *keycode_str;
+ gpointer value;
- 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,9 +96,17 @@
return GDK_FILTER_CONTINUE;
}
- egg_debug ("Key %i mapped to HAL key %s", keycode, key);
+ egg_debug ("Key %i mapped to key %s", keycode, key);
g_signal_emit (button, signals [BUTTON_PRESSED], 0, key);
+ /* As we are watching HAL and X, potentially we could get notified about
+ * the same button press twice.
+ * Keep a list of buttons seen in X, so we can filter then from the
+ * HAL signal emission */
+ value = g_hash_table_lookup (button->priv->emit_x_hash, (gpointer) key);
+ if (value == NULL)
+ g_hash_table_insert (button->priv->emit_x_hash, (gpointer) g_strdup (key), GINT_TO_POINTER(1));
+
return GDK_FILTER_REMOVE;
}
@@ -182,7 +192,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 +208,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 +230,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);
}
@@ -254,13 +263,12 @@
* button.type=""
*/
static void
-emit_button_pressed (GpmButton *button,
- HalDevice *device,
- const gchar *details)
+emit_button_pressed (GpmButton *button, HalDevice *device, const gchar *details)
{
gchar *type = NULL;
gboolean state;
const char *atype;
+ gpointer value;
g_return_if_fail (device != NULL);
g_return_if_fail (details != NULL);
@@ -272,7 +280,7 @@
/* hal may no longer be there */
if (type == NULL) {
egg_warning ("cannot get button type for %s", hal_device_get_udi (device));
- return;
+ goto out;
}
} else {
type = g_strdup (details);
@@ -282,16 +290,14 @@
/* Buttons without state should default to true. */
state = TRUE;
/* we need to get the button state for lid buttons */
- if (strcmp (type, "lid") == 0) {
+ if (strcmp (type, "lid") == 0)
hal_device_get_bool (device, "button.state.value", &state, NULL);
- }
/* abstact away that HAL has an extra parameter */
- if (strcmp (type, GPM_BUTTON_LID_DEP) == 0 && state == FALSE) {
+ if (strcmp (type, GPM_BUTTON_LID_DEP) == 0 && state == FALSE)
atype = GPM_BUTTON_LID_OPEN;
- } else if (strcmp (type, GPM_BUTTON_LID_DEP) == 0 && state) {
+ else if (strcmp (type, GPM_BUTTON_LID_DEP) == 0 && state)
atype = GPM_BUTTON_LID_CLOSED;
- }
/* filter out duplicate lid events */
if (strcmp (atype, GPM_BUTTON_LID_CLOSED) == 0) {
@@ -309,10 +315,17 @@
button->priv->lid_is_closed = FALSE;
}
+ /* have we already got this from X? */
+ value = g_hash_table_lookup (button->priv->emit_x_hash, (gpointer) atype);
+ if (value != NULL) {
+ egg_debug ("avoiding duplicate key, as already shown in X");
+ goto out;
+ }
+
/* 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);
-
+out:
g_free (type);
}
@@ -339,9 +352,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) {
@@ -368,9 +380,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);
- }
}
/**
@@ -394,8 +405,8 @@
g_signal_connect (device, "device-condition",
G_CALLBACK (hal_device_condition_cb), button);
- /* when added to the devicestore, devices are automatically unref'ed */
- hal_device_store_insert (button->priv->hal_devicestore, device);
+ /* when added to the device_store, devices are automatically unref'ed */
+ hal_device_store_insert (button->priv->hal_device_store, device);
}
/**
@@ -438,8 +449,8 @@
GpmButton *button)
{
/* get new devices, hal has come back up */
- if (button->priv->hal_devicestore == NULL) {
- button->priv->hal_devicestore = hal_device_store_new ();
+ if (button->priv->hal_device_store == NULL) {
+ button->priv->hal_device_store = hal_device_store_new ();
coldplug_buttons (button);
}
}
@@ -452,9 +463,9 @@
GpmButton *button)
{
/* clear devices, HAL is going down */
- if (button->priv->hal_devicestore != NULL) {
- g_object_unref (button->priv->hal_devicestore);
- button->priv->hal_devicestore = NULL;
+ if (button->priv->hal_device_store != NULL) {
+ g_object_unref (button->priv->hal_device_store);
+ button->priv->hal_device_store = NULL;
}
}
@@ -472,7 +483,8 @@
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->emit_x_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
button->priv->lid_is_closed = FALSE;
@@ -507,7 +519,7 @@
g_signal_connect (button->priv->hal_manager, "daemon-stop",
G_CALLBACK (hal_daemon_stop_cb), button);
- button->priv->hal_devicestore = hal_device_store_new ();
+ button->priv->hal_device_store = hal_device_store_new ();
coldplug_buttons (button);
}
@@ -527,9 +539,10 @@
button->priv = GPM_BUTTON_GET_PRIVATE (button);
g_object_unref (button->priv->hal_manager);
- g_object_unref (button->priv->hal_devicestore);
+ g_object_unref (button->priv->hal_device_store);
- g_hash_table_unref (button->priv->hash_to_hal);
+ g_hash_table_unref (button->priv->keysym_to_name_hash);
+ g_hash_table_unref (button->priv->emit_x_hash);
G_OBJECT_CLASS (gpm_button_parent_class)->finalize (object);
}
Modified: trunk/test/gpm-st-hal-devicestore.c
==============================================================================
--- trunk/test/gpm-st-hal-devicestore.c (original)
+++ trunk/test/gpm-st-hal-devicestore.c Thu Oct 23 10:19:36 2008
@@ -27,32 +27,32 @@
#include <hal-device-store.h>
void
-egg_test_hal_devicestore (GpmSelfTest *test)
+egg_test_hal_device_store (GpmSelfTest *test)
{
- HalDevicestore *devicestore;
+ HalDeviceStore *device_store;
HalDevice *device;
HalDevice *device2;
HalDevice *device3;
gboolean ret;
- if (egg_test_start (test, "HalDevicestore") == FALSE) {
+ if (egg_test_start (test, "HalDeviceStore") == FALSE) {
return;
}
/************************************************************/
- egg_test_title (test, "make sure we get a non null devicestore");
- devicestore = hal_device_store_new ();
- if (devicestore != NULL) {
- egg_test_success (test, "got HalDevicestore");
+ egg_test_title (test, "make sure we get a non null device_store");
+ device_store = hal_device_store_new ();
+ if (device_store != NULL) {
+ egg_test_success (test, "got HalDeviceStore");
} else {
- egg_test_failed (test, "could not get HalDevicestore");
+ egg_test_failed (test, "could not get HalDeviceStore");
}
/************************************************************/
- egg_test_title (test, "make sure device not in devicestore");
+ egg_test_title (test, "make sure device not in device_store");
device = hal_device_new ();
hal_device_set_udi (device, HAL_ROOT_COMPUTER);
- ret = hal_device_store_present (devicestore, device);
+ ret = hal_device_store_present (device_store, device);
if (!ret) {
egg_test_success (test, "could not get different device");
} else {
@@ -61,7 +61,7 @@
/************************************************************/
egg_test_title (test, "insert device");
- ret = hal_device_store_insert (devicestore, device);
+ ret = hal_device_store_insert (device_store, device);
if (ret) {
egg_test_success (test, "inserted device");
} else {
@@ -70,7 +70,7 @@
/************************************************************/
egg_test_title (test, "insert duplicate device");
- ret = hal_device_store_insert (devicestore, device);
+ ret = hal_device_store_insert (device_store, device);
if (!ret) {
egg_test_success (test, "cannot insert duplicate device");
} else {
@@ -79,7 +79,7 @@
/************************************************************/
egg_test_title (test, "make sure device in store");
- ret = hal_device_store_present (devicestore, device);
+ ret = hal_device_store_present (device_store, device);
if (ret) {
egg_test_success (test, "found device");
} else {
@@ -88,7 +88,7 @@
/************************************************************/
egg_test_title (test, "find device by UDI");
- device3 = hal_device_store_find_udi (devicestore, HAL_ROOT_COMPUTER);
+ device3 = hal_device_store_find_udi (device_store, HAL_ROOT_COMPUTER);
if (device3 == device) {
egg_test_success (test, "found device");
} else {
@@ -97,7 +97,7 @@
/************************************************************/
egg_test_title (test, "find missing device by UDI");
- device3 = hal_device_store_find_udi (devicestore, "/foo");
+ device3 = hal_device_store_find_udi (device_store, "/foo");
if (device3 == NULL) {
egg_test_success (test, "not found invalid device");
} else {
@@ -108,7 +108,7 @@
egg_test_title (test, "make sure we can match on UDI");
device2 = hal_device_new ();
hal_device_set_udi (device2, HAL_ROOT_COMPUTER);
- ret = hal_device_store_present (devicestore, device2);
+ ret = hal_device_store_present (device_store, device2);
if (ret) {
egg_test_success (test, "found device");
} else {
@@ -118,7 +118,7 @@
/************************************************************/
egg_test_title (test, "remove device");
g_object_ref (device); /* so we can test it in a minute */
- ret = hal_device_store_remove (devicestore, device);
+ ret = hal_device_store_remove (device_store, device);
if (ret) {
egg_test_success (test, "removed device");
} else {
@@ -126,17 +126,17 @@
}
/************************************************************/
- egg_test_title (test, "make sure device not in devicestore");
- ret = hal_device_store_present (devicestore, device);
+ egg_test_title (test, "make sure device not in device_store");
+ ret = hal_device_store_present (device_store, device);
if (!ret) {
- egg_test_success (test, "could not get device from empty devicestore");
+ egg_test_success (test, "could not get device from empty device_store");
} else {
egg_test_failed (test, "got computer in empty store");
}
g_object_unref (device);
g_object_unref (device2);
- g_object_unref (devicestore);
+ g_object_unref (device_store);
egg_test_end (test);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]