[engine/input] Re-enable mouse button parameter bindings

Re-enable the possibility to define custom mouse actions by binding
commands to "<alias|module>.<left-click|right-click|...>". These
commands are then executed as shell commands.

fixes #30
This commit is contained in:
Tobi-wan Kenobi 2016-12-15 19:41:50 +01:00
parent 41b61d05d5
commit 5e305bf3b6
5 changed files with 61 additions and 6 deletions

View file

@ -1,10 +1,12 @@
# pylint: disable=C0103,C0111,W0703,W0212
import shlex
import unittest
from bumblebee.error import ModuleLoadError
from bumblebee.engine import Engine
from bumblebee.config import Config
import bumblebee.input
from tests.util import MockOutput, MockInput
@ -52,4 +54,30 @@ class TestEngine(unittest.TestCase):
except Exception as e:
self.fail(e)
def test_custom_cmd(self):
testmodules = [
{ "name": "test", "button": "test.left-click", "action": "echo" },
{ "name": "test:alias", "button": "alias.right-click", "action": "echo2" },
]
cmd = "-m"
for test in testmodules:
cmd += " " + test["name"]
cmd += " -p"
for test in testmodules:
cmd += " " + test["button"] + "=" + test["action"]
cfg = Config(shlex.split(cmd))
inp = MockInput()
engine = Engine(config=cfg, output=MockOutput(), inp=inp)
i = 0
for module in engine.modules():
callback = inp.get_callback(module.id)
self.assertTrue(callback is not None)
self.assertEquals(callback["command"], testmodules[i]["action"])
if "left" in testmodules[i]["button"]:
self.assertTrue(callback["button"], bumblebee.input.LEFT_MOUSE)
if "right" in testmodules[i]["button"]:
self.assertTrue(callback["button"], bumblebee.input.RIGHT_MOUSE)
i += 1
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -37,14 +37,24 @@ def assertMouseEvent(mock_input, mock_output, mock_select, engine, module, butto
assertPopen(mock_output, cmd)
class MockInput(object):
def __init__(self):
self._callbacks = {}
def start(self):
pass
def stop(self):
pass
def get_callback(self, uid):
return self._callbacks.get(uid, None)
def register_callback(self, obj, button, cmd):
pass
if not obj:
return
self._callbacks[obj.id] = {
"button": button,
"command": cmd,
}
class MockEngine(object):
def __init__(self):