Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window icon and title are not set properly #268

Open
broughtong opened this issue Aug 17, 2023 · 5 comments
Open

Window icon and title are not set properly #268

broughtong opened this issue Aug 17, 2023 · 5 comments

Comments

@broughtong
Copy link

What doesn't work?

Changing a window icon using sdl2.SDL_SetWindowIcon doesn't work on Ubuntu 20.04.

Creating a window in the C++ SDL has no logo set by default (in pysdl2 it has a python logo by default).

Changing it with SDL_SetWindowIcon in C++ correctly sets it, but same code in python does nothing, the logo remains the Python logo. I've tried hiding the window to start with, setting the logo, and then showing it but same issue. Likewise the title showing in the taskbar is always "Python (v3.8)" regardless of what sdl2.SDL_SetWindowTitle is set to.

How To Reproduce
Any code that reproduces the bug, e.g.:

import time
import ctypes
import sdl2
import sdl2.ext
import sdl2.sdlimage

def main():
    sdl2.SDL_Init(sdl2.SDL_INIT_EVERYTHING)

    window = sdl2.SDL_CreateWindow(b"Test Window", sdl2.SDL_WINDOWPOS_UNDEFINED, sdl2.SDL_WINDOWPOS_UNDEFINED, 400, 400, 0) #sdl2.SDL_WINDOW_HIDDEN)

    icon = sdl2.sdlimage.IMG_Load(b"icon.png")
    sdl2.SDL_SetWindowIcon(window, icon)
    print(sdl2.SDL_GetError())

    sdl2.SDL_ShowWindow(window)

    sdl2.SDL_SetWindowTitle(window, b"New title")

    time.sleep(5)

    sdl2.SDL_DestroyWindow(window)
    sdl2.SDL_Quit()

if __name__ == "__main__":
    main()

Platform (if relevant):

  • OS: Ubuntu 20.04
  • Python Version: 3.8.10
  • PySDL2 version: 0.9.16
  • SDL2 Version: 2.0.10
  • Using pysdl2-dll: no
@broughtong
Copy link
Author

Similarly on Windows 11, in C++ SDL the taskbar icon is updated when the window icon is changed, but in PySDL the window icon will change, but the taskbar icon remains a default.

@a-hurst
Copy link
Member

a-hurst commented Aug 17, 2023

Hi @broughtong, this seems like a window manager-specific bug: with Fedora 38 and KDE, you test example works perfectly:
Screenshot_20230817_140824

Can you try adding an sdl2.SDL_PumpEvents() call after showing your window? That updates various window properties on some window managers, from what I remember.

@broughtong
Copy link
Author

Tried the Pump events, no change.

I tried also Kubuntu 20.04, which might clear up what is happening:

Screenshot_20230818_090614

The icon and title used on the window itself are correct.

The icon in the task bar though is just the regular python icon, and the title in this case "Python (v3.10)" with a subheading of the real window title of "some title".

In regular Ubuntu, due to the window manager the only logo visible at all is the Python one (in the taskbar to the left), the title on the window is correct, and the title at the top of the screen is just "Python (v3.x)".

In C++ SDL, in all cases the logo on both the window and taskbar are the one given by SDL_SetWindowIcon, and the title on both the window and taskbar is the one from SDL_SetWindowTitle

@a-hurst
Copy link
Member

a-hurst commented Aug 18, 2023

I can partially reproduce that: with the latest KDE Plasma from Fedora 38, I get the "python" main heading along with the proper window title as the subheading, but the custom-set window icon still shows fine for me in the task bar:

Screenshot_20230818_091006

From what I can tell, the top heading in the KDE taskbar is the name of the application itself, with the subheading being the title of that specific window (if there are multiple windows open for the same app, it lists the app title once and the window name for each separate window):

Screenshot_20230818_091947

As such, since whatever you're running with PySDL2 is run via the Python interpreter, most window managers will report that as the application name instead of the app's current window title. Seems this isn't an issue limited to PySDL2 either, with reports of the same problem applying to people using PyQT or PySide: https://stackoverflow.com/questions/27453436/set-application-name-in-pyside

Since this isn't PySDL2-specific, maybe there's a generic Python library out there that can set/override the current application title within a given Python script?

@broughtong
Copy link
Author

Ok so I'm now pretty sure this is actually a bug within SDL itself, not setting the class/classname property correctly in the x server.

In C++ it doesn't matter as there is nothing already set, but when called through Python , it is getting some wrong info about the window.

If I alter the class/classname manually in X for the window, all calls (including previous calls) now take effect correctly in the taskbar.

Will report it over there.

To see the difference, open your window.
Run xdotool selectwindow in a terminal and click the window to get the ID.

Then do xdotool set_window --class my_new_title WINDOWID and xdotool set_window --classname my_new_title WINDOWID

All icons and titles should now correctly appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants