(Optionally) switch from "i3-py" to "i3ipc" for i3 bindings
i3-py is no longer maintained
This commit is contained in:
parent
67f0995f16
commit
918fd8227d
|
@ -5,7 +5,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from threading import Lock
|
from threading import Lock, Timer
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
from powerline import Powerline
|
from powerline import Powerline
|
||||||
|
@ -20,14 +20,16 @@ class BarPowerline(Powerline):
|
||||||
super(BarPowerline, self).init(ext='wm', renderer_module='bar')
|
super(BarPowerline, self).init(ext='wm', renderer_module='bar')
|
||||||
|
|
||||||
|
|
||||||
def render(event=None, data=None, sub=None):
|
def render(reschedule=False):
|
||||||
|
if reschedule:
|
||||||
|
Timer(0.5, render, kwargs={"reschedule": True}).start()
|
||||||
|
|
||||||
global lock
|
global lock
|
||||||
with lock:
|
with lock:
|
||||||
write(powerline.render())
|
write(powerline.render())
|
||||||
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(
|
||||||
|
@ -37,16 +39,19 @@ if __name__ == '__main__':
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
powerline = BarPowerline()
|
powerline = BarPowerline()
|
||||||
|
|
||||||
interval = 0.5
|
|
||||||
lock = Lock()
|
lock = Lock()
|
||||||
|
|
||||||
write = get_unicode_writer(encoding='utf-8')
|
write = get_unicode_writer(encoding='utf-8')
|
||||||
|
render(reschedule=True)
|
||||||
|
|
||||||
if args.i3:
|
if args.i3:
|
||||||
|
try:
|
||||||
|
import i3ipc
|
||||||
|
conn = i3ipc.Connection()
|
||||||
|
conn.on('workspace::focus', lambda conn, evt: render())
|
||||||
|
conn.main()
|
||||||
|
except ImportError:
|
||||||
import i3
|
import i3
|
||||||
sub = i3.Subscription(render, 'workspace')
|
i3.Subscription(lambda evt, data, sub: print(render()), 'workspace')
|
||||||
|
|
||||||
while True:
|
while True: pass
|
||||||
start_time = monotonic()
|
|
||||||
render()
|
|
||||||
time.sleep(max(interval - (monotonic() - start_time), 0.1))
|
|
||||||
|
|
|
@ -1,7 +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)
|
||||||
|
|
||||||
import i3
|
conn = None
|
||||||
|
try:
|
||||||
|
import i3ipc
|
||||||
|
except ImportError:
|
||||||
|
import i3 as conn
|
||||||
|
|
||||||
|
|
||||||
def calcgrp(w):
|
def calcgrp(w):
|
||||||
|
@ -16,12 +20,19 @@ def calcgrp(w):
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
|
||||||
def workspaces(pl):
|
def workspaces(pl, strip=0):
|
||||||
'''Return workspace list
|
'''Return list of used workspaces
|
||||||
|
|
||||||
|
:param int strip:
|
||||||
|
Specifies how many characters from the front of each workspace name should
|
||||||
|
be stripped (e.g. to remove workspace numbers). Defaults to zero.
|
||||||
|
|
||||||
Highlight groups used: ``workspace``, ``w_visible``, ``w_focused``, ``w_urgent``
|
Highlight groups used: ``workspace``, ``w_visible``, ``w_focused``, ``w_urgent``
|
||||||
'''
|
'''
|
||||||
|
global conn
|
||||||
|
if not conn: conn = i3ipc.Connection()
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
'contents': w['name'],
|
'contents': w['name'][min(len(w['name']),strip):],
|
||||||
'highlight_groups': calcgrp(w)
|
'highlight_groups': calcgrp(w)
|
||||||
} for w in i3.get_workspaces()]
|
} for w in conn.get_workspaces()]
|
||||||
|
|
Loading…
Reference in New Issue