AddSysTrayIcon works under Windows but not Linux.
AddSysTrayIcon works under Windows but not Linux.
Can anyone offer any advice or pointers as to why this works on Windows but fails on Linux?
If OpenWindow(0, 100, 150, 300, 100, "Program Name", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_Minimize|#PB_Window_Invisible)
AddSysTrayIcon(0, WindowID(0), LoadImage(0, "Program.ico"))
; Other code here
EndIf
[ERROR] AddSysTrayIcon(): The specified 'ImageID' is null.
TIA
Dave
If OpenWindow(0, 100, 150, 300, 100, "Program Name", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_Minimize|#PB_Window_Invisible)
AddSysTrayIcon(0, WindowID(0), LoadImage(0, "Program.ico"))
; Other code here
EndIf
[ERROR] AddSysTrayIcon(): The specified 'ImageID' is null.
TIA
Dave
- Crusiatus Black
- Enthusiast
- Posts: 389
- Joined: Mon May 12, 2008 1:25 pm
- Location: The Netherlands
- Contact:
Re: AddSysTrayIcon works under Windows but not Linux.
The manual for LoadImage:
So, .ico is not supported on any other OS besides Windows
Code: Select all
The image can be in BMP, icon (.ico, only on Windows) or any other format supported by the ImagePlugin library. The following functions can be used to enable automatically more image formats:
UseJPEGImageDecoder()
UseJPEG2000ImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()
UseTGAImageDecoder()
UseGIFImageDecoder()
Re: AddSysTrayIcon works under Windows but not Linux.
Yes, my first idea was to use a png or jpg format (with the appropriate ImagePlugin) in place of ico, but the error was the same in all cases.
Thanks for trying to help.
Dave
Thanks for trying to help.
Dave
Re: AddSysTrayIcon works under Windows but not Linux.
You have made several mistakes in your code fragment (please always post a runnable code example because more users will test your code and try to help!):
- as Crusiatus Black has already written: .ico images are only supported by Windows
- Please always test whether the loading of an image was successful (you didn't give any path to your icon image, even with a correct path Linux would not have loaded an .ico file!)
- You have to use ImageID() with a successfully loaded image ID
I have tested the following example successfully on these operating systems:
- Linux Mint 18.3 'Sylvia' x64 with Cinnamon
- MacOS 10.6.8 'Snow Leopard'
- MacOS 10.13.6 'High Sierra'
- Windows 7 x64 SP1
- Windows 10 x64 Update 1809
- Xubuntu 18.04 x86 with Xfce
But be cautious on Linux: on my Xubuntu 18.04 the Systray expects an image with a width of 24 pixels - therefore the left half of the image is appended to the 16 pixels wide image, in consequence looking wierd. So in that case you would have to center the 16x16 image in an 24x24 image before displaying it. And several Linux distributions like Ubuntu and Elementary OS have deprecated the Systray!
- as Crusiatus Black has already written: .ico images are only supported by Windows
- Please always test whether the loading of an image was successful (you didn't give any path to your icon image, even with a correct path Linux would not have loaded an .ico file!)
- You have to use ImageID() with a successfully loaded image ID
I have tested the following example successfully on these operating systems:
- Linux Mint 18.3 'Sylvia' x64 with Cinnamon
- MacOS 10.6.8 'Snow Leopard'
- MacOS 10.13.6 'High Sierra'
- Windows 7 x64 SP1
- Windows 10 x64 Update 1809
- Xubuntu 18.04 x86 with Xfce
Code: Select all
UsePNGImageDecoder()
If OpenWindow(0, 100, 150, 300, 100, "Program Name")
If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png") = 0
MessageRequester("Error", "Loading of image failed!")
End
EndIf
AddSysTrayIcon(0, WindowID(0), ImageID(0))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: AddSysTrayIcon works under Windows but not Linux.
Thanks Shardik, your help is much appreciated.
As mentioned in my previous post, I had already tried png with he same result.
My mistake was forgetting that Linux really needs to be given a full path, even though the png was in the same directory.
Now if I can find an answer to viewtopic.php?f=13&t=72744 I can get this project finished.
As mentioned in my previous post, I had already tried png with he same result.
My mistake was forgetting that Linux really needs to be given a full path, even though the png was in the same directory.
Now if I can find an answer to viewtopic.php?f=13&t=72744 I can get this project finished.
Re: AddSysTrayIcon works under Windows but not Linux.
Therefore it's very important to check whether an image has been loaded properly before trying to use it. In Linux you have to consider further that paths and filenames are case sensitive! And you always have to remember to specify the necessary decoder for your image format, in my example UsePNGImageDecoder().davebar wrote:As mentioned in my previous post, I had already tried png with he same result.
My mistake was forgetting that Linux really needs to be given a full path, even though the png was in the same directory.
In cross-platform programs I would advise to not utilize the systray because some Linux distributions don't use a systray anymore. And as I have already remarked above, Xubuntu 18.04 uses 24x24 images in the systray. When running my example posted above on Xubuntu 18.04, you will see the following result:

For Xubuntu 18.04 you therefore have to center a 16 pixel image inside of a 24 pixel image:

This can be achieved with the following modified example:
Code: Select all
EnableExplicit
UsePNGImageDecoder()
If OpenWindow(0, 100, 150, 300, 100, "Program Name")
If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png") = 0
MessageRequester("Error", "Loading of image failed!")
End
EndIf
CreateImage(1, 24, 24, 32, #PB_Image_Transparent)
If StartDrawing(ImageOutput(1))
DrawAlphaImage(ImageID(0), 3, 3)
StopDrawing()
EndIf
AddSysTrayIcon(0, WindowID(0), ImageID(1))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: AddSysTrayIcon works under Windows but not Linux.
@ Shardik
Works fine on Ubuntu Budgie 18.04
Works fine on Ubuntu Budgie 18.04

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: AddSysTrayIcon works under Windows but not Linux.
Fresh install on Ubuntu 19 and it was complicated to install PB...
But after that, I tried your code and I didn't see the icon... sniff.
The only thing I have :
If someone has an idea 
edit : Ok Ubuntu doesn't support system tray ... Now it's Ubuntu appindicators" (package name: gnome-shell-extension-appindicator )
But after that, I tried your code and I didn't see the icon... sniff.
The only thing I have :
Code: Select all
[23:48:03] Waiting for executable to start...
[23:48:03] Executable type: Linux - x64 (64bit, Unicode)
[23:48:03] Executable started.
[23:48:03] [WARNING] Line: 1
[23:48:03] [WARNING] GLib-GIO (DEBUG): _g_io_module_get_default: Found default implementation gvfs (GDaemonVfs) for âgio-vfsâ
[23:48:10] The Program execution has finished.
[23:48:23] Waiting for executable to start...
[23:48:23] Executable type: Linux - x64 (64bit, Unicode)
[23:48:23] Executable started.
[23:48:23] [WARNING] Line: 1
[23:48:23] [WARNING] GLib-GIO (DEBUG): _g_io_module_get_default: Found default implementation gvfs (GDaemonVfs) for âgio-vfsâ

edit : Ok Ubuntu doesn't support system tray ... Now it's Ubuntu appindicators" (package name: gnome-shell-extension-appindicator )
Code: Select all
cat /usr/share/gnome-shell/extensions/ubuntu-appindicators@ubuntu.com/appIndicator.js
Re: AddSysTrayIcon works under Windows but not Linux.
Going a bit off-topic here, but it's interesting to see that we both had a battle to get PB installed.
Although different desktop environments, we get identical warnings:
[WARNING] Line: 1
[WARNING] GLib-GIO (DEBUG): _g_io_module_get_default: Found default implementation gvfs (GDaemonVfs) for âgio-vfsâ
While the errors don't appear to make PB any less usable, having the same warnings appearing continuously is irritating.
Although different desktop environments, we get identical warnings:
[WARNING] Line: 1
[WARNING] GLib-GIO (DEBUG): _g_io_module_get_default: Found default implementation gvfs (GDaemonVfs) for âgio-vfsâ
While the errors don't appear to make PB any less usable, having the same warnings appearing continuously is irritating.