You are not logged in.

#1 2014-08-31 19:16:18

ThePacman
Member
From: Classified
Registered: 2013-09-19
Posts: 127

[SOLVED] File to run on X logout?

I'm trying to find a way to set my dual-monitor setup to automatically "separate" the monitors (place them diagonally with xrandr) when I log in, but then make it go back to "mirrored mode" when I log out.
I could use a little help with the bash scripting to use an if loop to detect whether the second monitor is present at when I log in, but the main point of this post is to find out how to run a command when I log out.
Does anyone know of a ~/.xlogout file or something similar? I'm running Xfce/LXDM, and I'd be fine with something DE-specific.

Last edited by ThePacman (2014-09-01 20:57:44)


Fedora believes in "software freedom" - that is, restricting user software choices to those deemed appropriately licensed by The Powers That Be.
Arch believes in "freedom", as well - the user has control over his or her system and can do what he wants with it.
https://fedoraproject.org/wiki/Forbidden_items | https://wiki.archlinux.org/index.php/The_Arch_Way

Offline

#2 2014-08-31 19:55:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,349
Website

Re: [SOLVED] File to run on X logout?

I haven't used any display managers in a *long* time, but they run some file to launch your window manager.  Some may run ~/.xinitrc, some may use something like ~/.xsession instead, but in any case, a script file is called that contains your window manager.  So just add the commands to that file.  For example, an xinitrc excerpt:

xrandr | grep -q "VGA1 connected" && xrandr --output LVDS1 --auto --output VGA1 --auto --below LVDS1

startxfce4

xrandr | grep -q "VGA1 connected" && xrandr --output LVDS1 --auto --output VGA1 --auto --right-of LVDS1

The first line is directly out of my xinitrc as I use it.  You'd have to edit it to set the coordinates where you want the second screen.  But the last line should work as is.  The idea is that it checks if the external monitor is connected, and if it is it sets a screen layout.  Then it starts the window manager.  When the window manager exits, it again checks if an external screen is connected and sets a different layout if it is.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2014-09-01 20:57:15

ThePacman
Member
From: Classified
Registered: 2013-09-19
Posts: 127

Re: [SOLVED] File to run on X logout?

Okay, I found them.

The file that I needed to add it to was ~/.xprofile.. ~/.xinitrc is in charge of starting the window manager, and ~/.xsession just starts a login shell and executes ~/.xinitrc, so those only get run when selecting the custom of default session from the display manager. ~/.xprofile is always executed by DMs and is used for just this sort of thing.

And the logout script I needed to set LXDM's xrandr settings was /etc/lxdm/PostLogout

Here's what I ended up using, in case anyone wants to use it as a template wink

#!/bin/sh

#
# ~/.xprofile
#

if [ -n "$(xrandr | grep 'DVI-0 connected')" ] \
&& [ -n "$(xrandr | grep 'VGA-0 connected')" ]; then
        . ~/.screenlayout/DualDiagonal.sh
else
        . ~/.screenlayout/Mirrored.sh
fi

DualDiagonal.sh (Generated by ARandR, which I highly recommend, especially for multihead displays since it gets everything working out of the box with just the video drivers and xrandr):

#!/bin/sh
xrandr --output VGA-0 --mode 1280x1024 --pos 0x0 --rotate normal --output DIN --off --output DVI-0 --mode 1280x1024 --pos 1280x1024 --rotate normal

and Mirrored.sh:

#!/bin/sh
xrandr --output VGA-0 --mode 1280x1024 --pos 0x0 --rotate normal --output DIN --off --output DVI-0 --mode 1280x1024 --pos 0x0 --rotate normal

And I set up /etc/lxdm/PostLogout.sh with the same command that Mirrored.sh contains.


Fedora believes in "software freedom" - that is, restricting user software choices to those deemed appropriately licensed by The Powers That Be.
Arch believes in "freedom", as well - the user has control over his or her system and can do what he wants with it.
https://fedoraproject.org/wiki/Forbidden_items | https://wiki.archlinux.org/index.php/The_Arch_Way

Offline

Board footer

Powered by FluxBB