Check if con_id exists in cmd_swap (#2898)
Also adds some testcases for swap using con_id. Fixes #2895
This commit is contained in:
parent
dedfda1e01
commit
369c9ed50f
|
@ -152,6 +152,13 @@ bool con_has_parent(Con *con, Con *parent);
|
||||||
*/
|
*/
|
||||||
Con *con_by_window_id(xcb_window_t window);
|
Con *con_by_window_id(xcb_window_t window);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the container with the given container ID or NULL if no such
|
||||||
|
* container exists.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Con *con_by_con_id(long target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the container with the given frame ID or NULL if no such container
|
* Returns the container with the given frame ID or NULL if no such container
|
||||||
* exists.
|
* exists.
|
||||||
|
|
|
@ -1841,7 +1841,7 @@ void cmd_swap(I3_CMD, const char *mode, const char *arg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
con = (Con *)target;
|
con = con_by_con_id(target);
|
||||||
} else if (strcmp(mode, "mark") == 0) {
|
} else if (strcmp(mode, "mark") == 0) {
|
||||||
con = con_by_mark(arg);
|
con = con_by_mark(arg);
|
||||||
} else {
|
} else {
|
||||||
|
|
16
src/con.c
16
src/con.c
|
@ -557,6 +557,22 @@ Con *con_by_window_id(xcb_window_t window) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the container with the given container ID or NULL if no such
|
||||||
|
* container exists.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Con *con_by_con_id(long target) {
|
||||||
|
Con *con;
|
||||||
|
TAILQ_FOREACH(con, &all_cons, all_cons) {
|
||||||
|
if (con == (Con *)target) {
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the container with the given frame ID or NULL if no such container
|
* Returns the container with the given frame ID or NULL if no such container
|
||||||
* exists.
|
* exists.
|
||||||
|
|
|
@ -32,6 +32,38 @@ my ($nodes, $expected_focus, $A, $B, $F);
|
||||||
my ($result);
|
my ($result);
|
||||||
my @urgent;
|
my @urgent;
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Invalid con_id should not crash i3
|
||||||
|
# See issue #2895.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
$pid = launch_with_config($config);
|
||||||
|
$ws = fresh_workspace;
|
||||||
|
|
||||||
|
open_window;
|
||||||
|
cmd "swap container with con_id 1";
|
||||||
|
|
||||||
|
does_i3_live;
|
||||||
|
exit_gracefully($pid);
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Swap 2 windows in different workspaces using con_id
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
$pid = launch_with_config($config);
|
||||||
|
|
||||||
|
$ws = fresh_workspace;
|
||||||
|
open_window;
|
||||||
|
$A = get_focused($ws);
|
||||||
|
|
||||||
|
$ws = fresh_workspace;
|
||||||
|
open_window;
|
||||||
|
|
||||||
|
cmd "swap container with con_id $A";
|
||||||
|
is(get_focused($ws), $A, 'A is now focused');
|
||||||
|
|
||||||
|
exit_gracefully($pid);
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Swap two containers next to each other.
|
# Swap two containers next to each other.
|
||||||
# Focus should stay on B because both windows are on the focused workspace.
|
# Focus should stay on B because both windows are on the focused workspace.
|
||||||
|
|
Loading…
Reference in New Issue