[3.15] gh-66331: Set correct WM_CLASS on X11 for IDLE windows (GH-152733) (#152794)

gh-66331: Set correct WM_CLASS on X11 for IDLE windows (GH-152733)

Set the WM_CLASS of IDLE's long-lived windows (window-list windows and
the stack viewers) to "Idle" instead of the default "Toplevel", so that
window managers group and label them correctly.
(cherry picked from commit 4e16b8d4ee)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot)
2026-07-01 17:44:06 +02:00
committed by GitHub
parent 63da6c86eb
commit f7c26ed02f
6 changed files with 16 additions and 2 deletions
@@ -35,6 +35,8 @@ class StackBrowserTest(unittest.TestCase):
isi(stackviewer.sc, ScrolledCanvas)
isi(stackviewer.item, stackviewer.StackTreeItem)
isi(stackviewer.node, TreeNode)
top = stackviewer.sc.frame.winfo_toplevel()
self.assertEqual(top.winfo_class(), 'Idle')
if __name__ == '__main__':
+5
View File
@@ -39,6 +39,11 @@ class ListedToplevelTest(unittest.TestCase):
win = window.ListedToplevel(self.root)
self.assertIn(win, window.registry)
self.assertEqual(win.focused_widget, win)
self.assertEqual(win.winfo_class(), 'Idle')
def test_init_class_override(self):
win = window.ListedToplevel(self.root, class_='Other')
self.assertEqual(win.winfo_class(), 'Other')
if __name__ == '__main__':
+1 -1
View File
@@ -644,7 +644,7 @@ class ModifiedInterpreter(InteractiveInterpreter):
return
item = debugobj_r.StubObjectTreeItem(self.rpcclt, oid)
from idlelib.tree import ScrolledCanvas, TreeNode
top = Toplevel(self.tkconsole.root)
top = Toplevel(self.tkconsole.root, class_='Idle')
theme = idleConf.CurrentTheme()
background = idleConf.GetHighlight(theme, 'normal')['background']
sc = ScrolledCanvas(top, bg=background, highlightthickness=0)
+1 -1
View File
@@ -11,7 +11,7 @@ from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
def StackBrowser(root, exc, flist=None, top=None):
global sc, item, node # For testing.
if top is None:
top = tk.Toplevel(root)
top = tk.Toplevel(root, class_='Idle')
sc = ScrolledCanvas(top, bg="white", highlightthickness=0)
sc.frame.pack(expand=1, fill="both")
item = StackTreeItem(exc, flist)
+4
View File
@@ -61,6 +61,10 @@ unregister_callback = registry.unregister_callback
class ListedToplevel(Toplevel):
def __init__(self, master, **kw):
# Set the WM_CLASS property so that X11 window managers group and
# label IDLE's windows under 'Idle' instead of the default
# 'Toplevel' (gh-66331). It matches the class name passed to Tk().
kw.setdefault('class_', 'Idle')
Toplevel.__init__(self, master, kw)
registry.add(self)
self.focused_widget = self
@@ -0,0 +1,3 @@
Set the ``WM_CLASS`` window property of IDLE's windows to ``Idle`` on X11,
so that window managers group and label them correctly instead of using the
default ``Toplevel``.