aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrestis Floros <orestisflo@gmail.com>2023-01-22 18:33:23 +0100
committerOrestis Floros <orestisflo@gmail.com>2023-01-22 18:33:23 +0100
commitc52f13900df5da04d86809abbfe25178a4bbe305 (patch)
tree7e29c41cf6c7f8250f0533f5042a7961b7f09d7c
parent8d64937054d625f140dd5073b00f2c726253f051 (diff)
downloadi3-c52f13900df5da04d86809abbfe25178a4bbe305.tar.gz
i3-c52f13900df5da04d86809abbfe25178a4bbe305.zip
Add focus workspace command
-rw-r--r--docs/userguide10
-rw-r--r--include/commands.h2
-rw-r--r--parser-specs/commands.spec5
-rw-r--r--release-notes/changes/2-focus-workspace1
-rw-r--r--src/commands.c18
-rw-r--r--testcases/t/187-commands-parser.t15
6 files changed, 38 insertions, 13 deletions
diff --git a/docs/userguide b/docs/userguide
index 120e4b90..7fe0b9af 100644
--- a/docs/userguide
+++ b/docs/userguide
@@ -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:
diff --git a/include/commands.h b/include/commands.h
index 2ae2643c..17d06681 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -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]'.
diff --git a/parser-specs/commands.spec b/parser-specs/commands.spec
index 336a8d42..c0dcca7c 100644
--- a/parser-specs/commands.spec
+++ b/parser-specs/commands.spec
@@ -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'
diff --git a/release-notes/changes/2-focus-workspace b/release-notes/changes/2-focus-workspace
new file mode 100644
index 00000000..638266f2
--- /dev/null
+++ b/release-notes/changes/2-focus-workspace
@@ -0,0 +1 @@
+add "focus workspace" command
diff --git a/src/commands.c b/src/commands.c
index ae02ab75..a2f42dce 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -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,8 +1494,15 @@ void cmd_focus(I3_CMD) {
break;
}
- LOG("focusing %p / %s\n", current->con, current->con->name);
- con_activate_unblock(current->con);
+ 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;
diff --git a/testcases/t/187-commands-parser.t b/testcases/t/187-commands-parser.t
index 3404df1f..c2ff4a26 100644
--- a/testcases/t/187-commands-parser.t
+++ b/testcases/t/187-commands-parser.t
@@ -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