Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples/avoid-ws.py #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions examples/avoid-ws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
# coding=utf-8

"""
Moves windows from workspace 1 to workspace 10 unless marked "_dontmove".

Listens to i3 new/move events, and tells i3 to move windows from workspace 1 to
workspace 10 unless they have a mark that starts with "_dontmove".(It looks for
a prefix because marks need to be unique, and we might want to mark multiple
windows as not needing to be moved.)

Tips:

- You can have marks in an i3 workspace.json file by having an array named
"marks" in the nodes dictionary. For example:

"marks": ["_dontmove3"],
"swallows": [ ...

- This script does *not* move windows on startup, so you probably want to run
it early on. I run it from my .i3/config before starting any apps:

exec --no-startup-id ~/src/i3ipc-python/examples/avoid-ws.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend people use exec_always so the script will rerun on restarts.


See also https://redd.it/4fitpu
"""

import i3ipc

def on_window_event(i3, e):
w = e.container
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assignment does not appear to be necessary.


# This is necessary to find the workspace. The container in the event is
# not wired up to its parents, and the root is where the workspace info is
# kept.
w = i3.get_tree().find_by_id(e.container.id)

ws = w.workspace()
if ws and ws.name == '1'and not any(
mark.startswith('_dontmove') for mark in w.marks):
i3.command('[con_id=%d] move window to workspace 10' % w.id)
Copy link
Member

@acrisci acrisci Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try w.command('move... for this purpose.

i3.command('workspace 10')


def main():
i3 = i3ipc.Connection()
i3.on("window::move", on_window_event)
i3.on("window::new", on_window_event)
i3.main()

if __name__ == '__main__':
main()