From 447cce46aa4f5768bb417afc0cc8db8d957c23fb Mon Sep 17 00:00:00 2001 From: "J.M. Dana" Date: Tue, 24 Feb 2015 16:13:30 +0000 Subject: [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. --- py3status/modules/keyboard_layout.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'py3status/modules/keyboard_layout.py') 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: -- cgit v1.3