diff options
-rw-r--r-- | configure.in | 4 | ||||
-rw-r--r-- | libidletime/libidletime.c | 17 | ||||
-rw-r--r-- | ohmd/ohm-conf.c | 48 | ||||
-rw-r--r-- | ohmd/ohm-conf.h | 3 | ||||
-rw-r--r-- | ohmd/ohm-module.c | 2 | ||||
-rw-r--r-- | plugins/glue/backlight/ohm-plugin-backlight.c | 16 | ||||
-rw-r--r-- | plugins/glue/dpms/ohm-plugin-dpms.c | 16 | ||||
-rw-r--r-- | plugins/glue/idle/ohm-plugin-idle.c | 25 | ||||
-rw-r--r-- | plugins/policy/display/ohm-plugin-display.c | 10 |
9 files changed, 90 insertions, 51 deletions
diff --git a/configure.in b/configure.in index 1a4ecdd..6adc831 100644 --- a/configure.in +++ b/configure.in @@ -101,6 +101,10 @@ PKG_CHECK_MODULES(HAL, hal >= 0.5.7) AC_SUBST(HAL_CFLAGS) AC_SUBST(HAL_LIBS) +if pkg-config --atleast-version=0.5.10 hal; then + AC_DEFINE(HAL_SET_BRIGHTNESS_UNSIGNED, 1, [org.freedesktop.Hal.Device.LaptopPanel.SetBrightness returns UINT32]) +fi + PKG_CHECK_MODULES(GDK, gdk-2.0 >= 2.10.0 gdk-x11-2.0 >= 2.10.0) AC_SUBST(GDK_CFLAGS) AC_SUBST(GDK_LIBS) diff --git a/libidletime/libidletime.c b/libidletime/libidletime.c index feecef1..2a0775b 100644 --- a/libidletime/libidletime.c +++ b/libidletime/libidletime.c @@ -159,20 +159,6 @@ idletime_timeout (LibIdletime *idletime, LibIdletimeAlarm *alarm) } /** - * idletime_xsync_value_add_one: - * - * Just adds one to a XSyncValue. I love X. - */ -static void -idletime_xsync_value_add_one (XSyncValue *from, XSyncValue *to) -{ - int overflow; - XSyncValue add; - XSyncIntToValue (&add, -1); - XSyncValueAdd (to, *from, add, &overflow); -} - -/** * idletime_alarm_find_id: */ static LibIdletimeAlarm * @@ -202,7 +188,7 @@ idletime_x_set_reset (LibIdletime *idletime, XSyncAlarmNotifyEvent *alarm_event) if (idletime->priv->reset_set == FALSE) { /* don't match on the current value because * XSyncNegativeComparison means less or equal. */ - idletime_xsync_value_add_one (&alarm_event->counter_value, &alarm->timeout); + alarm->timeout = int64_to_xsyncvalue (xsyncvalue_to_int64 (&alarm_event->counter_value) - 1LL); /* set the reset alarm to fire the next time * idletime->priv->idle_counter < the current counter value */ @@ -254,6 +240,7 @@ idletime_x_event_filter (GdkXEvent *gdkxevent, GdkEvent *event, gpointer data) /* save the last state we triggered */ idletime->priv->last_event = alarm->id; + g_debug ("%s: alarm %d fired, idle time = %lld", G_STRFUNC, alarm->id, xsyncvalue_to_int64(&alarm_event->counter_value)); /* do the signal */ if (alarm->id != 0) { idletime_timeout (idletime, alarm); diff --git a/ohmd/ohm-conf.c b/ohmd/ohm-conf.c index b36259b..84314bf 100644 --- a/ohmd/ohm-conf.c +++ b/ohmd/ohm-conf.c @@ -45,6 +45,7 @@ struct OhmConfPrivate { GHashTable *keys; + gboolean initializing; }; enum { @@ -60,7 +61,8 @@ G_DEFINE_TYPE (OhmConf, ohm_conf, G_TYPE_OBJECT) typedef struct ConfValue ConfValue; struct ConfValue { - gboolean public; + gboolean public:1; + gboolean touched:1; gint value; }; @@ -89,6 +91,40 @@ ohm_conf_error_quark (void) } return quark; } +static void +emit_touched (gpointer key, + gpointer value, + gpointer user_data) +{ + OhmConf *conf = (OhmConf*) user_data; + ConfValue *cv = (ConfValue *)value; + cv->touched = 0; + g_signal_emit (conf, signals [KEY_CHANGED], 0, key, cv->value); +} + +/** + * ohm_conf_set_initializing + * @conf: an #OhmConf + * @state: OhmConf initialistion state + * + * Set or clear the conf object's initialisation state. + * When in initialisation state, no 'key-changed' signals are emitted and + * touched keys are just flagged. On switching from initialisation to normal, + * signals are emitted for all touched keys and the touched flags are cleared. + */ + +void +ohm_conf_set_initializing (OhmConf *conf, + gboolean state) +{ + if (state) { + conf->priv->initializing = TRUE; + } else { + conf->priv->initializing = FALSE; + g_hash_table_foreach (conf->priv->keys, emit_touched, conf); + } + +} /** * ohm_conf_get_key: @@ -175,6 +211,7 @@ ohm_conf_add_key (OhmConf *conf, cv = new_conf_value(); cv->public = public; + cv->touched = 0; cv->value = value; /* we need to create new objects in the store for each added user */ @@ -272,8 +309,13 @@ ohm_conf_set_key_internal (OhmConf *conf, /* Only force signal if different */ if (cv->value != value) { cv->value = value; - ohm_debug ("emit key-changed : %s", key); - g_signal_emit (conf, signals [KEY_CHANGED], 0, key, value); + if (conf->priv->initializing){ + ohm_debug ("initializing, setting %s to touched", key); + cv->touched = 1; + } else{ + ohm_debug ("emit key-changed : %s", key); + g_signal_emit (conf, signals [KEY_CHANGED], 0, key, value); + } } return TRUE; diff --git a/ohmd/ohm-conf.h b/ohmd/ohm-conf.h index 33cd06f..09e2ae5 100644 --- a/ohmd/ohm-conf.h +++ b/ohmd/ohm-conf.h @@ -62,8 +62,9 @@ typedef void (*OhmConfForeachFunc) (const char *key, GType ohm_conf_get_type (void); GQuark ohm_conf_error_quark (void); -OhmConf *ohm_conf_new (void); +OhmConf *ohm_conf_new (void); +void ohm_conf_set_initializing (OhmConf *conf, gboolean state); gboolean ohm_conf_get_key (OhmConf *conf, const gchar *key, gint *value, diff --git a/ohmd/ohm-module.c b/ohmd/ohm-module.c index f306aff..16d40b1 100644 --- a/ohmd/ohm-module.c +++ b/ohmd/ohm-module.c @@ -453,6 +453,7 @@ ohm_module_init (OhmModule *module) } } + ohm_conf_set_initializing (module->priv->conf, TRUE); /* initialize each plugin */ ohm_debug ("starting plugin initialization"); for (l=module->priv->plugins; l != NULL; l=l->next) { @@ -461,6 +462,7 @@ ohm_module_init (OhmModule *module) ohm_debug ("initialize %s", name); ohm_plugin_initialize (plugin); } + ohm_conf_set_initializing (module->priv->conf, FALSE); } /** diff --git a/plugins/glue/backlight/ohm-plugin-backlight.c b/plugins/glue/backlight/ohm-plugin-backlight.c index 19c0272..e5c0388 100644 --- a/plugins/glue/backlight/ohm-plugin-backlight.c +++ b/plugins/glue/backlight/ohm-plugin-backlight.c @@ -62,13 +62,24 @@ backlight_set_brightness (OhmPlugin *plugin, guint brightness) HAL_DBUS_SERVICE, udi, HAL_DBUS_INTERFACE_LAPTOP_PANEL); + g_debug ("%s: Calling " HAL_DBUS_INTERFACE_LAPTOP_PANEL ".SetBrightness %d", G_STRFUNC, brightness); + /* get the brightness from HAL */ error = NULL; +#ifdef HAL_SET_BRIGHTNESS_UNSIGNED ret = dbus_g_proxy_call (proxy, "SetBrightness", &error, G_TYPE_INT, (int)brightness, G_TYPE_INVALID, G_TYPE_UINT, &retval, G_TYPE_INVALID); +#else + ret = dbus_g_proxy_call (proxy, "SetBrightness", &error, + G_TYPE_INT, (int)brightness, + G_TYPE_INVALID, + G_TYPE_INT, &retval, + G_TYPE_INVALID); +#endif + if (error != NULL) { g_printerr ("Error: %s\n", error->message); g_error_free (error); @@ -148,6 +159,9 @@ plugin_initalize (OhmPlugin *plugin) /* get the only device with capability and watch it */ num = ohm_plugin_hal_add_device_capability (plugin, "laptop_panel"); + + g_debug ("%s: Got %d devices with laptop_panel capability", G_STRFUNC, num); + if (num > 1) { g_warning ("not tested with not one laptop_panel"); } @@ -155,6 +169,8 @@ plugin_initalize (OhmPlugin *plugin) if (num != 0) { /* get levels that the adapter supports -- this does not change ever */ ohm_plugin_hal_get_int (plugin, 0, "laptop_panel.num_levels", &data.levels); + g_debug ("%s: data.levels = %d", G_STRFUNC, data.levels); + if (data.levels == 0) { g_error ("levels zero!"); return; diff --git a/plugins/glue/dpms/ohm-plugin-dpms.c b/plugins/glue/dpms/ohm-plugin-dpms.c index 9826918..d23f311 100644 --- a/plugins/glue/dpms/ohm-plugin-dpms.c +++ b/plugins/glue/dpms/ohm-plugin-dpms.c @@ -37,6 +37,7 @@ static Display *dpy; enum { CONF_BACKLIGHT_STATE_CHANGED, + CONF_XORG_HASXAUTH_CHANGED, CONF_LAST }; @@ -109,11 +110,8 @@ ohm_dpms_set_mode (OhmDpmsMode mode) CARD16 state; OhmDpmsMode current_mode; - /* FIXME: why is dpy NULL if we don't do this? */ - dpy = XOpenDisplay (":0"); /* fixme: don't assume :0 */ - if (dpy == NULL) { - g_debug ("cannot open display"); + g_debug ("display not open"); return FALSE; } @@ -146,7 +144,6 @@ ohm_dpms_set_mode (OhmDpmsMode mode) } XSync (dpy, FALSE); - XCloseDisplay(dpy); return TRUE; } @@ -163,8 +160,6 @@ plugin_initalize (OhmPlugin *plugin) /* we can assume DPMS is on */ ohm_plugin_conf_set_key (plugin, "backlight.state", 1); - /* open display, need to free using XCloseDisplay */ - dpy = XOpenDisplay (":0"); /* fixme: don't assume :0 */ } /** @@ -197,6 +192,9 @@ plugin_notify (OhmPlugin *plugin, gint id, gint value) } else { ohm_dpms_set_mode (OHM_DPMS_MODE_ON); } + } else if (id == CONF_XORG_HASXAUTH_CHANGED && value == 1) { + /* open display, need to free using XCloseDisplay */ + dpy = XOpenDisplay (":0"); /* fixme: don't assume :0 */ } } @@ -210,6 +208,8 @@ OHM_PLUGIN_DESCRIPTION ( plugin_notify /* notify */ ); -OHM_PLUGIN_INTERESTED ({"backlight.state", CONF_BACKLIGHT_STATE_CHANGED}); +OHM_PLUGIN_INTERESTED ( + {"backlight.state", CONF_BACKLIGHT_STATE_CHANGED}, + {"xorg.has_xauthority", CONF_XORG_HASXAUTH_CHANGED}); OHM_PLUGIN_REQUIRES ("backlight"); diff --git a/plugins/glue/idle/ohm-plugin-idle.c b/plugins/glue/idle/ohm-plugin-idle.c index 3b55202..f163d9a 100644 --- a/plugins/glue/idle/ohm-plugin-idle.c +++ b/plugins/glue/idle/ohm-plugin-idle.c @@ -83,27 +83,6 @@ plugin_connect_idletime (OhmPlugin *plugin) } /** - * plugin_initalize: - * @plugin: This class instance - * - * Coldplug, i.e. read and set the initial state of the plugin. - * We can assume all the required modules have been loaded, although it's - * dangerous to assume the key values are anything other than the defaults. - */ -static void -plugin_initalize (OhmPlugin *plugin) -{ - gint value; - - /* check system inhibit - this is broken as any client can unref all */ - ohm_plugin_conf_get_key (plugin, "xorg.has_xauthority", &value); - if (value == 1) { - plugin_connect_idletime (plugin); - } - -} - -/** * plugin_notify: * @plugin: This class instance * @@ -153,9 +132,9 @@ OHM_PLUGIN_DESCRIPTION ( "0.0.1", /* version */ "richard@hughsie.com", /* author */ OHM_LICENSE_LGPL, /* license */ - plugin_initalize, /* initalize */ + NULL, /* initalize */ plugin_destroy, /* destroy */ - plugin_notify /* notify */ + plugin_notify /* notify */ ); OHM_PLUGIN_REQUIRES ("xorg"); diff --git a/plugins/policy/display/ohm-plugin-display.c b/plugins/policy/display/ohm-plugin-display.c index cfb032c..e8ba21a 100644 --- a/plugins/policy/display/ohm-plugin-display.c +++ b/plugins/policy/display/ohm-plugin-display.c @@ -44,12 +44,15 @@ reset_brightness (OhmPlugin *plugin) /* FIXME: turn on dcon -- why was this here? */ /* ohm_plugin_conf_set_key (plugin, "backlight.state", 1); */ + g_debug("%s", G_STRFUNC); + ohm_plugin_conf_get_key (plugin, "acadapter.state", &onac); if (onac == TRUE) { ohm_plugin_conf_get_key (plugin, "display.value_ac", &value); } else { ohm_plugin_conf_get_key (plugin, "display.value_battery", &value); } + g_debug("%s: acadapter.state = %d, setting brightness %d", G_STRFUNC, onac, value); /* dim screen to idle brightness */ ohm_plugin_conf_set_key (plugin, "backlight.percent_brightness", value); @@ -63,6 +66,8 @@ brightness_momentary (OhmPlugin *plugin, gboolean is_idle) gint value; gint state; + g_debug("%s", G_STRFUNC); + ohm_plugin_conf_get_key (plugin, "backlight.state", &state); if (state == 0) { /* work round a idletime bugs */ @@ -78,12 +83,14 @@ brightness_momentary (OhmPlugin *plugin, gboolean is_idle) /* if not idle any more */ if (is_idle == FALSE) { + g_debug("%s: is_idle=FALSE< restting brighness", G_STRFUNC); reset_brightness (plugin); return; } /* dim screen to idle brightness */ ohm_plugin_conf_get_key (plugin, "display.value_idle", &value); + g_debug ("%s: Setting brightness to %d", G_STRFUNC, value); ohm_plugin_conf_set_key (plugin, "backlight.percent_brightness", value); } @@ -95,7 +102,7 @@ backlight_powersave (OhmPlugin *plugin, gboolean is_idle) gint state; ohm_plugin_conf_get_key (plugin, "backlight.state", &state); - if (state == 0) { + if (is_idle && state == 0) { /* work round a idletime bugs */ return; } @@ -109,6 +116,7 @@ backlight_powersave (OhmPlugin *plugin, gboolean is_idle) /* if not idle any more */ if (is_idle == FALSE) { + ohm_plugin_conf_set_key (plugin, "backlight.state", 1); reset_brightness (plugin); return; } |