Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: focus previous #1492

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/commands.h
Expand Up @@ -174,6 +174,12 @@ void cmd_focus_direction(I3_CMD, char *direction);
*/
void cmd_focus_window_mode(I3_CMD, char *window_mode);

/**
* Implementation of 'focus previous'.
*
*/
void cmd_focus_previous(I3_CMD);

/**
* Implementation of 'focus parent|child'.
*
Expand Down
2 changes: 2 additions & 0 deletions include/tree.h
Expand Up @@ -13,6 +13,8 @@ extern Con *croot;
/* TODO: i am not sure yet how much access to the focused container should
* be permitted to source files */
extern Con *focused;
extern Con *previous_focused;
extern bool infocusloop;
TAILQ_HEAD(all_cons_head, Con);
extern struct all_cons_head all_cons;

Expand Down
2 changes: 2 additions & 0 deletions parser-specs/commands.spec
Expand Up @@ -138,6 +138,8 @@ state FOCUS:
-> call cmd_focus_direction($direction)
'output'
-> FOCUS_OUTPUT
'previous'
-> call cmd_focus_previous()
window_mode = 'tiling', 'floating', 'mode_toggle'
-> call cmd_focus_window_mode($window_mode)
level = 'parent', 'child'
Expand Down
13 changes: 13 additions & 0 deletions src/commands.c
Expand Up @@ -1493,6 +1493,19 @@ void cmd_focus_window_mode(I3_CMD, char *window_mode) {
ysuccess(true);
}

/*
* Implementation of 'focus previous'.
*
*/
void cmd_focus_previous(I3_CMD) {
if (focused != previous_focused)
con_focus(previous_focused);

cmd_output->needs_tree_render = true;
// XXX: default reply for now, make this a better reply
ysuccess(true);
}

/*
* Implementation of 'focus parent|child'.
*
Expand Down
10 changes: 8 additions & 2 deletions src/con.c
Expand Up @@ -194,13 +194,19 @@ void con_focus(Con *con) {
assert(con != NULL);
DLOG("con_focus = %p\n", con);

if (!infocusloop)
previous_focused = focused;

/* 1: set focused-pointer to the new con */
/* 2: exchange the position of the container in focus stack of the parent all the way up */
TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
TAILQ_INSERT_HEAD(&(con->parent->focus_head), con, focused);
if (con->parent->parent != NULL)
if (con->parent->parent != NULL) {
infocusloop = true;
con_focus(con->parent);

}

infocusloop = false;
focused = con;
/* We can't blindly reset non-leaf containers since they might have
* other urgent children. Therefore we only reset leafs and propagate
Expand Down
2 changes: 2 additions & 0 deletions src/tree.c
Expand Up @@ -13,6 +13,8 @@

struct Con *croot;
struct Con *focused;
struct Con *previous_focused;
bool infocusloop = false;

struct all_cons_head all_cons = TAILQ_HEAD_INITIALIZER(all_cons);

Expand Down