mirror of
https://github.com/swaywm/sway.git
synced 2026-04-26 06:46:26 -04:00
Add type hinting, moved things to main and use f string
This commit is contained in:
parent
3b23b0c95b
commit
19261c8cbe
1 changed files with 12 additions and 11 deletions
|
|
@ -7,11 +7,7 @@
|
||||||
|
|
||||||
import i3ipc
|
import i3ipc
|
||||||
|
|
||||||
ipc = i3ipc.Connection()
|
def on_window_focus(ipc: i3ipc.connection.Connection, event: i3ipc.events.WindowEvent):
|
||||||
prev_focused = ipc.get_tree().find_focused().id
|
|
||||||
windows = {}
|
|
||||||
|
|
||||||
def on_window_focus(ipc, event):
|
|
||||||
global windows, prev_focused
|
global windows, prev_focused
|
||||||
|
|
||||||
# Save current layout
|
# Save current layout
|
||||||
|
|
@ -23,21 +19,26 @@ def on_window_focus(ipc, event):
|
||||||
if event.container.id in windows:
|
if event.container.id in windows:
|
||||||
for (kdb_id, layout_index) in windows[event.container.id].items():
|
for (kdb_id, layout_index) in windows[event.container.id].items():
|
||||||
if layout_index != layouts[kdb_id]:
|
if layout_index != layouts[kdb_id]:
|
||||||
ipc.command("""input "{}" xkb_switch_layout {}""".format(
|
ipc.command(f"input \"{kdb_id}\" xkb_switch_layout {layout_index}")
|
||||||
kdb_id, layout_index))
|
break
|
||||||
|
|
||||||
prev_focused = event.container.id
|
prev_focused = event.container.id
|
||||||
|
|
||||||
def on_window_close(ipc, event):
|
def on_window_close(ipc: i3ipc.connection.Connection, event: i3ipc.events.WindowEvent):
|
||||||
global windows
|
global windows
|
||||||
if event.container.id in windows:
|
if event.container.id in windows:
|
||||||
del(windows[event.container.id])
|
del(windows[event.container.id])
|
||||||
|
|
||||||
def on_window(ipc, event):
|
def on_window(ipc: i3ipc.connection.Connection, event: i3ipc.events.WindowEvent):
|
||||||
if event.change == "focus":
|
if event.change == "focus":
|
||||||
on_window_focus(ipc, event)
|
on_window_focus(ipc, event)
|
||||||
elif event.change == "close":
|
elif event.change == "close":
|
||||||
on_window_close(ipc, event)
|
on_window_close(ipc, event)
|
||||||
|
|
||||||
ipc.on("window", on_window)
|
if __name__ == "__main__":
|
||||||
ipc.main()
|
ipc = i3ipc.Connection()
|
||||||
|
prev_focused = ipc.get_tree().find_focused().id
|
||||||
|
windows = {}
|
||||||
|
|
||||||
|
ipc.on("window", on_window)
|
||||||
|
ipc.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue