i3 - improved tiling WM


Implement raise_focus for floating windows.

Patch status: rejected

Patch by Marcos Moyano

Long description:

On commit 584a6b6b5951b5acd6839baae74c8306fd048fd1 raise floating windows when focusing was reverted.
This tries to solve that by introducing a new command (raise_focus) that will bring to the top of the stack the focused window (if floating). This honors keyboard focus and lets you decide if you wish to raise the window or not.

To apply this patch, use:
curl http://cr.i3wm.org/patch/86/raw.patch | git am

b/include/commands.h

18
@@ -265,4 +265,10 @@ void cmd_scratchpad_show(I3_CMD);
19
  */
20
 void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name);
21
 
22
+/**
23
+ * Implementation of 'raise_focus'.
24
+ *
25
+ */
26
+void cmd_raise_focus(I3_CMD);
27
+
28
 #endif

b/parser-specs/commands.spec

33
@@ -35,6 +35,7 @@ state INITIAL:
34
   'nop' -> NOP
35
   'scratchpad' -> SCRATCHPAD
36
   'mode' -> MODE
37
+  'raise_focus' -> call cmd_raise_focus()
38
 
39
 state CRITERIA:
40
   ctype = 'class' -> CRITERION
41
@@ -106,7 +107,7 @@ state WORKSPACE:
42
       -> call cmd_workspace_back_and_forth()
43
   'number'
44
       -> WORKSPACE_NUMBER
45
-  workspace = string 
46
+  workspace = string
47
       -> call cmd_workspace_name($workspace)
48
 
49
 state WORKSPACE_NUMBER:

b/src/commands.c

54
@@ -1898,3 +1898,20 @@ void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name) {
55
 
56
     ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"rename\"}");
57
 }
58
+
59
+/*
60
+ * Implementation of 'raise_focus'.
61
+ *
62
+ */
63
+void cmd_raise_focus(I3_CMD) {
64
+    DLOG("should raise the focus if the focused window is floating\n");
65
+    Con *floating = con_inside_floating(focused);
66
+
67
+    if (floating != NULL &&
68
+        floating->type == CT_FLOATING_CON) {
69
+      floating_raise_con(floating);
70
+      con_focus(con_descend_focused(floating));
71
+      cmd_output->needs_tree_render = true;
72
+    }
73
+      ysuccess(true);
74
+}

b/testcases/t/187-commands-parser.t

79
@@ -144,7 +144,7 @@ is(parser_calls("\nworkspace test"),
80
 ################################################################################
81
 
82
 is(parser_calls('unknown_literal'),
83
-   "ERROR: Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'split', 'floating', 'mark', 'resize', 'rename', 'nop', 'scratchpad', 'mode'\n" .
84
+   "ERROR: Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'split', 'floating', 'mark', 'resize', 'rename', 'nop', 'scratchpad', 'mode', 'raise_focus'\n" .
85
    "ERROR: Your command: unknown_literal\n" .
86
    "ERROR:               ^^^^^^^^^^^^^^^",
87
    'error for unknown literal ok');