summaryrefslogtreecommitdiffstats
path: root/py3status
diff options
context:
space:
mode:
authorJ.M. Dana <jmdana@gmail.com>2015-02-24 16:13:30 +0000
committerJ.M. Dana <jmdana@gmail.com>2015-02-24 16:13:30 +0000
commit447cce46aa4f5768bb417afc0cc8db8d957c23fb (patch)
tree135a5c16e0e54f02d7022121b521566fef925713 /py3status
parent151d108c57cc13ff7b140e78f746b1e6ba8e327c (diff)
[bugfix] incorrect parsing of "setxkbmap -query"
The setxkbmap method assumes that the layout appears at the end of the "setxkbmap -query" command, which is not always true (e.g. options defined with "setxkbmap -option" may appear after the layout). The module has been modified so it uses a regular expression for parsing.
Diffstat (limited to 'py3status')
-rw-r--r--py3status/modules/keyboard_layout.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/py3status/modules/keyboard_layout.py b/py3status/modules/keyboard_layout.py
index ffc3907..b62268e 100644
--- a/py3status/modules/keyboard_layout.py
+++ b/py3status/modules/keyboard_layout.py
@@ -13,6 +13,8 @@ Requires:
from subprocess import check_output
from time import time
+import shlex
+import re
# colors of layouts, check your command's output to match keys
LANG_COLORS = {
@@ -22,6 +24,7 @@ LANG_COLORS = {
'us': '#729FCF', # light blue
}
+LAYOUT_RE = re.compile(r".*layout:\s*(\w+).*", flags=re.DOTALL)
def xbklayout():
"""
@@ -39,9 +42,9 @@ def setxkbmap():
Please read issue 33 for more information :
https://github.com/ultrabug/py3status/pull/33
"""
- q = check_output(['setxkbmap', '-query']).decode('utf-8')
- return q.replace(' ', '').split(':')[-1]
+ out = check_output(shlex.split("setxkbmap -query")).decode("utf-8")
+ return re.match(LAYOUT_RE, out).group(1)
class Py3status: