I'm using manjaro linux with dwm (dynamic window manager) and I need to run some some commands that will only work after the x display server has been started. Lightdm is being used to login.

example commands:

/usr/bin/xrandr --output eDP1 --auto --right-of HDMI1
/usr/bin/xset r rate 280 40

I've tried adding these to ~/.xinitrc, /etc/X11/xinit/xinitrc, crontab with a delay and ~/.xsession

Placing them in ~/.xession did run them but then only the wallpaper loads and the window manager is never started.

Putting them in the user's crontab gave output such as this: Can't open display

xset: unable to open display ""

ERROR: QtFatal: This application failed to start because no Qt platform plugin could be initialized.

Where is the appropriate place to put commands such as these?


LightDM is the program which starts your X display server (hence "display manager"), so the commands should be in a place that LightDM looks in. (The other good alternative is using your window manager "autostart" script if it has one – but unfortunately dwm doesn't.)

For LightDM, ~/.xsession is a good place, but note that it is run synchronously – that is, your session only gets started after the xsession script ends. So if you want to start any long-running commands, you must run them "in background" with the & operator:

/usr/bin/copyq &

GDM instead uses ~/.xprofile in the same way.

Scripts can also be placed in /etc/X11/xinit/xinitrc.d/* with the same requirements.

~/.xinitrc is similar, but it is typically not used by display managers; only startx and SDDM read it, while other DMs find the session configuration in /usr/share/xsessions instead. Additionally, xinitrc also has the job of starting the actual session – i.e. it needs to invoke dwm at the very end.

  • Thank you so much! I was getting really frustrated. I should have thought of putting them in the background.
    – alrob
    Dec 9 '20 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.