The i3 FAQ has migrated to https://www.reddit.com/r/i3wm/. All content here is read-only.
Ask Your Question
3

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

asked 2015-07-15 06:01:35 +0000

diablo465 gravatar image

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2015-07-15 15:43:28 +0000

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.

edit flag offensive delete link more

Comments

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

Airblader gravatar imageAirblader ( 2015-07-15 16:02:54 +0000 )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 ( 2015-07-16 00:24:13 +0000 )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 ( 2015-07-16 03:04:55 +0000 )edit
2

answered 2015-07-15 07:23:16 +0000

Airblader gravatar image

updated 2015-07-15 07:25:07 +0000

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-07-15 06:01:35 +0000

Seen: 151 times

Last updated: Jul 15