diff options
Diffstat (limited to 'plugins/glue')
36 files changed, 1220 insertions, 0 deletions
diff --git a/plugins/glue/Makefile.am b/plugins/glue/Makefile.am new file mode 100644 index 0000000..bab5d1b --- /dev/null +++ b/plugins/glue/Makefile.am @@ -0,0 +1,14 @@ +SUBDIRS = \ + idle \ + battery \ + acadapter \ + timeremaining \ + powerstatus \ + backlight + +if HAVE_DPMS_EXTENSION +SUBDIRS += dpms +endif + +clean-local: + rm -f *~ diff --git a/plugins/glue/acadapter/.gitignore b/plugins/glue/acadapter/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/acadapter/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/acadapter/Makefile.am b/plugins/glue/acadapter/Makefile.am new file mode 100644 index 0000000..4928aee --- /dev/null +++ b/plugins/glue/acadapter/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(GLIB_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = acadapter + +lib_LTLIBRARIES = libohm_acadapter.la +libohm_acadapterincludedir = $(includedir)/ohm +libohm_acadapter_la_SOURCES = ohm-plugin-acadapter.c +libohm_acadapter_la_LIBADD = $(INTLLIBS) +libohm_acadapter_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/acadapter/README b/plugins/glue/acadapter/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/glue/acadapter/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/glue/acadapter/acadapter b/plugins/glue/acadapter/acadapter new file mode 100644 index 0000000..3e86554 --- /dev/null +++ b/plugins/glue/acadapter/acadapter @@ -0,0 +1 @@ +# acadapter preference values diff --git a/plugins/glue/acadapter/ohm-plugin-acadapter.c b/plugins/glue/acadapter/ohm-plugin-acadapter.c new file mode 100644 index 0000000..0c1475e --- /dev/null +++ b/plugins/glue/acadapter/ohm-plugin-acadapter.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2007 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <gmodule.h> +#include <glib.h> +#include <string.h> +#include <ohm-plugin.h> + +/** + * plugin_preload: + * @plugin: This class instance + * + * Called before the plugin is coldplg. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static gboolean +plugin_preload (OhmPlugin *plugin) +{ + ohm_plugin_conf_provide (plugin, "acadapter.state"); + return TRUE; +} + +static void +hal_property_changed_cb (OhmPlugin *plugin, + const gchar *key) +{ + gboolean state; + if (strcmp (key, "ac_adapter.present") == 0) { + ohm_plugin_hal_get_bool (plugin, "ac_adapter.present", &state); + ohm_plugin_conf_set_key (plugin, "acadapter.state", state); + } +} + +/** + * plugin_coldplug: + * @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_coldplug (OhmPlugin *plugin) +{ + gboolean state; + gboolean ret; + + /* initialise HAL */ + ohm_plugin_hal_init (plugin); + + /* we want this function to get the property modified events for all devices */ + ohm_plugin_hal_use_property_modified (plugin, hal_property_changed_cb); + + /* get the only device with capability and watch it */ + ret = ohm_plugin_hal_add_device_capability (plugin, "ac_adapter"); + if (ret == TRUE) { + ohm_plugin_hal_get_bool (plugin, "ac_adapter.present", &state); + } else { + g_warning ("not tested with not one acadapter"); + state = 1; + } + + ohm_plugin_conf_set_key (plugin, "acadapter.state", state); +} + +static OhmPluginInfo plugin_info = { + "OHM HAL AC Adapter", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_preload, /* preload */ + NULL, /* unload */ + plugin_coldplug, /* coldplug */ + NULL, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/glue/backlight/.gitignore b/plugins/glue/backlight/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/backlight/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/backlight/Makefile.am b/plugins/glue/backlight/Makefile.am new file mode 100644 index 0000000..48b98b9 --- /dev/null +++ b/plugins/glue/backlight/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(HAL_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = backlight + +lib_LTLIBRARIES = libohm_backlight.la +libohm_backlightincludedir = $(includedir)/ohm +libohm_backlight_la_SOURCES = ohm-plugin-backlight.c +libohm_backlight_la_LIBADD = @HAL_LIBS@ @DBUS_LIBS@ $(INTLLIBS) +libohm_backlight_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/backlight/README b/plugins/glue/backlight/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/glue/backlight/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/glue/backlight/backlight b/plugins/glue/backlight/backlight new file mode 100644 index 0000000..dc652cf --- /dev/null +++ b/plugins/glue/backlight/backlight @@ -0,0 +1,2 @@ +# backlight preference values + diff --git a/plugins/glue/backlight/ohm-plugin-backlight.c b/plugins/glue/backlight/ohm-plugin-backlight.c new file mode 100644 index 0000000..c671021 --- /dev/null +++ b/plugins/glue/backlight/ohm-plugin-backlight.c @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2007 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <gmodule.h> +#include <glib.h> + +#include <ohm-plugin.h> +#include <dbus/dbus-glib.h> + +#define HAL_DBUS_SERVICE "org.freedesktop.Hal" +#define HAL_DBUS_INTERFACE_LAPTOP_PANEL "org.freedesktop.Hal.Device.LaptopPanel" + +enum { + CONF_BRIGHTNESS_PERCENT_CHANGED, + CONF_BRIGHTNESS_HARDWARE_CHANGED, + CONF_LAST +}; + +typedef struct { + gint levels; +} OhmPluginCacheData; + +static OhmPluginCacheData data; + +static gboolean +backlight_set_brightness (OhmPlugin *plugin, guint brightness) +{ + DBusGConnection *connection; + DBusGProxy *proxy; + GError *error; + gboolean ret; + gint retval; + gchar *udi; + + /* get udi and connection, assume connected */ + udi = ohm_plugin_hal_get_udi (plugin); + connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); + + /* reuse the connection from HAL */ + proxy = dbus_g_proxy_new_for_name (connection, + HAL_DBUS_SERVICE, udi, + HAL_DBUS_INTERFACE_LAPTOP_PANEL); + + /* get the brightness from HAL */ + error = NULL; + ret = dbus_g_proxy_call (proxy, "SetBrightness", &error, + G_TYPE_INT, (int)brightness, + G_TYPE_INVALID, + G_TYPE_UINT, &retval, + G_TYPE_INVALID); + if (ret == FALSE) { + g_printerr ("Error: %s\n", error->message); + g_error_free (error); + } + g_object_unref (proxy); + g_free (udi); + return ret; +} + +#if 0 +static gboolean +backlight_get_brightness (OhmPlugin *plugin, guint *brightness) +{ + DBusConnection *connection; + DBusGProxy *proxy; + GError *error; + gboolean ret; + int level = 0; + + /* reuse the connection from HAL */ + connection = libhal_ctx_get_dbus_connection (ctx); + proxy = dbus_g_proxy_new_for_name (connection, HAL_DBUS_SERVICE, udi, HAL_DBUS_INTERFACE_LAPTOP_PANEL); + + /* get the brightness from HAL */ + error = NULL; + ret = dbus_g_proxy_call (proxy, "GetBrightness", &error, + G_TYPE_INVALID, + G_TYPE_UINT, &level, + G_TYPE_INVALID); + if (ret == FALSE) { + g_printerr ("Error: %s\n", error->message); + g_error_free (error); + level = 0; + } + *brightness = level; + g_object_unref (proxy); + return ret; +} +#endif + +/** + * plugin_preload: + * @plugin: This class instance + * + * Called before the plugin is coldplg. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static gboolean +plugin_preload (OhmPlugin *plugin) +{ + /* tell ohmd what keys we are going to provide so it can create them */ + ohm_plugin_conf_provide (plugin, "backlight.hardware_brightness"); + ohm_plugin_conf_provide (plugin, "backlight.percent_brightness"); + ohm_plugin_conf_provide (plugin, "backlight.num_levels"); + return TRUE; +} + +static guint +percent_to_discrete (guint percentage, + guint levels) +{ + /* check we are in range */ + if (percentage > 100) { + return levels; + } + if (levels == 0) { + g_warning ("levels is 0!"); + return 0; + } + return ((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f; +} + +/** + * plugin_coldplug: + * @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_coldplug (OhmPlugin *plugin) +{ + gboolean ret; + + /* interested keys, either can be changed without changing the other */ + ohm_plugin_conf_interested (plugin, "backlight.hardware_brightness", CONF_BRIGHTNESS_HARDWARE_CHANGED); + ohm_plugin_conf_interested (plugin, "backlight.percent_brightness", CONF_BRIGHTNESS_PERCENT_CHANGED); + + /* initialise HAL */ + ohm_plugin_hal_init (plugin); + + /* get the only device with capability and watch it */ + ret = ohm_plugin_hal_add_device_capability (plugin, "laptop_panel"); + if (ret == TRUE) { + ohm_plugin_hal_get_int (plugin, "laptop_panel.num_levels", &data.levels); + g_debug ("Laptop panel levels: %i", data.levels); + } else { + g_warning ("not tested with not one laptop_panel"); + } + + /* get levels that the adapter supports -- this does not change ever */ + ohm_plugin_hal_get_int (plugin, "laptop_panel.num_levels", &data.levels); + if (data.levels == 0) { + g_error ("levels zero!"); + return; + } + ohm_plugin_conf_set_key (plugin, "backlight.num_levels", data.levels); +} + +/** + * plugin_conf_notify: + * @plugin: This class instance + * + * Notify the plugin that a key marked with ohm_plugin_conf_interested () + * has it's value changed. + * An enumerated numeric id rather than the key is returned for processing speed. + */ +static void +plugin_conf_notify (OhmPlugin *plugin, gint id, gint value) +{ + guint hw; + if (id == CONF_BRIGHTNESS_PERCENT_CHANGED) { + hw = percent_to_discrete (value, data.levels); + ohm_plugin_conf_set_key (plugin, "backlight.hardware_brightness", hw); + // backlight_set_brightness (plugin, hw); ------ SHOULDN'T BE NEEDED + } else if (id == CONF_BRIGHTNESS_HARDWARE_CHANGED) { + backlight_set_brightness (plugin, value); + } +} + +static OhmPluginInfo plugin_info = { + "OHM Backlight", /* description */ + "0.0.2", /* version */ + "richard@hughsie.com", /* author */ + plugin_preload, /* preload */ + NULL, /* unload */ + plugin_coldplug, /* coldplug */ + plugin_conf_notify, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/glue/battery/.gitignore b/plugins/glue/battery/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/battery/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/battery/Makefile.am b/plugins/glue/battery/Makefile.am new file mode 100644 index 0000000..55d03cc --- /dev/null +++ b/plugins/glue/battery/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(GLIB_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = battery + +lib_LTLIBRARIES = libohm_battery.la +libohm_batteryincludedir = $(includedir)/ohm +libohm_battery_la_SOURCES = ohm-plugin-battery.c +libohm_battery_la_LIBADD = $(INTLLIBS) +libohm_battery_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/battery/README b/plugins/glue/battery/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/glue/battery/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/glue/battery/battery b/plugins/glue/battery/battery new file mode 100644 index 0000000..ed1b869 --- /dev/null +++ b/plugins/glue/battery/battery @@ -0,0 +1 @@ +# battery preference values diff --git a/plugins/glue/battery/ohm-plugin-battery.c b/plugins/glue/battery/ohm-plugin-battery.c new file mode 100644 index 0000000..da979be --- /dev/null +++ b/plugins/glue/battery/ohm-plugin-battery.c @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2007 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <gmodule.h> +#include <glib.h> +#include <string.h> + +#include <ohm-plugin.h> + +/** + * plugin_preload: + * @plugin: This class instance + * + * Called before the plugin is coldplug. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static gboolean +plugin_preload (OhmPlugin *plugin) +{ + /* tell ohmd what keys we are going to provide - don't set keys + * unless you provide them */ + ohm_plugin_conf_provide (plugin, "battery.percentage"); + return TRUE; +} + +static void +hal_property_changed_cb (OhmPlugin *plugin, + const gchar *key) +{ + gboolean state; + if (strcmp (key, "battery.charge_level.percentage") == 0) { + ohm_plugin_hal_get_int (plugin, "battery.percentage", &state); + ohm_plugin_conf_set_key (plugin, "battery.percentage", state); + } +} + +/** + * plugin_coldplug: + * @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_coldplug (OhmPlugin *plugin) +{ + gint state; + gboolean ret; + + /* initialise HAL */ + ohm_plugin_hal_init (plugin); + + /* we want this function to get the property modified events for all devices */ + ohm_plugin_hal_use_property_modified (plugin, hal_property_changed_cb); + + /* get the only device with capability and watch it */ + ret = ohm_plugin_hal_add_device_capability (plugin, "battery"); + if (ret == TRUE) { + ohm_plugin_hal_get_int (plugin, "battery.percentage", &state); + } else { + g_warning ("not tested with not one battery"); + state = 100; + } + ohm_plugin_conf_set_key (plugin, "battery.percentage", state); +} + +static OhmPluginInfo plugin_info = { + "OHM HAL Battery", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_preload, /* preload */ + NULL, /* unload */ + plugin_coldplug, /* coldplug */ + NULL, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/glue/dpms/.gitignore b/plugins/glue/dpms/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/dpms/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/dpms/Makefile.am b/plugins/glue/dpms/Makefile.am new file mode 100644 index 0000000..9c2525d --- /dev/null +++ b/plugins/glue/dpms/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = dpms + +lib_LTLIBRARIES = libohm_dpms.la +libohm_dpmsincludedir = $(includedir)/ohm +libohm_dpms_la_SOURCES = ohm-plugin-dpms.c +libohm_dpms_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) $(OHM_X11_LIBS) + +libohm_dpms_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/dpms/README b/plugins/glue/dpms/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/glue/dpms/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/glue/dpms/dpms b/plugins/glue/dpms/dpms new file mode 100644 index 0000000..d06aacf --- /dev/null +++ b/plugins/glue/dpms/dpms @@ -0,0 +1,7 @@ +# dpms preference values +# method: +# 0 stagger +# 1 standby +# 2 suspend +# 3 off +dpms.method 3 public diff --git a/plugins/glue/dpms/ohm-plugin-dpms.c b/plugins/glue/dpms/ohm-plugin-dpms.c new file mode 100644 index 0000000..8810865 --- /dev/null +++ b/plugins/glue/dpms/ohm-plugin-dpms.c @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2007 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include <stdlib.h> +#include <stdio.h> +#include <gmodule.h> +#include <glib.h> + +#include <ohm-plugin.h> + +#include <X11/Xutil.h> +#include <X11/Xproto.h> /* for CARD16 */ +#include <X11/extensions/dpms.h> +#include <X11/Xlib.h> +#include <X11/extensions/dpmsstr.h> + +enum { + CONF_BACKLIGHT_STATE_CHANGED, + CONF_LAST +}; + +typedef enum { + OHM_DPMS_MODE_ON, + OHM_DPMS_MODE_STANDBY, + OHM_DPMS_MODE_SUSPEND, + OHM_DPMS_MODE_OFF +} OhmDpmsMode; + +typedef struct { + gint state; + Display *dpy; +} OhmPluginCacheData; + +static OhmPluginCacheData data; + +/** + * plugin_preload: + * + * Called before the plugin is coldplg. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static gboolean +plugin_preload (OhmPlugin *plugin) +{ + /* add in the required, suggested and prevented plugins */ + ohm_plugin_require (plugin, "backlight"); + return TRUE; +} + + +/** + * ohm_dpms_get_mode: + */ +static gboolean +ohm_dpms_get_mode (OhmDpmsMode *mode) +{ + OhmDpmsMode result; + int event_number; + int error_number; + BOOL enabled = FALSE; + CARD16 state; + + if (! DPMSQueryExtension (data.dpy, &event_number, &error_number)) { + /* Server doesn't know -- assume the monitor is on. */ + result = OHM_DPMS_MODE_ON; + + } else if (! DPMSCapable (data.dpy)) { + /* Server says the monitor doesn't do power management -- so it's on. */ + result = OHM_DPMS_MODE_ON; + + } else { + DPMSInfo (data.dpy, &state, &enabled); + if (! enabled) { + /* Server says DPMS is disabled -- so the monitor is on. */ + result = OHM_DPMS_MODE_ON; + } else { + switch (state) { + case DPMSModeOn: + result = OHM_DPMS_MODE_ON; + break; + case DPMSModeStandby: + result = OHM_DPMS_MODE_STANDBY; + break; + case DPMSModeSuspend: + result = OHM_DPMS_MODE_SUSPEND; + break; + case DPMSModeOff: + result = OHM_DPMS_MODE_OFF; + break; + default: + result = OHM_DPMS_MODE_ON; + break; + } + } + } + + if (mode) { + *mode = result; + } + return TRUE; +} + +/** + * ohm_dpms_set_mode: + */ +static gboolean +ohm_dpms_set_mode (OhmDpmsMode mode) +{ + CARD16 state; + OhmDpmsMode current_mode; + + if (data.dpy == NULL) { + g_debug ("cannot open display"); + return FALSE; + } + + if (! DPMSCapable (data.dpy)) { + g_debug ("display not DPMS capable"); + return FALSE; + } + + if (mode == OHM_DPMS_MODE_ON) { + state = DPMSModeOn; + } else if (mode == OHM_DPMS_MODE_STANDBY) { + state = DPMSModeStandby; + } else if (mode == OHM_DPMS_MODE_SUSPEND) { + state = DPMSModeSuspend; + } else if (mode == OHM_DPMS_MODE_OFF) { + state = DPMSModeOff; + } else { + g_warning ("invalid state"); + state = DPMSModeOn; + } + + /* make sure we are not trying to set the current screen mode, else we flicker */ + ohm_dpms_get_mode (¤t_mode); + if (current_mode != mode) { + g_debug ("Setting DPMS state"); + if (! DPMSForceLevel (data.dpy, state)) { + g_warning ("Could not change DPMS mode"); + return FALSE; + } + } + + XSync (data.dpy, FALSE); + return TRUE; +} + +/** + * check_system_dpms_state: + * + * Check the battery, and set the low and critical values if battery is low + */ +static void +check_system_dpms_state (OhmPlugin *plugin) +{ + if (data.state == 0) { + ohm_dpms_set_mode (OHM_DPMS_MODE_OFF); + } else if (data.state == 1) { + ohm_dpms_set_mode (OHM_DPMS_MODE_ON); + } else { + g_error ("unknown mode, can't set with DPMS"); + } +} + +/** + * plugin_coldplug: + * + * 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_coldplug (OhmPlugin *plugin) +{ + /* interested keys */ + ohm_plugin_conf_interested (plugin, "backlight.state", CONF_BACKLIGHT_STATE_CHANGED); + + /* initial values */ + data.state = 1; + + /* open display, need to free using XCloseDisplay */ + data.dpy = XOpenDisplay (":0"); /* fixme: don't assume :0 */ + + check_system_dpms_state (plugin); +} + +/** + * plugin_unload: + * + * Unload drivers, free memory. + */ +static void +plugin_unload (OhmPlugin *plugin) +{ + XCloseDisplay (data.dpy); + data.dpy = NULL; +} + +/** + * plugin_conf_notify: + * + * Notify the plugin that a key marked with ohm_plugin_conf_interested () + * has it's value changed. + * An enumerated numeric id rather than the key is returned for processing speed. + */ +static void +plugin_conf_notify (OhmPlugin *plugin, gint id, gint value) +{ + if (id == CONF_BACKLIGHT_STATE_CHANGED) { + data.state = value; + check_system_dpms_state (plugin); + } +} + +static OhmPluginInfo plugin_info = { + "OHM DPMS", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_preload, /* preload */ + plugin_unload, /* unload */ + plugin_coldplug, /* coldplug */ + plugin_conf_notify, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/glue/idle/.gitignore b/plugins/glue/idle/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/idle/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/idle/Makefile.am b/plugins/glue/idle/Makefile.am new file mode 100644 index 0000000..c4af154 --- /dev/null +++ b/plugins/glue/idle/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = idle + +lib_LTLIBRARIES = libohm_idle.la +libohm_idleincludedir = $(includedir)/ohm +libohm_idle_la_SOURCES = ohm-plugin-idle.c +libohm_idle_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) +libohm_idle_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/idle/README b/plugins/glue/idle/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/glue/idle/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/glue/idle/idle b/plugins/glue/idle/idle new file mode 100644 index 0000000..61f8f33 --- /dev/null +++ b/plugins/glue/idle/idle @@ -0,0 +1 @@ +# idle preference values diff --git a/plugins/glue/idle/ohm-plugin-idle.c b/plugins/glue/idle/ohm-plugin-idle.c new file mode 100644 index 0000000..56d178b --- /dev/null +++ b/plugins/glue/idle/ohm-plugin-idle.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <gmodule.h> +#include <glib.h> + +#include <ohm-plugin.h> + +/** + * plugin_preload: + * @plugin: This class instance + * + * Called before the plugin is coldplg. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static gboolean +plugin_preload (OhmPlugin *plugin) +{ + /* tell ohmd what keys we are going to provide */ + ohm_plugin_conf_provide (plugin, "idle.system_idle"); + return TRUE; +} + +/** + * plugin_coldplug: + * @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_coldplug (OhmPlugin *plugin) +{ +} + +static OhmPluginInfo plugin_info = { + "OHM PowerStatus", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_preload, /* preload */ + NULL, /* unload */ + plugin_coldplug, /* coldplug */ + NULL, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/glue/powerstatus/.gitignore b/plugins/glue/powerstatus/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/powerstatus/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/powerstatus/Makefile.am b/plugins/glue/powerstatus/Makefile.am new file mode 100644 index 0000000..a948c44 --- /dev/null +++ b/plugins/glue/powerstatus/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = powerstatus + +lib_LTLIBRARIES = libohm_powerstatus.la +libohm_powerstatusincludedir = $(includedir)/ohm +libohm_powerstatus_la_SOURCES = ohm-plugin-powerstatus.c +libohm_powerstatus_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) +libohm_powerstatus_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/powerstatus/README b/plugins/glue/powerstatus/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/glue/powerstatus/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/glue/powerstatus/ohm-plugin-powerstatus.c b/plugins/glue/powerstatus/ohm-plugin-powerstatus.c new file mode 100644 index 0000000..d07fdf7 --- /dev/null +++ b/plugins/glue/powerstatus/ohm-plugin-powerstatus.c @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2007 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <gmodule.h> +#include <glib.h> + +#include <ohm-plugin.h> + +enum { + CONF_PERCENT_LOW_CHANGED, + CONF_PERCENT_CRITICAL_CHANGED, + CONF_BATTERY_CHANGED, + CONF_LAST +}; + +typedef struct { + gint percentage; + gint percentage_low; + gint percentage_critical; +} OhmPluginCacheData; + +static OhmPluginCacheData data; + +/** + * plugin_preload: + * @plugin: This class instance + * + * Called before the plugin is coldplg. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static gboolean +plugin_preload (OhmPlugin *plugin) +{ + /* add in the required, suggested and prevented plugins */ + ohm_plugin_suggest (plugin, "battery"); + + /* tell ohmd what keys we are going to provide so it can create them */ + ohm_plugin_conf_provide (plugin, "powerstatus.low"); + ohm_plugin_conf_provide (plugin, "powerstatus.critical"); + return TRUE; +} + +/** + * check_system_power_state: + * @plugin: This class instance + * + * Check the battery, and set the low and critical values if battery is low + */ +static void +check_system_power_state (OhmPlugin *plugin) +{ + gint is_low; + gint is_critical; + + if (data.percentage < data.percentage_critical) { + is_low = 1; + is_critical = 1; + } else if (data.percentage < data.percentage_low) { + is_low = 1; + is_critical = 0; + } else { + is_low = 0; + is_critical = 0; + } + ohm_plugin_conf_set_key (plugin, "powerstatus.low", is_low); + ohm_plugin_conf_set_key (plugin, "powerstatus.critical", is_critical); +} + +/** + * plugin_coldplug: + * @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_coldplug (OhmPlugin *plugin) +{ + /* interested keys */ + ohm_plugin_conf_interested (plugin, "battery.percentage", CONF_BATTERY_CHANGED); + ohm_plugin_conf_interested (plugin, "powerstatus.percentage_low", CONF_BATTERY_CHANGED); + ohm_plugin_conf_interested (plugin, "powerstatus.percentage_critical", CONF_BATTERY_CHANGED); + + /* initial values */ + ohm_plugin_conf_get_key (plugin, "battery.percentage", &(data.percentage)); + ohm_plugin_conf_get_key (plugin, "powerstatus.percentage_low", &(data.percentage_low)); + ohm_plugin_conf_get_key (plugin, "powerstatus.percentage_critical", &(data.percentage_critical)); + + check_system_power_state (plugin); +} + +/** + * plugin_conf_notify: + * @plugin: This class instance + * + * Notify the plugin that a key marked with ohm_plugin_conf_interested () + * has it's value changed. + * An enumerated numeric id rather than the key is returned for processing speed. + */ +static void +plugin_conf_notify (OhmPlugin *plugin, gint id, gint value) +{ + if (id == CONF_BATTERY_CHANGED) { + data.percentage = value; + check_system_power_state (plugin); + } else if (id == CONF_PERCENT_LOW_CHANGED) { + data.percentage_low = value; + check_system_power_state (plugin); + } else if (id == CONF_PERCENT_CRITICAL_CHANGED) { + data.percentage_critical = value; + check_system_power_state (plugin); + } +} + +static OhmPluginInfo plugin_info = { + "OHM PowerStatus", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_preload, /* preload */ + NULL, /* unload */ + plugin_coldplug, /* coldplug */ + plugin_conf_notify, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/glue/powerstatus/powerstatus b/plugins/glue/powerstatus/powerstatus new file mode 100644 index 0000000..d3814e5 --- /dev/null +++ b/plugins/glue/powerstatus/powerstatus @@ -0,0 +1,2 @@ +powerstatus.percentage_low 20 public +powerstatus.percentage_critical 10 public diff --git a/plugins/glue/timeremaining/.gitignore b/plugins/glue/timeremaining/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/timeremaining/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/timeremaining/Makefile.am b/plugins/glue/timeremaining/Makefile.am new file mode 100644 index 0000000..c1af09b --- /dev/null +++ b/plugins/glue/timeremaining/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = timeremaining + +lib_LTLIBRARIES = libohm_timeremaining.la +libohm_timeremainingincludedir = $(includedir)/ohm +libohm_timeremaining_la_SOURCES = ohm-plugin-timeremaining.c +libohm_timeremaining_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) +libohm_timeremaining_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/timeremaining/README b/plugins/glue/timeremaining/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/glue/timeremaining/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/glue/timeremaining/ohm-plugin-timeremaining.c b/plugins/glue/timeremaining/ohm-plugin-timeremaining.c new file mode 100644 index 0000000..7756b5d --- /dev/null +++ b/plugins/glue/timeremaining/ohm-plugin-timeremaining.c @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2007 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <gmodule.h> +#include <glib.h> + +#include <ohm-plugin.h> + +enum { + CONF_BATTERY_PERCENT_CHANGED, + CONF_AC_STATE_CHANGED, + CONF_LAST +}; + +typedef struct { + gint percentage; + gint ac_state; +} OhmPluginCacheData; + +static OhmPluginCacheData data; + +/** + * plugin_preload: + * @plugin: This class instance + * + * Called before the plugin is coldplg. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static gboolean +plugin_preload (OhmPlugin *plugin) +{ + /* add in the required, suggested and prevented plugins */ + ohm_plugin_suggest (plugin, "battery"); + ohm_plugin_suggest (plugin, "acadapter"); + + /* tell ohmd what keys we are going to provide so it can create them */ + ohm_plugin_conf_provide (plugin, "timeremaining.to_charge"); + ohm_plugin_conf_provide (plugin, "timeremaining.to_discharge"); + return TRUE; +} + +/** + * check_system_power_state: + * @plugin: This class instance + * + * Check the battery, and set the low and critical values if battery is low + */ +static void +check_system_power_state (OhmPlugin *plugin) +{ + ohm_plugin_conf_set_key (plugin, "timeremaining.to_charge", 10); + ohm_plugin_conf_set_key (plugin, "timeremaining.to_discharge", 10); +} + +/** + * plugin_coldplug: + * @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_coldplug (OhmPlugin *plugin) +{ + /* interested keys */ + ohm_plugin_conf_interested (plugin, "battery.percentage", CONF_BATTERY_PERCENT_CHANGED); + ohm_plugin_conf_interested (plugin, "acadapter.state", CONF_AC_STATE_CHANGED); + + /* initial values */ + ohm_plugin_conf_get_key (plugin, "battery.percentage", &(data.percentage)); + ohm_plugin_conf_get_key (plugin, "acadapter.state", &(data.ac_state)); + + check_system_power_state (plugin); +} + +/** + * plugin_conf_notify: + * @plugin: This class instance + * + * Notify the plugin that a key marked with ohm_plugin_conf_interested () + * has it's value changed. + * An enumerated numeric id rather than the key is returned for processing speed. + */ +static void +plugin_conf_notify (OhmPlugin *plugin, gint id, gint value) +{ + if (id == CONF_BATTERY_PERCENT_CHANGED) { + data.percentage = value; + check_system_power_state (plugin); + } else if (id == CONF_AC_STATE_CHANGED) { + data.ac_state = value; + check_system_power_state (plugin); + } +} + +static OhmPluginInfo plugin_info = { + "OHM timeremaining", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_preload, /* preload */ + NULL, /* unload */ + plugin_coldplug, /* coldplug */ + plugin_conf_notify, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/glue/timeremaining/timeremaining b/plugins/glue/timeremaining/timeremaining new file mode 100644 index 0000000..6b8a282 --- /dev/null +++ b/plugins/glue/timeremaining/timeremaining @@ -0,0 +1,2 @@ +# timeremaining preference values +timeremaining.calculate_hysteresis 1 public |