File: powerline-i3.py

package info (click to toggle)
powerline 2.7-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,828 kB
  • sloc: python: 22,536; sh: 1,789; ansic: 131; makefile: 74; csh: 51
file content (52 lines) | stat: -rwxr-xr-x 1,064 bytes parent folder | download | duplicates (6)
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/python3
# 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))