·6 min read
Desktop Grid: my Qt overlay swallowed every click on the desktop
At 04:27 on Jul 31, 2026 I committed a port of Desktop Grid from tkinter to PySide6. The commit message said the desktop was now "genuinely click-through". It was not. With the overlay running, no desktop icon answered a click, because a transparent window covered the whole screen and kept every mouse event for itself.
Three minutes later I committed the fix. This is what was wrong, why the first approach could not work, and the blunt solution that did.
- Project
- Desktop Grid
- Date
- Jul 2026
- Stack
- Python, PySide6, ctypes
- Commit
- 577149b
What broke
Desktop Grid draws labeled zones on top of the Windows desktop. The zones have to sit above the wallpaper and below every application window, and everything on the overlay that is not a zone label, gear or border has to behave as if it were not there. A double click on a shortcut must still open it.
The first version, 4a63a82 at 04:20, was tkinter, and it got that behaviour almost for free. It painted its empty area in a key colour, TRANSPARENT_COLOR = "#000001", and told the window to treat that colour as see-through with -transparentcolor. A comment in that file says it directly: no WS_EX_TRANSPARENT, colour-key pixels stay click-through on their own.
Seven minutes later, d88c7cf moved the whole UI to PySide6 for better rendering: per-pixel alpha, antialiased shapes and a proper colour dialog. A per-pixel alpha window is not a colour-key window. The tkinter trick no longer applied, so I needed a new way to say "let this click through". I chose the WM_NCHITTEST message. The overlay answered it per point: HTCLIENT over a label, gear, border or grip, and HTTRANSPARENT everywhere else.
It blocked the desktop.
What the code showed
This is the code I wrote in the port, from overlay.py before the fix:
def nativeEvent(self, eventType, message):
if eventType == b"windows_generic_MSG":
msg = wintypes.MSG.from_address(int(message))
if msg.message == WM_NCHITTEST:
...
zone, kind, _ = self._element_at(x, y)
if zone:
return True, HTCLIENT
return True, HTTRANSPARENTMy commit message for the fix is the best record of what I learned, so I quote its substance. Qt6 translucent top-level windows swallow input even on fully transparent pixels. And HTTRANSPARENT does not forward clicks to other processes. The icons belong to explorer.exe, a different process, so they never got the click.
I did not re-run the broken version for this write-up. The diagnosis is from that commit message and the code, and it matches what I saw on screen: nothing under the overlay responded.
The fix
The fix is 577149b (Jul 2026, 04:30). It stops answering hit tests and instead changes the window itself. With the extended style WS_EX_TRANSPARENT set, every click passes straight through to the icons underneath. The overlay turns the style on when the cursor is over nothing interactive and off when it is over a label, gear or border:
def _set_click_through(self, enabled):
if enabled == self._click_through:
return
self._click_through = enabled
hwnd = int(self.winId())
ex = _get_long(hwnd, GWL_EXSTYLE)
ex = (ex | WS_EX_TRANSPARENT) if enabled else (ex & ~WS_EX_TRANSPARENT)
_set_long(hwnd, GWL_EXSTYLE, ex)
def _hover_poll(self):
if not self.locked or self.busy or self.mode:
return
p = QCursor.pos()
x, y = p.x() - self.vx, p.y() - self.vy
...
zone, _kind, _ = self._element_at(x, y)
self._set_click_through(zone is None)The window cannot rely on mouse events to notice the cursor arriving, because with the style on it is not the target of clicks. So a timer asks. The poll interval went from 120 ms to 60 ms in the same commit (HOVER_MS = 60), and the style is only touched when the wanted state differs from the tracked one, so a still cursor costs no Win32 calls.
There was one trap, and the diff shows it. In Qt, calling setWindowFlag() recreates the native window, and the new window has default extended styles. Entering and leaving edit mode calls it, so the code has a helper that reapplies WS_EX_TOOLWINDOW, WS_EX_NOACTIVATE and the transparent bit after every flag change:
def _apply_base_styles(self, click_through):
hwnd = int(self.winId())
ex = _get_long(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE
self._click_through = None # force re-apply below
_set_long(hwnd, GWL_EXSTYLE, ex)
self._set_click_through(click_through)Edit mode calls it with click_through=False, so the whole overlay takes input while you are editing, and leaving edit mode calls it with True.
A follow-up came a minute later in 1b64965. The label pill is drawn above the zone rectangle, but the hover test only covered the rectangle. So when the cursor moved up onto the pill, hover cleared and the pill disappeared before you could click it. The test now counts the pill and gear, with six pixels of margin, as part of the hovered zone.
What I would do differently
I would not have written the commit message of the port the way I did. It claimed behaviour I had not checked by clicking something. A one minute check of double clicking an icon would have caught the problem before the commit and not after it.
The polling approach also has costs I did not measure. I have not profiled the CPU use of a 60 ms timer, and there is a short window after the cursor moves in which the old style still applies, so a click in that window goes to the previous state. A low-level mouse hook would remove the polling, but I have not tried it, so I cannot say it would be better.
And one wart is still in the repository. The docstring at the top of overlay.py still says WM_NCHITTEST is answered per point, which describes the approach this commit replaced.
Where this fits
This is the middle of a very dense first day for the project: a tkinter prototype, a port, and the fix all within ten minutes. The full Desktop Grid case study covers the rest, including how the app reads and moves desktop icons inside another process and keeps layouts per monitor setup. Many commits in this repository carry a Claude Code co-author trailer: I build with it, set the design and review every change.
Draw a zone and double click an icon underneath it to see the pass-through for yourself, or read the full project story.
Get Desktop Grid#python#pyside6#qt#win32
Keep reading
Have a project in mind?