We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
keyboard_layout: keyboard shortcut stop working
Problem
--------------------

Switching keyboard layout causes layout switching shortcut to stop working (This might related to #1742)


Analysis
---------------------

[`_set_active`](https://github.com/ultrabug/py3status/blob/65a609261095f7502fc2814e9a6feb478845a69c/py3status/modules/keyboard_layout.py#L159-L163) switch layout by replacing all layout in `XkbLayout` with the target layout, This causes switching layout shortcut to not work since there's only a single layout left.

Currently, It's not possible to choose layout without replacing `XkbLayout` through `setxkbmap`,
Fortunately, `xkblayout-state` provides a proper method to switch layout.

Will submit PR later.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `py3status/modules/keyboard_layout.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """
3 Display keyboard layout.
4 
5 Configuration parameters:
6     button_next: mouse button to cycle next layout (default 4)
7     button_prev: mouse button to cycle previous layout (default 5)
8     cache_timeout: refresh interval for this module (default 10)
9     format: display format for this module (default '{layout}')
10     layouts: specify a list of layouts to use (default None)
11 
12 Format placeholders:
13     {layout} keyboard layout
14 
15 Color options:
16     color_<layout>: colorize the layout. eg color_fr = '#729FCF'
17 
18 Requires:
19     xkblayout-state:
20         or
21     setxkbmap: and `xset` (works for the first two predefined layouts.)
22 
23 Examples:
24 ```
25 # define keyboard layouts that can be switched between
26 keyboard_layout {
27     layouts = ['gb', 'fr', 'dvorak']
28 }
29 ```
30 
31 @author shadowprince, tuxitop
32 @license Eclipse Public License
33 
34 SAMPLE OUTPUT
35 {'full_text': 'gb'}
36 
37 fr
38 {'color': '#268BD2', 'full_text': 'fr'}
39 
40 ru
41 {'color': '#F75252', 'full_text': 'ru'}
42 
43 ua
44 {'color': '#FCE94F', 'full_text': 'ua'}
45 
46 us
47 {'color': '#729FCF', 'full_text': 'us'}
48 
49 """
50 
51 import re
52 
53 LAYOUTS_RE = re.compile(r".*layout:\s*((\w+,?)+).*", flags=re.DOTALL)
54 LEDMASK_RE = re.compile(r".*LED\smask:\s*\d{4}([01])\d{3}.*", flags=re.DOTALL)
55 VARIANTS_RE = re.compile(r".*variant:\s*(([\w-]+,?)+).*", flags=re.DOTALL)
56 
57 
58 class Py3status:
59     """
60     """
61 
62     # available configuration parameters
63     button_next = 4
64     button_prev = 5
65     cache_timeout = 10
66     format = "{layout}"
67     layouts = None
68 
69     def post_config_hook(self):
70         self.colors = getattr(self, "colors", None)  # old config
71         try:
72             self._xkblayout()
73             self._command = self._xkblayout
74         except self.py3.CommandError:
75             self._command = self._setxkbmap
76 
77         if not self.layouts:
78             self.layouts = []
79         # We use a copy of layouts so that we can add extra layouts without
80         # affecting the original list
81         self._layouts = self.layouts[:]
82         self._last_layout = None
83 
84         self.colors_dict = {}
85         # old compatibility: set default values
86         self.defaults = {
87             "fr": "#268BD2",
88             "ru": "#F75252",
89             "ua": "#FCE94F",
90             "us": "#729FCF",
91         }
92 
93     def keyboard_layout(self):
94         layout, variant = self._command()
95         # If the current layout is not in our layouts list we need to add it
96         if layout not in self._layouts:
97             self._layouts = [layout] + self.layouts
98             self._active = 0
99         # show new layout if it has been changed externally
100         if layout != self._last_layout:
101             self._active = self._layouts.index(layout)
102             self._last_layout = layout
103         lang = self._layouts[self._active]
104 
105         response = {
106             "cached_until": self.py3.time_in(self.cache_timeout),
107             "full_text": self.py3.safe_format(
108                 self.format, {"layout": lang, "variant": variant}
109             ),
110         }
111 
112         if self.colors and not self.colors_dict:
113             self.colors_dict = dict(
114                 (k.strip(), v.strip())
115                 for k, v in (layout.split("=") for layout in self.colors.split(","))
116             )
117 
118         # colorize languages containing spaces and/or dashes too
119         language = lang.upper()
120         for character in " -":
121             if character in language:
122                 language = language.replace(character, "_")
123 
124         lang_color = getattr(self.py3, "COLOR_%s" % language)
125         if not lang_color:
126             lang_color = self.colors_dict.get(lang)
127         if not lang_color:  # old compatibility: try default value
128             lang_color = self.defaults.get(lang)
129         if lang_color:
130             response["color"] = lang_color
131 
132         return response
133 
134     def _xkblayout(self):
135         layout, variant = [
136             x.strip()
137             for x in self.py3.command_output(
138                 ["xkblayout-state", "print", "%s|SEPARATOR|%v"]
139             ).split("|SEPARATOR|")
140         ]
141         return layout, variant
142 
143     def _setxkbmap(self):
144         # this method works only for the first two predefined layouts.
145         out = self.py3.command_output(["setxkbmap", "-query"])
146         layouts = re.match(LAYOUTS_RE, out).group(1).split(",")
147         if len(layouts) == 1:
148             variant = re.match(VARIANTS_RE, out)
149             if variant:
150                 variant = variant.group(1)
151                 return "{} {}".format(layouts[0], variant), variant
152             else:
153                 return layouts[0], ""
154 
155         xset_output = self.py3.command_output(["xset", "-q"])
156         led_mask = re.match(LEDMASK_RE, xset_output).groups(0)[0]
157         return layouts[int(led_mask)], ""
158 
159     def _set_active(self, delta):
160         self._active += delta
161         self._active = self._active % len(self._layouts)
162         layout = self._layouts[self._active]
163         self.py3.command_run("setxkbmap -layout {}".format(layout))
164 
165     def on_click(self, event):
166         button = event["button"]
167         if button == self.button_next:
168             self._set_active(1)
169         if button == self.button_prev:
170             self._set_active(-1)
171 
172 
173 if __name__ == "__main__":
174     """
175     Run module in test mode.
176     """
177     from py3status.module_test import module_test
178 
179     module_test(Py3status)
180
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/py3status/modules/keyboard_layout.py b/py3status/modules/keyboard_layout.py
--- a/py3status/modules/keyboard_layout.py
+++ b/py3status/modules/keyboard_layout.py
@@ -18,7 +18,7 @@
 Requires:
     xkblayout-state:
         or
-    setxkbmap: and `xset` (works for the first two predefined layouts.)
+    setxkbmap: and `xset` (works for the first two predefined layouts. overrides `XkbLayout` when switching layout.)
 
 Examples:
 ```
@@ -68,11 +68,14 @@
 
     def post_config_hook(self):
         self.colors = getattr(self, "colors", None)  # old config
-        try:
-            self._xkblayout()
-            self._command = self._xkblayout
-        except self.py3.CommandError:
-            self._command = self._setxkbmap
+
+        avail_command = {
+            "xkblayout-state": (self._set_xkblayout, self._get_xkblayout),
+            "setxkbmap": (self._set_setxkbmap, self._get_setxkbmap),
+        }
+        self._set_command, self._get_command = avail_command[
+            self.py3.check_commands(avail_command.keys())
+        ]
 
         if not self.layouts:
             self.layouts = []
@@ -91,7 +94,7 @@
         }
 
     def keyboard_layout(self):
-        layout, variant = self._command()
+        layout, variant = self._get_command()
         # If the current layout is not in our layouts list we need to add it
         if layout not in self._layouts:
             self._layouts = [layout] + self.layouts
@@ -131,7 +134,7 @@
 
         return response
 
-    def _xkblayout(self):
+    def _get_xkblayout(self):
         layout, variant = [
             x.strip()
             for x in self.py3.command_output(
@@ -140,7 +143,7 @@
         ]
         return layout, variant
 
-    def _setxkbmap(self):
+    def _get_setxkbmap(self):
         # this method works only for the first two predefined layouts.
         out = self.py3.command_output(["setxkbmap", "-query"])
         layouts = re.match(LAYOUTS_RE, out).group(1).split(",")
@@ -156,11 +159,24 @@
         led_mask = re.match(LEDMASK_RE, xset_output).groups(0)[0]
         return layouts[int(led_mask)], ""
 
+    def _set_setxkbmap(self):
+        layout = self._layouts[self._active]
+        # Note: This will override user-defined layout, keyboard shortcut won't work
+        self.py3.command_run("setxkbmap -layout {}".format(layout))
+
+    def _set_xkblayout(self):
+        layout = self._layouts[self._active]
+        layout_pos = (
+            self.py3.command_output(["xkblayout-state", "print", "%S"])
+            .split()
+            .index(layout)
+        )
+        self.py3.command_run("xkblayout-state set {}".format(layout_pos))
+
     def _set_active(self, delta):
         self._active += delta
         self._active = self._active % len(self._layouts)
-        layout = self._layouts[self._active]
-        self.py3.command_run("setxkbmap -layout {}".format(layout))
+        self._set_command()
 
     def on_click(self, event):
         button = event["button"]

{"golden_diff": "diff --git a/py3status/modules/keyboard_layout.py b/py3status/modules/keyboard_layout.py\n--- a/py3status/modules/keyboard_layout.py\n+++ b/py3status/modules/keyboard_layout.py\n@@ -18,7 +18,7 @@\n Requires:\n     xkblayout-state:\n         or\n-    setxkbmap: and `xset` (works for the first two predefined layouts.)\n+    setxkbmap: and `xset` (works for the first two predefined layouts. overrides `XkbLayout` when switching layout.)\n \n Examples:\n ```\n@@ -68,11 +68,14 @@\n \n     def post_config_hook(self):\n         self.colors = getattr(self, \"colors\", None)  # old config\n-        try:\n-            self._xkblayout()\n-            self._command = self._xkblayout\n-        except self.py3.CommandError:\n-            self._command = self._setxkbmap\n+\n+        avail_command = {\n+            \"xkblayout-state\": (self._set_xkblayout, self._get_xkblayout),\n+            \"setxkbmap\": (self._set_setxkbmap, self._get_setxkbmap),\n+        }\n+        self._set_command, self._get_command = avail_command[\n+            self.py3.check_commands(avail_command.keys())\n+        ]\n \n         if not self.layouts:\n             self.layouts = []\n@@ -91,7 +94,7 @@\n         }\n \n     def keyboard_layout(self):\n-        layout, variant = self._command()\n+        layout, variant = self._get_command()\n         # If the current layout is not in our layouts list we need to add it\n         if layout not in self._layouts:\n             self._layouts = [layout] + self.layouts\n@@ -131,7 +134,7 @@\n \n         return response\n \n-    def _xkblayout(self):\n+    def _get_xkblayout(self):\n         layout, variant = [\n             x.strip()\n             for x in self.py3.command_output(\n@@ -140,7 +143,7 @@\n         ]\n         return layout, variant\n \n-    def _setxkbmap(self):\n+    def _get_setxkbmap(self):\n         # this method works only for the first two predefined layouts.\n         out = self.py3.command_output([\"setxkbmap\", \"-query\"])\n         layouts = re.match(LAYOUTS_RE, out).group(1).split(\",\")\n@@ -156,11 +159,24 @@\n         led_mask = re.match(LEDMASK_RE, xset_output).groups(0)[0]\n         return layouts[int(led_mask)], \"\"\n \n+    def _set_setxkbmap(self):\n+        layout = self._layouts[self._active]\n+        # Note: This will override user-defined layout, keyboard shortcut won't work\n+        self.py3.command_run(\"setxkbmap -layout {}\".format(layout))\n+\n+    def _set_xkblayout(self):\n+        layout = self._layouts[self._active]\n+        layout_pos = (\n+            self.py3.command_output([\"xkblayout-state\", \"print\", \"%S\"])\n+            .split()\n+            .index(layout)\n+        )\n+        self.py3.command_run(\"xkblayout-state set {}\".format(layout_pos))\n+\n     def _set_active(self, delta):\n         self._active += delta\n         self._active = self._active % len(self._layouts)\n-        layout = self._layouts[self._active]\n-        self.py3.command_run(\"setxkbmap -layout {}\".format(layout))\n+        self._set_command()\n \n     def on_click(self, event):\n         button = event[\"button\"]\n", "issue": "keyboard_layout: keyboard shortcut stop working\nProblem\r\n--------------------\r\n\r\nSwitching keyboard layout causes layout switching shortcut to stop working (This might related to #1742)\r\n\r\n\r\nAnalysis\r\n---------------------\r\n\r\n[`_set_active`](https://github.com/ultrabug/py3status/blob/65a609261095f7502fc2814e9a6feb478845a69c/py3status/modules/keyboard_layout.py#L159-L163) switch layout by replacing all layout in `XkbLayout` with the target layout, This causes switching layout shortcut to not work since there's only a single layout left.\r\n\r\nCurrently, It's not possible to choose layout without replacing `XkbLayout` through `setxkbmap`,\r\nFortunately, `xkblayout-state` provides a proper method to switch layout.\r\n\r\nWill submit PR later.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nDisplay keyboard layout.\n\nConfiguration parameters:\n    button_next: mouse button to cycle next layout (default 4)\n    button_prev: mouse button to cycle previous layout (default 5)\n    cache_timeout: refresh interval for this module (default 10)\n    format: display format for this module (default '{layout}')\n    layouts: specify a list of layouts to use (default None)\n\nFormat placeholders:\n    {layout} keyboard layout\n\nColor options:\n    color_<layout>: colorize the layout. eg color_fr = '#729FCF'\n\nRequires:\n    xkblayout-state:\n        or\n    setxkbmap: and `xset` (works for the first two predefined layouts.)\n\nExamples:\n```\n# define keyboard layouts that can be switched between\nkeyboard_layout {\n    layouts = ['gb', 'fr', 'dvorak']\n}\n```\n\n@author shadowprince, tuxitop\n@license Eclipse Public License\n\nSAMPLE OUTPUT\n{'full_text': 'gb'}\n\nfr\n{'color': '#268BD2', 'full_text': 'fr'}\n\nru\n{'color': '#F75252', 'full_text': 'ru'}\n\nua\n{'color': '#FCE94F', 'full_text': 'ua'}\n\nus\n{'color': '#729FCF', 'full_text': 'us'}\n\n\"\"\"\n\nimport re\n\nLAYOUTS_RE = re.compile(r\".*layout:\\s*((\\w+,?)+).*\", flags=re.DOTALL)\nLEDMASK_RE = re.compile(r\".*LED\\smask:\\s*\\d{4}([01])\\d{3}.*\", flags=re.DOTALL)\nVARIANTS_RE = re.compile(r\".*variant:\\s*(([\\w-]+,?)+).*\", flags=re.DOTALL)\n\n\nclass Py3status:\n    \"\"\"\n    \"\"\"\n\n    # available configuration parameters\n    button_next = 4\n    button_prev = 5\n    cache_timeout = 10\n    format = \"{layout}\"\n    layouts = None\n\n    def post_config_hook(self):\n        self.colors = getattr(self, \"colors\", None)  # old config\n        try:\n            self._xkblayout()\n            self._command = self._xkblayout\n        except self.py3.CommandError:\n            self._command = self._setxkbmap\n\n        if not self.layouts:\n            self.layouts = []\n        # We use a copy of layouts so that we can add extra layouts without\n        # affecting the original list\n        self._layouts = self.layouts[:]\n        self._last_layout = None\n\n        self.colors_dict = {}\n        # old compatibility: set default values\n        self.defaults = {\n            \"fr\": \"#268BD2\",\n            \"ru\": \"#F75252\",\n            \"ua\": \"#FCE94F\",\n            \"us\": \"#729FCF\",\n        }\n\n    def keyboard_layout(self):\n        layout, variant = self._command()\n        # If the current layout is not in our layouts list we need to add it\n        if layout not in self._layouts:\n            self._layouts = [layout] + self.layouts\n            self._active = 0\n        # show new layout if it has been changed externally\n        if layout != self._last_layout:\n            self._active = self._layouts.index(layout)\n            self._last_layout = layout\n        lang = self._layouts[self._active]\n\n        response = {\n            \"cached_until\": self.py3.time_in(self.cache_timeout),\n            \"full_text\": self.py3.safe_format(\n                self.format, {\"layout\": lang, \"variant\": variant}\n            ),\n        }\n\n        if self.colors and not self.colors_dict:\n            self.colors_dict = dict(\n                (k.strip(), v.strip())\n                for k, v in (layout.split(\"=\") for layout in self.colors.split(\",\"))\n            )\n\n        # colorize languages containing spaces and/or dashes too\n        language = lang.upper()\n        for character in \" -\":\n            if character in language:\n                language = language.replace(character, \"_\")\n\n        lang_color = getattr(self.py3, \"COLOR_%s\" % language)\n        if not lang_color:\n            lang_color = self.colors_dict.get(lang)\n        if not lang_color:  # old compatibility: try default value\n            lang_color = self.defaults.get(lang)\n        if lang_color:\n            response[\"color\"] = lang_color\n\n        return response\n\n    def _xkblayout(self):\n        layout, variant = [\n            x.strip()\n            for x in self.py3.command_output(\n                [\"xkblayout-state\", \"print\", \"%s|SEPARATOR|%v\"]\n            ).split(\"|SEPARATOR|\")\n        ]\n        return layout, variant\n\n    def _setxkbmap(self):\n        # this method works only for the first two predefined layouts.\n        out = self.py3.command_output([\"setxkbmap\", \"-query\"])\n        layouts = re.match(LAYOUTS_RE, out).group(1).split(\",\")\n        if len(layouts) == 1:\n            variant = re.match(VARIANTS_RE, out)\n            if variant:\n                variant = variant.group(1)\n                return \"{} {}\".format(layouts[0], variant), variant\n            else:\n                return layouts[0], \"\"\n\n        xset_output = self.py3.command_output([\"xset\", \"-q\"])\n        led_mask = re.match(LEDMASK_RE, xset_output).groups(0)[0]\n        return layouts[int(led_mask)], \"\"\n\n    def _set_active(self, delta):\n        self._active += delta\n        self._active = self._active % len(self._layouts)\n        layout = self._layouts[self._active]\n        self.py3.command_run(\"setxkbmap -layout {}\".format(layout))\n\n    def on_click(self, event):\n        button = event[\"button\"]\n        if button == self.button_next:\n            self._set_active(1)\n        if button == self.button_prev:\n            self._set_active(-1)\n\n\nif __name__ == \"__main__\":\n    \"\"\"\n    Run module in test mode.\n    \"\"\"\n    from py3status.module_test import module_test\n\n    module_test(Py3status)\n", "path": "py3status/modules/keyboard_layout.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nDisplay keyboard layout.\n\nConfiguration parameters:\n    button_next: mouse button to cycle next layout (default 4)\n    button_prev: mouse button to cycle previous layout (default 5)\n    cache_timeout: refresh interval for this module (default 10)\n    format: display format for this module (default '{layout}')\n    layouts: specify a list of layouts to use (default None)\n\nFormat placeholders:\n    {layout} keyboard layout\n\nColor options:\n    color_<layout>: colorize the layout. eg color_fr = '#729FCF'\n\nRequires:\n    xkblayout-state:\n        or\n    setxkbmap: and `xset` (works for the first two predefined layouts. overrides `XkbLayout` when switching layout.)\n\nExamples:\n```\n# define keyboard layouts that can be switched between\nkeyboard_layout {\n    layouts = ['gb', 'fr', 'dvorak']\n}\n```\n\n@author shadowprince, tuxitop\n@license Eclipse Public License\n\nSAMPLE OUTPUT\n{'full_text': 'gb'}\n\nfr\n{'color': '#268BD2', 'full_text': 'fr'}\n\nru\n{'color': '#F75252', 'full_text': 'ru'}\n\nua\n{'color': '#FCE94F', 'full_text': 'ua'}\n\nus\n{'color': '#729FCF', 'full_text': 'us'}\n\n\"\"\"\n\nimport re\n\nLAYOUTS_RE = re.compile(r\".*layout:\\s*((\\w+,?)+).*\", flags=re.DOTALL)\nLEDMASK_RE = re.compile(r\".*LED\\smask:\\s*\\d{4}([01])\\d{3}.*\", flags=re.DOTALL)\nVARIANTS_RE = re.compile(r\".*variant:\\s*(([\\w-]+,?)+).*\", flags=re.DOTALL)\n\n\nclass Py3status:\n    \"\"\"\n    \"\"\"\n\n    # available configuration parameters\n    button_next = 4\n    button_prev = 5\n    cache_timeout = 10\n    format = \"{layout}\"\n    layouts = None\n\n    def post_config_hook(self):\n        self.colors = getattr(self, \"colors\", None)  # old config\n\n        avail_command = {\n            \"xkblayout-state\": (self._set_xkblayout, self._get_xkblayout),\n            \"setxkbmap\": (self._set_setxkbmap, self._get_setxkbmap),\n        }\n        self._set_command, self._get_command = avail_command[\n            self.py3.check_commands(avail_command.keys())\n        ]\n\n        if not self.layouts:\n            self.layouts = []\n        # We use a copy of layouts so that we can add extra layouts without\n        # affecting the original list\n        self._layouts = self.layouts[:]\n        self._last_layout = None\n\n        self.colors_dict = {}\n        # old compatibility: set default values\n        self.defaults = {\n            \"fr\": \"#268BD2\",\n            \"ru\": \"#F75252\",\n            \"ua\": \"#FCE94F\",\n            \"us\": \"#729FCF\",\n        }\n\n    def keyboard_layout(self):\n        layout, variant = self._get_command()\n        # If the current layout is not in our layouts list we need to add it\n        if layout not in self._layouts:\n            self._layouts = [layout] + self.layouts\n            self._active = 0\n        # show new layout if it has been changed externally\n        if layout != self._last_layout:\n            self._active = self._layouts.index(layout)\n            self._last_layout = layout\n        lang = self._layouts[self._active]\n\n        response = {\n            \"cached_until\": self.py3.time_in(self.cache_timeout),\n            \"full_text\": self.py3.safe_format(\n                self.format, {\"layout\": lang, \"variant\": variant}\n            ),\n        }\n\n        if self.colors and not self.colors_dict:\n            self.colors_dict = dict(\n                (k.strip(), v.strip())\n                for k, v in (layout.split(\"=\") for layout in self.colors.split(\",\"))\n            )\n\n        # colorize languages containing spaces and/or dashes too\n        language = lang.upper()\n        for character in \" -\":\n            if character in language:\n                language = language.replace(character, \"_\")\n\n        lang_color = getattr(self.py3, \"COLOR_%s\" % language)\n        if not lang_color:\n            lang_color = self.colors_dict.get(lang)\n        if not lang_color:  # old compatibility: try default value\n            lang_color = self.defaults.get(lang)\n        if lang_color:\n            response[\"color\"] = lang_color\n\n        return response\n\n    def _get_xkblayout(self):\n        layout, variant = [\n            x.strip()\n            for x in self.py3.command_output(\n                [\"xkblayout-state\", \"print\", \"%s|SEPARATOR|%v\"]\n            ).split(\"|SEPARATOR|\")\n        ]\n        return layout, variant\n\n    def _get_setxkbmap(self):\n        # this method works only for the first two predefined layouts.\n        out = self.py3.command_output([\"setxkbmap\", \"-query\"])\n        layouts = re.match(LAYOUTS_RE, out).group(1).split(\",\")\n        if len(layouts) == 1:\n            variant = re.match(VARIANTS_RE, out)\n            if variant:\n                variant = variant.group(1)\n                return \"{} {}\".format(layouts[0], variant), variant\n            else:\n                return layouts[0], \"\"\n\n        xset_output = self.py3.command_output([\"xset\", \"-q\"])\n        led_mask = re.match(LEDMASK_RE, xset_output).groups(0)[0]\n        return layouts[int(led_mask)], \"\"\n\n    def _set_setxkbmap(self):\n        layout = self._layouts[self._active]\n        # Note: This will override user-defined layout, keyboard shortcut won't work\n        self.py3.command_run(\"setxkbmap -layout {}\".format(layout))\n\n    def _set_xkblayout(self):\n        layout = self._layouts[self._active]\n        layout_pos = (\n            self.py3.command_output([\"xkblayout-state\", \"print\", \"%S\"])\n            .split()\n            .index(layout)\n        )\n        self.py3.command_run(\"xkblayout-state set {}\".format(layout_pos))\n\n    def _set_active(self, delta):\n        self._active += delta\n        self._active = self._active % len(self._layouts)\n        self._set_command()\n\n    def on_click(self, event):\n        button = event[\"button\"]\n        if button == self.button_next:\n            self._set_active(1)\n        if button == self.button_prev:\n            self._set_active(-1)\n\n\nif __name__ == \"__main__\":\n    \"\"\"\n    Run module in test mode.\n    \"\"\"\n    from py3status.module_test import module_test\n\n    module_test(Py3status)\n", "path": "py3status/modules/keyboard_layout.py"}]}