From b7e13c7b86bb2044eee26ef1e6c2c801c76e3536 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Thu, 29 Aug 2019 21:32:52 +0200 Subject: [PATCH] Fix windows thumbbar --- src/CMakeLists.txt | 5 +++-- src/core/mainwindow.cpp | 18 ++++++++++++++---- src/core/mainwindow.h | 11 ++++++----- src/core/windows7thumbbar.cpp | 25 ++++++++----------------- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7817acfa1..9d8d9b492 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -110,7 +110,6 @@ set(SOURCES core/qtsystemtrayicon.cpp core/standarditemiconloader.cpp core/systemtrayicon.cpp - core/windows7thumbbar.cpp core/screensaver.cpp core/scopedtransaction.cpp core/translations.cpp @@ -308,7 +307,6 @@ set(HEADERS core/qtsystemtrayicon.h core/standarditemiconloader.h core/systemtrayicon.h - core/windows7thumbbar.h core/mimedata.h engine/enginebase.h @@ -875,6 +873,9 @@ optional_source(WIN32 SOURCES engine/directsounddevicefinder.cpp widgets/osd_win.cpp + core/windows7thumbbar.cpp + HEADERS + core/windows7thumbbar.h ) optional_source(HAVE_TIDAL diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 7fa24e6b0..8db086152 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -74,7 +74,6 @@ #include "stylehelper.h" #include "stylesheetloader.h" #include "systemtrayicon.h" -#include "windows7thumbbar.h" #include "application.h" #include "database.h" #include "player.h" @@ -167,6 +166,10 @@ # include "moodbar/moodbarproxystyle.h" #endif +#ifdef Q_OS_WIN +# include "windows7thumbbar.h" +#endif + using std::bind; using std::floor; using std::stable_sort; @@ -182,7 +185,9 @@ const int kTrackPositionUpdateTimeMs = 1000; MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, const CommandlineOptions &options, QWidget *parent) : QMainWindow(parent), ui_(new Ui_MainWindow), +#ifdef Q_OS_WIN thumbbar_(new Windows7ThumbBar(this)), +#endif app_(app), tray_icon_(tray_icon), osd_(osd), @@ -662,7 +667,9 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co } // Windows 7 thumbbar buttons +#ifdef Q_OS_WIN thumbbar_->SetActions(QList() << ui_->action_previous_track << ui_->action_play_pause << ui_->action_stop << ui_->action_next_track << nullptr << ui_->action_love); +#endif #if (defined(Q_OS_MACOS) && defined(HAVE_SPARKLE)) // Add check for updates item to application menu. @@ -2389,12 +2396,15 @@ void MainWindow::Raise() { activateWindow(); } -#ifdef Q_OS_WIN32 -bool MainWindow::winEvent(MSG *msg, long*) { +bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) { + +#ifdef Q_OS_WIN + MSG *msg = static_cast(message); thumbbar_->HandleWinEvent(msg); +#endif return false; + } -#endif // Q_OS_WIN32 #if defined(HAVE_GSTREAMER) && defined(HAVE_CHROMAPRINT) void MainWindow::AutoCompleteTags() { diff --git a/src/core/mainwindow.h b/src/core/mainwindow.h index 32d79a5ec..9add8543a 100644 --- a/src/core/mainwindow.h +++ b/src/core/mainwindow.h @@ -90,9 +90,11 @@ class TrackSelectionDialog; class TranscodeDialog; #endif class Ui_MainWindow; -class Windows7ThumbBar; class InternetSongsView; class InternetTabsView; +#ifdef Q_OS_WIN +class Windows7ThumbBar; +#endif class MainWindow : public QMainWindow, public PlatformInterface { Q_OBJECT @@ -117,10 +119,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { protected: void keyPressEvent(QKeyEvent *event); void closeEvent(QCloseEvent *event); - -#ifdef Q_OS_WIN - bool winEvent(MSG *message, long *result); -#endif + bool nativeEvent(const QByteArray &eventType, void *message, long *result); // PlatformInterface void Activate(); @@ -284,7 +283,9 @@ class MainWindow : public QMainWindow, public PlatformInterface { private: Ui_MainWindow *ui_; +#ifdef Q_OS_WIN Windows7ThumbBar *thumbbar_; +#endif Application *app_; SystemTrayIcon *tray_icon_; diff --git a/src/core/windows7thumbbar.cpp b/src/core/windows7thumbbar.cpp index 19e310538..1e8d2d364 100644 --- a/src/core/windows7thumbbar.cpp +++ b/src/core/windows7thumbbar.cpp @@ -27,15 +27,13 @@ #include #include -#ifdef Q_OS_WIN32 - #ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0600 - #endif - #include - #include - #include - extern HICON qt_pixmapToWinHICON(const QPixmap &p); -#endif // Q_OS_WIN32 +#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0600 +#endif +#include +#include +#include +extern HICON qt_pixmapToWinHICON(const QPixmap &p); #include "core/logging.h" #include "windows7thumbbar.h" @@ -51,7 +49,6 @@ Windows7ThumbBar::Windows7ThumbBar(QWidget *widget) void Windows7ThumbBar::SetActions(const QList& actions) { -#ifdef Q_OS_WIN32 qLog(Debug) << "Setting actions"; Q_ASSERT(actions.count() <= kMaxButtonCount); @@ -62,11 +59,9 @@ void Windows7ThumbBar::SetActions(const QList& actions) { } } qLog(Debug) << "Done"; -#endif // Q_OS_WIN32 } -#ifdef Q_OS_WIN32 static void SetupButton(const QAction *action, THUMBBUTTON *button) { if (action) { @@ -87,12 +82,11 @@ static void SetupButton(const QAction *action, THUMBBUTTON *button) { button->dwFlags = THBF_NOBACKGROUND; button->dwMask = THUMBBUTTONMASK(THB_FLAGS); } + } -#endif // Q_OS_WIN32 void Windows7ThumbBar::HandleWinEvent(MSG *msg) { -#ifdef Q_OS_WIN32 if (button_created_message_id_ == 0) { // Compute the value for the TaskbarButtonCreated message button_created_message_id_ = RegisterWindowMessage("TaskbarButtonCreated"); @@ -155,13 +149,11 @@ void Windows7ThumbBar::HandleWinEvent(MSG *msg) { } } } -#endif // Q_OS_WIN32 } void Windows7ThumbBar::ActionChanged() { -#ifdef Q_OS_WIN32 if (!taskbar_list_) return; ITaskbarList3 *taskbar_list = reinterpret_cast(taskbar_list_); @@ -176,6 +168,5 @@ void Windows7ThumbBar::ActionChanged() { } taskbar_list->ThumbBarUpdateButtons((HWND)widget_->winId(), actions_.count(), buttons); -#endif // Q_OS_WIN32 }