Skip to content

Commit

Permalink
Introduce con_activate_unblock
Browse files Browse the repository at this point in the history
  • Loading branch information
orestisfl committed Oct 8, 2019
1 parent 465447a commit 34c217a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
7 changes: 7 additions & 0 deletions include/con.h
Expand Up @@ -45,6 +45,13 @@ void con_focus(Con *con);
*/
void con_activate(Con *con);

/**
* Activates the container like in con_activate but removes fullscreen
* restrictions and properly warps the pointer if needed.
*
*/
void con_activate_unblock(Con *con);

/**
* Closes the given container.
*
Expand Down
36 changes: 2 additions & 34 deletions src/commands.c
Expand Up @@ -1238,20 +1238,6 @@ void cmd_focus_direction(I3_CMD, const char *direction) {
ysuccess(true);
}

/*
* Focus a container and disable any other fullscreen container not permitting the focus.
*
*/
static void cmd_focus_force_focus(Con *con) {
/* Disable fullscreen container in workspace with container to be focused. */
Con *ws = con_get_workspace(con);
Con *fullscreen_on_ws = con_get_fullscreen_covering_ws(ws);
if (fullscreen_on_ws && fullscreen_on_ws != con && !con_has_parent(con, fullscreen_on_ws)) {
con_disable_fullscreen(fullscreen_on_ws);
}
con_activate(con);
}

/*
* Implementation of 'focus tiling|floating|mode_toggle'.
*
Expand All @@ -1276,7 +1262,7 @@ void cmd_focus_window_mode(I3_CMD, const char *window_mode) {
(!to_floating && current->type == CT_FLOATING_CON))
continue;

cmd_focus_force_focus(con_descend_focused(current));
con_activate_unblock(con_descend_focused(current));
success = true;
break;
}
Expand Down Expand Up @@ -1353,26 +1339,8 @@ void cmd_focus(I3_CMD) {
break;
}

/* If the container is not on the current workspace,
* workspace_show() will switch to a different workspace and (if
* enabled) trigger a mouse pointer warp to the currently focused
* container (!) on the target workspace.
*
* Therefore, before calling workspace_show(), we make sure that
* 'current' will be focused on the workspace. However, we cannot
* just con_focus(current) because then the pointer will not be
* warped at all (the code thinks we are already there).
*
* So we focus 'current' to make it the currently focused window of
* the target workspace, then revert focus. */
Con *currently_focused = focused;
cmd_focus_force_focus(current->con);
con_activate(currently_focused);

/* Now switch to the workspace, then focus */
workspace_show(ws);
LOG("focusing %p / %s\n", current->con, current->con->name);
con_activate(current->con);
con_activate_unblock(current->con);
count++;
}

Expand Down
35 changes: 35 additions & 0 deletions src/con.c
Expand Up @@ -265,6 +265,41 @@ void con_activate(Con *con) {
con_raise(con);
}

/*
* Activates the container like in con_activate but removes fullscreen
* restrictions and properly warps the pointer if needed.
*
*/
void con_activate_unblock(Con *con) {
Con *ws = con_get_workspace(con);
Con *previous_focus = focused;
Con *fullscreen_on_ws = con_get_fullscreen_covering_ws(ws);

if (fullscreen_on_ws && fullscreen_on_ws != con && !con_has_parent(con, fullscreen_on_ws)) {
con_disable_fullscreen(fullscreen_on_ws);
}

con_activate(con);

/* If the container is not on the current workspace, workspace_show() will
* switch to a different workspace and (if enabled) trigger a mouse pointer
* warp to the currently focused container (!) on the target workspace.
*
* Therefore, before calling workspace_show(), we make sure that 'con' will
* be focused on the workspace. However, we cannot just con_focus(con)
* because then the pointer will not be warped at all (the code thinks we
* are already there).
*
* So we focus 'con' to make it the currently focused window of the target
* workspace, then revert focus. */
if (ws != con_get_workspace(previous_focus)) {
con_activate(previous_focus);
/* Now switch to the workspace, then focus */
workspace_show(ws);
con_activate(con);
}
}

/*
* Closes the given container.
*
Expand Down

0 comments on commit 34c217a

Please sign in to comment.