I finally found some time over last weekend to really sit down and try to explore and understand GtkStatusIcon — the new widget introduced in gtk+2.10 that allows us to develop system tray application using PHP-GTK2.
I was misled heavily by a paragraph in the official referenece manual of GTK+. It says: “Note that a GtkStatusIcon is not a widget, but just a GObject. Making it a widget would be impractical, since the system tray on Win32 doesn’t allow to embed arbitrary widgets.”
This led me into thinking that it must be a complicated process to establish the link between a system tray icon and the main PHP-GTK2 application.
And how do I pass control back and forth between the main PHP-GTK2 application and the system tray?
Anyway, after much trials and errors, I realized that I was looking in the totally wrong direction!
So, let me share these undocumented “secrets” about GtkStatusIcon with you:
- There’s only ONE main loop running, and that’s the main loop of your PHP-GTK2 application. NOT the GtkStatusIcon.
- Just think of GtkStatusIcon as a GtkButton.
- This “button” does not reside within your GtkWindow. It appears in the system tray, and is independent of your GtkWindow.
- The button can receive left click and right click with the signals ‘activate’ and ‘popup-menu’ respectively.
To understand what the above four lines mean, take a look at the sample code below and read the explanation.
Once you understand the “secrets” above, I think you will be extremely busy for the next couple of days devevloping your own system tray applications.
Have lots of fun with GtkStatusIcon!
The place for php-gtk2 sample codes
p.s.1 I will be coming out with more sample codes to show you how to use this exciting GtkStatusIcon. In particular, how to handle right mouse click so that you can place some of the commonly-used functions in a popup menu when the user clicks on the right mouse button.
p.s.2 I’m NOT saying that a GtkStatusIcon IS a GtkButton. It’s NOT. But it helps one to understand and use it by viewing it as a GtkButton.