Hi Michael, > Did you look into PowerDevilRunning() in the same file? This function gets the > module information from KDE. I guess the Gnome version could work similarly. Hmm, I was going to look at that function and then got distracted or something. Stupid I overlooked that.
> > Having said that, I guess this patch is a sufficient solution? > Actually the dbus version would be preferable if doable. Here's a new patch, that uses dbus. I've generalized the PowerDevil function to prevent duplicate code, but I haven't actually been able to test the code on KDE (but the changes are small enough to not expect any problems). I've also not tested this on an older gnome, but I did try running gnome-settings-daemon without the Power plugin loaded, which works as expected. Gr. Matthijs
--- policy-funcs.orig 2012-01-11 16:12:36.139926253 +0100 +++ policy-funcs 2012-01-11 16:15:01.684570189 +0100 @@ -21,19 +21,46 @@ pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedModules | grep -q klaptopdaemon; } || - PowerDevilRunning + PowerDevilRunning || + GnomeSettingsDaemonPowerRunning } -PowerDevilRunning() { +# Find a DBUS session bus, by looking at the given process' environment and +# then send a message to that bus. If multiple processes match the given name, +# the message is sent to all of the buses (and output is simply concatenated. +DBusSend() { + # The process to get the DBUS session address from + local PROC_NAME="$1" + + # Parameters for dbus-send + local DEST="$2" + local DBUS_PATH="$3" + local METHOD="$4" + test -x /usr/bin/dbus-send || return 1 local DBUS_SESS - for p in $(pidof kded4); do + for p in $(pidof "$PROC_NAME"); do test -r /proc/$p/environ || continue DBUS_SESS=$(grep -a -z "DBUS_SESSION_BUS_ADDRESS=" /proc/$p/environ || :) test "$DBUS_SESS" != "" || continue - ! su $(ps -o user= $p) -s /bin/sh -c "$DBUS_SESS dbus-send --print-reply --dest=org.kde.kded /kded org.kde.kded.loadedModules" | grep -q powerdevil || return 0 + su $(ps -o user= $p) -s /bin/sh -c "$DBUS_SESS dbus-send --print-reply --dest='$DEST' '$DBUS_PATH' '$METHOD'" done - - return 1 +} + +# Ask kde if the powerdevil module is loaded +PowerDevilRunning() { + DBusSend kde4 org.kde.kded /kded org.kde.kded.loadedModules | grep -q powerdevil +} + +# gnome-power-manager was integrated into gnome-settings-daemon from version +# 3.1.4, in a new Power plugin (though the handling of buttons is done in the +# MediaKeys plugin. +# +# gnome-settings-daemon does not export a list of loaded plugins, but +# fortunately the Power plugin does have its own Dbus interface we can check +# for (We can't check the MediaKeys plugin, since that has been around for +# longer). +GnomeSettingsDaemonPowerRunning() { + DBusSend gnome-session org.gnome.SettingsDaemon /org/gnome/SettingsDaemon/Power org.freedesktop.DBus.Introspectable.Introspect | grep -q 'interface name="org.gnome.SettingsDaemon.Power"' }
signature.asc
Description: Digital signature