#X11 #programming #tales – the magic pager powers! 🤩
There’s a general problem with windowing systems and desktop environments. You can do stuff with windows like, bring them to the front, activate them, move them to a different virtual desktop, and so on. That’s nice until something bad happens like a user accidentally typing sensitive stuff into a wrong window … or maybe just annoying the user.
So, windowing systems started to do things to prevent this. E.g. they just ignore something an application wants to do … or replace it with something different (hey, this window wants to be activated, let’s flash it in the taskbar instead).
But then, there are very valid usecases where e.g. bringing a window to the front is most likely exactly what the user wants. While implementing single-instance mode (which I plan to make optional of course!) in #Xmoji, I had such a usecase. So, the user only wants to have a single instance of that app running. Yet the user starts it again … 🤔 the natural expectation would be that the already running instance appears on the screen as if it was newly started, which is, of course, on top …
Well, enter #EWMH (which is used for communication with the window manager additionally to #ICCCM in all “modern” environments). They identified that pagers always have valid reasons to do anything to windows. So, they added a field to lots of requests, the “source identifier”, which must be set to 1
if the request is issued by a “normal” application, and to 2
if it is issued by a pager. Window managers are required to always obey the pager.
Now for the magic trick: What if we just tell the window manager “hey, I’m a pager”? Oh, I love it! 😂 (sudo make me a sandwich style, just better).
Of course that’s sarcasm. The initial problem just can’t be solved that way. It can only be solved in individual applications, that just shouldn’t do unexpected nonsense with their windows. 🙄
Side note: #Windows does it differently. An application on a windows desktop can only “self-activate” if the currently active application explicitly passes permission. That’s a lot more boring (I can’t just pretend something and make the desktop obey me 😞), but also doesn’t solve the problem. While I could certainly cover my usecase in Xmoji that way (I mean, the new instance can pass that permission to the already running one), I’m sure there are lots of other valid usecases for e.g. activating a window that just can’t be done on a Windows desktop…
Only slightly related: #fvwm gave me another thing to consider with its “pages” that aren’t virtual desktops (which fvwm can also handle), but an automatically managed larger viewport instead. I just added a commit implementing “bring to the current fvwm page”, by looking at the window’s position and comparing that to the size of the screen 🤔 …
https://github.com/Zirias/xmoji/commit/a3a041af7d41f901b8e795ccb93e8380f03da873
(@thomasadam@bsd.network does that look somewhat sane to you?)
Overall lots of stuff to do (some of that using the magical pager forces 😏) when a secondary instance is started:
puh … 🙈