v29.4-roots.2 · Commit 5: [PATCH 05/21] product: establish Roots identity and Qt experience
src/qt/wintaskbarprogress.cpp
Before: /dev/null · After: src/qt/wintaskbarprogress.cpp
File metadata
new file mode 100644 index 0000000000000000000000000000000000000000..c21684245b0f923ec80a1ab3fedf4ea8b3168954
Download original patch · Release notes
Diff rows 1–102 of 102. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/qt/wintaskbarprogress.cpp
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2025 The Bitcoin Roots developers
|
| 2 |
+
// Distributed under the MIT software license, see the accompanying
|
| 3 |
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 4 |
+
|
| 5 |
+
#include <qt/wintaskbarprogress.h>
|
| 6 |
+
|
| 7 |
+
#include <QWidget>
|
| 8 |
+
#include <QWindow>
|
| 9 |
+
|
| 10 |
+
#include <windows.h>
|
| 11 |
+
#include <shobjidl.h>
|
| 12 |
+
|
| 13 |
+
WinTaskbarProgress::WinTaskbarProgress(QObject* parent)
|
| 14 |
+
: QObject(parent),
|
| 15 |
+
m_taskbar_button_created_msg(RegisterWindowMessageW(L"TaskbarButtonCreated"))
|
| 16 |
+
{
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
WinTaskbarProgress::~WinTaskbarProgress()
|
| 20 |
+
{
|
| 21 |
+
releaseTaskbarButton();
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
void WinTaskbarProgress::setWindow(QWidget* widget)
|
| 25 |
+
{
|
| 26 |
+
QWindow* window = widget ? widget->windowHandle() : nullptr;
|
| 27 |
+
if (!window || m_window == window) return;
|
| 28 |
+
|
| 29 |
+
m_window = window;
|
| 30 |
+
initTaskbarButton();
|
| 31 |
+
updateProgress();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
void WinTaskbarProgress::setValue(int value)
|
| 35 |
+
{
|
| 36 |
+
if (m_value == value) return;
|
| 37 |
+
m_value = value;
|
| 38 |
+
updateProgress();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
void WinTaskbarProgress::setVisible(bool visible)
|
| 42 |
+
{
|
| 43 |
+
if (m_visible == visible) return;
|
| 44 |
+
m_visible = visible;
|
| 45 |
+
updateProgress();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void WinTaskbarProgress::updateProgress()
|
| 49 |
+
{
|
| 50 |
+
if (!m_taskbar_button || !m_window) return;
|
| 51 |
+
|
| 52 |
+
const HWND hwnd{reinterpret_cast<HWND>(m_window->winId())};
|
| 53 |
+
if (m_visible) {
|
| 54 |
+
m_taskbar_button->SetProgressValue(hwnd, m_value, 100);
|
| 55 |
+
m_taskbar_button->SetProgressState(hwnd, TBPF_NORMAL);
|
| 56 |
+
} else {
|
| 57 |
+
m_taskbar_button->SetProgressState(hwnd, TBPF_NOPROGRESS);
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void WinTaskbarProgress::initTaskbarButton()
|
| 62 |
+
{
|
| 63 |
+
if (m_taskbar_button || !m_window || !m_taskbar_ready) return;
|
| 64 |
+
|
| 65 |
+
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER,
|
| 66 |
+
IID_PPV_ARGS(&m_taskbar_button));
|
| 67 |
+
if (SUCCEEDED(hr)) {
|
| 68 |
+
hr = m_taskbar_button->HrInit();
|
| 69 |
+
if (FAILED(hr)) {
|
| 70 |
+
m_taskbar_button->Release();
|
| 71 |
+
m_taskbar_button = nullptr;
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
void WinTaskbarProgress::releaseTaskbarButton()
|
| 77 |
+
{
|
| 78 |
+
if (m_taskbar_button) {
|
| 79 |
+
m_taskbar_button->Release();
|
| 80 |
+
m_taskbar_button = nullptr;
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
| 85 |
+
bool WinTaskbarProgress::nativeEventFilter(const QByteArray& event_type, void* message, qintptr* result)
|
| 86 |
+
#else
|
| 87 |
+
bool WinTaskbarProgress::nativeEventFilter(const QByteArray& event_type, void* message, long* result)
|
| 88 |
+
#endif
|
| 89 |
+
{
|
| 90 |
+
Q_UNUSED(result);
|
| 91 |
+
if (event_type != "windows_generic_MSG" && event_type != "windows_dispatcher_MSG") return false;
|
| 92 |
+
|
| 93 |
+
const MSG* msg{static_cast<MSG*>(message)};
|
| 94 |
+
if (m_taskbar_button_created_msg != 0 && msg->message == m_taskbar_button_created_msg) {
|
| 95 |
+
m_taskbar_ready = true;
|
| 96 |
+
if (m_window) {
|
| 97 |
+
initTaskbarButton();
|
| 98 |
+
updateProgress();
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
return false;
|
| 102 |
+
}
|