python / cpython

The Python programming language
https://www.python.org
Other
61.88k stars 29.77k forks source link

IDLE: Set correct WM_CLASS on X11 #66331

Open 22200024-de1a-4081-ad85-2ac04e6b54d2 opened 10 years ago

22200024-de1a-4081-ad85-2ac04e6b54d2 commented 10 years ago
BPO 22133
Nosy @terryjreedy, @serhiy-storchaka
Files
  • idle-x11-class.diff
  • after-before.png
  • idle_wm_class.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = 'https://github.com/terryjreedy' closed_at = None created_at = labels = ['expert-IDLE', 'type-bug', '3.10'] title = 'IDLE: Set correct WM_CLASS on X11' updated_at = user = 'https://bugs.python.org/SaimadhavHeblikar' ``` bugs.python.org fields: ```python activity = actor = 'terry.reedy' assignee = 'terry.reedy' closed = False closed_date = None closer = None components = ['IDLE'] creation = creator = 'Saimadhav.Heblikar' dependencies = [] files = ['36251', '36252', '36702'] hgrepos = [] issue_num = 22133 keywords = ['patch'] message_count = 12.0 messages = ['224728', '224788', '224808', '224814', '224823', '224833', '224855', '224884', '225810', '227390', '227759', '243245'] nosy_count = 4.0 nosy_names = ['terry.reedy', 'jesstess', 'serhiy.storchaka', 'Saimadhav.Heblikar'] pr_nums = [] priority = 'normal' resolution = None stage = 'test needed' status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue22133' versions = ['Python 3.10'] ```

    22200024-de1a-4081-ad85-2ac04e6b54d2 commented 10 years ago

    I found this bug on gnome where IDLE's activity bar entry is named "Toplevel" instead of "IDLE". After digging through the X11 and gnome docs, the WM_CLASS was wrongly being set as "Toplevel". This patch has been verified using xprop, that the correct WM_CLASS value is getting set.

    (Does this have any other side effect on KDE, LXDE, XFCE et al?)

    terryjreedy commented 10 years ago
    Serhiy, do you know if the trivial addition of "class_='IDLE'" can have any ill effect on non-gnome systems? It looks sensible to me, and I see no effect on Windows.
    -    self.top = top = WindowList.ListedToplevel(root, menu=self.menubar)
    +    self.top = top = WindowList.ListedToplevel(root, class_='IDLE',
    +                                               menu=self.menubar)
    serhiy-storchaka commented 10 years ago

    I see no effect on KDE.

    We should change window class also for other toplevel windows (from stack viewer to calltip). And for turtledemo and other gui demos too.

    serhiy-storchaka commented 10 years ago

    And for turtledemo and other gui demos too.

    No, this is not needed because they are not installed as separate applications and have not specific .desctop file.

    As said on https://wiki.gnome.org/Projects/GnomeShell/ApplicationBased:

    """ To ensure the GNOME 3 Shell will track your application, you can also set the WMCLASS X window property to be the same as your application's .desktop file name, without the .desktop extension (the desktop file should be lower-case). """ Is "class='IDLE'" works when only IDLE for Python 3 (not for Python 2) is installed? Shouldn't it be 'IDLE3'?

    22200024-de1a-4081-ad85-2ac04e6b54d2 commented 10 years ago

    >Is "class_='IDLE'" works when only IDLE for Python 3 (not for Python 2) is installed? Shouldn't it be 'IDLE3'?

    I tried class_="IDLE"(or any other string) for python2 repo build, and it works.

    Most applications on Gnome set it to just the name of the program, like "Terminal", or "Google Chrome". So that is why I suggested "IDLE". Even though we have 2 versions of IDLE, we have the IDLE title bar to give more information related to the version etc. IIRC, OSX also has a system wide title bar which displays the program name which currently has focus. Could we use that as a precedence to choose "IDLE" vs {"IDLE2", "IDLE3"}?

    serhiy-storchaka commented 10 years ago

    I think we should use class="IDLE3" (or class="Idle3") on Python 3. I did not check, but I suppose this should has following effects on Gnome Shell:

    Saimadhav, please try class_="Idle" (title case). I suppose that IDLE's activity bar entry will be named "IDLE" (upper case), because Gnome Shell will get the name from IDLE's desktop file (/usr/share/applications/idle.desktop).

    There is duplicate issue (bpo-13553) but it doesn't provide good solution.

    For the demonstration, folowing code displays on KDE two windows with IDLE icon if IDLE3 is installed.

    >> from tkinter import * >> tk = Tk(className='Idle3') >> top = Toplevel(tk, class_='Idle3')

    22200024-de1a-4081-ad85-2ac04e6b54d2 commented 10 years ago

    "Saimadhav, please try class_="Idle" (title case). I suppose that IDLE's activity bar entry will be named "IDLE" (upper case), because Gnome Shell will get the name from IDLE's desktop file (/usr/share/applications/idle.desktop)."

    No. It stays "Idle". Also there was no file for me in /usr/share/applications/idle.desktop. An idle.desktop file was found in /usr/share/app-install/desktop/idle.desktop, whose content is [Desktop Entry] X-AppInstall-Package=idle X-AppInstall-Popcon=132 X-AppInstall-Section=main

    Name=IDLE
    Comment=Integrated Development Environment for Python
    Exec=/usr/bin/idle
    Icon=/usr/share/pixmaps/idle.xpm
    Terminal=false
    MultipleArgs=false
    Type=Application
    Categories=Application;Development;
    StartupNotify=true

    I don't have any icon file at /usr/share/pixmaps/idle.xpm

    After copying the above idle.desktop to /usr/share/applications/, the activity bar becomes "IDLE". There is NO icon. If I set class_='Idle3', it works as expected with icon and text.

    With 2.7, 'Idle2', displays same behavior with proper icon and text. With 2.7, 'Idle' it displays "IDLE" and no icon.

    terryjreedy commented 10 years ago

    We should change window class also for other toplevel windows (from stack viewer to calltip).

    Grepping idlelib for 'toplevel, there are about 10. Do all of the Toplevels get put on the activity bar? I would not expect that popups like calltip would.

    I expect that all ListedToplevels could be handled at once by adding the following as the first line of ListedToplevel.__init__. kw["class"] = 'IDLE'

    What is wrong with simply adding classname to the Tk() call, as Roger suggested in bpo-13553. Does KDE display 2 windows without name='Idle' in the toplevel call? Is this a KDE or tk bug?

    serhiy-storchaka commented 10 years ago

    Grepping idlelib for 'toplevel, there are about 10. Do all of the Toplevels get put on the activity bar? I would not expect that popups like calltip would.

    I don't know how dialogs and calltip popups behave on Gnome Shell. But I think we should do this at least for more or less long-lived windows such as stack viewer. On KDE when I added kw["class"] = 'Idle3' to ListedToplevel constructor, console and editor windows are grouped on taskbar, and stack viewer is separated (without this line all three windows are in the same group).

    I expect that all ListedToplevels could be handled at once by adding the following as the first line of ListedToplevel.__init__.

    May be, but this is not so simple. To be robust we should handle both 'class' and 'class_' keywords (and may be even '-class').

    What is wrong with simply adding classname to the Tk() call, as Roger suggested in bpo-13553.

    This affects only WM_CLASS of root window (which is withdrawn right after creation in IDLE).

    Does KDE display 2 windows without name='Idle' in the toplevel call? Is this a KDE or tk bug?

    tk = Tk(className='Idle3') creates first (root) window and top = Toplevel(tk, class_='Idle3') creates second window. The className argument affects root window (and some other things) and the class argument affects Toplevel window.

    Another example:

    >> from tkinter import * >> tk = Tk(className='Firefox') >> top = Toplevel(tk, class_='Chromium-browser')

    Created two windows: one with title "firefox" and Firefox icon, and other with title "firefox" and Chromium icon.

    I argue that we should add className="Idle3" to every Tk constructor and class_="Idle3" to most (iv not every) Toplevel constructor. On Python 2 it should be "Idle2" or "Idle" (not sure).

    serhiy-storchaka commented 9 years ago

    Here is a patch which sets WM_CLASS of all long-lived toplevel windows.

    22200024-de1a-4081-ad85-2ac04e6b54d2 commented 9 years ago

    I don't know how dialogs and calltip popups behave on Gnome Shell

    Can you reply what behaviour you want to confirm? If you meant, grouping - Toplevels like ClassBrowser, PathBrowser etc are always grouped as single unit in the "Activity Bar". But, in the popup which you get for "Alt + Tab", they are displayed as 2 different applications - stress on different. For example, if I have two different windows of Google Chrome open, they are listed as a single application, both windows nested under a single logo. With IDLE, its two different applications.

    tkMessageBox and tkFileDialog usage like in "open_classbrowser()" and "Save As" change the title of in the Activity Bar and "Alt+Tab" menu to "tkFDialog". I am not sure if there is a way to pass class argument in such a situation.

    Just a suggestion, can we use sys.version_info to get Python major version to have uniform code?

    serhiy-storchaka commented 9 years ago

    Just a suggestion, can we use sys.version_info to get Python major version to have uniform code?

    Uniform code is too verbose. WM_CLASS should be "Idle" on Python 2 and "Idle3" on Python 3.

        top = Toplevel(self.root, class_='Idle' if sys.version_info[0] <= 2 else 'Idle%s' % sys.version_info[0])

    It is easy to write just the constant literal. It is changed only when the major version is changed.