xfce4-session launched from .xinitrc, clobbers xrandr settings

Zenaan Harkness zen at freedbms.net
Mon Jul 31 12:24:36 CEST 2017

Does anyone here launch xfce4 from .xinitrc, or from console?

xfce4-session clobbers xrandr settings when run from .xinitrc (via
.xinit from Linux console).

When starting from console, I know the monitor layout I want, and
don't like the delay (and blanking between changes) of having to
manually re-run my preferred layout script, so I'd like xfce4 to
respect my "current" monitor layout as set by xrandr just prior to
launching the xfce4 desktop - is this possible?


Further details:

After running a few tests, it seems that xfce4 has its own idea of
the "current monitor configuration" and imposes this on each session

This kind of makes sense - normally one wants to begin a new xfce4
login with the same monitor configuration/layout as the previous

Although sometimes that's not possible due to disconnection of
monitors (common case when moving a laptop around, and where only one
of the normal laptop locations has one or more external monitors).

I have scriptified my xrandr settings, so that I can relatively
easily configure keyboard shortcuts to swap between different monitor
configurations/ layouts.

But .xinitrc is my ultimate startup script, not the opaque binary
known as xfce4-xsession - even though I have to run this from
.xinitrc to get my xfce4 desktop.

Good News ----------- xfce4-session respects other ".xinitrc"
environment without clobbering:
 - does not clobber .Xresources/xrdb loaded settings
 - does not clobber current keyboard repeat rate (actually not
   entirely sure, I may not be properly testing this one)
 - environment vars ARE passed through (very handy!)

Bad News ---------- xrandr configuration is clobbered.

Potential other preference: respect setting of root window, e.g.
xsetroot -gray -mod 5 5 # not very important

This custom randr script is necessary for me to use - to e.g.
establish some params for potential future xterm launches - another,
dynamic, script, which lays out arbitrary xterms based on "current"
monitor resolutions and of course orientations and offsets. Have not
yet coded a script to dynamically determine number of monitors and
their current rotation and offsets relative to one another, so I have
to decide in advance what I want, and pack various env vars, then run
xrandr, so that later I have the -full- parameters of the current
monitor layout.

Also, scripting randr means I can more easily get precise monitor
offsets (e.g. monitor 1 at y=646), which is useful to cause mouse
movement between monitors to line up properly.

Here's my environment:
 - Debian Stretch/9
 - Linux 4.9.0-3-amd64
 - oldish Core2Duo laptop
 - two external monitors, each same size
 - one monitor I normally rotate

Steps to reproduce evidencing this limitation:

1) login to Linux console

2) set env vars, init xauth, assemble and launch xinit e.g.:

# "mystartx"
export XDG_... env vars ...
export DESKTOP_SESSION="xfce"
which xdg-user-dirs-update >/dev/null 2>&1 && xdg-user-dirs-update

export XAUTHORITY="$HOME"/.Xauthority
xserverauthfile=`mktemp --tmpdir serverauth.XXXXXXX`
xauth -q -f ...

# This is the important line:
xinit $HOME/.xinitrc -- /usr/bin/X :0 vt1 -keeptty \
 -logverbose 5 -auth $xserverauthfile

3) here's ~/.xinitrc :

xrdb -load $HOME/.Xresources # these are not clobbered by xfce
xsetroot -gray -mod 5 5 # this is clobbered
 eval `dbus-launch --sh-syntax`
 dbus-update-activation-environment --systemd DBUS_SESSION_BUS_ADDRESS
dbus-update-activation-environment --systemd DISPLAY XAUTHORITY
# disable laptop internal monitor:
xrandr --output LVDS-1 --off
# enable two external monitors:
xrandr --verbose --output DP-1 --pos 0x646 --mode 1920x1200 --rotate \
 normal --output DP-2 --pos 1920x0 --mode 1920x1200 --rotate left

#exec xterm -geometry 80x60+0+646 # this alternative runs successfully

# this alternative clobbers xrandr layout, disabling second monitor:
exec ck-launch-session xfce4-session

More information about the Xfce mailing list