(Optionally) switch from "i3-py" to "i3ipc" for i3 bindings

i3-py is no longer maintained
This commit is contained in:
S0lll0s 2015-05-14 16:08:52 +02:00
parent 67f0995f16
commit 918fd8227d
2 changed files with 31 additions and 15 deletions

View File

@ -5,7 +5,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
import sys
import time
from threading import Lock
from threading import Lock, Timer
from argparse import ArgumentParser
from powerline import Powerline
@ -20,14 +20,16 @@ class BarPowerline(Powerline):
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
with lock:
write(powerline.render())
write('\n')
sys.stdout.flush()
if __name__ == '__main__':
parser = ArgumentParser(description='Powerline BAR bindings.')
parser.add_argument(
@ -37,16 +39,19 @@ if __name__ == '__main__':
args = parser.parse_args()
powerline = BarPowerline()
interval = 0.5
lock = Lock()
write = get_unicode_writer(encoding='utf-8')
render(reschedule=True)
if args.i3:
try:
import i3ipc
conn = i3ipc.Connection()
conn.on('workspace::focus', lambda conn, evt: render())
conn.main()
except ImportError:
import i3
sub = i3.Subscription(render, 'workspace')
i3.Subscription(lambda evt, data, sub: print(render()), 'workspace')
while True:
start_time = monotonic()
render()
time.sleep(max(interval - (monotonic() - start_time), 0.1))
while True: pass

View File

@ -1,7 +1,11 @@
# vim:fileencoding=utf-8:noet
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):
@ -16,12 +20,19 @@ def calcgrp(w):
return group
def workspaces(pl):
'''Return workspace list
def workspaces(pl, strip=0):
'''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``
'''
global conn
if not conn: conn = i3ipc.Connection()
return [{
'contents': w['name'],
'contents': w['name'][min(len(w['name']),strip):],
'highlight_groups': calcgrp(w)
} for w in i3.get_workspaces()]
} for w in conn.get_workspaces()]