diff options
author | Richard Hughes <richard@hughsie.com> | 2007-07-13 14:43:52 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2007-07-13 14:43:52 +0100 |
commit | dd0c310e15d31b089c5104a46d75d6d1a6f33fd3 (patch) | |
tree | d88a49d918472c2473e666d17c4eb52391f9ba91 | |
parent | 71585743d33e45d429562b7694e7be78bcd7275c (diff) |
add an xorg plugin to detect when X is up and to set XAUTHORITY
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | etc/modules.ini | 2 | ||||
-rw-r--r-- | plugins/glue/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/glue/xorg/.gitignore | 8 | ||||
-rw-r--r-- | plugins/glue/xorg/Makefile.am | 23 | ||||
-rw-r--r-- | plugins/glue/xorg/ohm-plugin-xorg.c | 110 | ||||
-rw-r--r-- | plugins/glue/xorg/xorg.ini | 3 |
7 files changed, 147 insertions, 1 deletions
diff --git a/configure.in b/configure.in index 74cb9c8..ef53f64 100644 --- a/configure.in +++ b/configure.in @@ -300,6 +300,7 @@ plugins/glue/timeremaining/Makefile plugins/glue/backlight/Makefile plugins/glue/battery/Makefile plugins/glue/xrandr/Makefile +plugins/glue/xorg/Makefile plugins/policy/Makefile plugins/policy/display/Makefile plugins/policy/suspend/Makefile diff --git a/etc/modules.ini b/etc/modules.ini index 1f53527..b4852b1 100644 --- a/etc/modules.ini +++ b/etc/modules.ini @@ -20,7 +20,7 @@ ModulesBanned=embedded # If a suggested module is not present, then startup will not fail. # Typically this should contain modules most likely to be used on the system # OHM is targeted for. Order is unimportant, separate entries with ';'. -ModulesSuggested=acadapter;backlight;battery;timeremaining;idle;powerstatus;dpms;buttons +ModulesSuggested=acadapter;backlight;battery;timeremaining;idle;powerstatus;dpms;buttons;xorg # This should list all the modules that are required for coldplug. # If a required module cannot be loaded, then startup will fail. diff --git a/plugins/glue/Makefile.am b/plugins/glue/Makefile.am index 565ac21..3cc7505 100644 --- a/plugins/glue/Makefile.am +++ b/plugins/glue/Makefile.am @@ -6,6 +6,7 @@ SUBDIRS = \ timeremaining \ powerstatus \ xrandr \ + xorg \ backlight if HAVE_DPMS_EXTENSION diff --git a/plugins/glue/xorg/.gitignore b/plugins/glue/xorg/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/glue/xorg/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/glue/xorg/Makefile.am b/plugins/glue/xorg/Makefile.am new file mode 100644 index 0000000..cd30f3f --- /dev/null +++ b/plugins/glue/xorg/Makefile.am @@ -0,0 +1,23 @@ +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 = xorg.ini + +plugindir = $(libdir)/ohm +plugin_LTLIBRARIES = libohm_xorg.la +libohm_xorgincludedir = $(includedir)/ohm +libohm_xorg_la_SOURCES = ohm-plugin-xorg.c +libohm_xorg_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) $(OHM_X11_LIBS) + +libohm_xorg_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *.la + rm -f *~ diff --git a/plugins/glue/xorg/ohm-plugin-xorg.c b/plugins/glue/xorg/ohm-plugin-xorg.c new file mode 100644 index 0000000..0758700 --- /dev/null +++ b/plugins/glue/xorg/ohm-plugin-xorg.c @@ -0,0 +1,110 @@ +/* + * 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 <stdlib.h> + +#include <ohm-plugin.h> + +/** + * 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_conf_provide (plugin, "xorg.has_xauthority"); + return TRUE; +} + +static gboolean +plugin_poll_startup (gpointer data) +{ + OhmPlugin *plugin = (OhmPlugin *) data; + gboolean ret; + const gchar *xauth; + + /* we should search all of home */ + xauth = "/home/olpc/.Xauthority"; + ret = g_file_test (xauth, G_FILE_TEST_EXISTS); + + /* be nice to hughsie... */ + if (ret == FALSE) { + xauth = "/home/hughsie/.Xauthority"; + ret = g_file_test (xauth, G_FILE_TEST_EXISTS); + } + if (ret == FALSE) { + /* not yet */ + return TRUE; + } + + /* woot! X is alive */ + g_debug ("Got X!"); + ohm_plugin_conf_set_key (plugin, "xorg.has_xauthority", 1); + setenv ("XAUTHORITY", xauth, 1); + setenv ("DISPLAY", ":0", 1); + /* we don't need to poll anymore */ + return FALSE; +} + +/** + * 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) +{ + gboolean ret; + + /* we can assume xorg is on */ + ohm_plugin_conf_set_key (plugin, "xorg.has_xauthority", 0); + + /* naive try... we might be running under X */ + ret = plugin_poll_startup (plugin); + if (ret == FALSE) { + /* we failed to connect to X - maybe X is not alive yet? */ + g_debug ("Could not connect to X, polling until we can"); + g_timeout_add (2000, plugin_poll_startup, plugin); + } +} + +static OhmPluginInfo plugin_info = { + "OHM xorg finder", /* 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/xorg/xorg.ini b/plugins/glue/xorg/xorg.ini new file mode 100644 index 0000000..8521046 --- /dev/null +++ b/plugins/glue/xorg/xorg.ini @@ -0,0 +1,3 @@ +# xorg preference values +xorg.display 0 + |