Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statusicon-qt: Set proper tooltip #147

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 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 @@ -161,7 +164,10 @@ bool SystemTrayIcon::event (QEvent * e)
{
case QEvent::ToolTip:
if (! aud_get_bool ("statusicon", "disable_popup"))
{
setToolTip (QString ()); /* prevent double tooltip */
audqt::infopopup_show_current ();
}
return true;

case QEvent::Wheel:
Expand All @@ -188,13 +194,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 +225,12 @@ void StatusIcon::cleanup ()
audqt::cleanup ();
}

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

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