From 2289712638b1d355aae30aadda2ff2a3db02b1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Fri, 11 Jun 2021 23:32:56 +0200 Subject: [PATCH] Better usage of .xsession / .xinitrc I guess --- config/shell/shenv | 3 +- config/xinitrc | 93 ++++++++++++++++++++++++++++++++++++++++++++-- xsession | 88 +++---------------------------------------- 3 files changed, 96 insertions(+), 88 deletions(-) diff --git a/config/shell/shenv b/config/shell/shenv index 184ee5d..151385c 100644 --- a/config/shell/shenv +++ b/config/shell/shenv @@ -49,7 +49,8 @@ export VIMINIT="source $MYVIMRC" direnv WINEPREFIX "$HOME/.cache/wineprefix/default" direnv YARN_CACHE_FOLDER "$HOME/.cache/yarn" export YARN_DISABLE_SELF_UPDATE_CHECK=true # This also disable the creation of a ~/.yarnrc file -export XAUTHORITY="$HOME/.config/Xauthority" +# Disabled since this causes lockups with DMs +# export XAUTHORITY="$HOME/.config/Xauthority" # And for the rest, see aliases direnv JUNKHOME "$HOME/.cache/junkhome" diff --git a/config/xinitrc b/config/xinitrc index 44fda3d..03e7cbe 100755 --- a/config/xinitrc +++ b/config/xinitrc @@ -2,8 +2,10 @@ # # ~/.xinitrc # -# Executed by xinit (startx) +# Executed by startx +# +# Execute system modules, just in case if [ -d /etc/X11/xinit/xinitrc.d ]; then for f in /etc/X11/xinit/xinitrc.d/*; do [ -x "$f" ] && . "$f" @@ -11,8 +13,91 @@ if [ -d /etc/X11/xinit/xinitrc.d ]; then unset f fi -[ -f /etc/xprofile ] && . /etc/xprofile -[ -f ~/.xprofile ] && . ~/.xprofile +# Load Xresources +[ -f ~/.config/Xresources/main ] && xrdb -I"$HOME" ~/.config/Xresources/main -[ -f ~/.xsession ] && . ~/.xsession +# Disable the bell +xset b off + +# Folders to search for desktop environments (DE) in +sessions_dirs="/usr/share/xsessions" + +# If we have locally installed DE try them before system ones +sessions_dir_local="$HOME/.local/share/xsessions" +if [ -d "$sessions_dir_local" ] +then + sessions_dirs="$sessions_dir_local $sessions_dirs" +fi + +# If we have junest installed DE try them before all others +sessions_dir_junest="$HOME/.local/share/xsessions" +if [ -d "$sessions_dir_junest" ] +then + sessions_dirs="$sessions_dir_junest $sessions_dirs" +fi + +startSession() { + session_dir="$1" + session_name="$2" + + session_file="${session_dir}/${session_name}.desktop" + executable="$(grep ^Exec= "$session_file" | cut -d'=' -f2)" + # TODO Does this work with parameters? + # gnome-classic might need some + + # If this is a Junest DE, we need to wrap it + if [ "$sessions_dir" = "$sessions_dir_junest" ] + then + # Some DMs enforce that to you, + # which shows warning on Junest + unset LD_PRELOAD + + # The intended way: + # exec ~/.local/bin/junest "$executable" $parameters + # Too restricted to the outside (e.g. Yubikey isn't accessible) + + # The custom way + exec ~/.local/bin/junest --backend-args "--dev-bind /run /run" "$executable" $parameters + + # The fallback wrappers way + # export PATH="$PATH:~/.junest/usr/bin_wrappers" + # exec "$executable" $parameters + # Should work but doesn't, I forgot why + + # The "I do what I want" way + #exec bwrap --bind $HOME/.junest / --bind $HOME $HOME --bind /tmp /tmp --proc /proc --dev-bind /dev /dev --dev-bind /run /run "$executable" $parameters + # Even Alacritty doesn't work here + + fi + + exec "$executable" $parameters +} + +trySession() { # session_name + session_name="$1" + for sessions_dir in $sessions_dirs + do + session_file="$sessions_dir/${session_name}.desktop" + if [ -f "$session_file" ] + then + startSession "$sessions_dir" "$session_name" + fi + done +} + +if [ -n "$1" ] +then + trySession "$1" +else + trySession i3 + trySession xfce4 + trySession mate + trySession plasma + trySession gnome + trySession kde +fi + +# If we found nothing by then, RIP +echo "Couldn't find a suitable DM." +exit 1 diff --git a/xsession b/xsession index a728d42..91b527a 100755 --- a/xsession +++ b/xsession @@ -6,88 +6,10 @@ # Sourced by display managers # -# Load Xresources -[ -f ~/.config/Xresources/main ] && xrdb -I"$HOME" ~/.config/Xresources/main - -# Disable the bell -xset b off - -# Folders to search for desktop environments (DE) in -sessions_dirs="/usr/share/xsessions" - -# If we have locally installed DE try them before system ones -sessions_dir_local="$HOME/.local/share/xsessions" -if [ -d "$sessions_dir_local" ] +. ~/.xprofile +if [ -f ~/.config/override_dm_choice ] then - sessions_dirs="$sessions_dir_local $sessions_dirs" + . ~/.config/xinitrc +else + . ~/.config/xinitrc $@ fi - -# If we have junest installed DE try them before all others -sessions_dir_junest="$HOME/.local/share/xsessions" -if [ -d "$sessions_dir_junest" ] -then - sessions_dirs="$sessions_dir_junest $sessions_dirs" -fi - -startSession() { - session_dir="$1" - session_name="$2" - - session_file="${session_dir}/${session_name}.desktop" - executable="$(grep ^Exec= "$session_file" | cut -d'=' -f2)" - # TODO Does this work with parameters? - # gnome-classic might need some - - # If this is a Junest DE, we need to wrap it - if [ "$sessions_dir" = "$sessions_dir_junest" ] - then - # Some DMs enforce that to you, - # which shows warning on Junest - unset LD_PRELOAD - - # The intended way: - # exec ~/.local/bin/junest "$executable" $parameters - # Too restricted to the outside (e.g. Yubikey isn't accessible) - - # The custom way - exec ~/.local/bin/junest --backend-args "--dev-bind /run /run" "$executable" $parameters - - # The fallback wrappers way - # export PATH="$PATH:~/.junest/usr/bin_wrappers" - # exec "$executable" $parameters - # Should work but doesn't, I forgot why - - # The "I do what I want" way - #exec bwrap --bind $HOME/.junest / --bind $HOME $HOME --bind /tmp /tmp --proc /proc --dev-bind /dev /dev --dev-bind /run /run "$executable" $parameters - # Even Alacritty doesn't work here - - fi - - exec "$executable" $parameters -} - -trySession() { # session_name - session_name="$1" - for sessions_dir in $sessions_dirs - do - session_file="$sessions_dir/${session_name}.desktop" - if [ -f "$session_file" ] - then - startSession "$sessions_dir" "$session_name" - fi - done -} - -if [ -n "$1" ] -then - trySession "$1" -fi -trySession i3 -trySession xfce4 -trySession mate -trySession plasma -trySession gnome -trySession kde - -# If we found nothing by then, -# I guess it's up to the DM to default to something