I3 floating mode misbehaving

I’m experiencing an odd behavior when toggling floating mode. The first time it appears to be working kinda fine, but with the floating window randomly placed; subsequent times every app gets a different treatment, it usually floats centered in the screen but with random sizes, including filling the whole screen.
Yet I have this line in my config:

for_window [floating] resize set 640 480

Post your entire i3 config.

If there are no recent changes (that you know of), the way I usually debug configs, when I have no clue why it’s doing what it’s doing, is to comment out large chunks of the config file and see if it still happens. Then reduce the size of the commented parts. You usually find the troublesome config/interaction quite quickly this way.

I commented out everything related to windows and now the issue seems to be confined to Kitty and Firefox only, I guess something in their configurations messes with the floating commands.

Post your i3 config if you don’t mind so that we can have a look. It’s likely that something in your i3 config is causing this behavior.

my full config:

# basics
set $mod Mod4
set $alt Mod1
set $ctl Control
set $sft Shift
font pango: Cousine 10
gaps inner 0
assign [class=".*nkscape.*"] → 2
assign [class="Gimp.*"] → 2
assign [class="stellarium"] → 3
focus_wrapping no

# autostart
exec_always --no-startup-id feh --bg-fill ~/.config/0-wallpapers/surf1.png
exec --no-startup-id /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1
exec --no-startup-id dex -a -s /etc/xdg/autostart/:~/.config/autostart/
exec --no-startup-id dex --autostart --environment i3
exec --no-startup-id /usr/bin/dunst
exec --no-startup-id syncthing-gtk -m
exec_always --no-startup-id autotiling --limit 2
exec_always --no-startup-id picom --config ~/.config/picom/picom.conf
exec_always --no-startup-id unclutter
exec_always --no-startup-id ~/.config/polybar/launch.sh --blocks
exec_always --no-startup-id greenclip daemon>/dev/null
exec_always "setxkbmap -layout it,us -variant us, -option grp:win_space_toggle compose:rwin"
exec_always --no-startup-id (sleep 5 && xset s off -dpms)&

# floating and exceptions
## floating modifier
floating_modifier $mod

## tiling exceptions
for_window [window_role="About"] floating enable
for_window [class="vlc"] floating enable
for_window [class="Galculator" instance="galculator"] floating enable resize set 320 320
for_window [class="gnome-calculator" instance="gnome-calculator"] floating enable resize set 320 320
for_window [class="Blueberry.py" instance="blueberry.py"] floating enable
for_window [class="Xsane" instance="xsane"] floating enable
for_window [class="Pavucontrol" instance="pavucontrol"] floating enable
for_window [class="qt5ct" instance="qt5ct"] floating enable
for_window [class="Bluetooth-sendto" instance="bluetooth-sendto"] floating enable
for_window [class="Syncthing GTK"] floating enable

## set size of floating window
for_window [floating] resize set 640 480

# visuals

default_border pixel 4
default_floating_border pixel 0
hide_edge_borders smart_no_gaps
for_window [class=gnome.*] border pixel 4
for_window [class=gcolor3] border pixel 4
for_window [class=obsidian] border pixel 4

# Define colors
set $white        #d8dee8
set $tokyol        #ebdbb2
set $accent     #ec7875
set $accentb    #ff9e64
set $blue        #6c77bb
set $grey       #4d5576
set $greyl      #969696
set $greyd    #2f343f
set $tokyod     #222436
set $black    #282828
#                       border     background   text       indicator
client.focused          $accent    $accent      $greyd     $blue
client.unfocused        $greyd     $tokyod      $blue      $tokyod
client.focused_inactive $grey      $grey        $tokyod    $tokyod
client.urgent           $accent    $accent      $greyd     $accent

# keybindings
## system
bindsym $mod+g    exec ~/.config/polybar/blocks/scripts/launcher.sh
bindsym $mod+$sft+g    exec --no-startup-id i3-dmenu-desktop
bindsym $mod+$sft+q    exec ~/.config/polybar/blocks/scripts/powermenu.sh
bindsym $mod+Tab    exec rofi -show window -theme ~/.config/polybar/blocks/scripts/rofi/launcher.rasi
bindsym $mod+p      exec rofi -modi "clipboard:greenclip print" -show clipboard -run-command '{cmd}' \
        -theme ~/.config/polybar/blocks/scripts/rofi/launcher.rasi

## programs
bindsym $mod+w    exec firefox
bindsym $mod+d    exec nautilus
bindsym $mod+$sft+d    exec ~/.config/scripts/vifmrun
bindsym $mod+c    exec kitty
bindsym $mod+v    exec kitty -e nvim

## windows
bindsym $mod+b    layout tabbed
bindsym $mod+$sft+b    layout default
bindsym $mod+x    layout toggle split
bindsym $mod+$sft+z    floating toggle
bindsym $mod+z    focus mode_toggle
bindsym $mod+f    fullscreen toggle
bindsym $mod+m    exec ~/.config/i3/scripts/mark.sh
bindsym $mod+apostrophe    exec ~/.config/i3/scripts/goto.sh

bindsym $mod+n    focus left
bindsym $mod+Left    focus left
bindsym $mod+o    focus up
bindsym $mod+Up    focus up
bindsym $mod+e    focus down
bindsym $mod+Down    focus down
bindsym $mod+i    focus right
bindsym $mod+Right    focus right
bindsym $mod+$sft+n    move left
bindsym $mod+$sft+Left    move left
bindsym $mod+$sft+o    move up
bindsym $mod+$sft+Up    move up
bindsym $mod+$sft+e    move down
bindsym $mod+$sft+Down    move down
bindsym $mod+$sft+i    move right
bindsym $mod+$sft+Right    move right
bindsym $mod+j    focus parent
bindsym $mod+$sft+j                focus child
bindsym $mod+q    kill

## workspaces
bindsym $mod+1    workspace 1
bindsym $mod+2    workspace 2
bindsym $mod+3    workspace 3
bindsym $mod+4    workspace 4
bindsym $mod+5    workspace 5
bindsym $mod+6    workspace 6
bindsym $mod+7    workspace 7
bindsym $mod+8    workspace 8
bindsym $mod+9    workspace 9
bindsym $mod+0    workspace 10
bindsym $mod+r    workspace prev
bindsym $mod+s    workspace next
bindsym $mod+$sft+r    exec ~/.config/i3/scripts/next-prev-follow.sh -1
bindsym $mod+$sft+s    exec ~/.config/i3/scripts/next-prev-follow.sh 1
bindsym $mod+t    exec ~/.config/i3/scripts/empty_workspace

## i3wM
bindsym $mod+l    resize grow width 15 px
bindsym $mod+y    resize shrink width 15 px
bindsym $mod+$sft+l    resize grow height 15 px
bindsym $mod+$sft+y    resize shrink height 15 px

bindsym $mod+comma    mode "adjust"
mode "adjust" {
    bindsym y    gaps inner current minus 4
    bindsym $sft+y    gaps outer current minus 4
    bindsym l    gaps inner current plus 4
    bindsym $sft+l    gaps outer current plus 4
    bindsym h    gaps horizontal current minus 4
    bindsym $sft+h    gaps horizontal current plus 4
    bindsym v    gaps vertical current minus 4
    bindsym $sft+v    gaps vertical current plus 4
    bindsym t    gaps top current minus 4
    bindsym $sft+t    gaps top current plus 4
    bindsym comma    restart
    bindsym Return    mode "default"
}

## audio/volume
bindsym XF86AudioRaiseVolume exec amixer -q set Master 5%+
bindsym XF86AudioLowerVolume exec amixer -q set Master 5%-
bindsym XF86AudioMute exec amixer set Master toggle
bindsym XF86AudioPlay exec playerctl play-pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous

## other: Simulate ctrl+pgdn/pgup upon pressing $mod+pgdn/pgup
bindsym --release $mod+Prior exec --no-startup-id xdotool key --clearmodifiers ctrl+0xff56
bindsym --release $mod+Next exec --no-startup-id xdotool key --clearmodifiers ctrl+0xff55

Even at first glance, I already see a potential for a race condition here.

Configs like these are why some of your apps do not follow the 640 x 480 rule. Because the actual behavior will depend on i3’s internal implementation (e.g: which ones of those for_window statements get executed last)

I will go through the rest of your configs later.

I see, so the question becomes: can I set a standard custom floating size, allowing for some apps to be smaller than that? It seems the issue remains independently of the order given in the config file.

Try this first (no guarantees that it’ll work but, but it’s worth a try):

for_window [class="Galculator" instance="galculator"] floating enable, resize set 320 320
for_window [class="gnome-calculator" instance="gnome-calculator"] floating enable, resize set 320 320

Note the , i’ve added to define the chain of commands. This help separate floating enable resize set 320 320 into two commands among which an order of execution can be defined.

For example, if we look at:

for_window[class="Galculator"...] floating enable, resize set 320 320

This means that as soon as Galculator is launched, it will first change it into a floating window (which will automatically trigger the default size for floating windows 640 480), which will then be resized to 320 320.

Depending on system performance, the window resize operation may or may not be noticeable on the screen (a flicker).

Make those changes in your i3 config, reload the config and test it out. Let me know how it goes.

mh, it still won’t work properly (it only works the second time I toggle the floating command).

If I dispense with the custom standard size, the following works (it avoids the issue but at least I can use the terminal floating centered (a “zen mode” of sorts for prose writing, note-taking, etc.), and that matters most.

for_window [floating class="Alacritty"] resize set 680 600
for_window [floating] move position center

## tiling exceptions
for_window [window_role="About"] floating enable
for_window [class="Galculator" instance="galculator"] floating enable, resize set 320 320
for_window [class="gnome-calculator" instance="gnome-calculator"] floating enable, resize set 320 320
for_window [class="Pavucontrol" instance="pavucontrol"] floating enable, resize set 1000 720
for_window [class="Syncthing GTK"] floating enable, resize set 1000 720

Just to clarify. Do you mean that when you launch Galculator for the first time after reloading the config, the resulting window will be size 640 x 480. But subsequent launches of Galculator will be 320 x 320?

What if you replace the line to set the default floating window size with this:

floating_maximum_size 680 x 680

Caveat:
This will only work if the default window size of a particular application is larger than 680 x 680. Applications with window sizes smaller than 680 x 680 will still open in their own sizes; on the other hand, applications with larger default window sizes will be forced to shrink down to 680 x 680.

correct ( when I launch Galculator for the first time after reloading the config, the resulting window will be size 640 x 480. But subsequent launches of Galculator will be 320 x 320); and as for your second solution below, it works as a workaround although it indeed shrinks down larger default window sizes.

I just thought of another alternative. Instead of using a generic, for_window [floating] to set the default, you can use a regular expression to exclude Galculator, gnome-calculator, etc. from the defaults.

for_window [class="...some regular expression to exclude other apps..."] resize set 640 480

That way, the default floating size will be applied to every other floating window except Galculator, gnome-calculator, etc.

Note that the regular expression used for the command criteria must be perl-compatible. You might want to refer to a manual for the exact syntax.

https://man.archlinux.org/man/core/pcre/pcresyntax.3.en

Which is indeed what you want, isn’t it? Since you are using

for_window [floating] resize set 640 480

Windows will always be resized to 640 x 480 the moment you changed them to floating mode.

well, yes, all the apps I use in floating mode behave properly with this solution; in fact, every app behaves now, even those that make no sense in a small floating mode, like Gimp, but it’s ok, it just nagged me that they behaved erratically.

So yes, this the solution for my case, thanks!

Yeah. It should because floating_maximum_size is a command itself, whereas for_window is a directive that will execute only when specific windows are encountered. Setting the default dimensions with floating_maximum_size will eliminate the race condition I mentioned above.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.