Dec 17, 2025

SwayWM Mouse-click Titlebars

This is a way of closing windows and to toggle floating on windows with the mouse in the sway tiling window manager.

To close a window:

  1. right-click titlebar
  2. right-click titlebar

To toggle floating

  1. right-click titlebar
  2. left-click titlebar

Config Lines


Modes and Swaynag


You can put modes in a separate config file if you have a lot of them. They are very helpful to run custom system-level script options.

This particular example does not actually use swaynag.

However, if you combine modes with swaynag messages and buttons, then you can provide temporary options that only require temporary single keystrokes, as opposed to dipping into the pool of all the other keystrokes needed for navigation and stuff.

Config Lines


01 set $killnag exec pkill -15 swaynag; mode "default"
02 
03 for_window [all] border normal 4
04 default_border normal 4
05 default_floating_border normal 4
06 
07 mode "Window Mode" { 
08 bindsym button1 floating toggle; $killnag
09 bindsym button3 kill; $killnag
10 bindsym Escape $killnag
11 }
12 
13 bindsym button3 mode "Window Mode"

Explanation


  • Line 13 binds "Window Mode" to button3 (right-click)
    • This means that you enter "window mode" by right-clicking the titlebar
  • Line 01 is the general mode escape command
    • It kills swaynag (although this specific example does not even use swaynag)
    • then it changes the sway mode to "default"
  • Line 03 changes all (floating and non-floating) windows to have a titlebar
    • this is so the mouse can be used on both floating and non-floating windows
  • Line 07 names the mode to "Window Mode"
  • Line 08 specifies second left-click
  • Line 09 specifies second right-click
  • Line 10 specifies ESC key to change back to default mode

No comments:

Post a Comment