Xfce Forum

Sub domains
 

You are not logged in.

#1 2011-11-09 22:16:36

AndyP
Member
Registered: 2011-11-09
Posts: 3

How to write something similar to gnome-inhibit-applet?

Hello everyone, I need a bit of help in making something roughly like gnome-inhibit-applet.
Since programs can inhibit xfce's power manager, it should theoretically be possible to do that with a script which gets started or killed by a second script which is run via a simple "launcher" panel plugin, thereby rudimentarily copying the basic functionality of gnome-inhibit-applet.

Now I wouldn't mind having to write that myself if something like that doesn't exist yet, but I need help in how to actually inhibit. In other words, making a script that checks whether a certain process is running (the inhibiting script), kills if it yes and calls it if no, as well as the panel icon that calls said script is no problem, but I have no idea how to write the actual inhibiting script.

I tried asking google and found something about dbus bindings, which seems to be way beyond my skills... Sadly my humble skills are limited to PHP, bash and a bit of Java. So I would like to ask if there would be someone so kind as to either write such a script that inhibits xfce's power manager and screensaver while it runs or instead at least help guide me in writing one myself without screwing up my laptop or needing to learn advanced C/C++ first >_>

Offline

#2 2012-01-04 21:06:31

thomask
Member
Registered: 2012-01-04
Posts: 2

Re: How to write something similar to gnome-inhibit-applet?

Hi Andy,

do you had some efforts to write such an applet?

I just switched from gnome-2 to xfce and I miss that applet too.

I know C/C++ but I do not know how to disable the power-management and I have no idea how to write an XFCE-applet.

Thanks and regards,
Thomas

Last edited by thomask (2012-01-04 21:06:47)

Offline

#3 2012-01-05 01:04:46

demosthenese
Member
From: Liverpool, UK
Registered: 2009-05-04
Posts: 71

Re: How to write something similar to gnome-inhibit-applet?

I’ve knocked together a quick script to turn off power management and screen blanking:

#!/bin/bash

#query dpms with xset and switch status

if xset -q | grep DPMS| grep -c Enabled ; then
  xset -dpms; xset s off
  notify-send DPMS "DPMS disabled"
else
  xset +dpms; xset s on
  notify-send DPMS "DPMS enabled"
fi

Note I don't have xscreensaver installed, so haven't checked whether that will interfere or not.

Save the script somewhere such as ~/bin/toggledpms, and set it to executable, then attach it to a launcher.

Hope this helps.

Edit:

Could someone with xscreensaver installed check this works:

#!/bin/bash

#query dpms with xset and switch status, also exit and restart xscreensaver

if xset -q | grep DPMS| grep -c Enabled ; then
  xset -dpms; xset s off; xscreensaver-command -exit
  notify-send -i gtk-dialog-info "Screen saving is OFF"
else
  xset +dpms; xset s on; xscreensaver &
  notify-send -i gtk-dialog-info "Screen saving is ON"
fi

Last edited by demosthenese (2012-01-05 04:22:38)

Offline

#4 2012-01-05 15:43:04

AndyP
Member
Registered: 2011-11-09
Posts: 3

Re: How to write something similar to gnome-inhibit-applet?

Thanks demosthenese
I haven't had the time yet to test your second script. I remember using something similar in the past as a (limited, as not completely effective) workaround though (might have not thought of xscreensaver).
If it works, I might expand your script a little so it can become a panel starter icon that changes icons depending on whether active or not.

However, the original idea was a script/little prog that uses xfce power manager's inhibit interface. Unless I'm mistaken, your script turns off power management off altogether, so I guess you wouldn't get any warnings about low power anymore either?

Offline

#5 2012-01-07 03:42:18

demosthenese
Member
From: Liverpool, UK
Registered: 2009-05-04
Posts: 71

Re: How to write something similar to gnome-inhibit-applet?

Ok. A slightly different tack. This one uses xdotool, which you may need to install.

Outline:
1. run a script to simulate tapping the ctrl key every couple of minutes.
2. have a launcher script to toggle the first script on and off.

screenpoke:

#!/bin/bash

while :
do
  xdotool key ctrl; sleep 120
done

and the launcher script - screenpoketoggle

#!/bin/bash

TASK=$HOME/bin/screenpoke

if pidof -x $TASK ; then
  kill -9 $(pidof -x $TASK) 
  notify-send -i gtk-dialog-info "Screen saving is ON"
else
  $TASK &
  notify-send -i gtk-dialog-info "Screen saving is OFF"
fi

No messing about with power management. smile

Offline

#6 2012-01-07 15:32:18

AndyP
Member
Registered: 2011-11-09
Posts: 3

Re: How to write something similar to gnome-inhibit-applet?

Nice workaround. Ugly but effective smile If I haven't expanded your toggle script to have its own toggling icon in, say, a month, poke me please (right now I really should write some &!$ essays >_>). tongue
Best would of course be something that actually interfaces with xfce power manager's "inhibit" API part, but I guess there's probably just a few people on the planet who know its workings. ¯'-Ö-'¯

Offline

#7 2013-07-14 02:40:06

llogg
Member
Registered: 2013-07-07
Posts: 2

Re: How to write something similar to gnome-inhibit-applet?

Here's my solution to this issue.  Not completely elegant, but less of a kludge than the above scripts (which I took as a jumping off place and really appreciate).

#!/bin/bash

PWRMGRKILL='killall -9 xfce4-power-manager'
PWRMGRSTART='xfce4-power-manager'
flash_check=$(ps x | awk '/libflashplayer.so\ /{print $1}' | grep -v ps)
FLASH_USAGE=$(ps aux | grep $flash_check | grep -v grep | grep -v ps | awk '{print $3*100}')
SPOTIFY_CHECK=$(pidof -x spotify)
PITHOS_CHECK=$(pidof -x pithos)
while true
do
 if pidof -x xfce4-power-manager  ; then
   (if [[ $SPOTIFY_CHECK ]] ; then
     $PWRMGRKILL &
     notify-send -i gtk-dialog-info "Power Manager disabled for Spotify."
   elif [[ $PITHOS_CHECK ]] ; then
     $PWRMGRKILL &
     notify-send -i gtk-dialog-info "Power Manager disabled for Pithos."
   elif [[ $flash_check ]] ; then
     if [[ $FLASH_USAGE -gt 1120 ]] ; then
      $PWRMGRKILL &
      notify-send -i gtk-dialog-info "Power Manager disabled for Flash."
     fi
   else
     notify-send -i gtk-dialog-info "Power Manager keepin' running, boss."
   fi)
 else
   (if [[ $SPOTIFY_CHECK ]] ; then
   notify-send -i gtk-dialog-info "Power Manager stays disabled for Spotify."
   elif [[ $PITHOS_CHECK ]] ; then
   notify-send -i gtk-dialog-info "Power Manager stays disabled for Pithos."
   elif  [[ $FLASH_USAGE -gt 1120 ]] ; then
      notify-send -i gtk-dialog-info "Power Manager stays disabled for Flash."
   elif [[ $FLASH_USAGE -lt 1120 ]] ; then
     $PWRMGRSTART &
     notify-send -i gtk-dialog-info "Starting Power Manager since Flash isn't active."
   else
     $PWRMGRSTART &
     notify-send -i gtk-dialog-info "Starting Power Manager, boss."
   fi)
  
 fi
sleep 900
done

See here for some discussion of the script.

Offline

#8 2013-08-04 16:02:30

d-tox
Member
Registered: 2013-08-04
Posts: 1

Re: How to write something similar to gnome-inhibit-applet?

Hi I made a few changes to the above script and it seems to work a little better, this disables the power manager and sets dpms to disabled.



#!/bin/bash

#query dpms with xset and switch status

if xset -q | grep DPMS| grep -c Disabled ; then
  xset +dpms; xset s on; xfce4-power-manager
  notify-send -i gtk-dialog-info "DPMS Enabled"
else
  xset -dpms; xset s off; xfce4-power-manager -q
  notify-send -i gtk-dialog-info "DPMS Disabled"
fi

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.056 seconds, 7 queries executed - Memory usage: 548.86 KiB (Peak: 566.14 KiB) ]