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/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

View File

@@ -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<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))
// 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<MSG*>(message);
thumbbar_->HandleWinEvent(msg);
#endif
return false;
}
#endif // Q_OS_WIN32
#if defined(HAVE_GSTREAMER) && defined(HAVE_CHROMAPRINT)
void MainWindow::AutoCompleteTags() {

View File

@@ -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_;

View File

@@ -27,15 +27,13 @@
#include <QAction>
#include <QtDebug>
#ifdef Q_OS_WIN32
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include <windows.h>
#include <commctrl.h>
#include <shobjidl.h>
extern HICON qt_pixmapToWinHICON(const QPixmap &p);
#endif // Q_OS_WIN32
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include <windows.h>
#include <commctrl.h>
#include <shobjidl.h>
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<QAction*>& actions) {
#ifdef Q_OS_WIN32
qLog(Debug) << "Setting actions";
Q_ASSERT(actions.count() <= kMaxButtonCount);
@@ -62,11 +59,9 @@ void Windows7ThumbBar::SetActions(const QList<QAction*>& 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<ITaskbarList3*>(taskbar_list_);
@@ -176,6 +168,5 @@ void Windows7ThumbBar::ActionChanged() {
}
taskbar_list->ThumbBarUpdateButtons((HWND)widget_->winId(), actions_.count(), buttons);
#endif // Q_OS_WIN32
}