Fix windows thumbbar

This commit is contained in:
Jonas Kvinge
2019-08-29 21:32:52 +02:00
parent 9b45f0661e
commit b7e13c7b86
4 changed files with 31 additions and 28 deletions

View File

@@ -110,7 +110,6 @@ set(SOURCES
core/qtsystemtrayicon.cpp core/qtsystemtrayicon.cpp
core/standarditemiconloader.cpp core/standarditemiconloader.cpp
core/systemtrayicon.cpp core/systemtrayicon.cpp
core/windows7thumbbar.cpp
core/screensaver.cpp core/screensaver.cpp
core/scopedtransaction.cpp core/scopedtransaction.cpp
core/translations.cpp core/translations.cpp
@@ -308,7 +307,6 @@ set(HEADERS
core/qtsystemtrayicon.h core/qtsystemtrayicon.h
core/standarditemiconloader.h core/standarditemiconloader.h
core/systemtrayicon.h core/systemtrayicon.h
core/windows7thumbbar.h
core/mimedata.h core/mimedata.h
engine/enginebase.h engine/enginebase.h
@@ -875,6 +873,9 @@ optional_source(WIN32
SOURCES SOURCES
engine/directsounddevicefinder.cpp engine/directsounddevicefinder.cpp
widgets/osd_win.cpp widgets/osd_win.cpp
core/windows7thumbbar.cpp
HEADERS
core/windows7thumbbar.h
) )
optional_source(HAVE_TIDAL optional_source(HAVE_TIDAL

View File

@@ -74,7 +74,6 @@
#include "stylehelper.h" #include "stylehelper.h"
#include "stylesheetloader.h" #include "stylesheetloader.h"
#include "systemtrayicon.h" #include "systemtrayicon.h"
#include "windows7thumbbar.h"
#include "application.h" #include "application.h"
#include "database.h" #include "database.h"
#include "player.h" #include "player.h"
@@ -167,6 +166,10 @@
# include "moodbar/moodbarproxystyle.h" # include "moodbar/moodbarproxystyle.h"
#endif #endif
#ifdef Q_OS_WIN
# include "windows7thumbbar.h"
#endif
using std::bind; using std::bind;
using std::floor; using std::floor;
using std::stable_sort; 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) : MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, const CommandlineOptions &options, QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui_(new Ui_MainWindow), ui_(new Ui_MainWindow),
#ifdef Q_OS_WIN
thumbbar_(new Windows7ThumbBar(this)), thumbbar_(new Windows7ThumbBar(this)),
#endif
app_(app), app_(app),
tray_icon_(tray_icon), tray_icon_(tray_icon),
osd_(osd), osd_(osd),
@@ -662,7 +667,9 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
} }
// Windows 7 thumbbar buttons // Windows 7 thumbbar buttons
#ifdef Q_OS_WIN
thumbbar_->SetActions(QList<QAction*>() << ui_->action_previous_track << ui_->action_play_pause << ui_->action_stop << ui_->action_next_track << nullptr << ui_->action_love); thumbbar_->SetActions(QList<QAction*>() << 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)) #if (defined(Q_OS_MACOS) && defined(HAVE_SPARKLE))
// Add check for updates item to application menu. // Add check for updates item to application menu.
@@ -2389,12 +2396,15 @@ void MainWindow::Raise() {
activateWindow(); activateWindow();
} }
#ifdef Q_OS_WIN32 bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) {
bool MainWindow::winEvent(MSG *msg, long*) {
#ifdef Q_OS_WIN
MSG *msg = static_cast<MSG*>(message);
thumbbar_->HandleWinEvent(msg); thumbbar_->HandleWinEvent(msg);
#endif
return false; return false;
} }
#endif // Q_OS_WIN32
#if defined(HAVE_GSTREAMER) && defined(HAVE_CHROMAPRINT) #if defined(HAVE_GSTREAMER) && defined(HAVE_CHROMAPRINT)
void MainWindow::AutoCompleteTags() { void MainWindow::AutoCompleteTags() {

View File

@@ -90,9 +90,11 @@ class TrackSelectionDialog;
class TranscodeDialog; class TranscodeDialog;
#endif #endif
class Ui_MainWindow; class Ui_MainWindow;
class Windows7ThumbBar;
class InternetSongsView; class InternetSongsView;
class InternetTabsView; class InternetTabsView;
#ifdef Q_OS_WIN
class Windows7ThumbBar;
#endif
class MainWindow : public QMainWindow, public PlatformInterface { class MainWindow : public QMainWindow, public PlatformInterface {
Q_OBJECT Q_OBJECT
@@ -117,10 +119,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
protected: protected:
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
#ifdef Q_OS_WIN
bool winEvent(MSG *message, long *result);
#endif
// PlatformInterface // PlatformInterface
void Activate(); void Activate();
@@ -284,7 +283,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
private: private:
Ui_MainWindow *ui_; Ui_MainWindow *ui_;
#ifdef Q_OS_WIN
Windows7ThumbBar *thumbbar_; Windows7ThumbBar *thumbbar_;
#endif
Application *app_; Application *app_;
SystemTrayIcon *tray_icon_; SystemTrayIcon *tray_icon_;

View File

@@ -27,15 +27,13 @@
#include <QAction> #include <QAction>
#include <QtDebug> #include <QtDebug>
#ifdef Q_OS_WIN32 #ifndef _WIN32_WINNT
#ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0600
#define _WIN32_WINNT 0x0600 #endif
#endif #include <windows.h>
#include <windows.h> #include <commctrl.h>
#include <commctrl.h> #include <shobjidl.h>
#include <shobjidl.h> extern HICON qt_pixmapToWinHICON(const QPixmap &p);
extern HICON qt_pixmapToWinHICON(const QPixmap &p);
#endif // Q_OS_WIN32
#include "core/logging.h" #include "core/logging.h"
#include "windows7thumbbar.h" #include "windows7thumbbar.h"
@@ -51,7 +49,6 @@ Windows7ThumbBar::Windows7ThumbBar(QWidget *widget)
void Windows7ThumbBar::SetActions(const QList<QAction*>& actions) { void Windows7ThumbBar::SetActions(const QList<QAction*>& actions) {
#ifdef Q_OS_WIN32
qLog(Debug) << "Setting actions"; qLog(Debug) << "Setting actions";
Q_ASSERT(actions.count() <= kMaxButtonCount); Q_ASSERT(actions.count() <= kMaxButtonCount);
@@ -62,11 +59,9 @@ void Windows7ThumbBar::SetActions(const QList<QAction*>& actions) {
} }
} }
qLog(Debug) << "Done"; qLog(Debug) << "Done";
#endif // Q_OS_WIN32
} }
#ifdef Q_OS_WIN32
static void SetupButton(const QAction *action, THUMBBUTTON *button) { static void SetupButton(const QAction *action, THUMBBUTTON *button) {
if (action) { if (action) {
@@ -87,12 +82,11 @@ static void SetupButton(const QAction *action, THUMBBUTTON *button) {
button->dwFlags = THBF_NOBACKGROUND; button->dwFlags = THBF_NOBACKGROUND;
button->dwMask = THUMBBUTTONMASK(THB_FLAGS); button->dwMask = THUMBBUTTONMASK(THB_FLAGS);
} }
} }
#endif // Q_OS_WIN32
void Windows7ThumbBar::HandleWinEvent(MSG *msg) { void Windows7ThumbBar::HandleWinEvent(MSG *msg) {
#ifdef Q_OS_WIN32
if (button_created_message_id_ == 0) { if (button_created_message_id_ == 0) {
// Compute the value for the TaskbarButtonCreated message // Compute the value for the TaskbarButtonCreated message
button_created_message_id_ = RegisterWindowMessage("TaskbarButtonCreated"); button_created_message_id_ = RegisterWindowMessage("TaskbarButtonCreated");
@@ -155,13 +149,11 @@ void Windows7ThumbBar::HandleWinEvent(MSG *msg) {
} }
} }
} }
#endif // Q_OS_WIN32
} }
void Windows7ThumbBar::ActionChanged() { void Windows7ThumbBar::ActionChanged() {
#ifdef Q_OS_WIN32
if (!taskbar_list_) return; if (!taskbar_list_) return;
ITaskbarList3 *taskbar_list = reinterpret_cast<ITaskbarList3*>(taskbar_list_); ITaskbarList3 *taskbar_list = reinterpret_cast<ITaskbarList3*>(taskbar_list_);
@@ -176,6 +168,5 @@ void Windows7ThumbBar::ActionChanged() {
} }
taskbar_list->ThumbBarUpdateButtons((HWND)widget_->winId(), actions_.count(), buttons); taskbar_list->ThumbBarUpdateButtons((HWND)widget_->winId(), actions_.count(), buttons);
#endif // Q_OS_WIN32
} }