From 3f25952c13d5847d510c0cae22a8ba876638d570 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:40:16 +0200 Subject: Adding upstream version 2.8.3. Signed-off-by: Daniel Baumann --- powerline/bindings/wm/__init__.py | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 powerline/bindings/wm/__init__.py (limited to 'powerline/bindings/wm/__init__.py') diff --git a/powerline/bindings/wm/__init__.py b/powerline/bindings/wm/__init__.py new file mode 100644 index 0000000..d2c6f30 --- /dev/null +++ b/powerline/bindings/wm/__init__.py @@ -0,0 +1,72 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +import re + +from powerline.theme import requires_segment_info +from powerline.lib.shell import run_cmd +from powerline.bindings.wm.awesome import AwesomeThread + + +DEFAULT_UPDATE_INTERVAL = 0.5 + + +conn = None + + +def i3_subscribe(conn, event, callback): + '''Subscribe to i3 workspace event + + :param conn: + Connection returned by :py:func:`get_i3_connection`. + :param str event: + Event to subscribe to, e.g. ``'workspace'``. + :param func callback: + Function to run on event. + ''' + conn.on(event, callback) + + from threading import Thread + + class I3Thread(Thread): + daemon = True + + def __init__(self, conn): + super(I3Thread, self).__init__() + self.__conn = conn + + def run(self): + self.__conn.main() + + thread = I3Thread(conn=conn) + + thread.start() + + +def get_i3_connection(): + '''Return a valid, cached i3 Connection instance + ''' + global conn + if not conn: + import i3ipc + conn = i3ipc.Connection() + return conn + + +XRANDR_OUTPUT_RE = re.compile(r'^(?P[0-9A-Za-z-]+) connected(?P primary)? (?P\d+)x(?P\d+)\+(?P\d+)\+(?P\d+)', re.MULTILINE) + + +def get_connected_xrandr_outputs(pl): + '''Iterate over xrandr outputs + + Outputs are represented by a dictionary with ``name``, ``width``, + ``height``, ``primary``, ``x`` and ``y`` keys. + ''' + return (match.groupdict() for match in XRANDR_OUTPUT_RE.finditer( + run_cmd(pl, ['xrandr', '-q']) + )) + + +wm_threads = { + 'awesome': AwesomeThread, +} -- cgit v1.2.3