The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
2

I want every n-th window appear on next empty workspace

asked Mar 22 '14

alikthename gravatar image

Let's say i want not to have more than 3 windows on a workspace. And if 4-th window appears it should open on next free workspace and focused. How to implement that?

2 answers

Sort by » oldest newest most voted
3

answered Mar 26 '14

TonyC gravatar image

This is not difficult with the new ipc project. This uses the JavaScript version but the same API exists in many languages. The latest version of this script can be found here.

#!/usr/bin/env gjs

/*
   This example shows how to define a maximum number of windows per workspace.
   If a window is opened and the workspace has more than the defined number of
   maximum children containers, the new window will open on the next available
   workspace.

   https://faq.i3wm.org/question/3551/i-want-every-n-th-window-appear-on-next-empty-workspace/
*/

const i3ipc = imports.gi.i3ipc

let conn = new i3ipc.Connection;

const MAX_WINDOWS = 3;

conn.on('window::new', function(conn, e) {
    let win = conn.get_tree().find_focused();
    let ws = win.workspace();

    if (ws.nodes.length > MAX_WINDOWS) {
        win.command('move to workspace next, focus');
    }
});

conn.main();
0

answered Mar 22 '14

joepd gravatar image

Gain some understanding about IPC, and pick your favorite language that has a i3 IPC library listed here.

Question Tools

Stats

Asked: Mar 22 '14

Seen: 235 times

Last updated: Mar 26 '14