diff --git a/bumblebee/modules/layout.py b/bumblebee/modules/layout.py index e41c8fd..79bd8d8 100644 --- a/bumblebee/modules/layout.py +++ b/bumblebee/modules/layout.py @@ -6,36 +6,40 @@ import bumblebee.util def description(): return "Showws current keyboard layout and change it on click." -#def parameters(): -# module = __name__.split(".")[-1] -# return +def parameters(): + return [ + "layout.lang: pipe-separated list of languages to cycle through (e.g. us|rs|de). Default: en" + ] class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) + self._languages = self._config.parameter("lang", "en").split("|") + self._idx = 0 - # click - output.add_callback(module="layout.cir", button=1, cmd="setxkbmap us") - output.add_callback(module="layout.us", button=1, cmd="setxkbmap rs") - output.add_callback(module="layout.rs", button=1, cmd="setxkbmap -layout rs -variant latin") + output.add_callback(module=self.instance(), button=1, cmd=self.next_keymap) + output.add_callback(module=self.instance(), button=3, cmd=self.prev_keymap) + def next_keymap(self, event, widget): + self._idx = self._idx + 1 if self._idx < len(self._languages) - 1 else 0 + self.set_keymap() + def prev_keymap(self, event, widget): + self._idx = self._idx - 1 if self._idx > 0 else len(self._languages) - 1 + self.set_keymap() + def set_keymap(self): + tmp = self._languages[self._idx].split(":") + layout = tmp[0] + variant = "" + if len(tmp) > 1: + variant = "-variant {}".format(tmp[1]) + bumblebee.util.execute("setxkbmap -layout {} {}".format(layout, variant)) def widgets(self): - output = subprocess.check_output(["setxkbmap", "-print"], stderr=subprocess.STDOUT) - for line in str(output).split("\\n"): - if "xkb_symbols" in line: - res = line.split("\"")[1].split("+")[1] - - if res == "rs": - return bumblebee.output.Widget(self, res, instance="layout.rs") - elif res == "us": - return bumblebee.output.Widget(self, res, instance="layout.us") - else: - return bumblebee.output.Widget(self, res, instance="layout.cir") - + lang = self._languages[self._idx] + return bumblebee.output.Widget(self, lang) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/output.py b/bumblebee/output.py index d24e0c6..0840523 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -93,10 +93,10 @@ class Output(object): ), None) cb = self._callbacks.get(( event.get("button", -1), - event.get("instance", event.get("name", None)), + event.get("instance", event.get("module", None)), ), cb) - identity = event.get("instance", event.get("name", None)) + identity = event.get("instance", event.get("module", None)) return Command(cb, event, self._widgets.get(identity, None)) def wait(self):