From 89420117a1942526f0673fdf0703513691f535d3 Mon Sep 17 00:00:00 2001 From: VectorKappa Date: Thu, 23 Sep 2021 11:28:28 +0200 Subject: [PATCH] added binfiles from chrysostomus/bspwm-scripts, fixed eaten space --- bin/DidIClickDesktop.sh | 10 ++++ bin/MouseCenter | 11 +++++ bin/WindowSelector | 16 ++++++ bin/auto-presel | 13 +++++ bin/autogap | 21 ++++++++ bin/bspcp | 60 ++++++++++++++++++++++ bin/bspwm_rename_desktop | 13 +++++ bin/bspwm_resize.sh | 41 +++++++++++++++ bin/cancel_presels | 2 + bin/clickpasser | 7 +++ bin/default-browser | 3 ++ bin/default-editor | 3 ++ bin/default-terminal | 3 ++ bin/edge-switcher | 13 +++++ bin/euclid_balancer | 14 ++++++ bin/euclid_mode | 15 ++++++ bin/euclid_mover | 85 ++++++++++++++++++++++++++++++++ bin/finder | 24 +++++++++ bin/focusdesktopofthismonitor | 7 +++ bin/focusmover | 13 +++++ bin/get-window-alignment | 13 +++++ bin/keybindings.sh | 66 +++++++++++++++++++++++++ bin/list_windows_by_size.sh | 56 +++++++++++++++++++++ bin/movetodesktopofthismonitor | 5 ++ bin/pseudo_automatic_mode | 29 +++++++++++ bin/resizetopresel.sh | 83 +++++++++++++++++++++++++++++++ bin/run_once | 3 ++ bin/smartsplit | 31 ++++++++++++ bin/summondesktop.sh | 14 ++++++ bin/swapOrMoveIn.sh | 4 ++ bin/toggle-focus-follows-pointer | 15 ++++++ bin/toggle-pointer-follows-focus | 7 +++ bin/whid | 78 +++++++++++++++++++++++++++++ bin/windowgrabber | 43 ++++++++++++++++ bin/windowpromoter | 26 ++++++++++ bin/workspaces_multimonitor | 2 +- 36 files changed, 848 insertions(+), 1 deletion(-) create mode 100755 bin/DidIClickDesktop.sh create mode 100755 bin/MouseCenter create mode 100755 bin/WindowSelector create mode 100755 bin/auto-presel create mode 100755 bin/autogap create mode 100755 bin/bspcp create mode 100755 bin/bspwm_rename_desktop create mode 100755 bin/bspwm_resize.sh create mode 100755 bin/cancel_presels create mode 100755 bin/clickpasser create mode 100755 bin/default-browser create mode 100755 bin/default-editor create mode 100755 bin/default-terminal create mode 100755 bin/edge-switcher create mode 100755 bin/euclid_balancer create mode 100755 bin/euclid_mode create mode 100755 bin/euclid_mover create mode 100755 bin/finder create mode 100755 bin/focusdesktopofthismonitor create mode 100755 bin/focusmover create mode 100755 bin/get-window-alignment create mode 100755 bin/keybindings.sh create mode 100755 bin/list_windows_by_size.sh create mode 100755 bin/movetodesktopofthismonitor create mode 100755 bin/pseudo_automatic_mode create mode 100755 bin/resizetopresel.sh create mode 100755 bin/run_once create mode 100755 bin/smartsplit create mode 100755 bin/summondesktop.sh create mode 100755 bin/swapOrMoveIn.sh create mode 100755 bin/toggle-focus-follows-pointer create mode 100755 bin/toggle-pointer-follows-focus create mode 100755 bin/whid create mode 100755 bin/windowgrabber create mode 100755 bin/windowpromoter diff --git a/bin/DidIClickDesktop.sh b/bin/DidIClickDesktop.sh new file mode 100755 index 0000000..d03fcb3 --- /dev/null +++ b/bin/DidIClickDesktop.sh @@ -0,0 +1,10 @@ +#!/bin/zsh +# Did I just click the desktop? + +#Get the window id of the window that is under the pointer and set variable WINDOW to it +eval $(xdotool getmouselocation --shell) + +#Get the window id of the rootwindow aka desktop and convert the id into decimal form that xdotool uses so we can easily compare the values +rootwindowid=$(xdotool search --class Bspwm|head -n 1) +#Compare window ids to see if window under mouse is the rootwindow. Returns false if not. +[ "$WINDOW" = "$rootwindowid" ] diff --git a/bin/MouseCenter b/bin/MouseCenter new file mode 100755 index 0000000..5fa855a --- /dev/null +++ b/bin/MouseCenter @@ -0,0 +1,11 @@ +#!/bin/bash +# Get the necessary info +#Script copied from https://github.com/tatou-tatou +IFS=" " read -a window <<< $(wattr whxy $(pfw)) + +# Find the center of the window +center_x=$(( ${window[0]} / 2 + ${window[2]} )) +center_y=$(( ${window[1]} / 2 + ${window[3]} )) + +# Move mouse +xdotool mousemove $center_x $center_y diff --git a/bin/WindowSelector b/bin/WindowSelector new file mode 100755 index 0000000..9945445 --- /dev/null +++ b/bin/WindowSelector @@ -0,0 +1,16 @@ +#!/bin/bash +# Script copied from AUR package dswitcher, and modified for theming and placement and removed unnecessary functions. +if ! [ -f "$HOME/.dmenurc" ]; then + cp /usr/share/dmenu/dmenurc $HOME/.dmenurc +fi +. $HOME/.dmenurc + +width=$(wattr w $(lsw -r)) +height=$(wattr h $(lsw -r)) +bar_width=$(( $width / 3 )) +left_shift=$(( ($width - $bar_width) / 2 )) +top_shift=$PANEL_HEIGHT + +num=$(wmctrl -l | sed 's/ / /' | cut -d " " -f 4- | nl -w 3 -n rn | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' | dmenu -i -l 10 -x $left_shift -y $top_shift -w $bar_width -fn $DMENU_FN -nb $DMENU_NB -nf $DMENU_NF -sf $DMENU_SF -sb $DMENU_SB | cut -d '-' -f -1) +[[ -z "$num" ]] && exit +wmctrl -l | sed -n "$num p" | cut -c -10 | xargs wmctrl -i -a diff --git a/bin/auto-presel b/bin/auto-presel new file mode 100755 index 0000000..5d79479 --- /dev/null +++ b/bin/auto-presel @@ -0,0 +1,13 @@ +#! /bin/sh +# Original script by https://github.com/ikn/ , modified to use splitting method of +# https://github.com/baskerville/bspwm/tree/master/examples/external_rules/pseudo_automatic_mode +fwid=$(bspc query -N -n focused) + +wattr wh $fwid | { + read width height + if [ $width -gt $height ] ; then + bspc node -p \~east + else + bspc node -p \~south + fi +} diff --git a/bin/autogap b/bin/autogap new file mode 100755 index 0000000..c460f27 --- /dev/null +++ b/bin/autogap @@ -0,0 +1,21 @@ +#!/bin/zsh + +if [ "$(pgrep -cx autogap)" -gt 1 ] ; then + killall autogap && exit 0 +else + +bspc config top_padding 0 +bspc config left_padding 0 +bspc config right_padding 0 +bspc config bottom_padding 0 +bspc config -m $(bspc query -M | awk NR==1) top_padding $PANEL_HEIGHT +bspc config gapless_monocle true + +bspc subscribe | while read line; do + W=$(bspc query -N -n .local.\!floating | wc -l) + G=$(echo "51 - ($W - 1) * 10" | bc) + [ "$G" -lt 1 ] && G=1 + bspc config --desktop focused window_gap $G +done + +fi diff --git a/bin/bspcp b/bin/bspcp new file mode 100755 index 0000000..97bd71a --- /dev/null +++ b/bin/bspcp @@ -0,0 +1,60 @@ +#!/bin/sh +i=1 +case $1 in +dsktp) # Add or remove a desktop + case $2 in + add) + current=$(bspc query -D | wc -l) + if [ "$current" -lt "10" ]; then + new=$((current + 1)) + bspc monitor -a $new + else + notify-send "You already have ten desktops" "Are those really necessary? Consider closing unneeded windows." -i warning + fi + ;; + rm) + current=$(bspc query -D | wc -l) + if [ "$current" -gt "4" ]; then + bspc monitor -r $(bspc query -D | sed -n ${current}p) + else + notify-send "You currently have four desktops" "That can be considered a bare minimum. You should not remove more." -i warning + fi + ;; + esac +;; +empty) + nextFreeDesktop=$(bspc query -D -d next.free) + + if [ -z "$nextFreeDesktop" ] + then + nextFreeDesktop=$(( $(bspc query -D | wc -l) + 1 )) + bspc monitor -a $nextFreeDesktop + fi + + case $2 in + move) + bspc window -d $nextFreeDesktop + ;; + next) + bspc rule -a \* -o desktop=$nextFreeDesktop follow=true + ;; + esac +;; +tile) # Force every existing window to tile (the opposite is dumb IMHO) + for window in $(bspc query -N -d focused) + do + bspc node $window -t tiled + done +;; +float) # Force every existing window to float and place the windows + for window in $(bspc query -N -d focused) + do + bspc node $window -t floating + let i++ + done +;; + +*) + exit +;; +esac diff --git a/bin/bspwm_rename_desktop b/bin/bspwm_rename_desktop new file mode 100755 index 0000000..f3a50cc --- /dev/null +++ b/bin/bspwm_rename_desktop @@ -0,0 +1,13 @@ +#!/bin/bash + +DMENU_NF="#A3A6AB" +DMENU_NB="#34322E" +DMENU_SF="#F6F9FF" +DMENU_SB="#5C5955" + +DESKTOP_NAME=`echo '' | dmenu -b $DMENU_THEME -p 'Rename:'` +if [ -z $DESKTOP_NAME ]; then + exit 0 +fi + +bspc desktop -n "$DESKTOP_NAME" diff --git a/bin/bspwm_resize.sh b/bin/bspwm_resize.sh new file mode 100755 index 0000000..b935126 --- /dev/null +++ b/bin/bspwm_resize.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +size=${2:-'10'} +dir=$1 + +# Find current window mode +is_tiled() { +bspc query -T -n | grep -q '"state":"tiled"' +} +# If the window is floating, move it +if ! is_tiled; then +#only parse input if window is floating,tiled windows accept input as is + case "$dir" in + west) switch="-w" + sign="-" + ;; + east) switch="-w" + sign="+" + ;; + north) switch="-h" + sign="-" + ;; + south) switch="-h" + sign="+" + ;; + esac + xdo resize ${switch} ${sign}${size} + +# Otherwise, window is tiled: switch with window in given direction +else + case "$dir" in + west) bspc node @west -r -$size || bspc node @east -r -${size} + ;; + east) bspc node @west -r +$size || bspc node @east -r +${size} + ;; + north) bspc node @south -r -$size || bspc node @north -r -${size} + ;; + south) bspc node @south -r +$size || bspc node @north -r +${size} + ;; + esac +fi diff --git a/bin/cancel_presels b/bin/cancel_presels new file mode 100755 index 0000000..21a1526 --- /dev/null +++ b/bin/cancel_presels @@ -0,0 +1,2 @@ +#!/bin/sh +for window in $(bspc query -N -d focused); do bspc node $window -p cancel; done diff --git a/bin/clickpasser b/bin/clickpasser new file mode 100755 index 0000000..fd0bfbc --- /dev/null +++ b/bin/clickpasser @@ -0,0 +1,7 @@ +#!/bin/bash +#Script to allow clicking desktop in bspwm even if focus_follows_pointer is enabled +pkill -USR2 -x sxhkd; \ +bspc config focus_follows_pointer off; \ +xdotool click $@; \ +bspc config focus_follows_pointer on; \ +pkill -USR2 -x sxhkd diff --git a/bin/default-browser b/bin/default-browser new file mode 100755 index 0000000..e0137be --- /dev/null +++ b/bin/default-browser @@ -0,0 +1,3 @@ +#!/bin/sh +. $HOME/.profile +$BROWSER $@ diff --git a/bin/default-editor b/bin/default-editor new file mode 100755 index 0000000..9bfec1f --- /dev/null +++ b/bin/default-editor @@ -0,0 +1,3 @@ +#!/bin/sh +. $HOME/.profile +$GUI_EDITOR $@ diff --git a/bin/default-terminal b/bin/default-terminal new file mode 100755 index 0000000..3f41254 --- /dev/null +++ b/bin/default-terminal @@ -0,0 +1,3 @@ +#!/bin/sh +. $HOME/.profile +$TERMINAL $@ diff --git a/bin/edge-switcher b/bin/edge-switcher new file mode 100755 index 0000000..58cf052 --- /dev/null +++ b/bin/edge-switcher @@ -0,0 +1,13 @@ +#!/bin/bash +function on_exit { + for child in $(jobs -p); do + jobs -p | grep -q $child && kill $child + done + # Extra paranoia + [[ -d "${state_path}" && -w "${state_path}" ]] && rm -rf -- "${state_path}" +} + +trap on_exit EXIT SIGHUP SIGINT SIGTERM + +xdotool behave_screen_edge left exec bspc desktop -f prev & +xdotool behave_screen_edge right exec bspc desktop -f next & diff --git a/bin/euclid_balancer b/bin/euclid_balancer new file mode 100755 index 0000000..644a787 --- /dev/null +++ b/bin/euclid_balancer @@ -0,0 +1,14 @@ +#!/bin/zsh + +if [ "$(pgrep -cx euclid_balancer)" -gt 1 ] ; then + killall euclid_balancer && exit 0 +else + +bspc subscribe node_add node_remove node_state node_geometry | while read line; do + for wid in $(bspc query -N -d -n .window); do + bspc node "${wid}#@north" -B || true + bspc node "${wid}#@south" -B || true + done +done + +fi diff --git a/bin/euclid_mode b/bin/euclid_mode new file mode 100755 index 0000000..d2fe3c5 --- /dev/null +++ b/bin/euclid_mode @@ -0,0 +1,15 @@ +#! /bin/sh + +fwid=$(bspc query -N -n focused.automatic) +wid=$1 +class=$2 +instance=$3 +title=$(xtitle "$wid") +#floats=$(bspc query -N -n .local.floating | wc -l) +if bspc query -N -n "@/.!automatic" > /dev/null ; then + echo "node=@/" +fi +if [ -n "$fwid" ] ; then + echo "split_dir=south" +fi +#window-placer $floats $wid diff --git a/bin/euclid_mover b/bin/euclid_mover new file mode 100755 index 0000000..93fe470 --- /dev/null +++ b/bin/euclid_mover @@ -0,0 +1,85 @@ +#!/bin/bash +# Originally by https://github.com/windelicato/ + +size=${2:-'20'} +dir=$1 + +transplanter() { + bspc node ${dir} -p south && bspc node -n ${dir} +} + +northplanter() { + bspc node north -p north && bspc node -n north +} + +rootplanter() { + bspc node @/ -p ${dir} && bspc node -n @/ || bspc node -s next.local && bspc node -n @/ + bspc node @/ -p cancel +} + +bspc config pointer_follows_focus true +# Find current window mode +is_floating() { +bspc query -T -n | grep -q '"state":"floating"' +} +# If the window is floating, move it +if is_floating; then +#only parse input if window is floating,tiled windows accept input as is + case "$dir" in + west) switch="-x" + sign="-" + ;; + east) switch="-x" + sign="+" + ;; + north) switch="-y" + sign="-" + ;; + *) switch="-y" + sign="+" + ;; + esac + xdo move ${switch} ${sign}${size} + +# Otherwise, window is tiled: switch with window in given direction +else + if [[ $(bspc query -N -n .local.\!floating | wc -l) != 2 ]]; then + case "$dir" in + north) northplanter || rootplanter + ;; + *) transplanter || rootplanter + ;; + esac + else + case "$dir" in + east) bspc node -s east || bspc query -N -n west.local || \ + if bspc query -N -n south.local ; then + bspc node @/ -R 90 + else + bspc node @/ -R 270 + fi + ;; + west) bspc node -s west || bspc query -N -n east.local || \ + if bspc query -N -n north.local ; then + bspc node @/ -R 90 + else + bspc node @/ -R 270 + fi + ;; + south) bspc node -s south || bspc query -N -n north.local || \ + if bspc query -N -n west.local ; then + bspc node @/ -R 90 + else + bspc node @/ -R 270 + fi + ;; + *) bspc node -s north || bspc query -N -n south.local || \ + if bspc query -N -n west.local ; then + bspc node @/ -R 270 + else + bspc node @/ -R 90 + fi + ;; + esac + fi +fi diff --git a/bin/finder b/bin/finder new file mode 100755 index 0000000..279a755 --- /dev/null +++ b/bin/finder @@ -0,0 +1,24 @@ +#!/bin/sh +# A fuzzy file-finder and opener based on dmenu +# Requires: dmenu, xdg-utils +if ! [ -f "$HOME/.dmenurc" ]; then + cp /usr/share/dmenu/dmenurc $HOME/.dmenurc +fi +. $HOME/.dmenurc + +eval $(xdotool getmouselocation --shell) +menu_widht=600 +monitor_widht=$(wattr w $(lsw -r)) +monitor_height=$(wattr h $(lsw -r)) +lines=20 +menu_height=$(( $lines * 23 )) +maxx=$(( $monitor_widht - $menu_widht )) +miny=$PANEL_HEIGHT +maxy=$(( $monitor_height - $menu_height )) +XP=$X +[[ $XP -gt $maxx ]] && XP=$maxx +YP=$Y +[[ $YP -lt $miny ]] && YP=$miny +[[ $YP -gt $maxy ]] && YP=$maxy + +find ~/ | sed 's/ /\\ /g' | sort -f | dmenu -i -l $lines -y $YP -x $XP -w $menu_widht -fn $DMENU_FN -nb $DMENU_NB -nf $DMENU_NF -sf $DMENU_SF -sb $DMENU_SB | xargs xdg-open diff --git a/bin/focusdesktopofthismonitor b/bin/focusdesktopofthismonitor new file mode 100755 index 0000000..4a61aa1 --- /dev/null +++ b/bin/focusdesktopofthismonitor @@ -0,0 +1,7 @@ +#!/bin/sh +#Focus nth desktop of focused monitor for i3 style keybinds +# +#super + {1-9} +# focusdesktopofthismonitor ^{1-9} + D=$@; \ + bspc desktop -f "$(bspc query -D -m | sed -n "$D p")" diff --git a/bin/focusmover b/bin/focusmover new file mode 100755 index 0000000..f3936be --- /dev/null +++ b/bin/focusmover @@ -0,0 +1,13 @@ +#!/bin/sh +#Focus windows by direction, works with multihead +#called like this in sxhkdrc: +#super + {a,s,w,d} +# focusmover {west,south,north,east} + bspc config pointer_follows_monitor true; \ + bspc config pointer_follows_focus true; \ + dir=$@; \ + if ! bspc node -f $dir; then \ + bspc monitor -f $dir; \ + fi; \ + bspc config pointer_follows_monitor false; \ + bspc config pointer_follows_focus false diff --git a/bin/get-window-alignment b/bin/get-window-alignment new file mode 100755 index 0000000..89ef983 --- /dev/null +++ b/bin/get-window-alignment @@ -0,0 +1,13 @@ +#! /bin/sh +# By https://github.com/tatou-tatou +id="$(bspc query -N -n "${1:-focused}" | head -n1)" +[ -z "$id" ] && exit 1 + +w=$(wattr w "$id") +h=$($(wattr h "$id") + +if [ "$w" -gt "$h" ]; then + echo horizontal +else + echo vertical +fi diff --git a/bin/keybindings.sh b/bin/keybindings.sh new file mode 100755 index 0000000..db412ca --- /dev/null +++ b/bin/keybindings.sh @@ -0,0 +1,66 @@ +#!/bin/bash + + less <<-EOF + List of some useful keybindings. + More can be found from the file ~/.config/sxhkd/sxhkdrc. + You can also edit keybindings there. + + Mod4 is super key, on many keyboards marked with windows logo. + As a rule of thumb, super+ moves focus, + super+shift+ moves focused window, + and super+ctrl+ resizes windows. + + Arrow keys, wasd and hjkl represent directions and numbers represent + different workspaces. + + ### Window manipulation ################################################################ + + Alt + Tab |- Cycle windows + Super + Tab |- Open window switcher + Super + x |- Close window + Super + shift + x |- Kill window + Super + |- Move focus to the direction + Super + shift + |- Move focused window to direction + Super + ctrl + |- Resize focused window to direction + Alt + shift + |- Preselect/split the rootwindow + Super + 1-9 |- Focus the desktop with that number + Super + shift + 1-9 |- Move focused window to desktop with that number + Super + Enter |- Move window to the biggest available space + | or preselection if there is one + Super + ctrl + Enter |- Preselect where the next window will be opened + Ctrl + space |- Preselect where the next window will be opened + Alt + Enter |- Preselect/split the rootwindow + Super + b |- Balance windows + Alt + b |- Toggle automatic window balancing + Super + i |- Make window sticky + Super + t |- Toggle tiling/floating + Super + shift + t |- Toggle pseudotiling + Super + shift + f |- Toggle fullscreen + Super + f |- Toggle monocle + Super + o |- Make window private + | (Avoids splitting it automatically) + Super + shift + q |- Cleanly quit bspwm + Super + shift + r |- Reload bspwms configuration file + ### Mousecommands ###################################################################### + + Leftclick menus |- Close menu + Super + scroll |- Adjust window gap + Super + drag |- Moves window + Super + rightclick drag |- Resizes window + Alt + leftclick |- Spawn window manipulation menu on cursor + Alt_gr + leftclick |- Split window depending on mouselocation + | and spawn application menu + ### Applications ####################################################################### + + Super + p |- Dmenu (Run applications) + Super + space |- Dmenu (Run applications) + Super + shift + b |- Browser + Super + r |- File search + Super + e |- Explore files with SpaceFM + Super + shift + e |- Explore files with Ranger + Super + shift + Return |- Terminal + Super + z |- Terminal + + + + EOF diff --git a/bin/list_windows_by_size.sh b/bin/list_windows_by_size.sh new file mode 100755 index 0000000..4f795d8 --- /dev/null +++ b/bin/list_windows_by_size.sh @@ -0,0 +1,56 @@ +#!/bin/bash + + #client != null => container mit window + #rectangle => container size + #client.window => window id +# USAGE=\ +# "$(basename $0) [option] +# options: +# num any real number 1 -> biggest window 2 -> second biggest ... +# nothing print all windwos on desktop sorted by size biggest first\ +# " + tree=$(bspc wm -d| jshon -e root -j) + + function print_childs { + tree=$1 + fChild=$(echo $tree| jshon -e firstChild -j) + sChild=$(echo $tree| jshon -e secondChild -j) + for Child in $fChild $sChild; do + if [ "$(echo $Child| jshon -e client)" != "null" ]; then + window=$(echo $Child| jshon -e client -e window) + #echo $Child| jshon -e rectangle + height=$(echo $Child| jshon -e rectangle -e height) + width=$(echo $Child| jshon -e rectangle -e width) + echo "$window:$(( height * width ))" + else + print_childs $Child + fi + done + } + + #store window ids in array sorted by size + windows=( $(print_childs $tree| sort -t":" -rnk2| cut -d":" -f1 ) ) + windows_len=$(( ${#windows[@]} -1 )) + + #getOpts + #no options => print all ids sorted by leave size (window tiled + border) + if [ $# -ne 1 ]; then + for id in ${windows[@]}; do + echo $id + done + + # check if $1 is a number + elif ! [ "$1" -eq "$1" ] 2> /dev/null; then + echo "$USAGE" + + # print the x. biggest window 1 biggest 2 second biggest ... + # number higher then windows => print last (tinyst window) + else + [ $1 -gt 0 ] && index=$(( $1 -1 )) + + if [ $index -gt $windows_len ]; then + index=$windows_len + fi + + echo ${windows[$index]} + fi diff --git a/bin/movetodesktopofthismonitor b/bin/movetodesktopofthismonitor new file mode 100755 index 0000000..5af0a23 --- /dev/null +++ b/bin/movetodesktopofthismonitor @@ -0,0 +1,5 @@ +#!/bin/sh +#super + shift + {1-9} +# movetodesktopofthismonitor ^{1-9} +D=$@; \ +bspc node -d "$(bspc query -D -m | sed -n "$D p")" diff --git a/bin/pseudo_automatic_mode b/bin/pseudo_automatic_mode new file mode 100755 index 0000000..0722700 --- /dev/null +++ b/bin/pseudo_automatic_mode @@ -0,0 +1,29 @@ +#! /bin/sh + +fwid=$(bspc query -N -n focused.automatic) +wid=$1 +class=$2 +instance=$3 +title=$(xtitle "$wid") +receptacle=$(bspc query -N -n ".leaf.!window.local" | awk NR==1) +#floats=$(bspc query -N -n .local.floating | wc -l) + +if bspc query -N -n "@/.!automatic" > /dev/null ; then + echo "node=@/" +fi + +if [ -n "$receptacle" ] > /dev/null ; then + echo "node=$receptacle" +elif [ -n "$fwid" ] ; then + wattr wh $fwid | { + read width height + if [ $width -gt $height ] ; then + echo "split_dir=west" + else + echo "split_dir=south" + fi +# echo "split_ratio=0.5" + } +fi +wmctrl -i -r "$wid" -b add,maximized_vert,maximized_horz &>/dev/null & +#window-placer $floats $wid diff --git a/bin/resizetopresel.sh b/bin/resizetopresel.sh new file mode 100755 index 0000000..3eb5681 --- /dev/null +++ b/bin/resizetopresel.sh @@ -0,0 +1,83 @@ +#!/bin/zsh + +# Check if the brother node is a receptacle +if [[ $(bspc query -T -n @brother/ | jshon -e client) = null ]]; then + # Yep, it's a receptacle. Get the real dimensions + eval $(grep "gap=" .config/bspwm/bspwmrc) + # Get orientation + wattr xywh $(pfw) | read focused_x focused_y focused_width focused_height + receptacle_y=$(bspc query -T -n @brother/ | jshon -e rectangle -e y) + + if [[ "$focused_y" -eq "$receptacle_y" ]]; then + receptacle_width=$(bspc query -T -n @brother/ | jshon -e rectangle -e width) + receptacle_x=$(bspc query -T -n @brother/ | jshon -e rectangle -e x) + # receptacle and window have the same height, so they are side by side + if [[ receptacle_x -gt focused_x ]]; then + echo "receptacle is right of the window" + # get the true window dimension + true_dim=$(( receptacle_width + gap )) + # kill the repectacle + for i in $(bspc query -N -n .leaf.!window.local); do bspc node $i -k; done + # resize the window + bspc node @east -r -$true_dim || bspc node @west -r +$true_dim + else + echo "receptacle is left of the window" + # get the true window dimension + true_dim=$(( receptacle_width + gap )) + # kill the repectacle + for i in $(bspc query -N -n .leaf.!window.local); do bspc node $i -k; done + # resize the window + bspc node @west -r +$true_dim || bspc node @east -r -$true_dim + fi + else + receptacle_height=$(bspc query -T -n @brother/ | jshon -e rectangle -e height) + # widht is necessarily equal if height is not, because the nodes are brothers + # Window are on the top of each other + if [[ receptacle_y -gt focused_y ]]; then + echo "receptacle is below the window" + # get the true window dimension + true_dim=$(( receptacle_height + gap)) + # kill the repectacle + for i in $(bspc query -N -n .leaf.!window.local); do bspc node $i -k; done + # resize the window + bspc node @south -r -$true_dim || bspc node @north -r +$true_dim + else + echo "receptacle is above the window" + # get the true window dimension + true_dim=$(( receptacle_height + gap)) + # kill the repectacle + for i in $(bspc query -N -n .leaf.!window.local); do bspc node $i -k; done + # resize the window + bspc node @north -r +$true_dim || bspc node @south -r -$true_dim + fi + fi + echo $true_dim + exit 0 +fi + +# If the focused window is not preselected, exit +[[ "$(bspc query -T -n focused | jshon -e presel)" == null ]] && exit 0 + +dir=$(bspc query -T -n focused | jshon -e presel -e splitDir | tr -d \") +ratio=$(bspc query -T -n focused | jshon -e presel -e splitRatio) + +case "$dir" in + west) + cur=$(bspc query -T -n focused | jshon -e rectangle -e width) + bspc node @west -r +$((${cur}*${ratio})) || bspc node @east -r -$((${cur}*${ratio})) + ;; + east) + cur=$(bspc query -T -n focused | jshon -e rectangle -e width) + bspc node @east -r -$((${cur}*${ratio})) || bspc node @west -r +$((${cur}*${ratio})) + ;; + + north) + cur=$(bspc query -T -n focused | jshon -e rectangle -e height) + bspc node @north -r +$((${cur}*${ratio})) || bspc node @south -r -$((${cur}*${ratio})) + ;; + south) + cur=$(bspc query -T -n focused | jshon -e rectangle -e height) + bspc node @south -r -$((${cur}*${ratio})) || bspc node @north -r +$((${cur}*${ratio})) +esac + +cancel_presels diff --git a/bin/run_once b/bin/run_once new file mode 100755 index 0000000..992aaf7 --- /dev/null +++ b/bin/run_once @@ -0,0 +1,3 @@ +#! /bin/bash +# Run program unless it's already running +pgrep $@ > /dev/null || ($@ &) diff --git a/bin/smartsplit b/bin/smartsplit new file mode 100755 index 0000000..af8b05d --- /dev/null +++ b/bin/smartsplit @@ -0,0 +1,31 @@ +#!/bin/bash +# Window splitting script for bspwm. Requires wmutils and xdotool. Splits window in its biggest dimension +# in the direction that is closer to the cursor. Inspired by MouseLaunch and pseudo_automatic_rule. +# Get the necessary info + +eval $(xdotool getmouselocation --shell) +IFS=" " read -a window <<< $(wattr whxy $(bspc query -N -n focused)) + +# Distance to each side +north=$(( $Y - ${window[3]})) +south=$(( ${window[3]} + ${window[1]} - $Y )) +west=$(( $X - ${window[2]})) +east=$(( ${window[2]} + ${window[0]} - $X )) +# Dimensions of window +widht=${window[0]} +height=${window[1]} + +# Determine which window edge in biggest dimension is closer + if [[ "$widht" -lt "$height" ]] && [[ "$north" -lt "$south" ]]; then + dir_final=north + elif [[ "$widht" -lt "$height" ]] && [[ "$north" -ge "$south" ]]; then + dir_final=south + elif [[ "$widht" -ge "$height" ]] && [[ "$east" -ge "$west" ]]; then + dir_final=west + else + dir_final=east + fi + +# Split the window accordingly +bspc node -p \~$dir_final +#echo "north=$north east=$east south=$south west=$west widht=$widht Height=$height $dir_final" diff --git a/bin/summondesktop.sh b/bin/summondesktop.sh new file mode 100755 index 0000000..523dceb --- /dev/null +++ b/bin/summondesktop.sh @@ -0,0 +1,14 @@ +#! /bin/sh +#in sxhkdrc call it with +#alt + {1-9,0} +# summonworkspace.sh {1-9,0} + D=$(bspc query -D -m | sed -n "$@ p"); \ + M=$(bspc query --monitors --desktop $D); \ + if [ $(bspc query --desktops --monitor $M | wc -l) -gt 1 ]; then \ + if [ $(bspc query --desktops --desktop focused) != $D ]; then \ + bspc desktop $D --to-monitor focused; \ + bspc desktop $D --focus; \ + fi; \ + elif [ $(bspc query --monitors --monitor focused) != $M ]; then \ + bspc desktop $(bspc query --monitors --desktop $D):focused --swap $(bspc query -M -m focused):focused; \ + fi diff --git a/bin/swapOrMoveIn.sh b/bin/swapOrMoveIn.sh new file mode 100755 index 0000000..de87b3f --- /dev/null +++ b/bin/swapOrMoveIn.sh @@ -0,0 +1,4 @@ +#!/bin/bash +#By https://github.com/ikn/ +dir=$1 +bspc node -n ${dir}.!automatic || bspc node -s ${dir} diff --git a/bin/toggle-focus-follows-pointer b/bin/toggle-focus-follows-pointer new file mode 100755 index 0000000..dc66e56 --- /dev/null +++ b/bin/toggle-focus-follows-pointer @@ -0,0 +1,15 @@ +#!/bin/sh + +# ------------------------------------------------------------ +# Purpose: toggle focus with mouse. This needs to be +# disabled for wonky java stuff, see: +# https://bbs.archlinux.org/viewtopic.php?pid=1448554#p1448554 +# +# Thanks matchew, for your awesome script! +# ------------------------------------------------------------ + +toggle=$(bspc config focus_follows_pointer | \ + awk -vtoggle="true" \ + '{ if ($1 == "true") toggle="false"; print toggle }') + +bspc config focus_follows_pointer $toggle diff --git a/bin/toggle-pointer-follows-focus b/bin/toggle-pointer-follows-focus new file mode 100755 index 0000000..e1b9929 --- /dev/null +++ b/bin/toggle-pointer-follows-focus @@ -0,0 +1,7 @@ +#!/bin/sh + +toggle=$(bspc config pointer_follows_focus | \ + awk -vtoggle="true" \ + '{ if ($1 == "true") toggle="false"; print toggle }') + +bspc config pointer_follows_focus $toggle diff --git a/bin/whid b/bin/whid new file mode 100755 index 0000000..dd8b0b2 --- /dev/null +++ b/bin/whid @@ -0,0 +1,78 @@ +#!/bin/bash +file="/tmp/.minimized" +touch $file +# By https://github.com/tatou-tatou +width=$(wattr w $(lsw -r)) +height=$(wattr h $(lsw -r)) +bar_width=$(( $width / 2 )) +left_shift=$(( ($width - $bar_width) / 2 )) +top_shift=$(( $height / 3 )) + +case $1 in +hide) + lines=$(wc -l < $file) + + if [[ $lines -ge 10 ]]; then ## Fight against bad practices + notify-send "Ten windows are already hidden" "You should consider closing some before hiding even more." -i warning + else + focusedID=$(xdo id) + if [[ "$focusedID" ]]; then + focusedName=$(xdotool getwindowname $focusedID) + focusedDesktop=$(xdotool get_desktop) + + echo "$focusedID $focusedDesktop $focusedName" >> $file && xdo hide $focusedID && notify-send "A window has been hidden (${lines})." "$focusedName" -i warning + fi + fi + ;; +dmenu) + miniList=$(cat $file) + + # Dmenu cannot draw more than 30 lines + lines=$(wc -l < $file) + if [[ $lines -gt 30 ]] + then linesDisplayed=30 + else linesDisplayed=$lines + fi + + # If the list is empty + if [ -z "$miniList" ] + then + miniList=" Nothing is hidden!" + linesDisplayed=1 + fi + + # Calculate where to draw the dmenu popup. + # Comment that line if you use vanilla dmenu. + yPos=$((410-$linesDisplayed*10)) + + + # Uncomment only one line with dmenu_cmd + # If you use rofi + dmenu_cmd="rofi -lines $linesDisplayed -dmenu -p Hidden:" + + # If you use dmenu, patched with eye candy + # dmenu_cmd="dmenu -l 9 -x $left_shift -y $top_shift -w $bar_width -fn sans-11 -nb #201F1D -nf #eddec9 -sb #8F3724 -sf #EDDEC9 -p Hidden:" + + # If you use vanilla dmenu + # dmenu_cmd="dmenu -b -i -l $linesDisplayed -p Hidden:" + + # Launch dmenu + lineNumber=$(echo "$miniList" | cut -d " " -f 3- | nl -w 3 -n rn | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' | $dmenu_cmd | cut -d '-' -f -1) + + # If you exited dmenu without selecting anything or if the list was empty + [ -z "$lineNumber" -o "$miniList" = " Nothing is hidden!" ] && exit + + # Show the selected hidden window + selectedID=$(sed -n "$lineNumber p" $file | cut -d ' ' -f 1) + selectedDesktop=$(sed -n "$lineNumber p" $file | cut -d ' ' -f 2) + xdotool set_desktop $selectedDesktop + xdo show $selectedID && sed -i "${lineNumber}d" $file + ;; +last) + lines=$(wc -l < $file) + selectedID=$(tail -n 1 $file | cut -d ' ' -f 1) + selectedDesktop=$(sed -n "$lines p" $file | cut -d ' ' -f 2) + xdotool set_desktop $selectedDesktop + xdo show $selectedID && sed -i "${lines}d" $file + ;; +esac diff --git a/bin/windowgrabber b/bin/windowgrabber new file mode 100755 index 0000000..651f238 --- /dev/null +++ b/bin/windowgrabber @@ -0,0 +1,43 @@ +#!/bin/zsh +# Originally by https://github.com/windelicato/ +# edited beyound recognition + +follower() { +if [ "$(pgrep -cx windowgrabber)" = 1 ] ; then + bspc config pointer_follows_focus false +fi +} + +trap 'follower' INT TERM QUIT EXIT + +size=${2:-'20'} +dir=$1 + +bspc config pointer_follows_focus true +# Find current window mode +is_floating() { +bspc query -T -n | grep -q '"state":"floating"' +} +# If the window is floating, move it +if is_floating; then +#only parse input if window is floating,tiled windows accept input as is + case "$dir" in + west) switch="-x" + sign="-" + ;; + east) switch="-x" + sign="+" + ;; + north) switch="-y" + sign="-" + ;; + *) switch="-y" + sign="+" + ;; + esac + xdo move ${switch} ${sign}${size} + +# Otherwise, window is tiled: switch with window in given direction +else + bspc node -n ${dir}.!automatic || bspc node -s ${dir} || bspc node -m ${dir} && bspc monitor -f +fi diff --git a/bin/windowpromoter b/bin/windowpromoter new file mode 100755 index 0000000..1a23dfb --- /dev/null +++ b/bin/windowpromoter @@ -0,0 +1,26 @@ +#!/usr/bin/sh + +receptacle=$(bspc query -N -n ".leaf.!window.local" | awk NR==1) + +window_promotion() +{ + if [ -n "$receptacle" ] > /dev/null ; then + bspc node -n "$receptacle" + elif [ -z "$(bspc query -N -n last.!automatic.local)" ]; then \ + bspc node -s biggest.!focused.local; \ + else \ + bspc node -n last.!automatic.local; \ + fi +} + +if bspc query -N -n "@/.!automatic" > /dev/null ; then + bspc node -n @/ || window_promotion + else + if [ -n "$receptacle" ] > /dev/null ; then + bspc node -n "$receptacle" + elif [ -z "$(bspc query -N -n last.!automatic.local)" ]; then \ + bspc node -s biggest.!focused.local; \ + else \ + bspc node -n last.!automatic.local; \ + fi +fi diff --git a/bin/workspaces_multimonitor b/bin/workspaces_multimonitor index 2c1f39e..8d5a3c3 100755 --- a/bin/workspaces_multimonitor +++ b/bin/workspaces_multimonitor @@ -1,6 +1,6 @@ #!/bin/bash -all_monitors=$(xrandr -q | awk '/connected/ {print $1}') +all_monitors=$(xrandr -q | awk '/ connected/ {print $1}') default_screen=$(xrandr | awk '/ connected/ {print $1;exit;}') extra_monitors=$(xrandr -q | awk '/ connected/ {print $1}' | grep -v $default_screen)