Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro application in Ubuntu (Unity)

This thread is locked; no one can reply to it. rss feed Print
Allegro application in Ubuntu (Unity)
Petko D
Member #12,874
May 2011

Hello everyone , I just finished an app that I've been developing for some time now , and I have a very specific problem , that I couldn't solve via googling . I made a launcher for my app , but Unity doesn't handle the app as expected . If I open one instance the app doesn't associate with its icon in the sidebar , and I if I click the icon again I don't focus the application , but get a new instance (whilst the first is still alive , but has no way to get focus except when I move all other windows out of the way) . Is it something allegro related (as in has anyone else experienced the problem) or is it more likely that I haven't made the launcher right ?

alehbeer
Member #12,996
July 2011
avatar

Its most-likely that Unity is trash. Ubuntu was great, but Unity introduces a whole can of regression. That said, post the script and I can take a look at it / try to replicate the error. These questions might not be relivent once you post the script / script example.
1) Is it a bash-script? Or python, etc?
2) Are you using Unity or Unity 2D, and could you post the version.
3) How are you assigning the icon to the application? There are a couple of ways of doing this.
4) Do you experience this same problem on other windowmanagers, such as xfce, gnome2, etc

Petko D
Member #12,874
May 2011

The app is in cpp , standard allegro5 stuff . I call the compiled binary with a .desktop launcher (that I added in the panel) which is as follows :

[Desktop Entry]
Version=1.0
Type=Application
Name=Bulfleet
Terminal=false
StartupNotify=true
Icon=/home/xxxx/bulfleet/bf.jpg
Exec=/home/xxxx/C++/Bulfleetmm/bin/Dev/Bulfleetmm
Categories=Application;Games;

When I start the app it has its own separate icon (well , with no icon) captioned "Untitled window" that can focus it's related instance . Are there any parameters of the display that I might have omitted to cause this behaviour (I didn't set a title , which I'll do to see if it causes the problem) .

alehbeer
Member #12,996
July 2011
avatar

Ah, well, '.Desktop scripts' are not my thing but I will try to help anyway. I don't think this has anything to do with allegro - its a Unity thing. Make sure its installed correctly.

My understanding is that Unity creates its own launcher, based on the .desktop file. I have no idea if there is a "proper" .desktop way to prevent multiple instances, but you could have your program check for instances at run-time - either every-time or only if a special parameter is passed. For example parse the parameters so if something like -one-instance is passed into main, terminate if another instance already is running. The your .desktop file would look like:

#SelectExpand
1 2[Desktop Entry] 3Version=1.0 4Type=Application 5Name=Bulfleet 6Terminal=false 7Comment=This might be my tooltip~! 8TryExec=Bulfleetmm --one-instance 9Exec=/home/xxxx/C++/Bulfleetmm/bin/Dev/Bulfleetmm --one-instance 10Icon=Bulfleetmm 11MimeType=image/x-foo; 12Categories=Games;Application

You should try pulling the icon directly from the application. Otherwise, you should use a vector icon, such as SVG. Icon will be an absolute path, or it will be searched for, but the method of handling this attribute is not explicit as some implementations will ignore it. More info on the Icon specification stuff can be found at: http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html

While I am not positive, .desktop files are GNOME/ GNOME-Compatible (really freedesktop.org standard compatible) only. There are several ways of launching applications, each with their own nuances. This should not be a problem if your target is Unity, and there is a relevant tutorial at https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles. That said, the sidebar of Unity is weird. You may also want to ask over at http://www.linuxquestions.org/ and see what they say.

Other useful links
1) The specification can be found at http://standards.freedesktop.org/desktop-entry-spec/latest/index.html.
2) this one may be useful: http://developer.gnome.org/integration-guide/stable/desktop-files.html.en
While not directly related, it might give you some additional scripting ideas: http://awesome.naquadah.org/wiki/Autostart

Petko D
Member #12,874
May 2011

Thank you for the extensive reply , I gave all the resources a look , and I tried a few more things but not much luck . When I hover the icon in the launcher (of a launched instance of my app - that no icon, no title thing that focuses the window correctly) - I get an "Untitled window" caption , even though the window has a title now (and it gets displayed correctly on the window itself) . So there is some gap in the communication between unity and allegro (I assume that some passing of arguments doesn't happen correctly ) . Do you know what arguments the passed between the window manager and the program to correctly associate everything ? (I'll continue reading myself ,and again thank you for all the help , I'm just throwing the question out there , since that's the page I'm on now) .

Thomas Fjellstrom
Member #476
June 2000
avatar

I think allegro needs to set the X11 "WM_CLASS" attribute on the window to something meaningful. Then the desktop file probably needs to match that, then it may be able to deal with allegro windows.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

alehbeer
Member #12,996
July 2011
avatar

While what I said before is generally correct and is so for older Unity versions, some things may have improved since the last time I gave up on Unity. That said, I think there may be a bug you found and it may be in both. Here's why: Non-Allegro5 programs (single icon) or allegro5 programs started through terminal (terminal gets a `?` icon and the allegro program gets the icon correctly) seems to appropriately associate the icon assuming they are configured in the script correctly. The presence of a .desktop icon parameter in the script should override that of the binary, especially if no proper icon is found. This may need to filed as such the Unity tracker - but check with the other allegro-ites as they know much more about this than I. The same problem occurs with EX_ICON packaged with Allegro5 itself, so A5 might have issues too as Thomas Fjellstrom suggested. I am not sure how to make the .desktop change the working directory so relative references ("./data/image.png" for example) will work.

First, just make sure you script is correct by ensure your permissions are correct and that the image is not referenced as an absolute location. ./my_image.jpg Will NOT work. So make sure you spell the image and location correctly.

Note this is only the freedesktop.org standard specification loading script, and that the icon is not pulled in this case from the program. In allegro5 I think you can use void al_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *icon) but I can't make it work even using the example program for it ex_icon.c.

I have installed a clean Ubuntu 12.04lts with Unity, and used the following script:

[Desktop Entry]
Version=1.0
Type=Application
Name=MidnightCommanderIZ
Terminal=true
Comment=This might be my tooltip~!
TryExec=mc
Exec=mc
Icon=/home/-------------/Desktop/TestFile/Alex.jpg
MimeType=image/x-foo;
Categories=Games;Application

Note I have mc installed and the PATH is configured (I can type "mc" to run the program from terminal no matter the directory I am in.).
I named "mysupamcscript.desktop" and set as executable. This can be done from GUI, by right clicking -> "Properties" -> goto tab "Permissions"-> Check "Allow executing file as a program".

This runs, loads the jpg icon I made by saving the Alex.gif as a single frame using gimp, and will only load one instance. Since the script is not really 'installed' (you can learn how in one of the links from earlier), right click it and click "lock to Launcher". It should say and work now, even after the program has terminated. Please note that This is specific to Unity.

To make a universal method of ensuring single instance, you will want to check using your own code.

Petko D
Member #12,874
May 2011

I made a new .desktop by your model and here's what I noted :
- If terminal is enabled the icon loads correctly - but for the terminal window . The Allegro window still has neither title nor icon.
-If terminal is disabled (set to false) the program runs ,again with no title/icon,in a single instance , but if you try to lock it to the launcher you will get a dysfunctional launcher
-There are problems with closing the program (the display close signal delays in some cases) and in these (as far as I've seen) cases Ubuntu returns an "Internal error" message (but the program still closes , just with a delay) .
-I think there was one more , but I forgot :D

So as the Title appears on the actual window (somebody that tried it can say if the icon appeared on the window) I make the conclusion that the communication with the display manager is OK , but for some reason Unity can't handle the allegro displays .

Alehbeer, if you haven't wiped your Ubuntu setup, can you see if the game (MC) runs correctly without being run through the terminal (there's still some chance that something in my code causes the problem). As in - do you have an icon and a working locked launcher with Terminal=false in the .desktop file ?

Edit: the segmentation problem (which caused Ubuntu to pop a "internal error") was my fault .

Elias
Member #358
May 2000

I didn't follow the thread, but you set the icon of the Allegro window with al_set_display_icon - most likely that same icon is also used by the task manager.

--
"Either help out or stop whining" - Evert

Petko D
Member #12,874
May 2011

On the Unity IRC channel they directed me to file a bug against the library that handles binding windows to their according processes in Unity- BAMF ( https://launchpad.net/bamf ) . So I guess that's what I'll do . Again - thanks for the help guys , I'll update the thread if some kind of solution comes up .

alehbeer
Member #12,996
July 2011
avatar

Petko D, keep us informed of new developments.

mc is a terminal program, but I suspect the terminal only icon thing is allegros inability to overcome Unity's errors. I tired the .Desktop with Jamestown, the commercial indie videogame, and ended up with the same problem. Jamestown was written with SDL and not allegro, and this version was bought through humblebundle - if that makes any difference. The fact that SDL and allegro5 share this same error under unity points to unity being the common denominator.

Edit!: Another interesting point is that Unity will call programs "Untitled window" often, even if the window has a title right on the window's titlebar.

Go to: