-
Notifications
You must be signed in to change notification settings - Fork 108
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
xenomachina
wants to merge
1
commit into
altdesktop:master
Choose a base branch
from
xenomachina:avoid-ws
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
See also https://redd.it/4fitpu | ||
""" | ||
|
||
import i3ipc | ||
|
||
def on_window_event(i3, e): | ||
w = e.container | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try |
||
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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.