File: powerline-lemonbar.py

package info (click to toggle)
powerline 2.8.1-3~bpo10%2B1
  • links: PTS, VCS
  • area: main
  • in suites: buster-backports
  • size: 2,856 kB
  • sloc: python: 22,736; sh: 1,783; ansic: 131; makefile: 69; csh: 51
file content (61 lines) | stat: -rwxr-xr-x 1,630 bytes parent folder | download | duplicates (5)
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
53
54
55
56
57
58
59
60
61
#!/usr/bin/python3
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)

import time
import re
import subprocess

from threading import Lock, Timer

from powerline.lemonbar import LemonbarPowerline
from powerline.commands.lemonbar import get_argparser
from powerline.bindings.wm import get_connected_xrandr_outputs


if __name__ == '__main__':
	parser = get_argparser()
	args = parser.parse_args()

	powerline = LemonbarPowerline()
	powerline.update_renderer()
	bars = []

	for screen in get_connected_xrandr_outputs(powerline.pl):
		command = [args.bar_command, '-g', '{0}x{1}+{2}+{3}'.format(screen['width'], args.height, screen['x'], screen['y'])] + args.args[1:]
		process = subprocess.Popen(command, stdin=subprocess.PIPE)
		bars.append((screen['name'], process, int(screen['width']) / 5))

	lock = Lock()
	modes = ['default']

	def render(reschedule=False):
		if reschedule:
			Timer(args.interval, render, kwargs={'reschedule': True}).start()

		global lock
		with lock:
			for output, process, width in bars:
				process.stdin.write(powerline.render(mode=modes[0], width=width, matcher_info=output).encode('utf-8') + b'\n')
				process.stdin.flush()

	def update(evt):
		modes[0] = evt.change
		render()

	render(reschedule=True)

	if args.i3:
		try:
			import i3ipc
		except ImportError:
			import i3
			i3.Subscription(lambda evt, data, sub: 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:
		time.sleep(1e8)