prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Firefox cpu usage escalates and then stops responding only when run in qtile
  Hi, 
  
  When starting firefox (firefox 69.0-1, qtile 0.14.2-2) its cpu usage starts rising to the point were the interface becomes unresponsive, also only parts of firefox interface are drawn, but like after 5 mins the window is not visible at all, may be the screenshots will make things clearer. 
  
  screenshots with description:
  https://imgur.com/a/V17wJrM
  
  Nothing is there in the logs (I only checked .local/share/qtile/qtile.log), this does not happen with me under i3 or bspwm. I also use optirun with my browsers but it does not matter if I start firefox without it. this bug happens every time I use firefox, and I use a lot of gtk3, gtk2, qt4, qt5, electron apps and it only happens with firefox on qtile only.
  
  I am not sure what other information I can provide.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `libqtile/widget/keyboardlayout.py`
  Content:
  ```
  1 # Copyright (c) 2013 Jacob Mourelos
  2 # Copyright (c) 2014 Shepilov Vladislav
  3 # Copyright (c) 2014-2015 Sean Vig
  4 # Copyright (c) 2014 Tycho Andersen
  5 # Copyright (c) 2019 zordsdavini
  6 #
  7 # Permission is hereby granted, free of charge, to any person obtaining a copy
  8 # of this software and associated documentation files (the "Software"), to deal
  9 # in the Software without restriction, including without limitation the rights
  10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11 # copies of the Software, and to permit persons to whom the Software is
  12 # furnished to do so, subject to the following conditions:
  13 #
  14 # The above copyright notice and this permission notice shall be included in
  15 # all copies or substantial portions of the Software.
  16 #
  17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23 # SOFTWARE.
  24 
  25 import re
  26 from subprocess import CalledProcessError
  27 
  28 from libqtile.log_utils import logger
  29 from libqtile.widget import base
  30 
  31 kb_layout_regex = re.compile(r'layout:\s+(?P<layout>\w+)')
  32 kb_variant_regex = re.compile(r'variant:\s+(?P<variant>\w+)')
  33 
  34 
  35 class KeyboardLayout(base.InLoopPollText):
  36     """Widget for changing and displaying the current keyboard layout
  37 
  38     It requires setxkbmap to be available in the system.
  39     """
  40     orientations = base.ORIENTATION_HORIZONTAL
  41     defaults = [
  42         ("update_interval", 1, "Update time in seconds."),
  43         ("configured_keyboards", ["us"], "A list of predefined keyboard layouts "
  44             "represented as strings. For example: "
  45             "['us', 'us colemak', 'es', 'fr']."),
  46         ("option", None, "string of setxkbmap option. Ex., 'compose:menu,grp_led:scroll'"),
  47     ]
  48 
  49     def __init__(self, **config):
  50         base.InLoopPollText.__init__(self, **config)
  51         self.add_defaults(KeyboardLayout.defaults)
  52 
  53     def button_press(self, x, y, button):
  54         if button == 1:
  55             self.next_keyboard()
  56 
  57     def next_keyboard(self):
  58         """Set the next layout in the list of configured keyboard layouts as
  59         new current layout in use
  60 
  61         If the current keyboard layout is not in the list, it will set as new
  62         layout the first one in the list.
  63         """
  64 
  65         current_keyboard = self.keyboard
  66         if current_keyboard in self.configured_keyboards:
  67             # iterate the list circularly
  68             next_keyboard = self.configured_keyboards[
  69                 (self.configured_keyboards.index(current_keyboard) + 1) %
  70                 len(self.configured_keyboards)]
  71         else:
  72             next_keyboard = self.configured_keyboards[0]
  73 
  74         self.keyboard = next_keyboard
  75 
  76         self.tick()
  77 
  78     def poll(self):
  79         return self.keyboard.upper()
  80 
  81     def get_keyboard_layout(self, setxkbmap_output):
  82         match_layout = kb_layout_regex.search(setxkbmap_output)
  83         match_variant = kb_variant_regex.search(setxkbmap_output)
  84 
  85         if match_layout is None:
  86             return 'ERR'
  87 
  88         kb = match_layout.group('layout')
  89         if match_variant:
  90             kb += " " + match_variant.group('variant')
  91         return kb
  92 
  93     @property
  94     def keyboard(self):
  95         """Return the currently used keyboard layout as a string
  96 
  97         Examples: "us", "us dvorak".  In case of error returns "unknown".
  98         """
  99         try:
  100             command = 'setxkbmap -verbose 10'
  101             setxkbmap_output = self.call_process(command.split(' '))
  102             keyboard = self.get_keyboard_layout(setxkbmap_output)
  103             return str(keyboard)
  104         except CalledProcessError as e:
  105             logger.error('Can not get the keyboard layout: {0}'.format(e))
  106         except OSError as e:
  107             logger.error('Please, check that xset is available: {0}'.format(e))
  108         return "unknown"
  109 
  110     @keyboard.setter
  111     def keyboard(self, keyboard):
  112         command = ['setxkbmap']
  113         command.extend(keyboard.split(" "))
  114         if self.option:
  115             command.extend(['-option', self.option])
  116         try:
  117             self.call_process(command)
  118         except CalledProcessError as e:
  119             logger.error('Can not change the keyboard layout: {0}'.format(e))
  120         except OSError as e:
  121             logger.error('Please, check that setxkbmap is available: {0}'.format(e))
  122 
  123     def cmd_next_keyboard(self):
  124         """Select next keyboard layout"""
  125         self.next_keyboard()
  126
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/libqtile/widget/keyboardlayout.py b/libqtile/widget/keyboardlayout.py
  --- a/libqtile/widget/keyboardlayout.py
  +++ b/libqtile/widget/keyboardlayout.py
  @@ -97,7 +97,7 @@
           Examples: "us", "us dvorak".  In case of error returns "unknown".
           """
           try:
  -            command = 'setxkbmap -verbose 10'
  +            command = 'setxkbmap -verbose 10 -query'
               setxkbmap_output = self.call_process(command.split(' '))
               keyboard = self.get_keyboard_layout(setxkbmap_output)
               return str(keyboard)
  
verification_info: {"golden_diff": "diff --git a/libqtile/widget/keyboardlayout.py b/libqtile/widget/keyboardlayout.py\n--- a/libqtile/widget/keyboardlayout.py\n+++ b/libqtile/widget/keyboardlayout.py\n@@ -97,7 +97,7 @@\n         Examples: \"us\", \"us dvorak\".  In case of error returns \"unknown\".\n         \"\"\"\n         try:\n-            command = 'setxkbmap -verbose 10'\n+            command = 'setxkbmap -verbose 10 -query'\n             setxkbmap_output = self.call_process(command.split(' '))\n             keyboard = self.get_keyboard_layout(setxkbmap_output)\n             return str(keyboard)\n", "issue": "Firefox cpu usage escalates and then stops responding only when run in qtile\nHi, \r\n\r\nWhen starting firefox (firefox 69.0-1, qtile 0.14.2-2) its cpu usage starts rising to the point were the interface becomes unresponsive, also only parts of firefox interface are drawn, but like after 5 mins the window is not visible at all, may be the screenshots will make things clearer. \r\n\r\nscreenshots with description:\r\nhttps://imgur.com/a/V17wJrM\r\n\r\nNothing is there in the logs (I only checked .local/share/qtile/qtile.log), this does not happen with me under i3 or bspwm. I also use optirun with my browsers but it does not matter if I start firefox without it. this bug happens every time I use firefox, and I use a lot of gtk3, gtk2, qt4, qt5, electron apps and it only happens with firefox on qtile only.\r\n\r\nI am not sure what other information I can provide.\r\n\n", "before_files": [{"content": "# Copyright (c) 2013 Jacob Mourelos\n# Copyright (c) 2014 Shepilov Vladislav\n# Copyright (c) 2014-2015 Sean Vig\n# Copyright (c) 2014 Tycho Andersen\n# Copyright (c) 2019 zordsdavini\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nimport re\nfrom subprocess import CalledProcessError\n\nfrom libqtile.log_utils import logger\nfrom libqtile.widget import base\n\nkb_layout_regex = re.compile(r'layout:\\s+(?P<layout>\\w+)')\nkb_variant_regex = re.compile(r'variant:\\s+(?P<variant>\\w+)')\n\n\nclass KeyboardLayout(base.InLoopPollText):\n    \"\"\"Widget for changing and displaying the current keyboard layout\n\n    It requires setxkbmap to be available in the system.\n    \"\"\"\n    orientations = base.ORIENTATION_HORIZONTAL\n    defaults = [\n        (\"update_interval\", 1, \"Update time in seconds.\"),\n        (\"configured_keyboards\", [\"us\"], \"A list of predefined keyboard layouts \"\n            \"represented as strings. For example: \"\n            \"['us', 'us colemak', 'es', 'fr'].\"),\n        (\"option\", None, \"string of setxkbmap option. Ex., 'compose:menu,grp_led:scroll'\"),\n    ]\n\n    def __init__(self, **config):\n        base.InLoopPollText.__init__(self, **config)\n        self.add_defaults(KeyboardLayout.defaults)\n\n    def button_press(self, x, y, button):\n        if button == 1:\n            self.next_keyboard()\n\n    def next_keyboard(self):\n        \"\"\"Set the next layout in the list of configured keyboard layouts as\n        new current layout in use\n\n        If the current keyboard layout is not in the list, it will set as new\n        layout the first one in the list.\n        \"\"\"\n\n        current_keyboard = self.keyboard\n        if current_keyboard in self.configured_keyboards:\n            # iterate the list circularly\n            next_keyboard = self.configured_keyboards[\n                (self.configured_keyboards.index(current_keyboard) + 1) %\n                len(self.configured_keyboards)]\n        else:\n            next_keyboard = self.configured_keyboards[0]\n\n        self.keyboard = next_keyboard\n\n        self.tick()\n\n    def poll(self):\n        return self.keyboard.upper()\n\n    def get_keyboard_layout(self, setxkbmap_output):\n        match_layout = kb_layout_regex.search(setxkbmap_output)\n        match_variant = kb_variant_regex.search(setxkbmap_output)\n\n        if match_layout is None:\n            return 'ERR'\n\n        kb = match_layout.group('layout')\n        if match_variant:\n            kb += \" \" + match_variant.group('variant')\n        return kb\n\n    @property\n    def keyboard(self):\n        \"\"\"Return the currently used keyboard layout as a string\n\n        Examples: \"us\", \"us dvorak\".  In case of error returns \"unknown\".\n        \"\"\"\n        try:\n            command = 'setxkbmap -verbose 10'\n            setxkbmap_output = self.call_process(command.split(' '))\n            keyboard = self.get_keyboard_layout(setxkbmap_output)\n            return str(keyboard)\n        except CalledProcessError as e:\n            logger.error('Can not get the keyboard layout: {0}'.format(e))\n        except OSError as e:\n            logger.error('Please, check that xset is available: {0}'.format(e))\n        return \"unknown\"\n\n    @keyboard.setter\n    def keyboard(self, keyboard):\n        command = ['setxkbmap']\n        command.extend(keyboard.split(\" \"))\n        if self.option:\n            command.extend(['-option', self.option])\n        try:\n            self.call_process(command)\n        except CalledProcessError as e:\n            logger.error('Can not change the keyboard layout: {0}'.format(e))\n        except OSError as e:\n            logger.error('Please, check that setxkbmap is available: {0}'.format(e))\n\n    def cmd_next_keyboard(self):\n        \"\"\"Select next keyboard layout\"\"\"\n        self.next_keyboard()\n", "path": "libqtile/widget/keyboardlayout.py"}], "after_files": [{"content": "# Copyright (c) 2013 Jacob Mourelos\n# Copyright (c) 2014 Shepilov Vladislav\n# Copyright (c) 2014-2015 Sean Vig\n# Copyright (c) 2014 Tycho Andersen\n# Copyright (c) 2019 zordsdavini\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nimport re\nfrom subprocess import CalledProcessError\n\nfrom libqtile.log_utils import logger\nfrom libqtile.widget import base\n\nkb_layout_regex = re.compile(r'layout:\\s+(?P<layout>\\w+)')\nkb_variant_regex = re.compile(r'variant:\\s+(?P<variant>\\w+)')\n\n\nclass KeyboardLayout(base.InLoopPollText):\n    \"\"\"Widget for changing and displaying the current keyboard layout\n\n    It requires setxkbmap to be available in the system.\n    \"\"\"\n    orientations = base.ORIENTATION_HORIZONTAL\n    defaults = [\n        (\"update_interval\", 1, \"Update time in seconds.\"),\n        (\"configured_keyboards\", [\"us\"], \"A list of predefined keyboard layouts \"\n            \"represented as strings. For example: \"\n            \"['us', 'us colemak', 'es', 'fr'].\"),\n        (\"option\", None, \"string of setxkbmap option. Ex., 'compose:menu,grp_led:scroll'\"),\n    ]\n\n    def __init__(self, **config):\n        base.InLoopPollText.__init__(self, **config)\n        self.add_defaults(KeyboardLayout.defaults)\n\n    def button_press(self, x, y, button):\n        if button == 1:\n            self.next_keyboard()\n\n    def next_keyboard(self):\n        \"\"\"Set the next layout in the list of configured keyboard layouts as\n        new current layout in use\n\n        If the current keyboard layout is not in the list, it will set as new\n        layout the first one in the list.\n        \"\"\"\n\n        current_keyboard = self.keyboard\n        if current_keyboard in self.configured_keyboards:\n            # iterate the list circularly\n            next_keyboard = self.configured_keyboards[\n                (self.configured_keyboards.index(current_keyboard) + 1) %\n                len(self.configured_keyboards)]\n        else:\n            next_keyboard = self.configured_keyboards[0]\n\n        self.keyboard = next_keyboard\n\n        self.tick()\n\n    def poll(self):\n        return self.keyboard.upper()\n\n    def get_keyboard_layout(self, setxkbmap_output):\n        match_layout = kb_layout_regex.search(setxkbmap_output)\n        match_variant = kb_variant_regex.search(setxkbmap_output)\n\n        if match_layout is None:\n            return 'ERR'\n\n        kb = match_layout.group('layout')\n        if match_variant:\n            kb += \" \" + match_variant.group('variant')\n        return kb\n\n    @property\n    def keyboard(self):\n        \"\"\"Return the currently used keyboard layout as a string\n\n        Examples: \"us\", \"us dvorak\".  In case of error returns \"unknown\".\n        \"\"\"\n        try:\n            command = 'setxkbmap -verbose 10 -query'\n            setxkbmap_output = self.call_process(command.split(' '))\n            keyboard = self.get_keyboard_layout(setxkbmap_output)\n            return str(keyboard)\n        except CalledProcessError as e:\n            logger.error('Can not get the keyboard layout: {0}'.format(e))\n        except OSError as e:\n            logger.error('Please, check that xset is available: {0}'.format(e))\n        return \"unknown\"\n\n    @keyboard.setter\n    def keyboard(self, keyboard):\n        command = ['setxkbmap']\n        command.extend(keyboard.split(\" \"))\n        if self.option:\n            command.extend(['-option', self.option])\n        try:\n            self.call_process(command)\n        except CalledProcessError as e:\n            logger.error('Can not change the keyboard layout: {0}'.format(e))\n        except OSError as e:\n            logger.error('Please, check that setxkbmap is available: {0}'.format(e))\n\n    def cmd_next_keyboard(self):\n        \"\"\"Select next keyboard layout\"\"\"\n        self.next_keyboard()\n", "path": "libqtile/widget/keyboardlayout.py"}]}