-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
contrib: add a keyboard layout per window script #4504
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||
#!/usr/bin/env python | ||||||
|
||||||
# This script keeps track of active keyboard layouts per window. | ||||||
# | ||||||
# This script requires i3ipc-python package (install it from a system package | ||||||
# manager or pip). | ||||||
|
||||||
import i3ipc | ||||||
|
||||||
ipc = i3ipc.Connection() | ||||||
prev_focused = -1 | ||||||
windows = {} | ||||||
|
||||||
def on_window_focus(ipc, event): | ||||||
global windows, prev_focused | ||||||
|
||||||
# Save current layout | ||||||
layouts = {} | ||||||
for input in ipc.get_inputs(): | ||||||
layouts[input.identifier] = input.xkb_active_layout_index | ||||||
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. Creating layouts = {input.identifier : input.xkb_active_layout_index
for input in ipc.get_inputs()} And it's faster as a bonus. |
||||||
windows[prev_focused] = layouts | ||||||
|
||||||
# Restore layout of the newly focused window | ||||||
if event.container.id in windows: | ||||||
emersion marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
for (input_id, layout_index) in windows[event.container.id].items(): | ||||||
emersion marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if layout_index != layouts[input_id]: | ||||||
ipc.command("input \"{}\" xkb_switch_layout {}".format( | ||||||
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.
Suggested change
maybe this is more readable, the back slashes really threw me off |
||||||
input_id, layout_index)) | ||||||
|
||||||
prev_focused = event.container.id | ||||||
|
||||||
def on_window_close(ipc, event): | ||||||
global windows | ||||||
if event.container.id in windows: | ||||||
del(windows[event.container.id]) | ||||||
|
||||||
def on_window(ipc, event): | ||||||
if event.change == "focus": | ||||||
on_window_focus(ipc, event) | ||||||
elif event.change == "close": | ||||||
on_window_close(ipc, event) | ||||||
|
||||||
ipc.on("window", on_window) | ||||||
ipc.main() |
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.
why not use current window id
ipc.get_tree().find_focused().id
?