#!/bin/ksh

# set shell
export ENV=$HOME/.kshrc
. $ENV

# allow ctrl+alt+backspace to kill X
setxkbmap -option "terminate:ctrl_alt_bksp"

# capslock shall be escape
setxkbmap -option caps:escape

# turn this annoying bell off
xset -b

# set keyboard layout
setxkbmap "de"

# accelerate keyboard
xset r rate 300 50

# accelerate mouse
xinput set-prop /dev/wsmouse "Device Accel Constant Deceleration" 0.4
xinput set-prop /dev/wsmouse "Device Accel Adaptive Deceleration" 1.2

# scroll with middle button
xinput set-prop /dev/wsmouse "WS Pointer Wheel Emulation" 1
xinput set-prop /dev/wsmouse "WS Pointer Wheel Emulation Button" 2
xinput set-prop /dev/wsmouse "WS Pointer Wheel Emulation Axes" 6 7 4 5

# xkeyboard preferences
export XKB_DEFAULT_LAYOUT=de
export XKB_DEFAULT_VARIANT=,nodeadkeys
export XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle

# set w3mimg patch for ranger
export W3MIMGDISPLAY_PATH="/usr/local/libexec/w3m/w3mimgdisplay"

# force webkit to one process mode
export WEBKIT_USE_SINGLE_WEB_PROCESS=1

# fixes
#export LIBGL_DRI3_DISABLE=1 # fix video on luakit
#export XLIB_SKIP_ARGB_VISUALS=1
#export SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS=0 # fix fullscreen loop
#export FNA3D_OPENGL_FORCE_ES3=1 # fnaifi fix for iris gpu
#export _JAVA_AWT_WM_NONREPARENTING=1
#export GSK_RENDERER=cairo # render gtk4 in cario instead of opengl

# accelerate firefox
export MOZ_ACCELERATED=1
export MOZ_WEBRENDER=1

# sndio devices
#export AUDIOPLAYDEVICE=snd/default
#export AUDIORECDEVICE=snd/rec
#export AUDIOMONDEVICE=snd/mon

# gtk/qt scaling
export QT_AUTO_SCREEN_SCALE_FACTOR=0
export QT_SCALE_FACTOR=1
export GDK_DPI_SCALE=1

# qt theme
export QT_QPA_PLATFORMTHEME=qt5ct # or lxqt

# add custom fonts
xset +fp $HOME/.fonts

# keep cutbuffer and selections in sync
autocutsel -fork
autocutsel -selection PRIMARY -fork

# set background
xsetroot -solid rgb:22/22/22
hsetroot -solid "#222222"

# allow local users to access X
xhost +local:

# give user access to camara and hid devices
doas chown sdk /dev/video* /dev/uhid* /dev/dri/card* /dev/cua*

# all those tools... *sigh*
# dunst &
# twmnd &
dunst &
#stalonetray &
xbanish &
#xautolock -time 30 -locker xlock &

export $(<~/.dbus_address)
gnome-keyring-daemon --replace --components=secrets
dbus-update-activation-environment --all
export GNOME_KEYRING_CONTROL GNOME_KEYRING_SOCKET GNOME_KEYRING_PID

# huh, we're hipster now
# picom &
#hsetroot -solid "#222"
srandrd /home/sdk/.bin/autorandr-c

mv $HOME/.xsession-wm $HOME/.xsession-wm.old
mv $HOME/.xsession-errors.log $HOME/.xsession-errors.old
#exec "/usr/local/bin/spectrwm" > $HOME/.xsession-wm 2>&1
#exec "/usr/local/bin/i3" > $HOME/.xsession-wm 2>&1
exec "/usr/local/bin/bspwm" > $HOME/.xsession-wm 2>&1
#exec "/usr/local/bin/notion" > $HOME/.xsession-wm 2>&1
