typedef enum { NO_ORIENTATION = 0, HORIZ, VERT } orientation_t;
typedef enum { BS_NORMAL = 0, BS_NONE = 1, BS_1PIXEL = 2 } border_style_t;
+/** parameter to specify whether tree_close() and x_window_kill() should kill
+ * only this specific window or the whole X11 client */
+typedef enum { DONT_KILL_WINDOW = 0, KILL_WINDOW = 1, KILL_CLIENT = 2 } kill_window_t;
+
enum {
BIND_NONE = 0,
BIND_SHIFT = XCB_MOD_MASK_SHIFT, /* (1 << 0) */
* Closes the current container using tree_close().
*
*/
-void tree_close_con();
+void tree_close_con(kill_window_t kill_window);
/**
* Changes focus in the given way (next/previous) and given orientation
* and the window is expected to kill itself.
*
*/
-bool tree_close(Con *con, bool kill_window, bool dont_kill_parent);
+bool tree_close(Con *con, kill_window_t kill_window, bool dont_kill_parent);
/**
* Loads tree from ~/.i3/_restart.json (used for in-place restarts).
* Kills the given X11 window using WM_DELETE_WINDOW (if supported).
*
*/
-void x_window_kill(xcb_window_t window);
+void x_window_kill(xcb_window_t window, kill_window_t kill_window);
/**
* Draws the decoration of the given container onto its parent.
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
- * © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* cmdparse.l: the lexer for commands you send to i3 (or bind on keys)
*
reload { return TOK_RELOAD; }
restart { return TOK_RESTART; }
kill { return TOK_KILL; }
+window { return TOK_WINDOW; }
+client { return TOK_CLIENT; }
fullscreen { return TOK_FULLSCREEN; }
global { return TOK_GLOBAL; }
layout { return TOK_LAYOUT; }
%}
-%expect 4
+%expect 5
%error-verbose
%lex-param { struct context *context }
%token TOK_RELOAD "reload"
%token TOK_RESTART "restart"
%token TOK_KILL "kill"
+%token TOK_WINDOW "window"
+%token TOK_CLIENT "client"
%token TOK_FULLSCREEN "fullscreen"
%token TOK_GLOBAL "global"
%token TOK_LAYOUT "layout"
%type <number> resize_px
%type <number> resize_way
%type <number> resize_tiling
+%type <number> optional_kill_mode
%%
;
kill:
- TOK_KILL
+ TOK_KILL optional_kill_mode
{
owindow *current;
printf("killing!\n");
/* check if the match is empty, not if the result is empty */
if (match_is_empty(¤t_match))
- tree_close_con();
+ tree_close_con($2);
else {
TAILQ_FOREACH(current, &owindows, owindows) {
printf("matching: %p / %s\n", current->con, current->con->name);
- tree_close(current->con, true, false);
+ tree_close(current->con, $2, false);
}
}
}
;
+optional_kill_mode:
+ /* empty */ { $$ = KILL_WINDOW; }
+ | WHITESPACE TOK_WINDOW { $$ = KILL_WINDOW; }
+ | WHITESPACE TOK_CLIENT { $$ = KILL_CLIENT; }
+ ;
+
workspace:
TOK_WORKSPACE WHITESPACE STR
{
int children = con_num_children(con);
if (children == 0) {
DLOG("Container empty, closing\n");
- tree_close(con, false, false);
+ tree_close(con, DONT_KILL_WINDOW, false);
return;
}
}
/* check if the parent container is empty and close it if so */
if ((con->parent->type == CT_CON || con->parent->type == CT_FLOATING_CON) && con_num_children(con->parent) == 0) {
DLOG("Old container empty after setting this child to floating, closing\n");
- tree_close(con->parent, false, false);
+ tree_close(con->parent, DONT_KILL_WINDOW, false);
}
char *name;
/* 2: kill parent container */
TAILQ_REMOVE(&(con->parent->parent->floating_head), con->parent, floating_windows);
TAILQ_REMOVE(&(con->parent->parent->focus_head), con->parent, focused);
- tree_close(con->parent, false, false);
+ tree_close(con->parent, DONT_KILL_WINDOW, false);
/* 3: re-attach to the parent of the currently focused con on the workspace
* this floating con was on */
return 1;
}
- tree_close(con, false, false);
+ tree_close(con, DONT_KILL_WINDOW, false);
tree_render();
x_push_changes(croot);
return 1;
}
DLOG("destroying disappearing con %p\n", output->con);
- tree_close(output->con, false, true);
+ tree_close(output->con, DONT_KILL_WINDOW, true);
DLOG("Done. Should be fine now\n");
output->con = NULL;
}
* and the window is expected to kill itself.
*
*/
-bool tree_close(Con *con, bool kill_window, bool dont_kill_parent) {
+bool tree_close(Con *con, kill_window_t kill_window, bool dont_kill_parent) {
bool was_mapped = con->mapped;
Con *parent = con->parent;
}
if (con->window != NULL) {
- if (kill_window) {
- x_window_kill(con->window->id);
+ if (kill_window != DONT_KILL_WINDOW) {
+ x_window_kill(con->window->id, kill_window);
return false;
} else {
/* un-parent the window */
if (con_is_floating(con)) {
Con *ws = con_get_workspace(con);
DLOG("Container was floating, killing floating container\n");
- tree_close(parent, false, false);
+ tree_close(parent, DONT_KILL_WINDOW, false);
DLOG("parent container killed\n");
if (con == focused) {
DLOG("This is the focused container, i need to find another one to focus. I start looking at ws = %p\n", ws);
}
if (was_mapped || con == focused) {
- if (kill_window || !dont_kill_parent || con == focused) {
+ if ((kill_window != DONT_KILL_WINDOW) || !dont_kill_parent || con == focused) {
DLOG("focusing %p / %s\n", next, next->name);
/* TODO: check if the container (or one of its children) was focused */
if (next->type == CT_DOCKAREA) {
* Closes the current container using tree_close().
*
*/
-void tree_close_con() {
+void tree_close_con(kill_window_t kill_window) {
assert(focused != NULL);
if (focused->type == CT_WORKSPACE) {
LOG("Cannot close workspace\n");
assert(focused->type != CT_ROOT);
/* Kill con */
- tree_close(focused, true, false);
+ tree_close(focused, kill_window, false);
}
/*
/* 4: close the redundant cons */
DLOG("closing redundant cons\n");
- tree_close(con, false, true);
+ tree_close(con, DONT_KILL_WINDOW, true);
/* Well, we got to abort the recursion here because we destroyed the
* container. However, if tree_flatten() is called sufficiently often,
/* check if this workspace is currently visible */
if (!workspace_is_visible(old)) {
LOG("Closing old workspace (%p / %s), it is empty\n", old, old->name);
- tree_close(old, false, false);
+ tree_close(old, DONT_KILL_WINDOW, false);
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"empty\"}");
changed_num_workspaces = true;
}
* Kills the given X11 window using WM_DELETE_WINDOW (if supported).
*
*/
-void x_window_kill(xcb_window_t window) {
+void x_window_kill(xcb_window_t window, kill_window_t kill_window) {
/* if this window does not support WM_DELETE_WINDOW, we kill it the hard way */
if (!window_supports_protocol(window, A_WM_DELETE_WINDOW)) {
- LOG("Killing window the hard way\n");
- xcb_kill_client(conn, window);
+ if (kill_window == KILL_WINDOW) {
+ LOG("Killing specific window 0x%08x\n", window);
+ xcb_destroy_window(conn, window);
+ } else {
+ LOG("Killing the X11 client which owns window 0x%08x\n", window);
+ xcb_kill_client(conn, window);
+ }
return;
}
--- /dev/null
+#!perl
+# vim:ts=4:sw=4:expandtab
+#
+# Tests if WM_STATE is WM_STATE_NORMAL when mapped and WM_STATE_WITHDRAWN when
+# unmapped.
+#
+use X11::XCB qw(:all);
+use X11::XCB::Connection;
+use i3test;
+
+my $x = X11::XCB::Connection->new;
+
+sub two_windows {
+ my $tmp = fresh_workspace;
+
+ ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
+
+ my $first = open_standard_window($x);
+ my $second = open_standard_window($x);
+
+ is($x->input_focus, $second->id, 'second window focused');
+ ok(@{get_ws_content($tmp)} == 2, 'two containers opened');
+
+ return $tmp;
+}
+
+##############################################################
+# 1: open two windows (in the same client), kill one and see if
+# the other one is still there
+##############################################################
+
+my $tmp = two_windows;
+
+cmd 'kill';
+
+sleep 0.25;
+
+ok(@{get_ws_content($tmp)} == 1, 'one container left after killing');
+
+##############################################################
+# 2: same test case as test 1, but with the explicit variant
+# 'kill window'
+##############################################################
+
+my $tmp = two_windows;
+
+cmd 'kill window';
+
+sleep 0.25;
+
+ok(@{get_ws_content($tmp)} == 1, 'one container left after killing');
+
+##############################################################
+# 3: open two windows (in the same client), use 'kill client'
+# and check if both are gone
+##############################################################
+
+my $tmp = two_windows;
+
+cmd 'kill client';
+
+sleep 0.25;
+
+ok(@{get_ws_content($tmp)} == 0, 'no containers left after killing');
+
+done_testing;