Skip to content

Commit

Permalink
statusicon-qt: Set basic tooltip
Browse files Browse the repository at this point in the history
Even though we override the QSystemTrayIcon::event() method,
it is never called by Qt (at least on Linux). And therefore our
custom info popop is not shown. Set a proper tooltip as workaround.
  • Loading branch information
radioactiveman committed Dec 29, 2023
1 parent 9dbbf3f commit 61000d5
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/statusicon-qt/statusicon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* the use of this software.
*/

#include <libaudcore/i18n.h>
#include <libaudcore/drct.h>
#include <libaudcore/hook.h>
#include <libaudcore/plugin.h>
#include <libaudcore/runtime.h>
#include <libaudcore/i18n.h>
#include <libaudcore/interface.h>
#include <libaudcore/plugin.h>
#include <libaudcore/preferences.h>
#include <libaudcore/runtime.h>

#include <libaudqt/menu.h>

Expand All @@ -32,7 +32,8 @@
#include <QSystemTrayIcon>
#include <QWheelEvent>

class StatusIcon : public GeneralPlugin {
class StatusIcon : public GeneralPlugin
{
public:
static const char about[];
static const char * const defaults[];
Expand All @@ -53,6 +54,8 @@ class StatusIcon : public GeneralPlugin {
bool init ();
void cleanup ();

private:
static void update_tooltip (void * data, void * user_data);
static void window_closed (void * data, void * user_data);
static void activate (QSystemTrayIcon::ActivationReason);
static void open_files ();
Expand Down Expand Up @@ -188,13 +191,21 @@ bool StatusIcon::init ()
tray->setContextMenu (menu);
tray->show ();

update_tooltip (nullptr, nullptr);

hook_associate ("title change", update_tooltip, nullptr);
hook_associate ("playback ready", update_tooltip, nullptr);
hook_associate ("playback stop", update_tooltip, nullptr);
hook_associate ("window close", window_closed, nullptr);

return true;
}

void StatusIcon::cleanup ()
{
hook_dissociate ("title change", update_tooltip);
hook_dissociate ("playback ready", update_tooltip);
hook_dissociate ("playback stop", update_tooltip);
hook_dissociate ("window close", window_closed);

/* Prevent accidentally hiding the interface by disabling
Expand All @@ -211,6 +222,12 @@ void StatusIcon::cleanup ()
audqt::cleanup ();
}

void StatusIcon::update_tooltip (void * data, void * user_data)
{
const char * title = aud_drct_get_title ();
tray->setToolTip (title);
}

void StatusIcon::window_closed (void * data, void * user_data)
{
bool * handled = (bool *) data;
Expand Down

0 comments on commit 61000d5

Please sign in to comment.