Add powerline.segments.i3wm.mode
also make powerline-bar.py redraw on mode change
This commit is contained in:
parent
918fd8227d
commit
b20a707222
|
@ -30,6 +30,7 @@ def render(reschedule=False):
|
|||
write('\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = ArgumentParser(description='Powerline BAR bindings.')
|
||||
parser.add_argument(
|
||||
|
@ -47,11 +48,14 @@ if __name__ == '__main__':
|
|||
if args.i3:
|
||||
try:
|
||||
import i3ipc
|
||||
conn = i3ipc.Connection()
|
||||
conn.on('workspace::focus', lambda conn, evt: render())
|
||||
conn.main()
|
||||
except ImportError:
|
||||
import i3
|
||||
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)
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
# vim:fileencoding=utf-8:noet
|
||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||
|
||||
from threading import Thread
|
||||
|
||||
from powerline.segments import Segment, with_docstring
|
||||
|
||||
|
||||
conn = None
|
||||
try:
|
||||
import i3ipc
|
||||
|
@ -36,3 +41,32 @@ def workspaces(pl, strip=0):
|
|||
'contents': w['name'][min(len(w['name']),strip):],
|
||||
'highlight_groups': calcgrp(w)
|
||||
} 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``
|
||||
''')
|
||||
|
|
Loading…
Reference in New Issue