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

Splitting a container fails on sway, works on i3 #8482

Open
bhepple opened this issue Nov 29, 2024 · 0 comments
Open

Splitting a container fails on sway, works on i3 #8482

bhepple opened this issue Nov 29, 2024 · 0 comments
Labels
bug Not working as intended

Comments

@bhepple
Copy link

bhepple commented Nov 29, 2024

  • Sway Version:

    • sway version 1.10
  • Debug Log:

    • Run sway -d 2> ~/sway.log from a TTY and upload it to a pastebin, such as gist.github.com.

This was run with -c /etc/sway/config:
gist

  • Description:
    • On an empty workspace, create 4 tiled windows - 'foot' will do
    • Find out their .ids
    • Move to a fresh empty workspace
    • set default layout to splith
    • move the first two 'foot' windows to the current workspace
    • focus parent
    • split v
    • move the remaining 2 windows to the current workspace

In i3wm we get a 2x2 grid of windows. In sway we get 4 horizontal windows with this workspace representation:

V[H[foot foot V[H[foot foot]]]]

It should be:

V[H[foot foot] H[foot foot]]

I have a simple script to do the above operations -

  • On an empty workspace, create 4 tiled windows - 'foot' will do
  • invoke the script with 'bash ./test.sh 2'

The script outputs the swaymsg operations and the workspace representation: workspace 20 is used as a 'scratch' workspace and is assumed to be empty.

swaymsg [con_id=7] move to workspace 20
swaymsg [con_id=8] move to workspace 20
swaymsg [con_id=15] move to workspace 20
swaymsg [con_id=16] move to workspace 20
swaymsg layout splith
swaymsg [con_id=7] move to workspace current, focus
H[foot]
swaymsg split h
H[foot]
swaymsg [con_id=8] move to workspace current, focus
H[foot foot]
swaymsg focus parent, split v                          <<<<<<< here be dragons
H[H[foot foot]]                                                     <<<<<<< should be V[H[foot foot]]
swaymsg [con_id=15] move to workspace current, focus
V[H[foot foot foot]]
swaymsg split h
V[H[foot foot H[foot]]]
swaymsg [con_id=16] move to workspace current, focus
V[H[foot foot H[foot foot]]]
swaymsg focus parent, split v
V[H[foot foot V[H[foot foot]]]]

Here is the script:

#!/usr/bin/env bash

do_msg() {
    echo "$msg $*"
    $msg "$*"
}

show_representation() {
    [[ "$SWAYSOCK" ]] &&
        $msg -t get_workspaces | jq -r '.[] | select(.focused==true)|.representation'
}

msg="i3-msg"
[[ "$SWAYSOCK" ]] && {
    msg="swaymsg"
}

cols="$1"

if [[ "$SWAYSOCK" ]]; then
    query="select(.visible==true) | select(.app_id != null or .window_properties.instance != null)"
else
    query='select(.window_properties?) | select(.floating == "auto_off" or .floating == "user_off") | select(.output != "__i3")'
fi

# Set the layout for all windows in the focused workspace to vertical/horizontal
tree=$( $msg -t get_tree )
id_list=$( echo "$tree" | jq ".. | select(.type?) | $query | .id" )

# NB we need to send everything off screen, change the layout and
# bring them back

for id in ${id_list[@]}; do
    do_msg "[con_id=$id] move to workspace 20"
done
do_msg "layout splith"

count=0
for id in ${id_list[@]}; do
    do_msg "[con_id=$id] move to workspace current, focus"
    show_representation
    if (( ( count + 1 ) % cols == 0 )); then
        do_msg 'focus parent, split v'
    elif (( ( count + 1 ) % cols == 1 )); then
        do_msg 'split h'
    fi
    show_representation
    count=$(( count + 1 ))
done

Curiously, if I create new windows (instead of moving them from another workspace) I end up with a correct grid:

  • Move to an empty workspace
  • Create a new 'foot' window
  • split h
  • Create a new 'foot' window
  • focus parent
  • split v
  • Create a new 'foot' window
  • split h
  • Create a new 'foot' window

We have a 2x2 grid with representation:

V[H[foot foot] H[foot foot]]
@bhepple bhepple added the bug Not working as intended label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended
Development

No branches or pull requests

1 participant