Forum > Linux
Suspending a screensaver
(1/1)
MarkMLl:
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
MarkMLl:
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
Hartmut:
--- Quote from: MarkMLl on February 23, 2023, 07:22:50 pm ---Is there a reliable way that an app can get its Window ID via the LCL?
--- End quote ---
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.
--- End quote ---
On Linux I use this way to disable the screensaver, when called periodically:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure noStandby; const d: integer = 0; {'0' works in Ubuntu 18.04, otherwise use '1'} var MP: TPoint; begin MP:=Mouse.CursorPos; inc(MP.x,d); inc(MP.y,d); Mouse.CursorPos:=MP; d:=-d; Application.ProcessMessages; end;
HTH
MarkMLl:
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
Navigation
[0] Message Index