Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sporadic Icon Failure in Ubuntu  (Read 10634 times)

0 Members and 1 Guest are viewing this topic.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Sporadic Icon Failure in Ubuntu
« on: October 18, 2013, 04:38:16 am »
So I've been trying to figure out how to give an SFML program the right icon or set of icons on each OS so that you see all the right-sized icons in all the right places, just like any professional program.

On Windows and Mac I believe I've already accomplished that (after modifying the SFML source code a little), but on my Ubuntu VM I'm getting some ludicrously inconsistent results, and I have no idea whether to blame myself, SFML, Ubuntu, Unity, X, or VMware.

When building from source I use CMake just as the tutorial describes, with BUILD_SHARED_LIBS turned off (I like static linking) and SFML_BUILD_EXAMPLES turned on (since they make great test programs), and all other variables left on their default values.  The source code itself is the official 2.1 release (I don't recall seeing any chances since then which might affect icons on Linux).

For the record I did a LOT of tests besides what I describe here.  I'm posting this one because here I decided to "steal" Firefox's icon in order to make absolutely sure I wasn't using the wrong size or wrong format or wrong folder or anything like that.

So after building everything, what I did was make a simple desktop entry with "Icon=firefox", since that's the exact line used in Firefox's desktop entry, and have its Exec line point to the SFML example program called "opengl."  I also modified opengl.cpp so that it loads firefox.png into an sf::Image which it then passes to setIcon().  I've confirmed that I'm loading the right firefox.png because changing its name causes the real Firefox to lose its icon too.  I've also confirmed in Pinta that it's exactly 128x128, which is the size I pass to setIcon.

For some strange reason, at best I get the Firefox icon in the sidebar and alt+tab menu but very blurry.  Sometimes I get Ubuntu's placeholder question mark.  And sometimes I get no icon at all; my program simply doesn't appear in the sidebar or the alt+tab list at all.  I've taken screenshots of all three of these cases, with the real Firefox browser running at the same time so you can clearly see the difference in icon resolution.  You can also see the code I added in opengl.cpp and the desktop entry I used and part of the opengl test window itself (with the spinning wooden cube).

These pictures were taken with my iPhone because it appears impossible to take a regular screenshot with the alt+tab menu open.

Case 1: Blurry custom icon in both places, Firefox has non-blurry custom icon


Case 2: Default question mark icon in both places, Firefox still has non-blurry custom icon


Case 3: No icon at all in both places, Firefox still has non-blurry custom icon


These three screenshots were taken during the same series of tests.  All I did was close and reopen the "opengl" test program several times (and I opened it by double clicking on the desktop entry, of course) until all three cases appeared.  How common each one is seems to be completely random, though I feel like the frequency of #2 is correlated to how recently I recompiled.

So, any idea what layer of software I should be blaming for this bizarre behavior?  I want to think it's Unity/Ubuntu, but every other program consistently has a non-blurry custom icon.  So then I want to think it's SFML, but what the hell could it be doing to cause a random distribution of these three behaviors?  I guess it could be VMware, but then it makes no sense that this would only be happening to my test program and nothing else in the VM.

I *think* that's all the potentially relevant information, but do tell me if I left something out.
« Last Edit: October 18, 2013, 04:40:26 am by Ixrec »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #1 on: October 18, 2013, 08:01:11 am »
I have some code waiting to be tested, that potentially fixes this kind of problem. But the window manager that I use in my Linux VM adds no decoration to windows so there's no icon. So would you like to test some code for me? I can post the code to change in SFML if you're ok.

Quote
On Windows and Mac I believe I've already accomplished that (after modifying the SFML source code a little)
Where is yor pull request? :P
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #2 on: October 18, 2013, 08:36:25 am »
I wanted to figure it out on all three OSes before I made any premature pull requests, and the only thing I really did was make the Windows setIcon() accept a bool to distinguish between the two icon sizes.  I don't even know for sure if other OSes have multiple "runtime" icon sizes to worry about yet, as opposed to "filesystem" icons that don't require the executable to go get them (I couldn't find any platform-agnostic terms for any of this icon stuff).  Though from what I've seen it looks like Mac/Linux only need one runtime size, since their windows don't have the little 16x16 titlebar icon that Windows windows do.

Testing code for you sounds awesome.  Post it wherever you want.  What's your window manager, out of curiosity?
« Last Edit: October 18, 2013, 08:38:38 am by Ixrec »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #3 on: October 18, 2013, 09:20:44 am »
My window manager is Awesome.

I'll post some code later, thanks for your help :)
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #4 on: October 18, 2013, 03:48:05 pm »
You can try to replace the implementation of WindowImplX11::setIcon with this one:

    std::vector<Uint32> icon(2 + width * height);
    icon[0] = width;
    icon[1] = height;
    for (std::size_t i = 0; i < width * height; ++i)
        icon[i + 2] = (pixels[i * 4 + 3] << 24) | (pixels[i * 4 + 1] << 16) | (pixels[i * 4 + 2] << 8) | pixels[i * 4 + 3];

    Atom iconAtom = XInternAtom(m_display, "_NET_WM_ICON", False);
    Atom cardinalAtom = XInternAtom(m_display, "CARDINAL", False);
    XChangeProperty(m_display, m_window, iconAtom, cardinalAtom, 32, PropModeReplace, reinterpret_cast<unsigned char*>(icon.data()), icon.size());

    XFlush(m_display);

This code may not work or even not compile, so I let you check for stupid (or other) errors ;)
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #5 on: October 18, 2013, 09:46:50 pm »
Good news: It does compile! After I fixed some typos.  It's possible I made others I didn't catch.

Bad news: The results are exactly the same as before except now the icon is also purple for some reason. 


While rerunning the program a few times to confirm I could get the question mark, one time I got both the question mark and the blurry purple fox in the sidebar at the same time (though only the question mark in alt+tab):


I tried adding the RGB to BGR code in the current implementation of setIcon, but that just changed it from a purple fox to a bright blue fox.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #6 on: October 18, 2013, 09:50:59 pm »
Hmm... this code was stolen from the Qt library, so it should work perfectly :-\
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #7 on: October 18, 2013, 09:53:10 pm »
I'm wondering if I should make a Kubuntu VM just to see if this is Unity's fault somehow.

(for those who don't know, Kubuntu is an Ubuntu-based distro that uses KDE as its window manager instead of Unity)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #8 on: October 18, 2013, 11:15:22 pm »
Can't you install multiple WM and switch between them on the same OS installation?
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #9 on: October 18, 2013, 11:27:44 pm »
What Ubuntu version(number) is that exactly?
Back to C++ gamedev with SFML in May 2023

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #10 on: October 18, 2013, 11:29:08 pm »
I've been using the long term support release, so 12.04 I think.

Installing some other window managers now.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #11 on: October 18, 2013, 11:32:12 pm »
Ok, no Mir there, XMir emulates X Server which may cause problems but it's optional in 13.10 or something so it shouldn't be in 12.x
Edit: Obviously no X emulation via XWayland either. ;D It's pure X so it's Unity + X problem. Soon to be Unity + Mir one. :P
« Last Edit: October 18, 2013, 11:39:04 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #12 on: October 19, 2013, 12:18:54 am »
Well now I'm stuck in a window manager that's incapable of accepting my login info or switching back to any of the others, even though it shows me a list of the others.

Fuck.

Edit: Everything I can find online assumes you can login to the terminal, but even that's rejecting every username/password combination I can think of.  Is my VM bricked?

Edit: Crisis solved.  Turns out my login name doesn't start with a capital letter.  Who knew.  Openbox still completely fails to load a desktop even after accepting my login info so no testing on that one.
« Last Edit: October 19, 2013, 01:02:33 am by Ixrec »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #13 on: October 19, 2013, 01:26:20 am »
Okay, did tests with a bunch of icon sizes across a bunch of window managers all in the same Ubuntu VM using the same modified opengl executable (now it takes a single command line argument so I can tell it what icon size to try without recompiling everything; using the old setIcon code for this).

I'll use the window manager names as shown on Ubuntu's login screen.

Ubuntu: The one I tested with above. Custom icons appear blurry, or are replaced by the question mark, or something even weirder happens like double icons or no icons or both types of icon; never do I get a custom icon in the right resolution.

Ubuntu 2D: The icons never failed to appear in the alt+tab menu and were in the proper resolution (though this alt+tab menu uses much smaller icons than the regular Ubuntu one; maybe 32x32?).  The sidebar was just as sporadic as usual though, so I saw a perfect icon in alt+tab but either a blurry one or a question mark in the sidebar.  In fact, I swear the sidebar was far more likely to give me question marks than before.

KDE/Plasma: Now windows have a titlebar icon again, like on Windows.  But no matter what I did I never once got a custom icon of any resolution to appear in the titlebar or taskbar.  It was always the default X logo.

LXDE: Titlebar icons exist here too.  Mostly the same as KDE, except  one time the test program somehow magically got the icon up and during that test Firefox had the blurrier icon.  I never replicated that.

So it looks the two flavors of Ubuntu/Unity are tied for least broken by a huge margin.  This is just sad.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Sporadic Icon Failure in Ubuntu
« Reply #14 on: October 19, 2013, 01:42:19 am »
I've seen it claimed on a handful of Ubuntu-related pages that the desktop entry icon will be used on the application, one guy even said it would override the application's own icon.  So I compiled the ordinary opengl test program, with no setIcon() calls at all, and ran that in all of the above desktop managers.  Not once did it ever have a non-default icon in any of them.  Unless SFML is inhibiting the icon inheritance(?) somehow I'm going to have to assume those people don't know what they're talking about.

Think I should redo any of this testing with the stolen Qt code instead?

 

anything