2016-11-26 12:33:42 +01:00
|
|
|
import subprocess
|
|
|
|
import shlex
|
|
|
|
import bumblebee.module
|
|
|
|
import bumblebee.util
|
|
|
|
|
|
|
|
def description():
|
|
|
|
return "Showws current keyboard layout and change it on click."
|
|
|
|
|
2016-11-27 18:08:22 +01:00
|
|
|
def parameters():
|
|
|
|
return [
|
|
|
|
"layout.lang: pipe-separated list of languages to cycle through (e.g. us|rs|de). Default: en"
|
|
|
|
]
|
2016-11-27 16:24:11 +01:00
|
|
|
|
|
|
|
|
2016-11-26 12:33:42 +01:00
|
|
|
class Module(bumblebee.module.Module):
|
|
|
|
def __init__(self, output, config, alias):
|
|
|
|
super(Module, self).__init__(output, config, alias)
|
|
|
|
|
2016-11-27 18:08:22 +01:00
|
|
|
self._languages = self._config.parameter("lang", "en").split("|")
|
|
|
|
self._idx = 0
|
2016-11-26 12:33:42 +01:00
|
|
|
|
2016-11-27 18:08:22 +01:00
|
|
|
output.add_callback(module=self.instance(), button=1, cmd=self.next_keymap)
|
|
|
|
output.add_callback(module=self.instance(), button=3, cmd=self.prev_keymap)
|
2016-11-26 12:33:42 +01:00
|
|
|
|
2016-11-27 18:08:22 +01:00
|
|
|
def next_keymap(self, event, widget):
|
|
|
|
self._idx = self._idx + 1 if self._idx < len(self._languages) - 1 else 0
|
|
|
|
self.set_keymap()
|
2016-11-26 12:33:42 +01:00
|
|
|
|
2016-11-27 18:08:22 +01:00
|
|
|
def prev_keymap(self, event, widget):
|
|
|
|
self._idx = self._idx - 1 if self._idx > 0 else len(self._languages) - 1
|
|
|
|
self.set_keymap()
|
2016-11-26 12:33:42 +01:00
|
|
|
|
2016-11-27 18:08:22 +01:00
|
|
|
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))
|
2016-11-26 12:33:42 +01:00
|
|
|
|
|
|
|
def widgets(self):
|
2016-11-27 18:08:22 +01:00
|
|
|
lang = self._languages[self._idx]
|
|
|
|
return bumblebee.output.Widget(self, lang)
|
2016-11-26 12:33:42 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|