Add i3 bindings and segments

This commit is contained in:
S0lll0s 2014-02-04 10:50:44 +01:00
parent 03594f2def
commit 253ad02c3c
3 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
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
lock.acquire()
s = '[\n' + powerline.render(side='right')[:-2] + '\n]\n'
s += ',[\n' + powerline.render(side='left' )[:-2] + '\n]'
print ',[\n' + s + '\n]'
sys.stdout.flush()
lock.release()
sub = i3.Subscription( render, 'workspace' )
while True:
start_time = monotonic()
render()
time.sleep(max(interval - (monotonic() - start_time), 0.1))

View File

@ -0,0 +1,38 @@
# 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])
"""
if attr is not None and attr is not False:
if attr & ATTR_BOLD:
awesome_attr += ['font_weight="bold"']
if attr & ATTR_ITALIC:
awesome_attr += ['font_style="italic"']
if attr & ATTR_UNDERLINE:
awesome_attr += ['underline="single"']
"""
return json.dumps( segment ) + ",\n"
renderer = i3bgbarRenderer

View File

@ -0,0 +1,18 @@
# vim:fileencoding=utf-8:noet
from powerline.theme import requires_segment_info
import i3
def calcgrp( w ):
group = ["workspace"]
if w['urgent']: group.append( 'w_urgent' )
if w['visible']: group.append( 'w_visible' )
if w['focused']: return "w_focused" #group.append( 'w_focused' )
return group
def workspaces( pl ):
'''Return workspace list
Highlight groups used: ``workspace, visible, focused, urgent``
'''
return [ {'contents': w['name'], 'highlight_group': calcgrp( w )} for w in i3.get_workspaces() ]