Skip to content

How to use wxPHP to create a taskbar icon using wxPHP in Ubuntu/Unity? #110

Description

@halfer

I've asked a question on Stack Overflow, but I wonder if this might be better regarded as an issue for wxPHP to address (despite largely being caused by Ubuntu/Unity).

I believe I am doing everything correctly to add a status icon to the task bar, but nothing seems to happen, despite wxPHP otherwise working fine.

My various pieces of research indicate that between 11.x and 13.10, Ubuntu required apps wanting a status icon to be white-listed, and since 13.10, the white-listing feature was taken out entirely. There is a binary available to install (from a non-standard repo) that will restore this feature, but that is obviously not a satisfying solution.

Is there a simple way to get status icons working in Ubuntu? The approaches to get this working that I think are desirable, in order of preference, are:

  • a code change in how I am using wxPHP
  • a library I can call in PHP to interact with Application Indicators
  • a system setting change (not great if it affects the user's environment generally)
  • a dependency available in the default Ubuntu repositories (users may baulk at adding new trusted repos for security reasons)

Presently I want to create an application for my own usage, but if it proves useful I may make it available for others. Given that the absence of wxwidgets.so from most Linux repos is already a barrier to installation, I don't want the installation process to be any more onerous!

Activity

  1. halfer commented on Nov 22, 2015

    @halfer
    ContributorAuthor

    I've seen a couple of non-PHP implementations, including this one and this general advice, which try to create an AppIndicator first, and if that fails, create a wxTaskBarIcon. Would wxPHP be an appropriate place to do this, or should I try to do this in my own app? (There is a suggestion here that it should be implemented upstream in wxWidgets, but someone else suggested that it might not be an appropriate change).

    There are no bindings for AppIndicator in PHP as far as I can tell, so if it is best for individual apps to take on this responsibility, how does one interact with libappindicator? I think I saw DBus mentioned somewhere.

  2. halfer commented on Nov 22, 2015

    @halfer
    ContributorAuthor

    This answer shows how menu items attached to taskbar icons can be queried (and possibly modified) using qdbus. This suggests to me that there is a DBus mechanism to create status area icons, though some hours of persistent research hasn't yet turned up anything concrete.

    DBus messages seem to be somewhat introspectable, so that will be my next avenue for research. Nevertheless any assistance here will be appreciated. I'll keep the ticket updated.

  3. halfer commented on Nov 22, 2015

    @halfer
    ContributorAuthor

    For information, I have asked a DBus question over at Ask Ubuntu. There are a variety of DBus queries there, but not - as far as I can tell - for creating an application status icon.

  4. jgmdev commented on Nov 22, 2015

    @jgmdev
    Member

    Gnome 3 had the same issue where they removed support for good old status icons, but they fixed it I think on 3.18 or 3.16 by adding a new tool bar on the lower left side of the screen that displays the status icon of all the applications that aren't making use of the new AppIndicator interface.

    Basically, I don't think there's a easy way to whitelist the application icon since the original intent of unity/gnome developers was for every developer to migrate there code to this new appindicator interface, and they removed support for old interface to force them or maybe to have a cleaner interface which I think is a mistake. In any case as you mentioned, I think the right place would be on wxWidgets itself, by writing an AppIndicator backend for wxTaskBarIcon but as you also said, there are limitations with AppIndicator since it doesn't has the same amount of features available to older status icon interface. There is a work around mentioned here http://stackoverflow.com/questions/14521006/wxtaskbaricon-in-ubuntu-12-10/14545805#14545805 by calling the gsetting command, but I'm not sure if that still applies.

    PHP should be more like python in terms of been considered a general purpose programming language, for python you see there's bindings for almost everything, PHP, in the contrary, with all the haters and language elitists hasn't grow outside of the web in terms of libraries ecosystem, thats why I adopted wxPHP and developed it further in order to have a working library for GUI development aside from php-gtk. Back in subject, maybe having a fully working ffi library for PHP would help to easily write bindings to C libraries, there was work on this https://pecl.php.net/package/ffi but that code is too old and doesn't compiles with new PHP versions. Some time ago I was researching it and playing with the idea of maintaining it and found that on the svn server there are some commits from 5 years ago that updated the library, and if I'm correct it compiles with php 5.5/5.6 http://svn.php.net/viewvc/pecl/ffi/trunk/ and it worked pretty well to call C functions with a basic parameters interface.

    Another alternative would be to have a PHP C binding generator that's easier to work with and that generates better interfaces than swig, so we can grow the PHP bindinds ecosystem more easily. I started working on such thing as you may have noticed on my comments and publications in what I call PEG (PHP Extension Generator) https://github.com/peg-org, the concepts of the generator are discussed on this gist https://gist.github.com/auroraeosrose/e90155727703190ab64c the work I did already generates C binding code for functions by reading doxygen xml documentation files, but the generated code is for PHP 5 and now there's PHP 7 with many internal changes on the zend engine, so another target has to be written for it. Would be great to make PEG generate code for HHVM too. And by they way, PHP 7 takes the language to a higher level with all the new features that are going to be available like scalars type hinting, twice the performance, etc... That it self should be enough to consider PHP a language suited for general purpose programming.

  5. halfer commented on Nov 22, 2015

    @halfer
    ContributorAuthor

    Thanks for your thoughts @jgmdev! I agree that PHP does tend to get a bit left behind when it comes to making general libraries available, but sometimes it is just the chicken and the egg problem: effort is not made on a particular library for PHP because there is a feeling that it wouldn't get widespread use. And so PHP developers stick to PHP just for web dev, feeding the cycle of no activity as a general-purpose language.

    However, your good work on wxPHP should help to reduce those assumptions, at least in the GUI space - an important task given that php-gtk development velocity seems to frequently stall.

    PEG sounds like a very good idea, and would certainly simplify bringing more system libraries in reach of PHP developers. However, the other challenge as I see it is to ensure the result of that cultural change (more PHP modules) actually reach the most popular distros. To take wxPHP as an example, it is not - as far as I know - in Ubuntu, and so either an wxPHP app author needs to set up an additional repo server, and risk users not trusting it, or set up a compilation step in his/her installer, with all the tricksy dependencies and edge cases this probably involves.

    As to the question at hand, I am happy to just use console tools and call them via exec - it's not the most elegant of approaches, but is fine for my purposes. In the event of my getting something working I'll create a GitHub repo for it.

    I think your analysis of AppIndicator's features being limited in comparison to wxTaskBarIcon is correct. However, in relation to wxWidgets, they would probably be best implementing it in some fashion, since the alternative is for it not to work at all, as I have discovered.

    I'll wait and see if I get any bites on my DBus question - I see Ted Gould posts over there, so if I don't get any interest in a couple of days I will ping him to see if he can shed any light. If he doesn't know the answer, it probably means there is no solution :-).

  6. halfer commented on Nov 22, 2015

    @halfer
    ContributorAuthor

    There is a work around mentioned here http://stackoverflow.com/questions/14521006/wxtaskbaricon-in-ubuntu-12-10/14545805#14545805 by calling the gsetting command, but I'm not sure if that still applies

    Sadly no, this is the thing that does not work after 13.10. At least in my 14.04, the gsetting key in that answer no longer exists. I assume the other solution I referenced would work, but I'm suspicious of needing to tinker with the trusted repo list, and I expect other users would be too.

  7. halfer commented on Nov 22, 2015

    @halfer
    ContributorAuthor

    As an alternative approach, could support for AppIndicator be added as a separate feature in wxPHP? What I mean is that rather than wxTaskBarIcon proxying to AppIndicator where it is detected as running (and possibly getting the features mapping wrong in the process) there is a separate class wxTaskBarAppIndicator which allows the app to detect whether AppIndicator is running, and if it is, to explicitly proxy to libappindicator with parameters designed for that library (so app authors select only from the features that are actually available).

    I suppose this really is trying to fill the void that PEG would be trying to fix, and now I've typed the above out, I wonder if it is conceptually the right place for it. Worth pondering, I suppose... :-)

  8. jgmdev commented on Nov 22, 2015

    @jgmdev
    Member

    A ticket was opened on wxWidgets trac system http://trac.wxwidgets.org/ticket/15644 by a wxPython user and it seems that a solution belongs to wxWidgets. From PHP side as I said before, if there was a mature FFI implementation it would be easy to interact with libappindicator and write some sort of PHP class/library wrapper to work with it, now that I remember there was a php gtk developer working on a new ffi php extension, but he said to me that doing FFI calls would be slower on huge libraries than writing a native C binding. And as you mentioned, PEG as a project if completed, would ease the generation of native bindings for C/C++ libraries which would help a lot.

  9. halfer commented on Nov 22, 2015

    @halfer
    ContributorAuthor

    OK, fair enough. I'll persist with DBus as an approach for now, and will let you know if I get anywhere with it. Thanks for your advice, much appreciated.

    Feel free to close this, unless you feel there is value in keeping it open.

  10. halfer commented on Nov 30, 2015

    @halfer
    ContributorAuthor

    I've hit on an idea to get this working in the short term, and wonder if you might have two minutes to suggest whether it is worth persisting with, or whether there is something easier?

    I've got an AppIndicator working in Python very easily (I had to install python-appindicator from the Ubuntu repository). I thought I might therefore start up a Python task to look after the task bar, and set up a bidirectional communication channel between them. PHP needs to send messages to Python to change the indicator icon, and Python would need to call PHP to handle menu clicks.

    In PHP I plan to start a wxThread where I'll listen on a Unix Socket, so it can receive messages sent by the Python app, and I expect Python will have some sort of threading system natively, so I'll set up a listener there too. However I wonder, is there something in wxPHP that will raise an event in response to a message from another app, handled in the normal wx event system? That would be a bit easier than setting up separate threads.

    If I get anything working, I'll put it on GitHub - this will probably be a bit convoluted, but better than not having AppIndicators at all!

  11. jgmdev commented on Dec 1, 2015

    @jgmdev
    Member

    Well maybe wxFileSystemWatcher could be used to monitor for changes in a file http://wxphp.org/reference/wxFileSystemWatcher.html I don't have experience setting it up but it may work. Also theres a inotify php extension which does something similar to wxFileSystemWatcher if I'm not mistaken. In any case you could setup a wxTimer and check a file modification timestamp for changes as a simple way of communication, and use file locking stuff which should be simple.

    On the other hand you can also make use of one of the following extensions: sysvsem, sysvshm, sysvmsg which I guess also works on python, in order to pass messages from one application to another.

    And finally is to use swig to generate PHP bindings of libappindicator which would be something nice to have.

  12. halfer commented on Dec 1, 2015

    @halfer
    ContributorAuthor

    Ah, wxFileSystemWatcher sounds ideal, thanks! I've been trying to set up threads, but they seem to result in frequent core dumps (I am probably doing something wrong). I'll switch to file monitoring for the short term.

  13. halfer commented on Dec 2, 2015

    @halfer
    ContributorAuthor

    wxFileSystemWatcher works perfectly on the PHP side - I'll beef up the example I have and will make it publicly available. I've now also answered the Stack Overflow question I linked to in the first report here.

  14. jgmdev commented on Dec 2, 2015

    @jgmdev
    Member

    Good to know that you had success! Would be nice to add your example on examples/filesystemwatcher.php

  15. halfer commented on Dec 10, 2015

    @halfer
    ContributorAuthor

    I think this can be closed as "not a bug".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions