The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
3

prompt to close a window (by mod+shift+q)

asked Jul 15 '15

diablo465 gravatar image

closing a window now becomes too easy. Is it possible to have a prompt to close a window?

2 answers

Sort by » oldest newest most voted
3

answered Jul 15 '15

i3convert gravatar image

You can use i3 modes for this purpose. Pressing $mod+Shift+q moves you to a special mode, where it asks you if you really want to close the window. Then, in my example, pressing Enter or y will close the window. Pressing Escape or n will get you out of this mode.

set $close "Close the window? (y/n)"

mode $close {
    bindsym y kill, mode default
    bindsym Return kill, mode default

    bindsym n mode default
    bindsym Escape mode default
}

bindsym $mod+Shift+q mode $close

This is not perfect, but perhaps you'll like it.

Comments

A great alternative indeed! Never occurred to me to use modes like that.

Airblader gravatar imageAirblader (Jul 15 '15)edit

Thanks so much for the update. actually I just wish to enforce such prompt to iterm and rdesktop (WM_CLASS(STRING) = "xterm", "XTerm" and WM_CLASS(STRING) = "rdesktop", "rdesktop" ). how can i add an if function for this?

diablo465 gravatar imagediablo465 (Jul 16 '15)edit

@diablo456: You could write a script that uses the output of `i3-msg -t get_tree` to figure out the type of the currently focused window. Then it could either execute `i3-msg kill` (to kill the current window) or `i3-msg "mode Close the window? (y/n)"` (to switch to the auxiliary mode).

i3convert gravatar imagei3convert (Jul 16 '15)edit
2

answered Jul 15 '15

Airblader gravatar image

updated Jul 15 '15

Sure, but not from i3 itself. You can change your keybinding to execute this:

bindsym $mod+Shift+q exec --no-startup-id xdotool getactivewindow | xargs -I '{}' i3-nagbar -t warning -m "Do you really want to close this?" -b "Yes" "killall i3-nagbar; i3-msg [id='{}'] kill" -b "No" "killall i3-nagbar; i3-msg nop"

Not exactly pretty, but works. I don't think i3-nagbar is a great tool for this, though, but you can replace it with whatever tool you want to create the dialog with. For example, you can use zenity:

bindsym $mod+Shift+q exec --no-startup-id xdotool getactivewindow | xargs -I '{}' zenity --question && i3-msg [id='{}'] kill

I use xdotool to get the focused window first because if I simply do the dialog and kall i3-msg kill, you end up killing the wrong window.

Question Tools

1 follower

Stats

Asked: Jul 15 '15

Seen: 151 times

Last updated: Jul 15