57 lines
1.3 KiB
Bash
Executable File
57 lines
1.3 KiB
Bash
Executable File
#!/bin/zsh
|
|
#####################################################################
|
|
|
|
USAGE="$0 APPLICATION CLIENT_CLASS"
|
|
|
|
function ERROR() {
|
|
local ERROR_CODE=$1
|
|
local MESSAGE="$2"
|
|
|
|
echo -e "$MESSAGE\n\nUSAGE : $USAGE\n" >&2
|
|
|
|
[ $MESSAGE ] && notify-send "Application Launcher" "$MESSAGE"
|
|
exit $ERROR_CODE
|
|
}
|
|
|
|
#####################################################################
|
|
|
|
APPLICATION="$1"
|
|
which $APPLICATION >/dev/null 2>&1 \
|
|
|| ERROR 2 "Application '$APPLICATION' not found"
|
|
|
|
CLIENT_CLASS="${@:2}"
|
|
[ ! $CLIENT_CLASS ] && CLIENT_CLASS="$APPLICATION"
|
|
|
|
|
|
XFFSET=0.0
|
|
YFFSET=0.0
|
|
FACTOR=0.8
|
|
xrandr | grep primary | awk '{print $4;}' | grep -q '^3840' \
|
|
&& FACTOR=0.5
|
|
case $APPLICATION in
|
|
pavucontrol ) FACTOR=0.4 YFFSET=200 ;;
|
|
esac
|
|
|
|
LAUNCH_APP=0
|
|
|
|
xdotool search --class "$CLIENT_CLASS" || LAUNCH_APP=1
|
|
[[ $CLIENT_CLASS =~ discord ]] && LAUNCH_APP=1
|
|
|
|
[[ $LAUNCH_APP -eq 1 ]] && {
|
|
i3-msg "exec --no-startup-id $APPLICATION;"
|
|
sleep .5
|
|
}
|
|
|
|
WINDOW_SIZE=$(\
|
|
xrandr \
|
|
| grep 'connected primary' \
|
|
| sed 's/.*connected primary \([^x]*\)x\([^+]*\).*/\1 \2/' \
|
|
| awk -v f=$FACTOR -v x=$XFFSET -v y=$YFFSET \
|
|
'{print int($1*f+x)," ",int($2*f+y);}'\
|
|
)
|
|
|
|
i3-msg "[class=$CLIENT_CLASS] move scratchpad"
|
|
i3-msg "[class=$CLIENT_CLASS] resize set $WINDOW_SIZE"
|
|
i3-msg "[class=$CLIENT_CLASS] scratchpad show"
|
|
i3-msg "[class=$CLIENT_CLASS] move position center"
|