[modules/layout] Add autodetection and auto-adding of languages
Whenever the language is changed outside the bar, update the bar accordingly. Also, when a new language is used, automatically append it to the list of available languages.
This commit is contained in:
parent
ca64851687
commit
4819147410
2 changed files with 25 additions and 1 deletions
|
@ -39,7 +39,29 @@ class Module(bumblebee.module.Module):
|
|||
bumblebee.util.execute("setxkbmap -layout {} {}".format(layout, variant))
|
||||
|
||||
def widgets(self):
|
||||
res = bumblebee.util.execute("setxkbmap -query")
|
||||
layout = None
|
||||
variant = None
|
||||
for line in res.split("\n"):
|
||||
if not line:
|
||||
continue
|
||||
if "layout" in line:
|
||||
layout = line.split(":")[1].strip()
|
||||
if "variant" in line:
|
||||
variant = line.split(":")[1].strip()
|
||||
if variant:
|
||||
layout += ":" + variant
|
||||
|
||||
lang = self._languages[self._idx]
|
||||
|
||||
if lang != layout:
|
||||
if layout in self._languages:
|
||||
self._idx = self._languages.index(layout)
|
||||
else:
|
||||
self._languages.append(layout)
|
||||
self._idx = len(self._languages) - 1
|
||||
lang = layout
|
||||
|
||||
return bumblebee.output.Widget(self, lang)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -24,7 +24,9 @@ def durationfmt(duration):
|
|||
def execute(cmd):
|
||||
args = shlex.split(cmd)
|
||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
out = p.communicate()
|
||||
out, err = p.communicate()
|
||||
|
||||
if p.returncode != 0:
|
||||
raise RuntimeError("{} exited with {}".format(cmd, p.returncode))
|
||||
|
||||
return out.decode("utf-8")
|
||||
|
|
Loading…
Reference in a new issue