mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 07:44:36 +02:00
Abstract away subscription to workspace event
This commit is contained in:
parent
da3a0fab68
commit
8150d38bd2
@ -7,7 +7,7 @@ import time
|
|||||||
|
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
|
|
||||||
import i3
|
from powerline.bindings.wm import get_i3_connection, i3_subscribe
|
||||||
|
|
||||||
from powerline import Powerline
|
from powerline import Powerline
|
||||||
from powerline.lib.monotonic import monotonic
|
from powerline.lib.monotonic import monotonic
|
||||||
@ -43,7 +43,8 @@ if __name__ == '__main__':
|
|||||||
print (',[' + powerline.render()[:-1] + ']')
|
print (',[' + powerline.render()[:-1] + ']')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
sub = i3.Subscription(render, 'workspace')
|
i3 = get_i3_connection()
|
||||||
|
i3_subscribe(i3, 'workspace', render)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
start_time = monotonic()
|
start_time = monotonic()
|
||||||
|
@ -14,6 +14,43 @@ DEFAULT_UPDATE_INTERVAL = 0.5
|
|||||||
conn = None
|
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():
|
def get_i3_connection():
|
||||||
'''Return a valid, cached i3 Connection instance
|
'''Return a valid, cached i3 Connection instance
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user