Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix visuals when floating window #72

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 73 additions & 10 deletions src/layout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ previous_layout() {
while [[ $# != 0 ]]; do
case $1 in
--layouts)
[ "$2" ] && layouts=$(echo "$2" | tr ',' '\n')
shift
;;
[ "$2" ] && layouts=$(echo "$2" | tr ',' '\n')
shift
;;
--desktop)
desktop_selector="$2"
shift
;;
;;
esac
shift
done
Expand All @@ -106,13 +106,13 @@ next_layout() {
while [[ $# != 0 ]]; do
case $1 in
--layouts)
[ "$2" ] && layouts=$(echo "$2" | tr ',' '\n')
shift
;;
[ "$2" ] && layouts=$(echo "$2" | tr ',' '\n')
shift
;;
--desktop)
desktop_selector="$2"
shift
;;
;;
esac
shift
done
Expand Down Expand Up @@ -154,14 +154,77 @@ start_listener() {
# ->
__recalculate_layout() { run_layout $layout $args 2> /dev/null || true; }

cache_node_was_added=""
cache_node_id=""
prev_node_state=""
shopt -s extglob # not sure if needed
# Then listen to node changes and recalculate as required
bspc subscribe node_{add,remove,transfer,flag,state} desktop_focus | while read -a line; do
bspc subscribe node_{add,remove,transfer,flag,state,geometry} desktop_focus | while read -a line; do
event="${line[0]}"
[ "$event" = "node_transfer" ] && arg_index="5" || arg_index="2"
desktop_id="${line[$arg_index]}"
desktop_name=$(get_desktop_name_from_id "$desktop_id")
node_id="${line[3]}"
node_state="${line[4]}${line[5]}"
node_is_not_floating=""

if [ "$event" = "node_add" ]; then
cache_node_was_added=1
node_id="${line[4]}"
cache_node_id="$node_id"
fi

# maintain list of non-floating visible nodes to fix layout after tiled becomes floating
#if [[ ("$event" != node_add && "$event" != node_state && "$event" != node_geometry) || ("$event" = node_state && "$node_state" != floatingon && "$prev_node_state") ]]; then
if [[ "$event" != @(node_add|node_state|node_geometry) || \
("$event" = node_state && "$node_state" != floatingon && "$prev_node_state") ]]; then
new_window_list=$(bspc query -N -n .local.!floating.!hidden)
fi

if [[ "$event" = node_state && "$node_state" = floatingon && "$prev_node_state" ]]; then
# floating node was added
# remove all node info
prev_node_state="none"
cache_node_was_added=""
cache_node_id=""
elif [[ ("$event" = node_state && "$node_state" != floatingon && "$prev_node_state") || \
("$event" != node_add && "$event" != node_geometry && -z "$cache_node_was_added") || \
("$event" = node_geometry && "$cache_node_was_added") ]]; then
node_is_not_floating=1

prev_node_state="none"
cache_node_was_added=""
if [ "$cache_node_id" ]; then
node_id="$cache_node_id"
cache_node_id=""
fi

# protection against floating node transfers
# evaluate if node_id exist & is not floating
#
# node_id has value at node_remove event, but bspc query $node_id \
# will return false because node already doesn't exist
if ! echo "$new_window_list" | grep -q "$node_id" && \
! echo "$old_window_list" | grep -q "$node_id" ; then
node_is_not_floating=""
if bspc query -N -n "$node_id".!floating >/dev/null; then
# allow update layout when node becomes tiled
new_window_list=$(bspc query -N -n .local.!floating.!hidden)
node_is_not_floating=1
fi
fi
old_window_list="$new_window_list"
fi

if [ "$prev_node_state" = "none" ]; then
prev_node_state=""
elif [ "$event" = "node_state" ] && [ -z "$prev_node_state" ]; then
# to determine first node_state
# when creating new floating node it will first trigger tiled off
prev_node_state="$node_state"
fi

if [ "$desktop_name" = "$selected_desktop" ]; then
if [ "$desktop_name" = "$selected_desktop" ] && [ "$node_is_not_floating" ]; then
__initialize_layout

if [ "$event" = "node_transfer" ]; then
Expand Down
13 changes: 7 additions & 6 deletions src/layouts/rtall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source "$ROOT/utils/config.sh"

master_size=$TALL_RATIO

node_filter="!hidden"
node_filter="!hidden.!floating"

# List[args] -> ()
execute_layout() {
Expand All @@ -20,18 +20,18 @@ execute_layout() {
done

# ensure the count of the master child is 1, or make it so
local nodes=$(bspc query -N '@/2' -n .descendant_of.window.$node_filter)
local nodes=$(bspc query -N '@/2' -n .local.window.$node_filter)
local win_count=$(echo "$nodes" | wc -l)

if [ $win_count -ne 1 ]; then
local new_node=$(bspc query -N '@/2' -n last.descendant_of.window.$node_filter | head -n 1)
local new_node=$(bspc query -N '@/2' -n last.local.window.$node_filter | head -n 1)

[ -z "$new_node" ] && new_node=$(bspc query -N '@/1' -n last.descendant_of.window.$node_filter | head -n 1)
[ -z "$new_node" ] && new_node=$(bspc query -N '@/1' -n last.local.window.$node_filter | head -n 1)

local root=$(echo "$nodes" | head -n 1)

# move everything into 2 that is not our new_node
for wid in $(bspc query -N '@/2' -n .descendant_of.window.$node_filter | grep -v $root); do
for wid in $(bspc query -N '@/2' -n .local.window.$node_filter | grep -v $root); do
bspc node "$wid" -n '@/1'
done

Expand All @@ -42,7 +42,7 @@ execute_layout() {
rotate '@/2' horizontal 90

local stack_node=$(bspc query -N '@/1' -n)
for parent in $(bspc query -N '@/1' -n .descendant_of.!window.$node_filter | grep -v $stack_node); do
for parent in $(bspc query -N '@/1' -n .local.!window.$node_filter | grep -v $stack_node); do
rotate $parent horizontal 90
done

Expand All @@ -54,6 +54,7 @@ execute_layout() {
local have=$(jget width "$(bspc query -T -n '@/2')")

bspc node '@/2' --resize left $((have - want)) 0
bspc node any.local -E
}

cmd=$1
Expand Down
13 changes: 7 additions & 6 deletions src/layouts/tall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source "$ROOT/utils/config.sh"

master_size=$TALL_RATIO

node_filter="!hidden"
node_filter="!hidden.!floating"

# List[args] -> ()
execute_layout() {
Expand All @@ -20,18 +20,18 @@ execute_layout() {
done

# ensure the count of the master child is 1, or make it so
local nodes=$(bspc query -N '@/1' -n .descendant_of.window.$node_filter)
local nodes=$(bspc query -N '@/1' -n .local.window.$node_filter)
local win_count=$(echo "$nodes" | wc -l)

if [ $win_count -ne 1 ]; then
local new_node=$(bspc query -N '@/1' -n last.descendant_of.window.$node_filter | head -n 1)
local new_node=$(bspc query -N '@/1' -n last.local.window.$node_filter | head -n 1)

[ -z "$new_node" ] && new_node=$(bspc query -N '@/2' -n last.descendant_of.window.$node_filter | head -n 1)
[ -z "$new_node" ] && new_node=$(bspc query -N '@/2' -n last.local.window.$node_filter | head -n 1)

local root=$(echo -e "$nodes" | head -n 1)

# move everything into 2 that is not our new_node
for wid in $(bspc query -N '@/1' -n .descendant_of.window.$node_filter | grep -v $root); do
for wid in $(bspc query -N '@/1' -n .local.window.$node_filter | grep -v $root); do
bspc node "$wid" -n '@/2'
done

Expand All @@ -42,7 +42,7 @@ execute_layout() {
rotate '@/2' horizontal 90

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

Expand All @@ -54,6 +54,7 @@ execute_layout() {
local have=$(jget width "$(bspc query -T -n '@/1')")

bspc node '@/1' --resize right $((want - have)) 0
bspc node any.local -E
}

cmd=$1
Expand Down