Merge pull request #782 from S0lll0s/feature/i3
Add i3 bindings, segments and renderer
This commit is contained in:
commit
97c93fc7c0
|
@ -73,6 +73,7 @@ Python packages
|
|||
* ``pygit2``
|
||||
* ``mercurial``
|
||||
* ``psutil``
|
||||
* ``i3-py``, `available on github <https://github.com/ziberna/i3-py>`_. Only used with i3wm bindings and segments.
|
||||
|
||||
Other applications
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
@ -233,3 +234,19 @@ Add the following to your :file:`~/.config/qtile/config.py`:
|
|||
),
|
||||
),
|
||||
]
|
||||
|
||||
with i3bar replacement
|
||||
-----------------
|
||||
|
||||
.. note:: Until the patch is done in i3, you will need a custom ``i3bar`` build called ``i3bgbar``.
|
||||
The source is available `here <https://github.com/S0lll0s/i3bgbar>`_.
|
||||
|
||||
Add the following to your :file:`~/.i3/config`::
|
||||
bar {
|
||||
i3bar_command i3bgbar
|
||||
|
||||
status_command python /path/to/powerline/bindings/i3/powerline-i3.py
|
||||
font pango:PowerlineFont 12
|
||||
}
|
||||
|
||||
where ``i3bgbar`` may be replaced with the path to the custom i3bar binary and ``PowerlineFont`` is any system font with powerline support.
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8:noet
|
||||
from __future__ import print_function
|
||||
|
||||
from powerline import Powerline
|
||||
from powerline.lib.monotonic import monotonic
|
||||
|
||||
import sys
|
||||
import time
|
||||
import i3
|
||||
from threading import Lock
|
||||
|
||||
name = 'wm'
|
||||
if len( sys.argv ) > 1:
|
||||
name = sys.argv[1]
|
||||
powerline = Powerline(name, renderer_module='i3bgbar')
|
||||
powerline.update_renderer()
|
||||
|
||||
interval = 0.5
|
||||
|
||||
print( '{"version": 1, "custom_workspace": true}' )
|
||||
print( '[' )
|
||||
print( ' [[],[]]' )
|
||||
|
||||
lock = Lock()
|
||||
|
||||
def render( event=None, data=None, sub=None ):
|
||||
global lock
|
||||
with lock:
|
||||
s = '[\n' + powerline.render(side='right')[:-2] + '\n]\n'
|
||||
s += ',[\n' + powerline.render(side='left' )[:-2] + '\n]'
|
||||
print( ',[\n' + s + '\n]' )
|
||||
sys.stdout.flush()
|
||||
|
||||
sub = i3.Subscription( render, 'workspace' )
|
||||
|
||||
while True:
|
||||
start_time = monotonic()
|
||||
render()
|
||||
time.sleep(max(interval - (monotonic() - start_time), 0.1))
|
|
@ -0,0 +1,29 @@
|
|||
# vim:fileencoding=utf-8:noet
|
||||
|
||||
from powerline.renderer import Renderer
|
||||
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
|
||||
import json
|
||||
|
||||
class i3bgbarRenderer(Renderer):
|
||||
'''i3bgbar Segment Renderer'''
|
||||
|
||||
@staticmethod
|
||||
def hlstyle(*args, **kwargs):
|
||||
# We don't need to explicitly reset attributes, so skip those calls
|
||||
return ''
|
||||
|
||||
def hl(self, contents, fg=None, bg=None, attr=None):
|
||||
'''Highlight a segment.'''
|
||||
|
||||
segment = { "full_text": contents, "separator": False, "separator_block_width": 0 } # no seperators
|
||||
|
||||
if fg is not None:
|
||||
if fg is not False and fg[1] is not False:
|
||||
segment['color'] = "#{0:06x}".format(fg[1])
|
||||
if bg is not None:
|
||||
if bg is not False and bg[1] is not False:
|
||||
segment['background_color'] = "#{0:06x}".format(bg[1])
|
||||
return json.dumps( segment ) + ",\n" # i3bar "pseudo json" requires one line at a time
|
||||
|
||||
|
||||
renderer = i3bgbarRenderer
|
|
@ -0,0 +1,19 @@
|
|||
# vim:fileencoding=utf-8:noet
|
||||
|
||||
from powerline.theme import requires_segment_info
|
||||
import i3
|
||||
|
||||
def calcgrp( w ):
|
||||
group = []
|
||||
if w['focused']: group.append( 'w_focused' )
|
||||
if w['urgent']: group.append( 'w_urgent' )
|
||||
if w['visible']: group.append( 'w_visible' )
|
||||
group.append( 'workspace' )
|
||||
return group
|
||||
|
||||
def workspaces( pl ):
|
||||
'''Return workspace list
|
||||
|
||||
Highlight groups used: ``workspace``, ``w_visible``, ``w_focused``, ``w_urgent``
|
||||
'''
|
||||
return [ {'contents': w['name'], 'highlight_group': calcgrp( w )} for w in i3.get_workspaces() ]
|
Loading…
Reference in New Issue