diff options
author | Richard Hughes <richard@hughsie.com> | 2007-07-11 20:33:09 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2007-07-11 20:33:09 +0100 |
commit | a4cb006dd6ff2d2dae3dce2a32bb9334946fdfd9 (patch) | |
tree | 23c87211f908bf362d5993ab19afc782661691f2 | |
parent | 4b47b16ac54a5da8436a6c60bf6b342a8f6657f5 (diff) |
add xrandr functionality
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | ohmd/ohm-plugin.c | 17 | ||||
-rw-r--r-- | ohmd/ohm-plugin.h | 4 | ||||
-rw-r--r-- | plugins/glue/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/glue/xrandr/.gitignore | 8 | ||||
-rw-r--r-- | plugins/glue/xrandr/Makefile.am | 21 | ||||
-rw-r--r-- | plugins/glue/xrandr/ohm-plugin-xrandr.c | 91 | ||||
-rw-r--r-- | plugins/glue/xrandr/xrandr.ini | 1 | ||||
-rw-r--r-- | plugins/policy/display/ohm-plugin-display.c | 9 |
9 files changed, 153 insertions, 0 deletions
diff --git a/configure.in b/configure.in index 726855f..74cb9c8 100644 --- a/configure.in +++ b/configure.in @@ -299,6 +299,7 @@ plugins/glue/powerstatus/Makefile plugins/glue/timeremaining/Makefile plugins/glue/backlight/Makefile plugins/glue/battery/Makefile +plugins/glue/xrandr/Makefile plugins/policy/Makefile plugins/policy/display/Makefile plugins/policy/suspend/Makefile diff --git a/ohmd/ohm-plugin.c b/ohmd/ohm-plugin.c index b71fd78..893a774 100644 --- a/ohmd/ohm-plugin.c +++ b/ohmd/ohm-plugin.c @@ -438,6 +438,23 @@ ohm_plugin_hal_get_udi (OhmPlugin *plugin, guint id) } G_MODULE_EXPORT gboolean +ohm_plugin_spawn_async (OhmPlugin *plugin, + const gchar *commandline) +{ + gboolean ret; + GError *error; + + error = NULL; + ohm_debug ("spawning %s", commandline); + ret = g_spawn_commandline_async (commandline, &error); + if (ret == FALSE) { + ohm_warning ("spawn failed: %s", commandline, error->message); + g_error_free (error); + } + return ret; +} + +G_MODULE_EXPORT gboolean ohm_plugin_conf_interested (OhmPlugin *plugin, const gchar *key, gint id) diff --git a/ohmd/ohm-plugin.h b/ohmd/ohm-plugin.h index b36b34d..2c13250 100644 --- a/ohmd/ohm-plugin.h +++ b/ohmd/ohm-plugin.h @@ -94,6 +94,10 @@ const gchar *ohm_plugin_get_name (OhmPlugin *plugin); const gchar *ohm_plugin_get_version (OhmPlugin *plugin); const gchar *ohm_plugin_get_author (OhmPlugin *plugin); +/* used by plugin to do crazy stuff */ +gboolean ohm_plugin_spawn_async (OhmPlugin *plugin, + const gchar *commandline); + /* used by plugin to manager */ gboolean ohm_plugin_conf_provide (OhmPlugin *plugin, const gchar *name); diff --git a/plugins/glue/Makefile.am b/plugins/glue/Makefile.am index cf763e2..565ac21 100644 --- a/plugins/glue/Makefile.am +++ b/plugins/glue/Makefile.am @@ -5,6 +5,7 @@ SUBDIRS = \ acadapter \ timeremaining \ powerstatus \ + xrandr \ backlight if HAVE_DPMS_EXTENSION diff --git a/plugins/glue/xrandr/.gitignore b/plugins/glue/xrandr/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/xrandr/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/xrandr/Makefile.am b/plugins/glue/xrandr/Makefile.am new file mode 100644 index 0000000..685de30 --- /dev/null +++ b/plugins/glue/xrandr/Makefile.am @@ -0,0 +1,21 @@ +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 = xrandr.ini + +plugindir = $(libdir)/ohm +plugin_LTLIBRARIES = libohm_xrandr.la +libohm_xrandrincludedir = $(includedir)/ohm +libohm_xrandr_la_SOURCES = ohm-plugin-xrandr.c +libohm_xrandr_la_LIBADD = $(INTLLIBS) +libohm_xrandr_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/xrandr/ohm-plugin-xrandr.c b/plugins/glue/xrandr/ohm-plugin-xrandr.c new file mode 100644 index 0000000..decc957 --- /dev/null +++ b/plugins/glue/xrandr/ohm-plugin-xrandr.c @@ -0,0 +1,91 @@ +/* + * 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> + +enum { + CONF_XRANDR_POSITION_CHANGED, + CONF_LAST +}; + +/** + * 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, "xrandr.position"); + 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) +{ + ohm_plugin_conf_set_key (plugin, "xrandr.position", 0); + ohm_plugin_conf_interested (plugin, "xrandr.position", CONF_XRANDR_POSITION_CHANGED); +} + +/** + * 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_XRANDR_POSITION_CHANGED) { + if (value == 0) { + ohm_plugin_spawn_async (plugin, "/usr/bin/xrandr -o left"); + } else { + ohm_plugin_spawn_async (plugin, "/usr/bin/xrandr -o normal"); + } + } +} + +static OhmPluginInfo plugin_info = { + "OHM HAL XRANDR", /* 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/xrandr/xrandr.ini b/plugins/glue/xrandr/xrandr.ini new file mode 100644 index 0000000..d1a2c49 --- /dev/null +++ b/plugins/glue/xrandr/xrandr.ini @@ -0,0 +1 @@ +# xrandr preference values diff --git a/plugins/policy/display/ohm-plugin-display.c b/plugins/policy/display/ohm-plugin-display.c index 7f19e6c..e4b1a84 100644 --- a/plugins/policy/display/ohm-plugin-display.c +++ b/plugins/policy/display/ohm-plugin-display.c @@ -25,6 +25,7 @@ enum { CONF_AC_STATE_CHANGED, CONF_LID_STATE_CHANGED, + CONF_TABLET_STATE_CHANGED, CONF_BRIGHTNESS_AC_CHANGED, CONF_BRIGHTNESS_BATTERY_CHANGED, CONF_BRIGHTNESS_IDLE_CHANGED, @@ -67,6 +68,7 @@ plugin_coldplug (OhmPlugin *plugin) /* interested keys */ ohm_plugin_conf_interested (plugin, "acadapter.state", CONF_AC_STATE_CHANGED); ohm_plugin_conf_interested (plugin, "button.lid", CONF_LID_STATE_CHANGED); + ohm_plugin_conf_interested (plugin, "button.tablet", CONF_TABLET_STATE_CHANGED); ohm_plugin_conf_interested (plugin, "idle.powersave", CONF_IDLE_POWERSAVE_CHANGED); ohm_plugin_conf_interested (plugin, "idle.momentary", CONF_IDLE_MOMENTARY_CHANGED); ohm_plugin_conf_interested (plugin, "display.value_ac", CONF_BRIGHTNESS_AC_CHANGED); @@ -178,6 +180,13 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value) case CONF_LID_STATE_CHANGED: lid_closed (plugin, (value == 1)); break; + case CONF_TABLET_STATE_CHANGED: + if (value == 0) { + ohm_plugin_conf_set_key (plugin, "xrandr.position", 0); + } else { + ohm_plugin_conf_set_key (plugin, "xrandr.position", 1); + } + break; case CONF_AC_STATE_CHANGED: reset_brightness (plugin); break; |