From 08f30a96843a6ed687030a5cfeb69703cc7f7991 Mon Sep 17 00:00:00 2001
From: Luca Bilke <luca@snaile.de>
Date: Wed, 24 May 2023 16:53:44 +0200
Subject: [PATCH] use default xinit scripts again

---
 .config/X11/xinitrc                           |   7 +
 .config/X11/xinitrc.d/40display-setup         |   4 +
 .../X11/{xsession.d => xinitrc.d}/60gpg-agent |   2 +-
 .../X11/{xsession.d => xinitrc.d}/80autostart |   7 +-
 .../{xsession.d => xinitrc.d}/90xsecurelock   |   2 +-
 .../{xsession.d => xinitrc.d}/99host-setup    |   3 +-
 .config/X11/xsession                          | 125 ------------------
 .config/X11/xsession.d/20dbus_xdg-runtime     |  23 ----
 .config/X11/xsession.d/30x11-resources        |   3 -
 .config/X11/xsession.d/40display-setup        |   3 -
 .config/X11/xsession.d/50atk-adaptor          |  23 ----
 .config/X11/xsession.d/50qt-a11y              |   7 -
 .config/zsh/profile                           |   7 +-
 .local/bin/remaps                             |   4 +-
 .local/bin/startgraphical                     |  97 +-------------
 15 files changed, 23 insertions(+), 294 deletions(-)
 create mode 100644 .config/X11/xinitrc
 create mode 100755 .config/X11/xinitrc.d/40display-setup
 rename .config/X11/{xsession.d => xinitrc.d}/60gpg-agent (92%)
 mode change 100644 => 100755
 rename .config/X11/{xsession.d => xinitrc.d}/80autostart (82%)
 mode change 100644 => 100755
 rename .config/X11/{xsession.d => xinitrc.d}/90xsecurelock (97%)
 mode change 100644 => 100755
 rename .config/X11/{xsession.d => xinitrc.d}/99host-setup (84%)
 mode change 100644 => 100755
 delete mode 100755 .config/X11/xsession
 delete mode 100644 .config/X11/xsession.d/20dbus_xdg-runtime
 delete mode 100644 .config/X11/xsession.d/30x11-resources
 delete mode 100644 .config/X11/xsession.d/40display-setup
 delete mode 100644 .config/X11/xsession.d/50atk-adaptor
 delete mode 100644 .config/X11/xsession.d/50qt-a11y

diff --git a/.config/X11/xinitrc b/.config/X11/xinitrc
new file mode 100644
index 00000000..289fcd56
--- /dev/null
+++ b/.config/X11/xinitrc
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "$XDG_CONFIG_HOME/X11/xprofile"
+
+run-parts "$XDG_CONFIG_HOME/X11/xinitrc.d"
+
+exec dbus-run-session -- dwm
diff --git a/.config/X11/xinitrc.d/40display-setup b/.config/X11/xinitrc.d/40display-setup
new file mode 100755
index 00000000..120c85ce
--- /dev/null
+++ b/.config/X11/xinitrc.d/40display-setup
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# Any host specific display configuration goes here
+# This file is excluded from the dotsync script
diff --git a/.config/X11/xsession.d/60gpg-agent b/.config/X11/xinitrc.d/60gpg-agent
old mode 100644
new mode 100755
similarity index 92%
rename from .config/X11/xsession.d/60gpg-agent
rename to .config/X11/xinitrc.d/60gpg-agent
index bd340706..bac228ef
--- a/.config/X11/xsession.d/60gpg-agent
+++ b/.config/X11/xinitrc.d/60gpg-agent
@@ -1,4 +1,4 @@
-# vim:set ft=sh:
+#!/bin/sh
 
 if [ "${SSH_AUTH_SOCK:-0}" -ne $$ ]; then
     sock="$(gpgconf --list-dirs agent-ssh-socket)"
diff --git a/.config/X11/xsession.d/80autostart b/.config/X11/xinitrc.d/80autostart
old mode 100644
new mode 100755
similarity index 82%
rename from .config/X11/xsession.d/80autostart
rename to .config/X11/xinitrc.d/80autostart
index 6ec5ff59..52f36375
--- a/.config/X11/xsession.d/80autostart
+++ b/.config/X11/xinitrc.d/80autostart
@@ -1,14 +1,13 @@
-# vim:set ft=sh:
+#!/bin/sh
 
 start() {
 	pidof -sx $1 || $@ &
 }
 
 xwallpaper --zoom "${XDG_DATA_HOME:-$HOME/.local/share}/bg" &
-killall remaps
-remaps &
-checkup &
 
+start remaps
+start checkup
 start playerctld daemon
 start picom
 start unclutter -noevents
diff --git a/.config/X11/xsession.d/90xsecurelock b/.config/X11/xinitrc.d/90xsecurelock
old mode 100644
new mode 100755
similarity index 97%
rename from .config/X11/xsession.d/90xsecurelock
rename to .config/X11/xinitrc.d/90xsecurelock
index 9e36d3af..4f18cd64
--- a/.config/X11/xsession.d/90xsecurelock
+++ b/.config/X11/xinitrc.d/90xsecurelock
@@ -1,4 +1,4 @@
-# vim:set ft=sh:
+#!/bin/sh
 
 export XSECURELOCK_AUTH_BACKGROUND_COLOR="#24283b"
 export XSECURELOCK_AUTH_FOREGROUND_COLOR="#c0caf5"
diff --git a/.config/X11/xsession.d/99host-setup b/.config/X11/xinitrc.d/99host-setup
old mode 100644
new mode 100755
similarity index 84%
rename from .config/X11/xsession.d/99host-setup
rename to .config/X11/xinitrc.d/99host-setup
index 31b99fd6..afdc5a53
--- a/.config/X11/xsession.d/99host-setup
+++ b/.config/X11/xinitrc.d/99host-setup
@@ -1,3 +1,4 @@
-# vim:set ft=sh:
+#!/bin/sh
+
 # Any host specific configuration goes here
 # This file is excluded from the dotsync script
diff --git a/.config/X11/xsession b/.config/X11/xsession
deleted file mode 100755
index f383583c..00000000
--- a/.config/X11/xsession
+++ /dev/null
@@ -1,125 +0,0 @@
-#!/bin/sh
-
-set -e
-
-PROGNAME=Xsession
-
-OPTIONFILE=/etc/X11/Xsession.options
-
-[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xresources" ] && USRRESOURCES=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xresources || USRRESOURCES=$HOME/.Xresources
-[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession.d" ] && SESSIONDIR=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession.d || SESSIONDIR=/etc/X11/Xsession.d
-[ -r "${XDG_DATA_HOME:-$HOME/.local/share}/xorg/xsession-errors" ] &&
-	ERRFILE=${XDG_DATA_HOME:-$HOME/.local/share}/xorg/xsession-errors ||
-	ERRFILE=$HOME/.xsession-errors && touch $ERRFILE
-
-message() {
-	# pretty-print messages of arbitrary length; use xmessage if it
-	# is available and $DISPLAY is set
-	MESSAGE="$PROGNAME: $*"
-	echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2
-	# if [ -n "$DISPLAY" ] && command -v xmessage > /dev/null 2>&1; then
-	#   echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
-	# fi
-}
-
-message_nonl() {
-	# pretty-print messages of arbitrary length (no trailing newline); use
-	# xmessage if it is available and $DISPLAY is set
-	MESSAGE="$PROGNAME: $*"
-	echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2
-	# if [ -n "$DISPLAY" ] && command -v xmessage > /dev/null 2>&1; then
-	#   echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
-	# fi
-}
-
-errormsg() {
-	# exit script with error
-	message "$*"
-	exit 1
-}
-
-internal_errormsg() {
-	# exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
-	# One big call to message() for the sake of xmessage; if we had two then
-	# the user would have dismissed the error we want reported before seeing the
-	# request to report it.
-	errormsg "$*" \
-		"Please report the installed version of the \"x11-common\"" \
-		"package and the complete text of this error message to" \
-		"<debian-x@lists.debian.org>."
-}
-
-OPTIONS="$(
-	if [ -r "$OPTIONFILE" ]; then
-		cat "$OPTIONFILE"
-	fi
-	if [ -d /etc/X11/Xsession.options.d ]; then
-		run-parts --list --regex '\.conf$' /etc/X11/Xsession.options.d | xargs -d '\n' cat
-	fi
-)"
-
-has_option() {
-	# Ensure that a later no-foo overrides an earlier foo
-	if [ "$(echo "$OPTIONS" | grep -Eo "^(no-)?$1\>" | tail -n 1)" = "$1" ]; then
-		return 0
-	else
-		return 1
-	fi
-}
-
-# attempt to create an error file; abort if we cannot
-if (umask 077 && touch "$ERRFILE") 2>/dev/null && [ -w "$ERRFILE" ] &&
-	[ ! -L "$ERRFILE" ]; then
-	chmod 600 "$ERRFILE"
-elif ERRFILE=$(mktemp 2>/dev/null); then
-	if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then
-		message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \
-			"\"$ERRFILE\"; look for session log/errors in" \
-			"\"$TMPDIR/xsession-$USER\"."
-	fi
-else
-	errormsg "unable to create X session log/error file; aborting."
-fi
-
-# truncate ERRFILE if it is too big to avoid disk usage DoS
-if [ "$(stat -c%s "$ERRFILE")" -gt 500000 ]; then
-	T=$(mktemp -p "$HOME")
-	tail -c 500000 "$ERRFILE" >"$T" && mv -f "$T" "$ERRFILE" || rm -f "$T"
-fi
-
-exec >>"$ERRFILE" 2>&1
-
-# sanity check; is our session script directory present?
-if [ ! -d "$SESSIONDIR" ]; then
-	errormsg "no \"$SESSIONDIR\" directory found; aborting."
-fi
-
-# Attempt to create a file of non-zero length in /tmp; a full filesystem can
-# cause mysterious X session failures.  We do not use touch, :, or test -w
-# because they won't actually create a file with contents.  We also let standard
-# error from mktemp and echo go to the error file to aid the user in
-# determining what went wrong.
-WRITE_TEST=$(mktemp)
-if ! echo "*" >>"$WRITE_TEST"; then
-	message "warning: unable to write to ${WRITE_TEST%/*}; X session may exit" \
-		"with an error"
-fi
-rm -f "$WRITE_TEST"
-
-SESSIONFILES=$(run-parts --list $SESSIONDIR)
-if [ -n "$SESSIONFILES" ]; then
-	set +e
-	for SESSIONFILE in $SESSIONFILES; do
-		message "Executing $SESSIONFILE"
-		. $SESSIONFILE
-	done
-	set -e
-fi
-
-if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xprofile" ]; then
-	. ${XDG_CONFIG_HOME:-$HOME/.config}/X11/xprofile
-else
-	. $HOME/.xprofile
-fi
-
-exec dwm
diff --git a/.config/X11/xsession.d/20dbus_xdg-runtime b/.config/X11/xsession.d/20dbus_xdg-runtime
deleted file mode 100644
index a1490361..00000000
--- a/.config/X11/xsession.d/20dbus_xdg-runtime
+++ /dev/null
@@ -1,23 +0,0 @@
-# vim:set ft=sh:
-
-if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && [ -n "$XDG_RUNTIME_DIR" ] &&
-	[ "$XDG_RUNTIME_DIR" = "/run/user/$(id -u)" ] &&
-	[ -S "$XDG_RUNTIME_DIR/bus" ]; then
-	# We are under systemd-logind or something remarkably similar, and
-	# a user-session socket has already been set up.
-	#
-	# Be nice to non-libdbus, non-sd-bus implementations by using
-	# that as the session bus address in the environment. The check for
-	# XDG_RUNTIME_DIR = "/run/user/`id -u`" is because we know that
-	# form of the address, from systemd-logind, doesn't need escaping,
-	# whereas arbitrary addresses might.
-	export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
-fi
-
-if [ -x "/usr/bin/dbus-update-activation-environment" ]; then
-	# tell dbus-daemon --session (and systemd --user, if running)
-	# to put a minimal subset of the Xsession's environment in activated
-	# services' environments
-	dbus-update-activation-environment --verbose --systemd \
-		DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY
-fi
diff --git a/.config/X11/xsession.d/30x11-resources b/.config/X11/xsession.d/30x11-resources
deleted file mode 100644
index 2b248b15..00000000
--- a/.config/X11/xsession.d/30x11-resources
+++ /dev/null
@@ -1,3 +0,0 @@
-# vim:set ft=sh:
-
-xrdb -merge $USRRESOURCES
diff --git a/.config/X11/xsession.d/40display-setup b/.config/X11/xsession.d/40display-setup
deleted file mode 100644
index a58e24f9..00000000
--- a/.config/X11/xsession.d/40display-setup
+++ /dev/null
@@ -1,3 +0,0 @@
-# vim:set ft=sh
-# Any host specific disylay configuration goes here
-# This file is excluded from the dotsync script
diff --git a/.config/X11/xsession.d/50atk-adaptor b/.config/X11/xsession.d/50atk-adaptor
deleted file mode 100644
index 14366948..00000000
--- a/.config/X11/xsession.d/50atk-adaptor
+++ /dev/null
@@ -1,23 +0,0 @@
-# vim:set ft=sh:
-
-add_module() {
-	case :$GTK_MODULES: in
-	*:$1:*) ;;
-
-	*)
-		if [ -z "$GTK_MODULES" ]; then
-			GTK_MODULES=$1
-		else
-			GTK_MODULES=$GTK_MODULES:$1
-		fi
-		;;
-	esac
-}
-
-add_module gail
-add_module atk-bridge
-
-export GTK_MODULES
-if [ -x "/usr/bin/dbus-update-activation-environment" ]; then
-	dbus-update-activation-environment --verbose --systemd GTK_MODULES
-fi
diff --git a/.config/X11/xsession.d/50qt-a11y b/.config/X11/xsession.d/50qt-a11y
deleted file mode 100644
index 84dac0ff..00000000
--- a/.config/X11/xsession.d/50qt-a11y
+++ /dev/null
@@ -1,7 +0,0 @@
-# vim:set ft=sh:
-
-export QT_ACCESSIBILITY=1
-
-if [ -x "/usr/bin/dbus-update-activation-environment" ]; then
-	dbus-update-activation-environment --verbose --systemd QT_ACCESSIBILITY
-fi
diff --git a/.config/zsh/profile b/.config/zsh/profile
index a15ed5b6..ebbdf9b9 100644
--- a/.config/zsh/profile
+++ b/.config/zsh/profile
@@ -17,11 +17,11 @@ export XDG_PICTURES_DIR="$HOME/Pictures"
 export XDG_PUBLICSHARE_DIR="$HOME/Public"
 export XDG_TEMPLATES_DIR="$HOME/Templates"
 export XDG_VIDEOS_DIR="$HOME/Videos"
-
 export XDG_CONFIG_HOME="$HOME/.config"
 export XDG_DATA_HOME="$HOME/.local/share"
 export XDG_CACHE_HOME="$HOME/.cache"
-export KEYMAPS_DIR="$HOME/.local/bin/keymaps"
+export XINITRC="$XDG_CONFIG_HOME/X11/xinitrc"
+
 export ZSH_COMPDUMP="$XDG_CACHE_HOME/zcompdump"
 export NOTMUCH_CONFIG="$XDG_CONFIG_HOME/notmuch-config"
 export GTK2_RC_FILES="$XDG_CONFIG_HOME/.config}/gtk-2.0/gtkrc-2.0"
@@ -61,6 +61,3 @@ export ANSIBLE_NOCOWS=1			# Stop those fucking cows in Ansible
 
 localpath="$(find -L ~/.local/bin -type d -printf %p: | sed 's/.$//')"
 export PATH="$PATH:$HOME/.local/share/npm-global/bin:$localpath"
-
-# Start X Server if logging in on TTY1 and no other server is running
-[ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ] && ! pidof -s Xorg >/dev/null 2>&1 && exec startgraphical
diff --git a/.local/bin/remaps b/.local/bin/remaps
index 876b4acd..e090176f 100755
--- a/.local/bin/remaps
+++ b/.local/bin/remaps
@@ -2,8 +2,8 @@
 
 DISPLAY=:0
 
-XKBDIR="${XDG_CONFIG_HOME:-$HOME/.config}/X11/xkb"
-XKBMAPFILE="$XKBDIR/keymap/$(hostname --fqdn)"
+XKBDIR="$XDG_CONFIG_HOME/X11/xkb"
+XKBMAPFILE="$XKBDIR/keymap/$(hostname)"
 [ -r "$XKBMAPFILE" ] || XKBMAPFILE="$XKBDIR/keymap/default"
 xkbcomp -I"$XKBDIR" "$XKBMAPFILE" "${DISPLAY%%.*}" 1>/dev/null 2>&1
 unset XKBDIR XKBMAPFILE
diff --git a/.local/bin/startgraphical b/.local/bin/startgraphical
index a6cceadf..6179839c 100755
--- a/.local/bin/startgraphical
+++ b/.local/bin/startgraphical
@@ -1,98 +1,3 @@
 #!/bin/sh
 
-if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc" ]; then
-	server=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc
-elif [ -r "$HOME/.xserverrc" ]; then
-	server=$HOME/.xserverrc
-else
-	server=/etc/X11/xinit/xserverrc
-fi
-
-if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession" ]; then
-	client=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession
-elif [ -r "$HOME/.xsession" ]; then
-	client="$HOME/.xsession"
-else
-	client=/etc/X11/xinit/xinitrc
-fi
-
-# Automatically determine an unused $DISPLAY
-d=0
-while true; do
-	[ -e "/tmp/.X$d-lock" ] || [ -S "/tmp/.X11-unix/X$d" ] || break
-	d=$((d + 1))
-done
-display=":$d"
-unset d
-
-if [ -z "${XAUTHORITY+x}" ]; then
-	XAUTHORITY=$HOME/.Xauthority
-	export XAUTHORITY
-fi
-
-removelist=
-
-# check for GNU hostname
-if hostname --version >/dev/null 2>&1; then
-	if ! hostname --version 2>&1 | grep GNU -q; then
-		hostname=$(hostname -f)
-	fi
-fi
-
-if [ -z "$hostname" ]; then
-	hostname=$(hostname)
-fi
-
-authdisplay=${display:-:0}
-
-mcookie=$(/usr/bin/mcookie)
-
-if [ -z "${mcookie+x}" ]; then
-	echo "Couldn't create cookie"
-	exit 1
-fi
-dummy=0
-
-# create a file with auth information for the server. ':0' is a dummy.
-xserverauthfile=$(mktemp --tmpdir serverauth.XXXXXXXXXX)
-trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP BUS TERM
-xauth -q -f "$xserverauthfile" <<EOF
-add :$dummy . $mcookie
-EOF
-
-serverargs=${serverargs}" -auth "${xserverauthfile}
-
-# now add the same credentials to the client authority file
-# if '$displayname' already exists do not overwrite it as another
-# server may need it. Add them to the '$xserverauthfile' instead.
-for displayname in $authdisplay $hostname$authdisplay; do
-	authcookie=$(xauth list "$displayname" | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p") 2>/dev/null
-	if [ -n "${authcookie+x}" ]; then
-		xauth -q <<EOF
-add $displayname . $mcookie
-EOF
-		removelist="$displayname $removelist"
-	else
-		dummy=$((dummy + 1))
-		xauth -q -f "$xserverauthfile" <<EOF
-add :$dummy . $authcookie
-EOF
-	fi
-done
-
-xinit $client -- $server $serverargs $display
-
-retval=$?
-
-if [ -z "${removelist+x}" ]; then
-	xauth remove $removelist
-fi
-if [ x"$xserverauthfile" != x ]; then
-	rm -f "$xserverauthfile"
-fi
-
-if command -v deallocvt >/dev/null 2>&1; then
-	deallocvt
-fi
-
-exit $retval
+echo lol