Merge pull request #1770 from ZyX-I/fix-i3bar-i3ipc
Abstract away subscription to workspace event
This commit is contained in:
commit
be5879379e
|
@ -7,7 +7,7 @@ import time
|
|||
|
||||
from threading import Lock
|
||||
|
||||
import i3
|
||||
from powerline.bindings.wm import get_i3_connection, i3_subscribe
|
||||
|
||||
from powerline import Powerline
|
||||
from powerline.lib.monotonic import monotonic
|
||||
|
@ -43,7 +43,8 @@ if __name__ == '__main__':
|
|||
print (',[' + powerline.render()[:-1] + ']')
|
||||
sys.stdout.flush()
|
||||
|
||||
sub = i3.Subscription(render, 'workspace')
|
||||
i3 = get_i3_connection()
|
||||
i3_subscribe(i3, 'workspace', render)
|
||||
|
||||
while True:
|
||||
start_time = monotonic()
|
||||
|
|
|
@ -14,6 +14,43 @@ DEFAULT_UPDATE_INTERVAL = 0.5
|
|||
conn = None
|
||||
|
||||
|
||||
def i3_subscribe(conn, event, callback):
|
||||
'''Subscribe to i3 workspace event
|
||||
|
||||
:param conn:
|
||||
Connection returned by :py:func:`get_i3_connection`.
|
||||
:param str event:
|
||||
Event to subscribe to, e.g. ``'workspace'``.
|
||||
:param func callback:
|
||||
Function to run on event.
|
||||
'''
|
||||
try:
|
||||
import i3
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
conn.Subscription(callback, event)
|
||||
return
|
||||
|
||||
conn.on(event, callback)
|
||||
|
||||
from threading import Thread
|
||||
|
||||
class I3Thread(Thread):
|
||||
daemon = True
|
||||
|
||||
def __init__(self, conn):
|
||||
super(I3Thread, self).__init__()
|
||||
self.__conn = conn
|
||||
|
||||
def run(self):
|
||||
self.__conn.main()
|
||||
|
||||
thread = I3Thread(conn=conn)
|
||||
|
||||
thread.start()
|
||||
|
||||
|
||||
def get_i3_connection():
|
||||
'''Return a valid, cached i3 Connection instance
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue