ArchLabs Linux

Desktop Resolution Weird Issue

Hello everyone, I was wondering if someone could help me correct this stupid issue I am having. Well its really not an issue, its more annoying, ok let me explain.

ISSUE:
So when I login my primary monitor does not get set, I have to rerun the script once more and woila, primary monitor gets set…which leads me to believe its not the script but how I have it running/autostarting

So I set my desktop resolution though a script:

#!/bin/zsh

xrandr --output DP-0 --mode 1920x1080 --rate 240 --pos 0x0 --output DP-4 --primary --mode 1920x1080 --rate 240 --pos 1920x1080+0+0 --right-of DP-0

exit 0

I’ve made it hidden in my home folder but appending a . at the beginning of the filename and I have added it to BOTH my autostart file for openbox which looks like this:

# compton
al-compositor --start &

# enable numlock, commented out for laptop users
# numlockx &

# restore wallpaper
nitrogen --restore &

# required for xfce settings to work
xfsettingsd &

# fancy window switcher
skippy-xd --config ~/.config/skippy-xd/skippy-xd.rc --start-daemon &

# desktop resolution
~/.desktopres.sh &

# start polybar
al-polybar-session &

#start plank
plank &

#XFCE Power manager
xfce4-power-manager &

and like I said I also added the file to my autostart folder, which I think gets run once I login…but again for some strange reason, which I cant seem to figure out is that it doesnt set the primary monitor until I run the script once more in the terminal and within less than a milisecond it completes. I rerun xrandr, and see that my primary has been set…

If anyone can help me, I would really REALLY appreciate it!

Thanks,

Just to be sure, you made the script executable right?

It might just be executing too fast I’m not sure, to test you can wrap it in a subshell and sleep for a bit first, eg.

( sleep 5; ~/.desktopres.sh ) &

You could also just cut out the middleman and run the xrandr command there instead. Generally with xrandr commands I put them in ~/.xinitrc but it depends how you’re logging in.


Side question, do you really have 240Hz monitors?

1 Like

Hey, sorry been busy with work and hadn’t had a chance to login to the forum. Yes I made the script executable. I will need to play around with the sleep option as I think that may work. I had also configured my autostart to run it twice before but that didn’t help in the past. Unfortunately I dont have xinitrc, i’m using lightdm. Lastly, yes, I have 2x240hz monitors and absolutely love them. I use to have 144hz ones before, just recently got these bad boys! This is my first 240hz monitor/s and I wasn’t sure if I would see a difference, but you definitely notice it, everything is just a bit smoother. Its great for gaming, which I love to do as well :smiley:

You can put the xrandr command in ~/.xprofile, lightdm and most DMs source it when logging in.

Damn, I bet it’s smooth lol, I used to run 144hz as well but decided to go for 4k in a recent upgrade instead.

1 Like

Thanks mate, I’ve literally havent even messed with it. I will try your suggestions though and place my xrandr command in .xprofile! I love 4k but the refresh rate is just a bummer, and Im not willing to pay $1700 for 4k at 120hz, thats just cray cray! Anyways, Im actually quite happy with 1080p at 240hz, dont miss 4k or higher res at all!

Cheers

On a side note, have you ever messed around with artix linux?? I was messing around with void for a bit, but I’m not sure I want to go down the path of learning another package manager especially considering how well pacman works. Artix is Arch based but uses runit instead of openrc/systemd / sysv…

Let me know your thoughts…sorry totally unrelated to this topic…

Nah, I’ve been using the same arch install for years and I don’t see a need to switch.

@natemaia Hey I just wanted to say thank you again for helping me with this ‘issue’. I tried the sleep option within my autostart and that seemed to do the trick!

I do have one other question, sort of related, whats the difference between separating commands with ; and &?? I know that to make a program run in the background you provide this &&, but wasnt sure about the other two. So I think if I use & between my commands, it runs them parallel without waiting for one to finish, but if I use ; it runs them consecutively/sequentially, right??

Thanks for your insights and guidance, I really appreciate them!!!

Cheers

Not to derail the thread or anything, but can xrandr be set up as a systemd service so the resolution gets set at boot time?

Essentially in shell there’s 4 command separators ;, &, &&, and ||

  • & executes the preceding command in the background in a subshell, the shell doesn’t wait for exit status and continues execution.

  • ; just acts as a delimiter to commands same as a newline would, it does not affect control flow and will execute whatever comes after it regardless of the exit status of the previous command (when used on the same line)

  • && is basically a short-circuit if, meaning it will execute the right side of && if the left side’s exit status was zero (success)

  • || is a negation of &&, meaning the right will get executed when the left exits non-zero (failure)

Try them out yourself

false & true
false; echo true
true && echo true
false || echo false

I won’t get into it here as it get’s a bit complex for an intro but it’s important to understand that

test && command1 || command2

is not the same as

if test; then command1; else command2; fi

There are ways of making it so but like I said I’ll keep it simple.

Hope that makes sense, this site has a nice breakdown of short circuiting in shell
http://wresch.github.io/2014/04/24/bash-short-circuit-evaluation.html


& when used after a command will be executed in the background, in a subshell. From the bash manpage

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. These are referred to as asynchronous commands. Commands separated by a ; are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed.

You can learn more by reading the shell grammar section of the bash manpage.

3 Likes