[output] Add support for click-events in i3

The i3 output now has a separate thread that continuously monitors stdin
for incoming click events. The generic output class also has methods for
registering callbacks (as commands). For now, by default, scroll events
will be used to emulate the next/previous workspace.
This commit is contained in:
Tobias Witek 2016-11-01 07:46:26 +01:00
parent 36ff727165
commit 579381978e
4 changed files with 66 additions and 2 deletions

View file

@ -1,16 +1,44 @@
from __future__ import unicode_literals
import os
import sys
import json
import shlex
import threading
import subprocess
import bumblebee.output
def read_input(output):
while True:
line = sys.stdin.readline().strip(",").strip()
if line == "[": continue
if line == "]": break
DEVNULL = open(os.devnull, 'wb')
event = json.loads(line)
cb = output.callback(event)
if cb:
cb = cb.format(
name = event.get("name", ""),
instance = event.get("instance", ""),
button = event.get("button", -1)
)
subprocess.call(shlex.split(cb), stdout=DEVNULL, stderr=DEVNULL)
class i3bar(bumblebee.output.Output):
def __init__(self, theme):
super(i3bar, self).__init__(theme)
self._data = []
self.add_callback("i3-msg workspace prev", 4)
self.add_callback("i3-msg workspace next", 5)
self._thread = threading.Thread(target=read_input, args=(self,))
self._thread.start()
def start(self):
return json.dumps({ "version": 1 }) + "["
return json.dumps({ "version": 1, "click_events": True }) + "["
def add(self, obj):
theme = self.theme()
@ -21,6 +49,8 @@ class i3bar(bumblebee.output.Output):
u"full_text": "{}{}{}".format(theme.prefix(obj), d, theme.suffix(obj)),
"color": theme.color(obj),
"background": theme.background(obj),
"name": obj.__module__.replace("bumblebee.modules.",""),
"instance": obj.instance() if hasattr(obj, "instance") else None,
}
if theme.urgent(obj) and obj.critical():