Skip to content
Permalink
Browse files

bring in new qutebrowser layout stuff, stack_layout.sh

  • Loading branch information
neeasade committed Mar 16, 2020
1 parent fc04539 commit c384921d6c01e3936923c63991a9ccdcea8edf78
No changes.
@@ -0,0 +1,22 @@
#!/bin/sh
# clone a repo that we are looking in, regardless of where we are in it
# pop open a terminal in the cloned repo

get_repo() {
short=$(echo "$*" | grep -oE "${domain}/[a-zA-Z0-9]+/[a-zA-Z0-9]/")
if [ -z "$short" ]; then
return 1
else
printf 'https://%s' "$short"
return 0
fi
}

target=
for domain in github.com gitlab.com; do
if target=$(get_repo "$QUTE_URL"); then
cd "${HOME}/git"

break
fi
done
@@ -0,0 +1,5 @@
#!/bin/sh
# todo: make it possible to not create a url note when viewing it
popup_window.sh -r
emacsclient -c --no-wait
elisp "(ns/urlnote-jump \"${QUTE_URL}\")"
@@ -11,7 +11,7 @@
# p_title_show_mode
# active - only active
# all - all all the time
# monocle - only active when tiling, all when tiled
# monocle - only active when tiling, all when monocle
show_mode=${p_title_show_mode:-monocle}

# Maxium window title length
@@ -0,0 +1,31 @@
#!/bin/sh
# jump to some window by classname
# goal is to find last focused window by classname

# note: other way:
# bspc wm -d | jq '.focusHistory[] | select(.desktopId == '${current_desk}') | .nodeId' | sort -r
# for wid in $(); do echo nop done

# current_desk=$(printf "%d\n" $(bspc query -D -d))
current_desk=$(bspc query -D -d)

# WM_CLASS(STRING) = "emacs-26_3", "Emacs"
class=${*:-Emacs}

# todo: cache/don't retry checks
for wid in $(bspc wm -d | jq '.focusHistory[] | select(.desktopId == '${current_desk}') | .nodeId' | sort -r); do
if xprop -id $wid | grep "^WM_CLASS" | grep "$class"; then
echo bspc node -f $wid
bspc node -f $wid
exit 0
fi
done

# if that fails, try all windows
for wid in $(bspc query -N -n .window | sort -r); do
if xprop -id $wid | grep "^WM_CLASS" | grep "$class"; then
echo bspc node -f $wid
bspc node -f $wid
exit 0
fi
done
@@ -0,0 +1,79 @@

#!/usr/bin/env bash
# a stack layout for bspwm
# bspc subscribe node_{remove,add} | while read _; do ./stack_layout.sh; done

master_size=.63

jget() {
# thanks camille
key=$1
shift
var=${*#*\"$key\":}
var=${var%%[,\}]*}
echo "$var"
}

vdo() {
echo "$*"
"$@"
}

# ensure the count of the master child is 1, or make it so
win_count=$(bspc query -N '@/1' -n .descendant_of.window | wc -l)
echo win_count: $win_count
if [ $win_count -ne 1 ]; then
if [ -z "$*" ]; then
new_master=$(bspc query -N '@/1' -n last.descendant_of.window | head -n 1)
# new_master=$(bspc query -N '@/1' -n .descendant_of.window | head -n 1)
else
new_master=$*
fi

if [ -z "$new_master" ]; then
new_master=$(bspc query -N '@/2' -n last.descendant_of.window | head -n 1)
fi

echo "new master: $new_master"
# move everything into 2 that is not our new_master
for wid in $(bspc query -N '@/1' -n .descendant_of.window | grep -v $new_master); do
vdo bspc node "$wid" -n '@/2'
done

vdo bspc node "$new_master" -n '@/1'
fi

# amend the split type so we are arranged correctly
# on all stacking children
correct_rotation() {
# sleep 5
# sleep 0.5
node=$1
want=$2
have=$(jget splitType "$(bspc query -T -n "$node")")
# the only bashism
have=${have:1:${#have}-2}

if [ ! "$have" = "$want" ]; then
vdo bspc node "$node" -R 270
fi
}


vdo correct_rotation '@/' vertical
vdo correct_rotation '@/2' horizontal

stack_node=$(bspc query -N '@/2' -n)
for parent in $(bspc query -N '@/2' -n '.descendant_of.!window' | grep -v $stack_node); do
vdo correct_rotation $parent horizontal
done

stack_node=$(bspc query -N '@/2' -n)
bspc node '@/2' -B

# mon_width=$(bspc query -T -m | jq .rectangle.width)
mon_width=$(jget width "$(bspc query -T -m)")

want=$(echo $master_size \* $mon_width | bc -l | sed 's/\..*//')
have=$(jget width "$(bspc query -T -n '@/1')")
bspc node '@/1' --resize right $((want - have)) 0

0 comments on commit c384921

Please sign in to comment.
You can’t perform that action at this time.