Merge pull request #365 from ncoop/iss359
Stricter criteria for including query output
This commit is contained in:
commit
4611295475
@ -10,7 +10,8 @@ class Xkblayout(IntervalModule):
|
|||||||
current layout is not in the ``layouts`` setting the first layout
|
current layout is not in the ``layouts`` setting the first layout
|
||||||
is enabled.
|
is enabled.
|
||||||
|
|
||||||
``layouts`` can be stated with or without variants, e.g.: status.register("xkblayout", layouts=["de neo", "de"])
|
``layouts`` can be stated with or without variants,
|
||||||
|
e.g.: status.register("xkblayout", layouts=["de neo", "de"])
|
||||||
"""
|
"""
|
||||||
|
|
||||||
interval = 1
|
interval = 1
|
||||||
@ -22,7 +23,7 @@ class Xkblayout(IntervalModule):
|
|||||||
on_leftclick = "change_layout"
|
on_leftclick = "change_layout"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
kblayout = subprocess.check_output("setxkbmap -query | awk '/layout/,/variant/{print $2}'", shell=True).decode('utf-8').replace("\n", " ").strip()
|
kblayout = self.kblayout()
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": self.format.format(name=kblayout).upper(),
|
"full_text": self.format.format(name=kblayout).upper(),
|
||||||
@ -31,12 +32,21 @@ class Xkblayout(IntervalModule):
|
|||||||
|
|
||||||
def change_layout(self):
|
def change_layout(self):
|
||||||
layouts = self.layouts
|
layouts = self.layouts
|
||||||
kblayout = subprocess.check_output("setxkbmap -query | awk '/layout/,/variant/{print $2}'", shell=True).decode('utf-8').replace("\n", " ").strip()
|
kblayout = self.kblayout()
|
||||||
if kblayout in layouts:
|
if kblayout in layouts:
|
||||||
position = layouts.index(kblayout)
|
position = layouts.index(kblayout)
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(["setxkbmap"] + layouts[position + 1].split())
|
subprocess.check_call(["setxkbmap"] +
|
||||||
|
layouts[position + 1].split())
|
||||||
except IndexError:
|
except IndexError:
|
||||||
subprocess.check_call(["setxkbmap"] + layouts[0].split())
|
subprocess.check_call(["setxkbmap"] + layouts[0].split())
|
||||||
else:
|
else:
|
||||||
subprocess.check_call(["setxkbmap"] + layouts[0].split())
|
subprocess.check_call(["setxkbmap"] + layouts[0].split())
|
||||||
|
|
||||||
|
def kblayout(self):
|
||||||
|
kblayout = subprocess.check_output("setxkbmap -query", shell=True)\
|
||||||
|
.decode("utf-8").splitlines()
|
||||||
|
kblayout = [l.split() for l in kblayout]
|
||||||
|
kblayout = [l[1].strip() for l in kblayout
|
||||||
|
if l[0].startswith(("layout", "variant"))]
|
||||||
|
return (" ").join(kblayout)
|
||||||
|
Loading…
Reference in New Issue
Block a user