Skip to content

Instantly share code, notes, and snippets.

@trapd00r
Last active September 22, 2024 16:54
Show Gist options
  • Save trapd00r/1914f83477fb126f737fa764083a2627 to your computer and use it in GitHub Desktop.
Save trapd00r/1914f83477fb126f737fa764083a2627 to your computer and use it in GitHub Desktop.
i3 persistent workspaces multi-monitor setup

1. Patch i3 so that workspaces stay persistent once defined

diff --git a/src/workspace.c b/src/workspace.c
index 526a2bf7..53ea09d1 100644
--- a/src/workspace.c
+++ b/src/workspace.c
@@ -526,33 +526,6 @@ void workspace_show(Con *workspace) {
     ipc_send_workspace_event("focus", workspace, current);
 
     DLOG("old = %p / %s\n", old, (old ? old->name : "(null)"));
-    /* Close old workspace if necessary. This must be done *after* doing
-     * urgency handling, because tree_close_internal() will do a con_focus() on the next
-     * client, which will clear the urgency flag too early. Also, there is no
-     * way for con_focus() to know about when to clear urgency immediately and
-     * when to defer it. */
-    if (old && TAILQ_EMPTY(&(old->nodes_head)) && TAILQ_EMPTY(&(old->floating_head))) {
-        /* check if this workspace is currently visible */
-        if (!workspace_is_visible(old)) {
-            LOG("Closing old workspace (%p / %s), it is empty\n", old, old->name);
-            yajl_gen gen = ipc_marshal_workspace_event("empty", old, NULL);
-            tree_close_internal(old, DONT_KILL_WINDOW, false);
-
-            const unsigned char *payload;
-            ylength length;
-            y(get_buf, &payload, &length);
-            ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, (const char *)payload);
-
-            y(free);
-
-            /* Avoid calling output_push_sticky_windows later with a freed container. */
-            if (old == old_focus) {
-                old_focus = NULL;
-            }
-
-            ewmh_update_desktop_properties();
-        }
-    }
 
     workspace->fullscreen_mode = CF_OUTPUT;
     LOG("focused now = %p / %s\n", focused, focused->name);

2. Configure workspaces and lock them to specific outputs

# define outputs
set $middle DP-2
set $left DP-0
set $top DP-5
set $behind HDMI-0

set $ws1 1
set $ws2 2
set $ws3 3
set $ws4 4
set $ws5 5
set $ws6 6
set $ws7 7
set $ws8 8
set $ws9 9

# lock workspaces to outputs
workspace $ws1 output $middle
workspace $ws2 output $middle
workspace $ws3 output $middle
workspace $ws4 output $middle
workspace $ws5 output $middle
workspace $ws6 output $left
workspace $ws7 output $left
workspace $ws8 output $top
workspace $ws9 output $top

# Bind key shortcuts to workspaces
bindsym $mod+1 workspace number $ws1
bindsym $mod+2 workspace number $ws2
bindsym $mod+3 workspace number $ws3
bindsym $mod+4 workspace number $ws4
bindsym $mod+5 workspace number $ws5
bindsym $mod+6 workspace number $ws6
bindsym $mod+7 workspace number $ws7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment