You are not logged in.

#1 2024-01-31 21:34:07

Luviz
Member
Registered: 2024-01-31
Posts: 2

automating xrandr using systemd

Hi. today I added a new feature to my OS xrandr-auto and xrandr-move-disp. these two commands now allow me to use my luncher (rofi) auto connect to displays and then move the display around.
However when I showed my colleges (windows and mac users), they where like; really do have to run a command to connect you display...

- I mean n00bs right... I mean it's not like their OS:es are just magically connect there displays...

Anyhow, I thought that at least run `xrandr --auto`  on display device changed, so I started googling, but didn't find anything good. **if you know of any good articles please link me**
(NOTE: that I'm running a laptop and have a very flexible platform, I want to able to connect any display and have my os to setup the best connection possible)

After failing on google, I turned to Chat-GPT, it recommend my to add an udav rule to trigger on display change

ENV{HOTPLUG}=="1", RUN+="/bin/systemctl start display-hotplug.service"

and then write a systemd unit to execute the command.

And that worked I could see the unit triggering when I connect and disconnect my HDMI port (I also need support for usb-c). the issue began when I change the exec start to "ExecStart=/usr/bin/xrandr --auto" then I got error. I wasn't able to get anything good from the journal either.

At this point I know that my knowledge on arch comes to an end, so here I'm asking you for help to one up dose windows users and mac users who is actually the boss of Operative systems!

With kind regards
Bardia "Luviz" Jedi!
(yeah that is my name!)

##  xrandr-move-disp
#!/bin/bash

function sel_disp {
    xrandr --listactivemonitors | tail +2 |\
      rofi -dmenu -p "Select Display" -l 4 |\
      awk '{print $NF}'
}

options="above|left|below|right"
opt_count=4

disp_one="$(sel_disp)"
option=$(echo "$options" | rofi -dmenu -i -sep "|" -l $opt_count -i)
disp_two="$(sel_disp)"

case $option in
    "above")
        xrandr --output $disp_one --above $disp_two
    ;;
    "below")
        xrandr --output $disp_one --below $disp_two
    ;;
    "left")
        xrandr --output $disp_one --left-of $disp_two
    ;;
    "right")
        xrandr --output $disp_one --right-of $disp_two
    ;;
esac

Last edited by Luviz (2024-01-31 21:39:15)

Offline

#2 2024-01-31 22:11:37

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

Re: automating xrandr using systemd

After failing on google, I turned to Chat-GPT, it recommend my to add an udav rule to trigger on display change

And another proof that the thing is dumb as fuck.
1. it forgot to tell you that you need to import some environment variables and should change the user to whoever is currently controlling the X11 authority, https://gist.github.com/AladW/de1c5676d93d05a5a0e1
2. it could have linked you https://aur.archlinux.org/packages/x-on-resize

Please stop asking this bullshit generator questions, use it to write better starwars scripts than disney or whatever.

Offline

#3 2024-02-02 08:54:10

Luviz
Member
Registered: 2024-01-31
Posts: 2

Re: automating xrandr using systemd

seth wrote:

After failing on google, I turned to Chat-GPT, it recommend my to add an udav rule to trigger on display change

And another proof that the thing is dumb as fuck.
...
Please stop asking this bullshit generator questions, use it to write better starwars scripts than disney or whatever.

Yeah and this is an area where, I don't lack some experience, them damn thing drives my nuts in areas where I'm an expert. However the damn thing is usually very good at getting me to the right areas, in this case I think the issue is more with the scope of linux.

I was look for hours for a blog or a form that covered this title, and it dos't help where a good portion of the Linux community hate systemd.

But thank I'll read the link, and will try to summarize me results here for the next lost sole.

Thank you
L

Offline

Board footer

Powered by FluxBB