summaryrefslogtreecommitdiffstats
path: root/powerline/bindings/i3/powerline-i3.py
blob: f44e9281e1e4877bb240a98f6591eac3f9b05053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)

import sys
import time

from threading import Lock

from powerline.bindings.wm import get_i3_connection, i3_subscribe

from powerline import Powerline
from powerline.lib.monotonic import monotonic


class I3Powerline(Powerline):
	'''Powerline child for i3bar

	Currently only changes the default log target.
	'''
	default_log_stream = sys.stderr


if __name__ == '__main__':
	name = 'wm'
	if len(sys.argv) > 1:
		name = sys.argv[1]

	powerline = I3Powerline(name, renderer_module='i3bar')
	powerline.update_renderer()

	interval = 0.5

	print ('{"version": 1}')
	print ('[')
	print ('[]')

	lock = Lock()

	def render(event=None, data=None, sub=None):
		global lock
		with lock:
			print (',[' + powerline.render()[:-1] + ']')
			sys.stdout.flush()

	i3 = get_i3_connection()
	i3_subscribe(i3, 'workspace', render)

	while True:
		start_time = monotonic()
		render()
		time.sleep(max(interval - (monotonic() - start_time), 0.1))