You are not logged in.

#1 2022-09-29 16:27:18

Karl_Yeurl
Member
Registered: 2011-02-28
Posts: 30

Run script when a specific screen is plugged in

Hello,

I would like to set up something which, upon plugging a specific external screen through HDMI, will "do stuff", and I'm not quite sure what the idiomatic way of doing that is.
(Here's what I'm actually trying to achieve: when I plug in a specific monitor (the one on my desk), some xrandr command is run. When I plug in a monitor that isn't the one on my desk, nothing happens.)

Here's what I tried:
As I've been using udev triggers to set the compose key only for specific keyboards, I looked into udev, but either I'm missing something obvious, or udev does not handle USB and HDMI devices in a comparable way. With USB, one can leverage udev attributes such as ATTR{idVendor} and ATTR{idProduct} to distinguish between different USB keyboards, but HDMI seems to not expose that kind of information, only "something has been plugged in/out" (the "drm change" events).

I could go ahead and make a shell script that is triggered on "drm change" events and handles the rest through other userspace commands to figure out if it was indeed my screen that was plugged in/out, but I feel like that isn't the "correct" way of getting that to work.

Can someone guide me towards the appropriate mechanism I should hook myself to in order to do what I want?

Thanks in advance,

Last edited by Karl_Yeurl (2022-09-29 16:27:47)

Offline

#2 2022-09-29 19:39:52

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,485

Offline

#3 2022-09-30 08:15:12

Karl_Yeurl
Member
Registered: 2011-02-28
Posts: 30

Re: Run script when a specific screen is plugged in

Thanks. Quickly browsing the x-on-resize code, it seems to be pretty much doing what I described I could do (there's a script that is triggered on a "something changed" event, and the userspace `xrandr-auto` script figures out what should actually be done with the existing screens), the only difference with what I considered is that I would trigger off of drm change udev events whereas that program listens to ConfigureNotify X events, and happens to be an additional daemon.

This leads me to think that there might be no "right way" of figuring out that "a new screen has been plugged in, here's the screen's unique ID, do whatever you want with it".

Last edited by Karl_Yeurl (2022-09-30 08:16:01)

Offline

#4 2022-09-30 11:24:19

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,485

Re: Run script when a specific screen is plugged in

If you only care about X11 ("Here's what I'm actually trying to achieve: when I plug in a specific monitor (the one on my desk), some xrandr command is run.") x-on-resize operates on the proper abstraction level and the dameon was written for that exact purpose.

For udev monitor change events on the drm subsystem for the relevant card, see eg. https://bbs.archlinux.org/viewtopic.php … 4#p1584974
This will work w/ most drivers (as pretty much everything supports drm), but not eg. virtual outputs in X11.
The usual trap is that the xrandr script lacks the DISPLAY and AUTHORITY context.

Offline

#5 2022-09-30 12:40:56

Karl_Yeurl
Member
Registered: 2011-02-28
Posts: 30

Re: Run script when a specific screen is plugged in

Thanks for the pointers and answers! I don't necessarily only care about X11, but x-on-resize is well-worth exploring as, for now, I am not planning on switching to something else than X11.

Have a good day!

Offline

Board footer

Powered by FluxBB