Add focus workspace command

This commit is contained in:
Orestis Floros 2023-01-22 18:33:23 +01:00
parent 8d64937054
commit c52f13900d
No known key found for this signature in database
GPG Key ID: A09DBD7D3222C1C3
6 changed files with 38 additions and 13 deletions

View File

@ -2397,6 +2397,9 @@ available:
<criteria>::
Sets focus to the container that matches the specified criteria.
See <<command_criteria>>.
workspace::
Sets focus to the workspace that contains the container that matches the
specified criteria.
left|right|up|down::
Sets focus to the nearest container in the given direction.
parent::
@ -2423,6 +2426,7 @@ output::
*Syntax*:
----------------------------------------------
<criteria> focus
<criteria> focus workspace
focus left|right|down|up
focus parent|child|floating|tiling|mode_toggle
focus next|prev [sibling]
@ -2434,6 +2438,10 @@ focus output left|right|down|up|current|primary|nonprimary|next|<output1> [outpu
# Focus firefox
bindsym $mod+F1 [class="Firefox"] focus
# Focus the workspace where firefox is, without necessarily focusing firefox
# itself.
bindsym $mod+x [class="Firefox"] focus workspace
# Focus container on the left, bottom, top, right
bindsym $mod+j focus left
bindsym $mod+k focus down
@ -2462,7 +2470,7 @@ bindsym $mod+x focus output primary
bindsym $mod+x focus output nonprimary
# Cycle focus between outputs VGA1 and LVDS1 but not DVI0
bindsym $mod+x move workspace to output VGA1 LVDS1
bindsym $mod+x focus output VGA1 LVDS1
-------------------------------------------------
Note that you might not have a primary output configured yet. To do so, run:

View File

@ -198,7 +198,7 @@ void cmd_focus_level(I3_CMD, const char *level);
* Implementation of 'focus'.
*
*/
void cmd_focus(I3_CMD);
void cmd_focus(I3_CMD, bool focus_workspace);
/**
* Implementation of 'fullscreen [enable|disable|toggle] [global]'.

View File

@ -186,6 +186,7 @@ state WORKSPACE_NUMBER:
# focus output <output>
# focus tiling|floating|mode_toggle
# focus parent|child
# focus workspace
# focus
state FOCUS:
direction = 'left', 'right', 'up', 'down'
@ -198,8 +199,10 @@ state FOCUS:
-> call cmd_focus_window_mode($window_mode)
level = 'parent', 'child'
-> call cmd_focus_level($level)
workspace = 'workspace'
-> call cmd_focus(1)
end
-> call cmd_focus()
-> call cmd_focus(0)
state FOCUS_AUTO:
'sibling'

View File

@ -0,0 +1 @@
add "focus workspace" command

View File

@ -1459,7 +1459,7 @@ void cmd_focus_level(I3_CMD, const char *level) {
* Implementation of 'focus'.
*
*/
void cmd_focus(I3_CMD) {
void cmd_focus(I3_CMD, bool focus_workspace) {
DLOG("current_match = %p\n", current_match);
if (match_is_empty(current_match)) {
@ -1481,11 +1481,12 @@ void cmd_focus(I3_CMD) {
Con *ws = con_get_workspace(current->con);
/* If no workspace could be found, this was a dock window.
* Just skip it, you cannot focus dock windows. */
if (!ws)
if (!ws) {
continue;
}
/* In case this is a scratchpad window, call scratchpad_show(). */
if (ws == __i3_scratch) {
if (ws == __i3_scratch && !focus_workspace) {
scratchpad_show(current->con);
/* While for the normal focus case we can change focus multiple
* times and only a single window ends up focused, we could show
@ -1493,9 +1494,16 @@ void cmd_focus(I3_CMD) {
break;
}
if (focus_workspace) {
/* Show the workspace of the matched container, without necessarily
* focusing it. */
LOG("focusing workspace %p / %s - %p / %s\n", current->con, current->con->name, ws, ws->name);
workspace_show(ws);
} else {
LOG("focusing %p / %s\n", current->con, current->con->name);
con_activate_unblock(current->con);
}
}
cmd_output->needs_tree_render = true;
ysuccess(true);

View File

@ -106,30 +106,35 @@ is(parser_calls('resize shrink left 25 px or 33 ppt;'),
is(parser_calls('[con_mark=yay] focus'),
"cmd_criteria_add(con_mark, yay)\n" .
"cmd_focus()",
"cmd_focus(0)",
'criteria focus ok');
is(parser_calls('[con_mark=yay] focus workspace'),
"cmd_criteria_add(con_mark, yay)\n" .
"cmd_focus(1)",
'criteria focus workspace ok');
is(parser_calls("[con_mark=yay con_mark=bar] focus"),
"cmd_criteria_add(con_mark, yay)\n" .
"cmd_criteria_add(con_mark, bar)\n" .
"cmd_focus()",
"cmd_focus(0)",
'criteria focus ok');
is(parser_calls("[con_mark=yay\tcon_mark=bar] focus"),
"cmd_criteria_add(con_mark, yay)\n" .
"cmd_criteria_add(con_mark, bar)\n" .
"cmd_focus()",
"cmd_focus(0)",
'criteria focus ok');
is(parser_calls("[con_mark=yay\tcon_mark=bar]\tfocus"),
"cmd_criteria_add(con_mark, yay)\n" .
"cmd_criteria_add(con_mark, bar)\n" .
"cmd_focus()",
"cmd_focus(0)",
'criteria focus ok');
is(parser_calls('[con_mark="yay"] focus'),
"cmd_criteria_add(con_mark, yay)\n" .
"cmd_focus()",
"cmd_focus(0)",
'quoted criteria focus ok');
# Make sure trailing whitespace is stripped off: While this is not an issue for