internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: qtile/qtile

Issue:
Ampersand in window name return an error
### The issue:

## Qtile version
0.22.1

## Issue
Ampersands in window name return an error with the WindowTabs widget
```
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/libqtile/hook.py", line 404, in fire
    i(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/libqtile/widget/windowtabs.py", line 82, in update
    self.text = self.separator.join(names)
  File "/usr/lib/python3.10/site-packages/libqtile/widget/base.py", line 483, in text
    self.layout.text = self.formatted_text
  File "/usr/lib/python3.10/site-packages/libqtile/drawer.py", line 72, in text
    attrlist, value, accel_char = pangocffi.parse_markup(value)
  File "/usr/lib/python3.10/site-packages/libqtile/pangocffi.py", line 186, in parse_markup
    raise Exception("parse_markup() failed for %s" % value)
Exception: parse_markup() failed for b'<b>Search \xc2\xb7 & \xe2\x80\x94 Mozilla Firefox</b>'
```

The same goes for the Mpris2 widget
```
2023-01-07 17:07:22,656 ERROR libqtile loop.py:_handle_exception():L63 parse_markup() failed for b'Fireman & Dancer - Royal Republic'
NoneType: None
2023-01-07 17:07:22,656 ERROR libqtile loop.py:_handle_exception():L63 parse_markup() failed for b'Fireman & Dancer - Royal Republic'
NoneType: None
````

Found a similar issue [#1685](https://github.com/qtile/qtile/issues/1685) but for the WindowName widget

### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:

Resolving patch:
diff --git a/libqtile/widget/windowtabs.py b/libqtile/widget/windowtabs.py
--- a/libqtile/widget/windowtabs.py
+++ b/libqtile/widget/windowtabs.py
@@ -22,7 +22,7 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-from libqtile import bar, hook
+from libqtile import bar, hook, pangocffi
 from libqtile.log_utils import logger
 from libqtile.widget import base
 
@@ -76,6 +76,7 @@ def update(self, *args):
             elif w.floating:
                 state = "V "
             task = "%s%s" % (state, w.name if w and w.name else " ")
+            task = pangocffi.markup_escape_text(task)
             if w is self.bar.screen.group.current_window:
                 task = task.join(self.selected)
             names.append(task)


Test patch:
diff --git a/test/widgets/test_windowtabs.py b/test/widgets/test_windowtabs.py
--- a/test/widgets/test_windowtabs.py
+++ b/test/widgets/test_windowtabs.py
@@ -125,3 +125,14 @@ def widget_text():
 
     manager.kill_window(window_one)
     assert widget_text() == ""
+
+
+@windowtabs_config
+def test_escaping_text(manager):
+    """
+    Ampersands can cause a crash if not escaped before passing to
+    pangocffi.parse_markup.
+    Test that the widget can parse text safely.
+    """
+    manager.test_window("Text & Text")
+    assert manager.c.widget["windowtabs"].info()["text"] == "<b>Text &amp; Text</b>"
Repository: qtile/qtile

Issue:
`ThermalSensor` doesn't respect `foreground` in `widget_defaults`
### The issue:

(reported on Discord/IRC)

ThermalSensor widget doesn't respect foreground colour in widget defaults. This is because the foreground value is copied to `foreground_normal` during `__init__` but this happens before `widget_defaults` are copied to the widget (which happens in `_configure`

### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:

Resolving patch:
diff --git a/libqtile/widget/sensors.py b/libqtile/widget/sensors.py
--- a/libqtile/widget/sensors.py
+++ b/libqtile/widget/sensors.py
@@ -67,7 +67,6 @@ def __init__(self, **config):
         base.InLoopPollText.__init__(self, **config)
         self.add_defaults(ThermalSensor.defaults)
         temp_values = self.get_temp_sensors()
-        self.foreground_normal = self.foreground
 
         if temp_values is None:
             self.data = "sensors command not found"
@@ -81,6 +80,7 @@ def __init__(self, **config):
     def _configure(self, qtile, bar):
         self.unit = "°C" if self.metric else "°F"
         base.InLoopPollText._configure(self, qtile, bar)
+        self.foreground_normal = self.foreground
 
     def get_temp_sensors(self):
         """


Test patch:
diff --git a/test/widgets/test_sensors.py b/test/widgets/test_sensors.py
--- a/test/widgets/test_sensors.py
+++ b/test/widgets/test_sensors.py
@@ -44,17 +44,17 @@ def sensors_temperatures(cls, fahrenheit=False):
 
 @pytest.fixture
 def sensors_manager(monkeypatch, manager_nospawn, minimal_conf_noscreen, request):
+    params = getattr(request, "param", dict())
     monkeypatch.setitem(sys.modules, "psutil", MockPsutil("psutil"))
     from libqtile.widget import sensors
 
     reload(sensors)
 
     config = minimal_conf_noscreen
-    config.screens = [
-        libqtile.config.Screen(
-            top=Bar([sensors.ThermalSensor(**getattr(request, "param", dict()))], 10)
-        )
-    ]
+    config.screens = [libqtile.config.Screen(top=Bar([sensors.ThermalSensor(**params)], 10))]
+
+    if "set_defaults" in params:
+        config.widget_defaults = {"foreground": "123456"}
 
     manager_nospawn.start(config)
     yield manager_nospawn
@@ -95,3 +95,9 @@ def test_thermal_sensor_colour_normal(sensors_manager):
 def test_thermal_sensor_colour_alert(sensors_manager):
     _, temp = sensors_manager.c.widget["thermalsensor"].eval("self.layout.colour")
     assert temp == "ff0000"
+
+
+@pytest.mark.parametrize("sensors_manager", [{"set_defaults": True}], indirect=True)
+def test_thermal_sensor_widget_defaults(sensors_manager):
+    _, temp = sensors_manager.c.widget["thermalsensor"].eval("self.layout.colour")
+    assert temp == "123456"
Repository: qtile/qtile

Issue:
Tasklist Widget Icons not vertically centered
### The issue:

Depending on the icon size, the placement of the icon relative to the text shifts. Here is an example with icon size = 45 and text size = 30.

![1664826413](https://user-images.githubusercontent.com/12877032/193666223-f80a1051-ecbd-45fc-894a-1c50ba4d9159.png)

And here it is with icon size = 30 as well:

![1664826716](https://user-images.githubusercontent.com/12877032/193666538-9f88eb29-d0b5-4676-8dc9-c8b423b5cc8d.png)

A simple fix would be to add a user-defined variable to the `y` calculation for `draw_icon`. I subclassed tasklist and manually modified the `y` value to match my icon size, and that works okay. A more flexible solution would be to modify the y value so it is always drawn such that it is centered. 

#1714 discussed the same issue but was never fixed. 

### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:
Sorry for the delay.

Agreed that the best solution here is to adapt the vertical positioning based on the icon size. We should do this without a user setting.
That would work great. 
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.
I believe this is still outstanding?

Resolving patch:
diff --git a/libqtile/widget/tasklist.py b/libqtile/widget/tasklist.py
--- a/libqtile/widget/tasklist.py
+++ b/libqtile/widget/tasklist.py
@@ -531,7 +531,7 @@ def draw_icon(self, surface, offset):
             return
 
         x = offset + self.borderwidth + self.padding_x
-        y = self.padding_y + self.borderwidth
+        y = (self.height - self.icon_size) // 2
 
         self.drawer.ctx.save()
         self.drawer.ctx.translate(x, y)


Test patch:
Repository: qtile/qtile

Issue:
CurrentLayoutIcon widget's size affected by bar margins
### The issue:

**qtile version:** 0.22.2.dev185+g4ecf1bde

After upgrading my qtile to the latest version, I was looking at my top bar and noticed that the CurrentLayoutIcon widget was getting out of the bar and its size was different. After playing with qtile's default config and mine, it seems that North and South bar's margins are causing the issue. Widget's size was not affected by bar's margins previously

**Then**
![before](https://github.com/qtile/qtile/assets/47400747/1bcc4428-607b-4e35-97c5-db75fab24844)

**Now**
margins=[10, 10, 10, 10]
![error1](https://github.com/qtile/qtile/assets/47400747/0b1f6ad2-b1d3-40d0-8d88-83efa6ff656a)
margins=[0, 10, 0, 10]
![error2](https://github.com/qtile/qtile/assets/47400747/369241da-7ecc-42f4-a227-e0b0e3629842)


### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:
Thanks. There were some changes to this widget recently so I obviously broke something!

Will take a look.

Resolving patch:
diff --git a/libqtile/widget/currentlayout.py b/libqtile/widget/currentlayout.py
--- a/libqtile/widget/currentlayout.py
+++ b/libqtile/widget/currentlayout.py
@@ -160,7 +160,7 @@ def draw(self):
                 self.drawer.clear(self.background or self.bar.background)
                 self.drawer.ctx.save()
                 self.drawer.ctx.translate(
-                    (self.width - surface.width) / 2, (self.height - surface.height) / 2
+                    (self.width - surface.width) / 2, (self.bar.height - surface.height) / 2
                 )
                 self.drawer.ctx.set_source(surface.pattern)
                 self.drawer.ctx.paint()
@@ -225,7 +225,7 @@ def _setup_images(self):
 
             img = Img.from_path(icon_file_path)
 
-            new_height = (self.height - 2) * self.scale
+            new_height = (self.bar.height - 2) * self.scale
             img.resize(height=new_height)
             if img.width > self.length:
                 self.length = img.width + self.actual_padding * 2


Test patch:
Repository: qtile/qtile

Issue:
`qtile_info` root command returns empty dict
### The issue:

This is maybe not that big of a deal, as there's plenty of other things currently on track to be solved, but I'm not one for throwing this under the bed and calling it a day 😄  As a starting point, maybe we could have the path of the currently loaded config? What do you think?

```console
$ qtile cmd-obj -o cmd -f qtile_info
{}
```

### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:
Sure. Maybe add the version number and log level too.

PR would be welcome.
I was looking through the `start` script and I noticed that's where the config is loaded:
```py
config = confreader.Config(options.configfile)
```
Is this where I'm supposed to get the config path from?
I'm currently clueless as to how I'm supposed to get the `options.configfile` into `core.manager.Qtile` as I believe the options that are passed on the command line are not accessible there.
Should just be `self.config.file_path`.
> Should just be `self.config.file_path`.

Oof. That's just me not knowing the innerworkings of qtile once again. I'll get on with doing that then :)

Resolving patch:
diff --git a/libqtile/core/manager.py b/libqtile/core/manager.py
--- a/libqtile/core/manager.py
+++ b/libqtile/core/manager.py
@@ -31,6 +31,7 @@
 import subprocess
 import tempfile
 from collections import defaultdict
+from logging.handlers import RotatingFileHandler
 from typing import TYPE_CHECKING
 
 import libqtile
@@ -51,6 +52,7 @@
 from libqtile.group import _Group
 from libqtile.log_utils import logger
 from libqtile.scratchpad import ScratchPad
+from libqtile.scripts.main import VERSION
 from libqtile.utils import (
     cancel_tasks,
     get_cache_dir,
@@ -1353,7 +1355,15 @@ def internal_windows(self) -> list[dict[str, Any]]:
     @expose_command()
     def qtile_info(self) -> dict:
         """Returns a dictionary of info on the Qtile instance"""
-        return {}
+        dictionary = {
+            "config_path": self.config.file_path,
+            "version": VERSION,
+            "log_level": self.loglevelname(),
+        }
+        if isinstance(logger.handlers[0], RotatingFileHandler):
+            log_path = logger.handlers[0].baseFilename
+            dictionary["log_path"] = log_path
+        return dictionary
 
     @expose_command()
     def shutdown(self) -> None:


Test patch:
Repository: qtile/qtile

Issue:
Logs pollution - keyboardlayout.py
### The issue:

Bunch of these:
```
2023-07-15 15:28:06,304 ERROR libqtile keyboardlayout.py:set_keyboard():L102 Can not load ~/.Xmodmap:
```
My humble opinion is that if I don't use something optional, I shouldn't have an error about it in the logs. Oh and it's supposed to be **"Cannot"**. I don't have another idea on how this should be done atm.

### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:

Resolving patch:
diff --git a/libqtile/widget/keyboardlayout.py b/libqtile/widget/keyboardlayout.py
--- a/libqtile/widget/keyboardlayout.py
+++ b/libqtile/widget/keyboardlayout.py
@@ -26,6 +26,7 @@
 
 import re
 from abc import ABCMeta, abstractmethod
+from pathlib import Path
 from subprocess import CalledProcessError, check_output
 from typing import TYPE_CHECKING
 
@@ -92,16 +93,16 @@ def set_keyboard(self, layout: str, options: str | None) -> None:
         try:
             check_output(command)
         except CalledProcessError:
-            logger.error("Can not change the keyboard layout:")
+            logger.error("Cannot change the keyboard layout.")
         except OSError:
-            logger.error("Please, check that setxkbmap is available:")
+            logger.error("Please, check that setxkbmap is available.")
         else:
-            try:
-                check_output("xmodmap $HOME/.Xmodmap", shell=True)
-            except CalledProcessError:
-                logger.error("Can not load ~/.Xmodmap:")
-            except OSError:
-                logger.error("Please, check that xmodmap is available:")
+            # Load Xmodmap if it's available
+            if Path("~/.Xmodmap").expanduser().is_file():
+                try:
+                    check_output("xmodmap $HOME/.Xmodmap", shell=True)
+                except CalledProcessError:
+                    logger.error("Could not load ~/.Xmodmap.")
 
 
 class _WaylandLayoutBackend(_BaseLayoutBackend):


Test patch:
Repository: qtile/qtile

Issue:
Key input going to wrong window on recent focus change
### The issue:

I have this issue, it started approximately 8-12 months ago but I was unable to figure out reliable steps to reproduce, apologies for the following instructions:

 -   Set follow_mouse_focus = False, aside from that the config I am using is entirely default
 -   Install BurpSuite Community Edition, https://portswigger.net/burp/communitydownload
 -   Open BurpSuite (it is in path pointing to /usr/local/bin/BurpSuiteCommunity at the top of the display there is a tab called 'Repeater', within the main panel, click the 'X' to show the request/response input fields
 -   Open Firefox
 -   Open a third window (this is my current workaround)
 -   In firefox, I click the address bar, type 'aaaa'
 -   In BurpSuite, I click the 'request' area and type 'bbbb'
 -   In firefox, I cilck the address bar and type 'cccc' - the 'cccc' is inputted into burpsuite, despite firefox having focus
-    If I reproduce the same steps, but after typing 'bbbb', I click the terminal, and then click the firefox address bar, it works fine. Focus seems to work fine with the terminal (e.g., if instead of Firefox I reproduce with the terminal). I am able to reproduce if I use a HTML text input in firefox (it is not specific to the the address bar).

BurpSuite is (from my understanding) a Java/SWING application. I have no idea if this is relevant but I have not seen the issue manifest elsewhere.

Tested Ubuntu 23.04 using Qtile git master (and previous versions) using X11. As I said above, this issue appears to have been introduced in the last 8-12 months (maybe a bit earlier, idk), I'm unsure if this is a Qtile bug or an underlying lib, but either way the issue does not seem to be widespread to other Window Managers.


![focus-bug](https://github.com/qtile/qtile/assets/54927313/8d50c6a7-467c-41cb-b787-44f71593a633)


### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:

Resolving patch:
diff --git a/libqtile/backend/x11/window.py b/libqtile/backend/x11/window.py
--- a/libqtile/backend/x11/window.py
+++ b/libqtile/backend/x11/window.py
@@ -1243,6 +1243,7 @@ def _do_focus(self):
             )
 
             self.window.send_event(e)
+            return True
 
         # we didn't focus this time. but now the window knows if it wants
         # focus, it should SetFocus() itself; we'll get another notification


Test patch:
Repository: qtile/qtile

Issue:
[Docs] Broken Links
# TLDR:

- [ ] Fix http://docs.qtile.org/en/latest/manual/commands/scripting.html in https://github.com/qtile/qtile/blob/6357381aa54b47f9e5ecb0f434d728dd165a83fb/libqtile/extension/base.py#L95
- [ ] Add quotes to https://github.com/qtile/qtile/blob/6357381aa54b47f9e5ecb0f434d728dd165a83fb/docs/manual/config/lazy.rst?plain=1#L8

# The Issues:
While looking at the documentation I discovered two broken links.

## RunCommand
There is a broken (404) link in the documentation of the RunCommand extension (Configuration -> Built-in Extensions -> RunCommand).
https://docs.qtile.org/en/latest/manual/ref/extensions.html#libqtile.extension.CommandSet
The documentation states the following:
`Also consider simply using lazy.spawn() or writing a [client](http://docs.qtile.org/en/latest/manual/commands/scripting.html).`
But http://docs.qtile.org/en/latest/manual/commands/scripting.html does not exist.
We should fix this in: https://github.com/qtile/qtile/blob/6357381aa54b47f9e5ecb0f434d728dd165a83fb/libqtile/extension/base.py#L95
Should we refer to https://docs.qtile.org/en/latest/manual/commands/advanced.html#tying-it-together-command-client and use `:doc:`?

## Lazy objects
There is no link when referencing the Commands API part of the documentation in https://docs.qtile.org/en/latest/manual/config/lazy.html. Should be fixed in: https://github.com/qtile/qtile/blob/6357381aa54b47f9e5ecb0f434d728dd165a83fb/docs/manual/config/lazy.rst?plain=1#L8
Should we change it to: ```:doc:`commands API </manual/commands/api/index>` ```?

# Versions and Logs:
qtile version: not relevant
logs: not relevant
branch: master
Last time I checked the documentation: 2023-08-07 10:30 UTC

### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:
Thanks. Do you want to submit a pull request with the required changes?

Resolving patch:
diff --git a/libqtile/extension/base.py b/libqtile/extension/base.py
--- a/libqtile/extension/base.py
+++ b/libqtile/extension/base.py
@@ -92,7 +92,7 @@ class RunCommand(_Extension):
     interact with the qtile object.
 
     Also consider simply using lazy.spawn() or writing a
-    `client <http://docs.qtile.org/en/latest/manual/commands/scripting.html>`_.
+    `client <https://docs.qtile.org/en/latest/manual/commands/advanced.html#client-server-scripting-model>`_.
     """
 
     defaults: list[tuple[str, Any, str]] = [


Test patch:
Repository: qtile/qtile

Issue:
Make fullscreen windows non-draggable or restore previous state before dragging
It doesn't make sense to drag a window that's taking the whole screen size.

Thank you @drishal for the idea.


Discussion:
Yeah, sounds good. I really like the fact I can drag a fullscreen window but it definitely makes sense to restore its dimensions before moving it (and make it floating if it wasn't), so I vote for the latter.
Why do you like that? I'm rather leaning towards disabling drag completely.
Guess I'm lazy and like to skip the un-fullscreen step if i want to float it and
then drag it.

On 210415 11:32, Guillaume Gelin wrote:
>Why do you like that? I'm rather leaning towards disabling drag completely.
>
>-- 
>You are receiving this because you commented.
>Reply to this email directly or view it on GitHub:
>https://github.com/qtile/qtile/issues/2387#issuecomment-820645499


Resolving patch:
diff --git a/libqtile/core/manager.py b/libqtile/core/manager.py
--- a/libqtile/core/manager.py
+++ b/libqtile/core/manager.py
@@ -796,7 +796,7 @@ def process_button_click(self, button_code: int, modmask: int, x: int, y: int) -
                         if status in (interface.ERROR, interface.EXCEPTION):
                             logger.error("Mouse command error %s: %s", i.name, val)
                         handled = True
-            elif isinstance(m, Drag):
+            elif isinstance(m, Drag) and not self.current_window.fullscreen:
                 if m.start:
                     i = m.start
                     status, val = self.server.call((i.selectors, i.name, i.args, i.kwargs))


Test patch:
Repository: qtile/qtile

Issue:
Wayland LaunchBar not rendering image
### Issue description

Using the LaunchBar widget configured like this: 
```python
widget.LaunchBar(progs=[("/home/silas/Nextcloud/uni/stundenplan.png", "mupdf /home/silas/Nextcloud/uni/stundenplan.png","stundenplan")]),
```
leads to not showing the image but a hole in my bar when using wayland (X11 works fine).

I tested with older versions of this widget. This widget works fine in Wayland before the changes in #3857 by @elParaguayo .

After revoking some changes by this pr it wokred again after replacing https://github.com/qtile/qtile/blob/1e0f09f45a4396d563039bf711ed82bdbeae8b36/libqtile/widget/launchbar.py#L291
with
```python
self.drawer.draw(offsetx=self.offset + xoffset, offsety=self.offsety, width=self.width)
```
Seems to work fine in X11 as well but I'm not sure if this may lead to other problems or if this is an appropriate fix for this bug as the X11 _version_ seems to render this differently than the wayland _version_

### Version

0.23.0

### Backend

Wayland (experimental)

### Config

_No response_

### Logs

_No response_

### Required

- [X] I have searched past issues to see if this bug has already been reported, and it hasn't been.
- [X] I understand that people give their precious time for free, and thus I've done my very best to make this problem as easy as possible to investigate.


Discussion:
Sorry for the delay.

They should render in exactly the same way so this change _shouldn't_ be necessary. I'll take a look.

Resolving patch:
diff --git a/libqtile/widget/launchbar.py b/libqtile/widget/launchbar.py
--- a/libqtile/widget/launchbar.py
+++ b/libqtile/widget/launchbar.py
@@ -272,20 +272,13 @@ def draw(self):
                 )
             else:
                 # display an icon
-                self.drawer.ctx.save()
+                # Translate to vertically centre the icon
                 self.drawer.ctx.translate(0, self._icon_padding + self.padding_y)
                 self.drawer.ctx.set_source(self.surfaces[name])
                 self.drawer.ctx.paint()
-                self.drawer.ctx.restore()
 
             self.drawer.ctx.restore()
 
-            self.drawer.draw(
-                offsetx=self.offset + xoffset,
-                offsety=self.offsety,
-                width=icon_width + self.padding,
-            )
-
             xoffset += icon_width + self.padding
 
         self.drawer.draw(offsetx=self.offset, offsety=self.offsety, width=self.width)


Test patch: