title: Is there a decent way to inhibit screensavers in linux?
body: <p>I'm looking for a decent, non-lame way to inhibit xscreensaver, kscreensaver, or gnome-screensaver, whichever might be running, preferably in a screensaver-agnostic manner, and it absolutely positively must execute <em>fast</em>.</p>
  <p>I've read the <a href="http://www.jwz.org/xscreensaver/faq.html" rel="nofollow noreferrer">xscreensaver FAQ</a>.</p>
  <p>I have a gtk based game program that's cranking out 30 frames/second while mixing several channels of audio, and since it's controlled by a joystick, sometimes &quot;the&quot; screensaver will kick in.  I put &quot;the&quot; in quotes, because there are at least three different popular screensavers, xscreensaver, gnome-screensaver, and kscreensaver, each with their own unique and clunky methods by which an application might inhibit them.</p>
  <p>Has anybody encapsulated the code to inhibit all of these into a <em>fast</em> chunk of code?  Oh, and it has to be GPL compatible.</p>
  <p>Currently my code simply whines piteously about the uncooperative screensaver developers if any screensaver is detected and the joystick is in use, and doesn't actually try to do anything other than advise the user to manually disable the screensaver, as the only other thing I can think to do is so incredibly ugly that I simply refuse to do it.</p>
  <p>Just wondering if anybody else has run into this, and what they've done, and if they did anything, if it was as ugly as it seems to me it would have to be, or if there's some elegant solution out there...  Seems like maybe synthesizing X events somehow to fool the screensaver into thinking there's some activity might do the trick in a universal way, but I'm really not sure how to do that (and hoping you wouldn't need to be root to do it.)</p>
  <p>Any ideas?</p>
  <hr />
  <p>Hmm, unfortunately, at least on Fedora core 8, this does not appear to work.</p>
  <p>The xdg-screensaver script is there, and seems to be intended to work, it just doesn't actually work.</p>
  <p>Once you do &quot;xdg-screensaver suspend window-id&quot;, where window id is gotten from within the program via</p>
  <pre><code>xwindow_id = GDK_WINDOW_XWINDOW (GTK_WIDGET (widget)-&amp;gt;window);
  </code></pre>
  <p>Or whether the window id is gotten via xprop, and xdg-screensaver run manually, two processes are created:</p>
  <pre><code>[scameron@zuul wordwarvi]$ ps -efa | grep xdg
  scameron  4218     1  0 20:12 pts/2    00:00:00 /bin/sh /usr/bin/xdg-screensaver suspend 0x3a00004
  scameron  4223     1  0 20:12 pts/2    00:00:00 /bin/sh /usr/bin/xdg-screensaver suspend 0x3a00004
  scameron  4313  3151  0 20:15 pts/1    00:00:00 grep xdg
  [scameron@zuul wordwarvi]$ 
  </code></pre>
  <p>And they never die, even after the program they are supposedly waiting for dies, and the screensaver is never re-enabled.</p>
  <pre><code>[scameron@zuul wordwarvi]$ xdg-screensaver status
  disabled
  [scameron@zuul wordwarvi]$ ls -ltr /tmp | grep xdg
  -rw------- 1 scameron scameron    15 2009-01-20 20:12 xdg-screensaver-scameron--0.0
  [scameron@zuul wordwarvi]$ 
  </code></pre>
  <p>Running xdg-screensaver resume window-id does not resume the screensaver.</p>
  <p>To re-enable the screensaver, I have to manually kill them, and manually remove the files it leaves around in /tmp:</p>
  <pre><code>[scameron@zuul wordwarvi]$ kill 4218 4223
  [scameron@zuul wordwarvi]$ rm /tmp/xdg-screensaver-scameron--0.0 
  [scameron@zuul wordwarvi]$ xdg-screensaver status
  enabled
  [scameron@zuul wordwarvi]$ 
  </code></pre>
  <p>So, good intentions, but doesn't seem to actually work.</p>
  <hr />
  <p>No, of course not expecting to run it every frame, but don't want it causing hiccups when it does run, is all.  With my thought of synthesizing X events, I was imagining it would be just often enough to make the screen saver think there was activity.</p>
  <p>Looking at xdg-screensaver (which seems to be a shell script that ultimately just does a &quot;wait&quot; for my process -- cool) it seems to be made to do just what I want.  I knew I couldn't be the only or first one to face this problem.</p>