con_set_layout: always use the parent container, handle workspaces properly

Previously, in case 'layout stacked' (for example) had been called
interactively, con_set_layout would be called with focused->parent,
while with for_window, it’d be called on the actual matching container.

This difference in behavior was the cause for the inability to use
'for_window [class="XTerm"] layout tabbed', which now works \o/, but
more on that below.

The change also allows us to handle the case of the user selecting a
CT_WORKSPACE container properly, that is, by using the special case and
creating a new split container on the workspace which gets all the
contents, but a new layout.

Now, before you are enthusiastic about the change and try to use
for_window magic in your config file, keep in mind: The 'layout' command
acts on the parent split container. That is, when using a line such as
this one:

    for_window [class="XTerm"] layout tabbed

…and opening an XTerm when on a workspace with one single other window,
the whole workspace will be set tabbed (just as previously when you
opened an XTerm and sent 'layout tabbed' manually).

Therefore, to open XTerm in its own tabbed split container, you need to
split before:

    for_window [class="XTerm"] split v, layout tabbed

The comma here is important! It says that the second command should not
be treated as an entirely unrelated command, but it should also relate
the matching window (while it does work with a ';', that is prone to
race-conditions and should be avoided).

fixes #358
This commit is contained in:
Michael Stapelberg
2012-09-05 00:22:38 +02:00
parent 2a37089ad1
commit 4976fa3350
3 changed files with 65 additions and 13 deletions

View File

@ -1114,9 +1114,17 @@ void cmd_move_workspace_to_output(I3_CMD, char *name) {
*
*/
void cmd_split(I3_CMD, char *direction) {
owindow *current;
/* TODO: use matches */
LOG("splitting in direction %c\n", direction[0]);
tree_split(focused, (direction[0] == 'v' ? VERT : HORIZ));
if (match_is_empty(current_match))
tree_split(focused, (direction[0] == 'v' ? VERT : HORIZ));
else {
TAILQ_FOREACH(current, &owindows, owindows) {
DLOG("matching: %p / %s\n", current->con, current->con->name);
tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
}
}
cmd_output->needs_tree_render = true;
// XXX: default reply for now, make this a better reply
@ -1429,7 +1437,7 @@ void cmd_layout(I3_CMD, char *layout_str) {
/* check if the match is empty, not if the result is empty */
if (match_is_empty(current_match))
con_set_layout(focused->parent, layout);
con_set_layout(focused, layout);
else {
TAILQ_FOREACH(current, &owindows, owindows) {
DLOG("matching: %p / %s\n", current->con, current->con->name);
@ -1456,7 +1464,7 @@ void cmd_layout_toggle(I3_CMD, char *toggle_mode) {
/* check if the match is empty, not if the result is empty */
if (match_is_empty(current_match))
con_toggle_layout(focused->parent, toggle_mode);
con_toggle_layout(focused, toggle_mode);
else {
TAILQ_FOREACH(current, &owindows, owindows) {
DLOG("matching: %p / %s\n", current->con, current->con->name);