From 1e6f486865af85d850f2d6eac97b979e8b27eefb Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 27 Sep 2018 23:10:30 -0600 Subject: [PATCH] Adjusted X startup sequence * Moved most X startup logic to ~/.update_x * This is called by both i3 and openbox * Network logic moved to .zlogin * This avoids a bug where apps can no longer connect to the $DISPLAY --- .../airootfs/etc/skel/.config/i3/config | 2 + .../etc/skel/.config/openbox/autostart | 21 +---- .../include/airootfs/etc/skel/.update_network | 22 +++++ .../include/airootfs/etc/skel/.update_x | 94 +++++++++++++++++++ .../include/airootfs/etc/skel/.xinitrc | 14 +-- .../include/airootfs/etc/skel/.zlogin | 4 +- 6 files changed, 124 insertions(+), 33 deletions(-) mode change 100644 => 100755 .linux_items/include/airootfs/etc/skel/.config/openbox/autostart create mode 100755 .linux_items/include/airootfs/etc/skel/.update_network create mode 100755 .linux_items/include/airootfs/etc/skel/.update_x diff --git a/.linux_items/include/airootfs/etc/skel/.config/i3/config b/.linux_items/include/airootfs/etc/skel/.config/i3/config index cf09a2ca..ca1a5439 100644 --- a/.linux_items/include/airootfs/etc/skel/.config/i3/config +++ b/.linux_items/include/airootfs/etc/skel/.config/i3/config @@ -319,3 +319,5 @@ bar { status_command i3status height 26 } + +exec --no-startup-id /home/tech/.update_x diff --git a/.linux_items/include/airootfs/etc/skel/.config/openbox/autostart b/.linux_items/include/airootfs/etc/skel/.config/openbox/autostart old mode 100644 new mode 100755 index 6eaa6cc3..13b9088c --- a/.linux_items/include/airootfs/etc/skel/.config/openbox/autostart +++ b/.linux_items/include/airootfs/etc/skel/.config/openbox/autostart @@ -1,20 +1,3 @@ -# -# These things are run when an Openbox X Session is started. -# You may place a similar script in $HOME/.config/openbox/autostart -# to run user-specific things. -# +#openbox-autostart -# If you want to use GNOME config tools... -# -#if test -x /usr/lib/openbox/gnome-settings-daemon >/dev/null; then -# /usr/lib/openbox/gnome-settings-daemon & -#elif which gnome-settings-daemon >/dev/null 2>&1; then -# gnome-settings-daemon & -#fi - -# If you want to use XFCE config tools... -# -#xfce-mcs-manager & - -tint2 & -cbatticon --hide-notification & +$HOME/.update_x & diff --git a/.linux_items/include/airootfs/etc/skel/.update_network b/.linux_items/include/airootfs/etc/skel/.update_network new file mode 100755 index 00000000..97b5783b --- /dev/null +++ b/.linux_items/include/airootfs/etc/skel/.update_network @@ -0,0 +1,22 @@ +## .update_network ## +#!/bin/env bash +# +## Connect to network and update hostname + +# Connect +connect-to-network + +IP="$(ip a show scope global \ + | grep inet \ + | head -1 \ + | sed -r 's#.*inet ([0-9]+.[0-9]+.[0-9]+.[0-9]+.)/.*#\1#')" +HOSTNAME="$(dig +noall +answer +short -x "$IP" \ + | grep -v ';' \ + | head -1 \ + | sed 's/\.$//')" + +# Set hostname +if [[ "${HOSTNAME:+x}" ]]; then + sudo hostnamectl set-hostname "${HOSTNAME}" +fi + diff --git a/.linux_items/include/airootfs/etc/skel/.update_x b/.linux_items/include/airootfs/etc/skel/.update_x new file mode 100755 index 00000000..4763a175 --- /dev/null +++ b/.linux_items/include/airootfs/etc/skel/.update_x @@ -0,0 +1,94 @@ +#!/bin/env bash +# +## Calculate DPI, update settings if necessary, then start desktop apps + +REGEX_XRANDR='^.* ([0-9]+)x([0-9]+)\+[0-9]+\+[0-9]+.* ([0-9]+)mm x ([0-9]+)mm.*$' +REGEX_URXVT='(URxvt.geometry:\s+).*' + +# Get screen data +xrandr_str="$(xrandr | grep mm | head -1)" +width_px="$(echo "${xrandr_str}" | sed -r "s/${REGEX_XRANDR}/\1/")" +height_px="$(echo "${xrandr_str}" | sed -r "s/${REGEX_XRANDR}/\2/")" +width_mm="$(echo "${xrandr_str}" | sed -r "s/${REGEX_XRANDR}/\3/")" +height_mm="$(echo "${xrandr_str}" | sed -r "s/${REGEX_XRANDR}/\4/")" + +# Convert to in +width_in="$(echo "${width_mm} * 0.03937" | bc)" +height_in="$(echo "${height_mm} * 0.03937" | bc)" + +# Calculate diagonals +diag_px="$(echo "sqrt(${width_px}^2 + ${height_px}^2)" | bc)" +diag_in="$(echo "sqrt(${width_in}^2 + ${height_in}^2)" | bc)" + +# Calculate DPI +dpi="$(echo "${diag_px} / ${diag_in}" | bc 2>/dev/null || True)" +dpi="${dpi:-0}" + +# Calculate URxvt default window size +width_urxvt="$(echo "${width_px} * 112/1280" | bc)" +height_urxvt="$(echo "${height_px} * 33/720" | bc)" +offset_urxvt="24" + +# Update settings if necessary +if [[ "${dpi}" -ge 192 ]]; then + # Conky + sed -i 's/minimum_size 180 0/minimum_size 360 0/' "${HOME}/.conkyrc" + sed -i 's/maximum_width 180/maximum_width 360/' "${HOME}/.conkyrc" + sed -i 's/gap_x 20/gap_x 40/' "${HOME}/.conkyrc" + sed -i 's/gap_y 24/gap_y 48/' "${HOME}/.conkyrc" + + # Fonts + sed -i 's/!Xft.dpi: 192/Xft.dpi: 192/' "${HOME}/.Xresources" + + # GDK + export GDK_SCALE=2 + export GDK_DPI_SCALE=0.5 + + # i3 + sed -i -r 's/(height\s+) 26/\1 52/' "${HOME}/.config/i3/config" + + # Tint2 + sed -i 's/panel_size = 100% 30/panel_size = 100% 60/' \ + "${HOME}/.config/tint2/tint2rc" + sed -i 's/Inconsolata 10/Inconsolata 20/g' \ + "${HOME}/.config/tint2/tint2rc" + sed -i 's/Inconsolata 12/Inconsolata 24/g' \ + "${HOME}/.config/tint2/tint2rc" + sed -i 's/systray_icon_size = 24/systray_icon_size = 48/' \ + "${HOME}/.config/tint2/tint2rc" + + # URxvt + width_urxvt="$(echo "${width_urxvt} / 2" | bc)" + height_urxvt="$(echo "${height_urxvt} / 2" | bc)" + offset_urxvt="$(echo "${offset_urxvt} * 2" | bc)" +fi + +# Update URxvt (Always) +urxvt_geometry="${width_urxvt}x${height_urxvt}+${offset_urxvt}+${offset_urxvt}" +sed -i -r "s/${REGEX_URXVT}/\1${urxvt_geometry}/" "${HOME}/.Xresources" + +# Update X +xset s off +xset -dpms +xrdb -merge $HOME/.Xresources + +# Start common desktop apps +feh --bg-fill "$HOME/.wallpaper" +compton --backend xrender --xrender-sync --xrender-sync-fence & +sleep 1s +x0vncserver -display :0 -passwordfile $HOME/.vnc/passwd -AlwaysShared & +conky & +nm-applet & +volumeicon & + +# Start WM specific apps +if fgrep -q "i3" /proc/cmdline; then + # i3 + i3-msg restart +else + # openbox + openbox --restart + tint2 & + cbatticon --hide-notification & +fi + diff --git a/.linux_items/include/airootfs/etc/skel/.xinitrc b/.linux_items/include/airootfs/etc/skel/.xinitrc index abb71f45..7085a4df 100755 --- a/.linux_items/include/airootfs/etc/skel/.xinitrc +++ b/.linux_items/include/airootfs/etc/skel/.xinitrc @@ -1,19 +1,7 @@ #!/bin/sh dbus-update-activation-environment --systemd DISPLAY -$HOME/.update_dpi_settings -xrdb -merge $HOME/.Xresources -xset s off -xset -dpms eval $(ssh-agent) export SSH_AUTH_SOCK -compton --backend xrender --xrender-sync --xrender-sync-fence & -sleep 1s -conky -d -nm-applet & -volumeicon & -connect-to-network & -$HOME/.update_hostname & -feh --bg-fill "$HOME/.wallpaper" & -x0vncserver -display :0 -passwordfile $HOME/.vnc/passwd -AlwaysShared & exec openbox-session + diff --git a/.linux_items/include/airootfs/etc/skel/.zlogin b/.linux_items/include/airootfs/etc/skel/.zlogin index 0898d1e2..338a8198 100644 --- a/.linux_items/include/airootfs/etc/skel/.zlogin +++ b/.linux_items/include/airootfs/etc/skel/.zlogin @@ -1,5 +1,8 @@ setterm -blank 0 -powerdown 0 if [ "$(fgconsole 2>/dev/null)" -eq "1" ]; then + # Connect to network and update hostname + $HOME/.update_network + # Update settings if using i3 if fgrep -q "i3" /proc/cmdline; then sed -i -r 's/#(own_window_type override)/\1/' ~/.conkyrc @@ -16,4 +19,3 @@ if [ "$(fgconsole 2>/dev/null)" -eq "1" ]; then hw-diags cli fi fi -