Recent

Author Topic: Suspending a screensaver  (Read 821 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Suspending a screensaver
« on: February 23, 2023, 07:22:50 pm »
I've got a program here which will be controlled via Telnet rather than a local keyboard etc., basically it's for calibrating a particular kind of display.

In order to keep it running usefully, it's necessary to disable the screensaver.

I've been playing with various things relating to the X11 screensaver etc., noting that this is not necessarily what's being used by a modern desktop environment. In practical terms, I think that the only moderately-reliable way of controlling the screensaver of by way of xdg-screensaver, which typically knows about different window managers etc.

xdg-screensaver needs the numeric Window ID of the application window. I can get this by running xwininfo with the window name as the parameter, but this can get messed up if e.g. the IDE is also running and the window name gains a numeric suffix.

Is there a reliable way that an app can get its Window ID via the LCL?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Suspending a screensaver
« Reply #1 on: February 24, 2023, 11:58:57 am »
I've been having a play from the command line, on the assumption that even if slow this is something that only needs to be done at- or shortly after- program startup. If I were doing this in anger I'd expect the relevant functions to be available via xlib or extensions.

A complete list of windows may be obtained using e.g.

xwininfo -tree -root | less

A name pattern may be searched from this, hence e.g.

0x520000c "Untitled * — Kate"

The window info may be obtained e.g.

xwininfo -id 0x520000c

The name may be verified (even if the WM has appended a numeric suffix) and PID (assuming this is local etc.) obtained by reading X11 atoms:

xprop -id 0x520000c    WM_NAME    _NET_WM_PID

Hence the screensaver may also be suspended

xdg-screensaver suspend 0x520000c

It's obviously somewhat roundabout, but assuming that the X Server and app are running on the same host it does provide a way to unambiguously associate a process with the window being used for output, even if the LCL and widgetset do their best to be in the way.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Hartmut

  • Hero Member
  • *****
  • Posts: 751
Re: Suspending a screensaver
« Reply #2 on: February 24, 2023, 06:12:07 pm »
Is there a reliable way that an app can get its Window ID via the LCL?

When I needed this function, I did not find a way via the LCL. I installed 'xdotool' for that. With

xdotool search --onlyvisible --pid <PID>

you get a list of all Window-ID's which have a certain PID.

If your program is a console program, you must search for the Parent-PID of your program (if your program was started e.g. via /home/<user>/.config/autostart/) or for the Grand-Parent-ID of your program (if your program was started manually in a console).

If you need help finding the PID / Parent-PID of a program, let me know (but I think you know this better then me).

Quote
In order to keep it running usefully, it's necessary to disable the screensaver.

On Linux I use this way to disable the screensaver, when called periodically:

Code: Pascal  [Select][+][-]
  1. procedure noStandby;
  2.    const d: integer = 0; {'0' works in Ubuntu 18.04, otherwise use '1'}
  3.    var MP: TPoint;
  4.    begin
  5.    MP:=Mouse.CursorPos;
  6.    inc(MP.x,d);
  7.    inc(MP.y,d);
  8.    Mouse.CursorPos:=MP;
  9.    d:=-d;
  10.    Application.ProcessMessages;
  11.    end;

HTH

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Suspending a screensaver
« Reply #3 on: February 24, 2023, 06:32:16 pm »
Thanks, I'd forgotten xdotool. As it is I've just had a "fun" session writing a parser for the list output that does the same and can take a windowname pattern regex into account, and which I /think/ will work without anything special being installed (xdotool isn't in Debian by default). I'm happy to post it if anybody's interested.

One thing that's come out of it is that even if xdg-screensaver isn't installed/available it appears to be well-enough written to be portable: I've just moved a copy from Debian "Bookworm" all the way to my old "Lenny"-based laptop and the suspend/resume operations are fine even though status testing doesn't appear to work.

I also had a session yesterday with the xlib extension that in principle controls a screensaver, but I suspect that that relates /only/ to the X11 screensavers rather than to anything provided by a desktop environment.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018