Merge pull request #1372 from ZyX-I/pull-1366
Switch the underlying i3-IPC layer and deprecate i3bgbar bindings
This commit is contained in:
commit
bf6191d144
|
@ -51,8 +51,8 @@ Add the following to :file:`~/.config/qtile/config.py`:
|
|||
|
||||
.. _bar-usage:
|
||||
|
||||
LemonBoy’s bar
|
||||
==============
|
||||
bar-aint-recursive
|
||||
==================
|
||||
|
||||
To run the bar simply pipe the output of the binding script into ``bar`` and
|
||||
specify appropriate options, for example like this::
|
||||
|
@ -63,6 +63,9 @@ to run with i3, simply ``exec`` this in i3 config file::
|
|||
|
||||
exec python /path/to/powerline/bindings/bar/powerline-bar.py --i3 | bar
|
||||
|
||||
Running the binding in i3-mode will require `i3ipc <https://github.com/acrisci/i3ipc-python>`_
|
||||
(or the outdated `i3-py <https://github.com/ziberna/i3-py>`_).
|
||||
|
||||
See the `bar documentation <https://github.com/LemonBoy/bar>`_ for more
|
||||
information and options.
|
||||
|
||||
|
|
|
@ -5,11 +5,10 @@ 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
|
||||
from powerline.lib.monotonic import monotonic
|
||||
from powerline.lib.encoding import get_unicode_writer
|
||||
|
||||
|
||||
|
@ -20,14 +19,6 @@ class BarPowerline(Powerline):
|
|||
super(BarPowerline, self).init(ext='wm', renderer_module='bar')
|
||||
|
||||
|
||||
def render(event=None, data=None, sub=None):
|
||||
global lock
|
||||
with lock:
|
||||
write(powerline.render())
|
||||
write('\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = ArgumentParser(description='Powerline BAR bindings.')
|
||||
parser.add_argument(
|
||||
|
@ -36,17 +27,37 @@ if __name__ == '__main__':
|
|||
)
|
||||
args = parser.parse_args()
|
||||
powerline = BarPowerline()
|
||||
|
||||
interval = 0.5
|
||||
lock = Lock()
|
||||
|
||||
modes = ['default']
|
||||
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)
|
||||
|
||||
if args.i3:
|
||||
try:
|
||||
import i3ipc
|
||||
except ImportError:
|
||||
import i3
|
||||
sub = i3.Subscription(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: update(evt))
|
||||
conn.main()
|
||||
|
||||
while True:
|
||||
start_time = monotonic()
|
||||
render()
|
||||
time.sleep(max(interval - (monotonic() - start_time), 0.1))
|
||||
time.sleep(1e10)
|
||||
|
|
|
@ -35,10 +35,10 @@ class BarRenderer(Renderer):
|
|||
|
||||
return text + contents + '%{F-B--u}'
|
||||
|
||||
def render(self):
|
||||
def render(self, *args, **kwargs):
|
||||
return '%{{l}}{0}%{{r}}{1}'.format(
|
||||
super(BarRenderer, self).render(side='left'),
|
||||
super(BarRenderer, self).render(side='right'),
|
||||
super(BarRenderer, self).render(side='left', *args, **kwargs),
|
||||
super(BarRenderer, self).render(side='right', *args, **kwargs),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# vim:fileencoding=utf-8:noet
|
||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||
|
||||
import i3
|
||||
from powerline.theme import requires_segment_info
|
||||
|
||||
|
||||
conn = None
|
||||
|
||||
|
||||
def calcgrp(w):
|
||||
|
@ -16,12 +19,46 @@ def calcgrp(w):
|
|||
return group
|
||||
|
||||
|
||||
def workspaces(pl):
|
||||
'''Return workspace list
|
||||
def workspaces(pl, only_show=None, strip=0):
|
||||
'''Return list of used workspaces
|
||||
|
||||
Highlight groups used: ``workspace``, ``w_visible``, ``w_focused``, ``w_urgent``
|
||||
: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:
|
||||
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`` or ``w_visible``, ``workspace`` or ``w_focused``, ``workspace`` or ``w_urgent``.
|
||||
'''
|
||||
global conn
|
||||
if not conn:
|
||||
try:
|
||||
import i3ipc
|
||||
except ImportError:
|
||||
import i3 as conn
|
||||
else:
|
||||
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() if not only_show or any((w[typ] for typ in only_show))]
|
||||
|
||||
|
||||
@requires_segment_info
|
||||
def mode(pl, segment_info, names={'default': None}):
|
||||
'''Returns current i3 mode
|
||||
|
||||
:param dict names:
|
||||
Specifies the string to show for various modes.
|
||||
Use ``null`` to hide a mode (``default`` is hidden by default).
|
||||
|
||||
Highligh groups used: ``mode``
|
||||
'''
|
||||
mode = segment_info['mode']
|
||||
if mode in names:
|
||||
return names[mode]
|
||||
return mode
|
||||
|
|
|
@ -8,7 +8,7 @@ from functools import partial
|
|||
from collections import namedtuple
|
||||
from time import sleep
|
||||
|
||||
from powerline.segments import shell, tmux, pdb
|
||||
from powerline.segments import shell, tmux, pdb, i3wm
|
||||
from powerline.lib.vcs import get_fallback_create_watcher
|
||||
from powerline.lib.unicode import out_u
|
||||
|
||||
|
@ -815,6 +815,50 @@ class TestWthr(TestCommon):
|
|||
self.module.weather.shutdown()
|
||||
|
||||
|
||||
class TestI3WM(TestCase):
|
||||
def test_workspaces(self):
|
||||
pl = Pl()
|
||||
with replace_attr(i3wm, 'conn', Args(get_workspaces=lambda: iter([
|
||||
{'name': '1: w1', 'focused': False, 'urgent': False, 'visible': False},
|
||||
{'name': '2: w2', 'focused': False, 'urgent': False, 'visible': True},
|
||||
{'name': '3: w3', 'focused': False, 'urgent': True, 'visible': True},
|
||||
{'name': '4: w4', 'focused': True, 'urgent': True, 'visible': True},
|
||||
]))):
|
||||
self.assertEqual(i3wm.workspaces(pl=pl), [
|
||||
{'contents': '1: w1', 'highlight_groups': ['workspace']},
|
||||
{'contents': '2: w2', 'highlight_groups': ['w_visible', 'workspace']},
|
||||
{'contents': '3: w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']},
|
||||
{'contents': '4: w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']},
|
||||
])
|
||||
self.assertEqual(i3wm.workspaces(pl=pl, only_show=None), [
|
||||
{'contents': '1: w1', 'highlight_groups': ['workspace']},
|
||||
{'contents': '2: w2', 'highlight_groups': ['w_visible', 'workspace']},
|
||||
{'contents': '3: w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']},
|
||||
{'contents': '4: w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']},
|
||||
])
|
||||
self.assertEqual(i3wm.workspaces(pl=pl, only_show=['focused', 'urgent']), [
|
||||
{'contents': '3: w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']},
|
||||
{'contents': '4: w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']},
|
||||
])
|
||||
self.assertEqual(i3wm.workspaces(pl=pl, only_show=['visible']), [
|
||||
{'contents': '2: w2', 'highlight_groups': ['w_visible', 'workspace']},
|
||||
{'contents': '3: w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']},
|
||||
{'contents': '4: w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']},
|
||||
])
|
||||
self.assertEqual(i3wm.workspaces(pl=pl, only_show=['visible'], strip=3), [
|
||||
{'contents': 'w2', 'highlight_groups': ['w_visible', 'workspace']},
|
||||
{'contents': 'w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']},
|
||||
{'contents': 'w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']},
|
||||
])
|
||||
|
||||
def test_mode(self):
|
||||
pl = Pl()
|
||||
self.assertEqual(i3wm.mode(pl=pl, segment_info={'mode': 'default'}), None)
|
||||
self.assertEqual(i3wm.mode(pl=pl, segment_info={'mode': 'test'}), 'test')
|
||||
self.assertEqual(i3wm.mode(pl=pl, segment_info={'mode': 'default'}, names={'default': 'test'}), 'test')
|
||||
self.assertEqual(i3wm.mode(pl=pl, segment_info={'mode': 'test'}, names={'default': 'test', 'test': 't'}), 't')
|
||||
|
||||
|
||||
class TestMail(TestCommon):
|
||||
module_name = 'mail'
|
||||
|
||||
|
|
Loading…
Reference in New Issue