Archive:
Subtopics:
Comments disabled |
Wed, 27 Jul 2016
Controlling KDE screen locking from a shell script
Lately I've started watching stuff on Netflix. Every time I do this, the screen locker kicks in sixty seconds in, and I have to unlock it, pause the video, and adjust the system settings to turn off the automatic screen locker. I can live with this. But when the show is over, I often forget to re-enable the automatic screen locker, and that I can't live with. So I wanted to write a shell script:
Then I'll run the script in the background before I start watching, or at least after the first time I unlock the screen, and if I forget to re-enable the automatic locker, the script will do it for me. The question is: how to write straceMy first idea was: maybe there is actually an So I tried running System Settings under It wasn't, and the trace was 93,000 lines long and frighting. Halfway
through, it stopped recording filenames and started recording their
string addresses instead, which meant I could see a lot of calls to
The first thing the cloned process did was to call
And then I felt like an ass because, of course, everyone knows all about the robust futex list, duh, how silly of me to have forgotten ha ha just kidding WTF is a futex? Are the robust kind better than regular wimpy futexes? It turns out that Ingo Molnár wrote a lovely explanation of robust futexes which are actually very interesting. In all seriousness, do check it out. I seem to have digressed. This whole section can be summarized in one sentence:
Sorry, Julia! Stack ExchangeThe next thing I tried was Google search for
When I saw this, it was like a new section of my brain coming on line. So many things that had been obscure suddenly became clear. Things I had wondered for years. Things like “What are these horrible
messages that KDE apps are always spewing into my terminal?” But now the light was on. KDE is built atop a toolkit called Qt, and Qt provides an interprocess
communication mechanism called “D-Bus”. The Often these sorts of address hierarchies work well in theory and then
fail utterly because there is no way to learn the secret names. The X
Window System has always had a feature called “resources” by which
almost every aspect of every application can be individually
customized. If you are running In theory these secret names are documented somewhere, maybe. In
practice, they are not documented anywhere. you can only extract them
from the source, and not only from the source of D-Bus has a directoryHowever! The authors of Qt did not forget to include a directory mechanism in D-Bus. If you run
you get a list of all the addressable services, which you can grep for
suggestive items, including
you get a list of all the objects provided by the
and get a list of all the methods that can be called on this object, and their argument types and return value types. And you see for example
and say “I wonder if that will lock the screen when I invoke it?” And then you try it:
and it does. That was the most important thing I learned today, that I can go
wandering around in the When I was first learning Unix I used to wander around in the filesystem looking at all the files, and I learned a lot that way also.
Later I learned (by browsing in The right secret namesEverything after this point was pure fun of the “what happens if I
turn this knob” variety. I tinkered around with the
method which someone should be calling, because that's evidently what you call if you are a program playing a video and you want to inhibit the screen locker. But the unknown someone was delinquent and it wasn't what I needed for this problem. Then I moved on to the
which wasn't quite what I was looking for either, but it might do: I
could perhaps modify the configuration and then invoke this method. I
dimly remembered that KDE keeps configuration files under
among other things. I hand-edited the file to change the
and then opened up the System Settings app. Sure enough, the System
Settings app now reported that the lock timeout setting was “4
minutes”. And changing The answerSo the script I wanted turned out to be:
Problem solved, but as so often happens, the journey was more important than the destination. I am greatly looking forward to exploring the D-Bus hierarchy and sending all sorts of inappropriate messages to the wrong objects. Just before he gets his ass kicked by Saruman, that insufferable know-it-all Gandalf says “He who breaks a thing to find out what it is has left the path of wisdom.” If I had been Saruman, I would have kicked his ass at that point too. AddendumRight after I posted this, I started watching Netflix. The screen locker cut in after sixty seconds. “Aha!” I said. “I'll run my new script!” I did, and went back to watching. Sixty seconds later, the screen
locker cut in again. My script doesn't work! The System Settings app
says the locker has been disabled, but it's mistaken. Probably it's only
reporting the contents of the configuration file that I edited, and
the secret sauce is still missing. The System Settings app does
something to update the state of the locker when I click that “Apply”
button, and I thought that my I'll figure this out, but maybe not today. Good night all! [ Addendum 20160728: I figured it out the next day ] [ Addendum 20160729: It has come to my attention that there is
actually a program called [Other articles in category /Unix] permanent link |