2017-09-30 11:17:18 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2017-09-30 11:50:33 +02:00
|
|
|
"""Displays the current keyboard layout using libX11
|
|
|
|
|
|
|
|
Requires the following library:
|
|
|
|
* libX11.so.6
|
2017-09-30 16:26:20 +02:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* layout-xkb.showname: Boolean that indicate whether the full name should be displayed. Defaults to false (only the symbol will be displayed)
|
2017-09-30 11:50:33 +02:00
|
|
|
"""
|
|
|
|
|
2017-09-30 11:17:18 +02:00
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
2017-10-01 05:42:29 +02:00
|
|
|
from xkbgroup import *
|
2017-09-30 11:17:18 +02:00
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.current_layout)
|
|
|
|
)
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
|
|
cmd=self._next_keymap)
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE,
|
|
|
|
cmd=self._prev_keymap)
|
|
|
|
|
|
|
|
def _next_keymap(self, event):
|
|
|
|
self._set_keymap(1)
|
|
|
|
|
|
|
|
def _prev_keymap(self, event):
|
|
|
|
self._set_keymap(-1)
|
|
|
|
|
|
|
|
def _set_keymap(self, rotation):
|
2017-09-30 16:21:51 +02:00
|
|
|
xkb = XKeyboard()
|
|
|
|
if xkb.groups_count < 2: return # nothing to doA
|
|
|
|
|
|
|
|
layouts = xkb.groups_symbols[rotation:] + xkb.groups_symbols[:rotation]
|
|
|
|
variants = xkb.groups_variants[rotation:] + xkb.groups_variants[:rotation]
|
|
|
|
|
|
|
|
try:
|
|
|
|
bumblebee.util.execute("setxkbmap -layout {} -variant {}".format(",".join(layouts), ",".join(variants)))
|
|
|
|
except RuntimeError:
|
|
|
|
pass
|
2017-09-30 11:17:18 +02:00
|
|
|
|
|
|
|
def current_layout(self, widget):
|
2017-09-30 11:53:28 +02:00
|
|
|
try:
|
|
|
|
xkb = XKeyboard()
|
|
|
|
log.debug("group num: {}".format(xkb.group_num))
|
2017-09-30 16:26:20 +02:00
|
|
|
name = xkb.group_name if bumblebee.util.asbool(self.parameter("showname")) else xkb.group_symbol
|
|
|
|
return "{} ({})".format(name, xkb.group_variant) if xkb.group_variant else name
|
2017-09-30 11:53:28 +02:00
|
|
|
except Exception:
|
|
|
|
return "n/a"
|
2017-09-30 11:17:18 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|