Add powerline.segments.i3wm.mode

also make powerline-bar.py redraw on mode change
This commit is contained in:
S0lll0s 2015-05-15 23:33:14 +02:00
parent 918fd8227d
commit b20a707222
2 changed files with 42 additions and 4 deletions

View File

@ -30,6 +30,7 @@ def render(reschedule=False):
write('\n') write('\n')
sys.stdout.flush() sys.stdout.flush()
if __name__ == '__main__': if __name__ == '__main__':
parser = ArgumentParser(description='Powerline BAR bindings.') parser = ArgumentParser(description='Powerline BAR bindings.')
parser.add_argument( parser.add_argument(
@ -47,11 +48,14 @@ if __name__ == '__main__':
if args.i3: if args.i3:
try: try:
import i3ipc import i3ipc
conn = i3ipc.Connection()
conn.on('workspace::focus', lambda conn, evt: render())
conn.main()
except ImportError: except ImportError:
import i3 import i3
i3.Subscription(lambda evt, data, sub: print(render()), 'workspace') i3.Subscription(lambda evt, data, sub: print(render()), 'workspace')
else:
conn = i3ipc.Connection()
conn.on('workspace::focus', lambda conn, evt: render())
conn.on('mode', lambda conn, evt: render())
conn.main()
while True: pass while True:
time.sleep(0.5)

View File

@ -1,6 +1,11 @@
# vim:fileencoding=utf-8:noet # vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function) from __future__ import (unicode_literals, division, absolute_import, print_function)
from threading import Thread
from powerline.segments import Segment, with_docstring
conn = None conn = None
try: try:
import i3ipc import i3ipc
@ -36,3 +41,32 @@ def workspaces(pl, strip=0):
'contents': w['name'][min(len(w['name']),strip):], 'contents': w['name'][min(len(w['name']),strip):],
'highlight_groups': calcgrp(w) 'highlight_groups': calcgrp(w)
} for w in conn.get_workspaces()] } for w in conn.get_workspaces()]
class ModeSegment(Segment):
def startup(self, pl, shutdown_event):
self.mode = 'default'
def callback(conn, e):
self.mode = e.change
conn = i3ipc.Connection()
conn.on('mode', callback)
self.thread = Thread(target=conn.main)
self.thread.daemon = True
self.thread.start()
def __call__(self, pl, default=None):
if self.mode == 'default':
return default
return self.mode
mode = with_docstring(ModeSegment(),
'''Returns the current i3 mode
:param str default:
Specifies the name to be displayed instead of "default".
By default the segment is left out in the default mode.
Highligh groups used: ``mode``
''')