mirror of
https://github.com/powerline/powerline.git
synced 2025-07-31 01:35:40 +02:00
Add support for i3 modes in segment_info for bar
also fix the bar-renderer's argument handling
This commit is contained in:
parent
32a278b8a8
commit
e8b502bb42
@ -20,17 +20,6 @@ class BarPowerline(Powerline):
|
|||||||
super(BarPowerline, self).init(ext='wm', renderer_module='bar')
|
super(BarPowerline, self).init(ext='wm', renderer_module='bar')
|
||||||
|
|
||||||
|
|
||||||
def render(reschedule=False):
|
|
||||||
if reschedule:
|
|
||||||
Timer(0.5, render, kwargs={"reschedule": True}).start()
|
|
||||||
|
|
||||||
global lock
|
|
||||||
with lock:
|
|
||||||
write(powerline.render())
|
|
||||||
write('\n')
|
|
||||||
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(
|
||||||
@ -39,10 +28,24 @@ if __name__ == '__main__':
|
|||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
powerline = BarPowerline()
|
powerline = BarPowerline()
|
||||||
|
|
||||||
lock = Lock()
|
lock = Lock()
|
||||||
|
modes = [None]
|
||||||
write = get_unicode_writer(encoding='utf-8')
|
write = get_unicode_writer(encoding='utf-8')
|
||||||
|
|
||||||
|
def render(reschedule=False):
|
||||||
|
if reschedule:
|
||||||
|
Timer(0.5, render, kwargs={"reschedule": True}).start()
|
||||||
|
|
||||||
|
global lock
|
||||||
|
with lock:
|
||||||
|
write(powerline.render(mode=modes[0]))
|
||||||
|
write('\n')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
def update(evt):
|
||||||
|
modes[0] = evt.change
|
||||||
|
render()
|
||||||
|
|
||||||
render(reschedule=True)
|
render(reschedule=True)
|
||||||
|
|
||||||
if args.i3:
|
if args.i3:
|
||||||
@ -54,8 +57,8 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
conn = i3ipc.Connection()
|
conn = i3ipc.Connection()
|
||||||
conn.on('workspace::focus', lambda conn, evt: render())
|
conn.on('workspace::focus', lambda conn, evt: render())
|
||||||
conn.on('mode', lambda conn, evt: render())
|
conn.on('mode', lambda conn, evt: update(evt))
|
||||||
conn.main()
|
conn.main()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(0.5)
|
time.sleep(1e10)
|
||||||
|
@ -35,10 +35,10 @@ class BarRenderer(Renderer):
|
|||||||
|
|
||||||
return text + contents + '%{F-B--u}'
|
return text + contents + '%{F-B--u}'
|
||||||
|
|
||||||
def render(self):
|
def render(self, *args, **kwargs):
|
||||||
return '%{{l}}{0}%{{r}}{1}'.format(
|
return '%{{l}}{0}%{{r}}{1}'.format(
|
||||||
super(BarRenderer, self).render(side='left'),
|
super(BarRenderer, self).render(side='left', *args, **kwargs),
|
||||||
super(BarRenderer, self).render(side='right'),
|
super(BarRenderer, self).render(side='right', *args, **kwargs),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
|||||||
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
|
from powerline.theme import requires_segment_info
|
||||||
from powerline.segments import Segment, with_docstring
|
from powerline.segments import Segment, with_docstring
|
||||||
|
|
||||||
|
|
||||||
@ -25,9 +26,14 @@ def calcgrp(w):
|
|||||||
return group
|
return group
|
||||||
|
|
||||||
|
|
||||||
def workspaces(pl, strip=0):
|
def workspaces(pl, only_show=None, strip=0):
|
||||||
'''Return list of used workspaces
|
'''Return list of used workspaces
|
||||||
|
|
||||||
|
:param list only_show:
|
||||||
|
Specifies which workspaces to show.
|
||||||
|
Valid entries are "visible", "urgent" and "focused".
|
||||||
|
If omitted or ``null`` all workspaces are shown.
|
||||||
|
|
||||||
:param int strip:
|
:param int strip:
|
||||||
Specifies how many characters from the front of each workspace name should
|
Specifies how many characters from the front of each workspace name should
|
||||||
be stripped (e.g. to remove workspace numbers). Defaults to zero.
|
be stripped (e.g. to remove workspace numbers). Defaults to zero.
|
||||||
@ -40,33 +46,20 @@ def workspaces(pl, strip=0):
|
|||||||
return [{
|
return [{
|
||||||
'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() if not only_show or any(w[typ] for typ in only_show)]
|
||||||
|
|
||||||
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(),
|
@requires_segment_info
|
||||||
'''Returns the current i3 mode
|
def mode(pl, segment_info, names={"default": None}):
|
||||||
|
'''Returns current i3 mode
|
||||||
|
|
||||||
:param str default:
|
:param dict names:
|
||||||
Specifies the name to be displayed instead of "default".
|
Specifies the string to show for various modes.
|
||||||
By default the segment is left out in the default mode.
|
Use ``null`` to hide a mode (``default`` is hidden by default).
|
||||||
|
|
||||||
Highligh groups used: ``mode``
|
Highligh groups used: ``mode``
|
||||||
''')
|
'''
|
||||||
|
mode = segment_info['mode']
|
||||||
|
if mode in names:
|
||||||
|
return names[mode]
|
||||||
|
return mode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user