altdesktop / i3ipc-python

🐍 An improved Python library to control i3wm and sway.
http://i3ipc-python.readthedocs.io
BSD 3-Clause "New" or "Revised" License
851 stars 109 forks source link

After last commits doesn't work #119

Closed hovnatan closed 5 years ago

hovnatan commented 5 years ago

Simple following script hangs without showing any window or workspace focus changes after the latest commits

#!/usr/bin/env python3

import sh
import threading

import i3ipc

class FocusWatcher:
    def __init__(self):
        self.i3 = i3ipc.Connection()
        print("Connection to I3 established.")
        self.i3.on('window::focus', self.on_window_focus)
        self.i3.on("workspace::focus", self.on_workspace_focus)

    def on_workspace_focus(self, i3conn, event):
        print(f"hello ws")

    def on_window_focus(self, i3conn, event):
        window_id = event.container.props.id
        print(f"window focus on {window_id}")

    def launch_i3(self):
        print("i3 started")
        self.i3.main()

    def run(self):
        threads = []
        threads.append(threading.Thread(target=self.launch_i3))
        for t in threads:
            t.start()

 if __name__ == '__main__':
     focus_watcher = FocusWatcher()
     focus_watcher.run()