-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform_win.cpp
121 lines (101 loc) · 3.7 KB
/
platform_win.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2022-present Contributors to the jobman project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/mikaelsundell/jobman
#include "platform.h"
#include <QApplication>
#include <QScreen>
#include <windows.h>
#include <wingdi.h>
#include <debugapi.h>
namespace platform
{
namespace utils {
QPointF toNativeCursor(int x, int y) {
Q_UNUSED(x);
Q_UNUSED(y);
QPoint globalPos = QCursor::pos();
return QPointF(globalPos.x(), globalPos.y());
}
struct IccProfileData {
QString profilePath;
IccProfileData() : profilePath() {}
};
QMap<uint32_t, IccProfileData> iccCache;
IccProfileData grabIccProfileData() {
IccProfileData iccProfile;
HDC hdc = GetDC(nullptr);
if (hdc) {
DWORD pathSize = MAX_PATH;
WCHAR iccPath[MAX_PATH];
BOOL result = GetICMProfileW(hdc, &pathSize, iccPath);
if (result) {
iccProfile.profilePath = QString::fromWCharArray(iccPath);
}
ReleaseDC(nullptr, hdc);
}
return iccProfile;
}
IccProfileData grabDisplayProfile() {
uint32_t displayId = 0;
if (iccCache.contains(displayId)) {
return iccCache.value(displayId);
}
IccProfileData iccProfile = grabIccProfileData();
iccCache.insert(displayId, iccProfile);
return iccProfile;
}
}
void setDarkTheme() {
}
IccProfile grabIccProfile(WId wid) {
Q_UNUSED(wid);
utils::IccProfileData iccData = utils::grabDisplayProfile();
return IccProfile{
0, // Screen number (always 0 for primary display)
iccData.profilePath
};
}
QString getIccProfileUrl(WId wid) {
return grabIccProfile(wid).displayProfileUrl;
}
QString getApplicationPath() {
return QApplication::applicationDirPath();
}
QString resolveBookmark(const QString& bookmark) {
return bookmark; // ignore on win32
}
QString saveBookmark(const QString& bookmark) {
return bookmark; // ignore on win32
}
double getCpuUsage() {
static FILETIME prevIdleTime, prevKernelTime, prevUserTime;
FILETIME idleTime, kernelTime, userTime;
if (GetSystemTimes(&idleTime, &kernelTime, &userTime) == 0) {
return -1.0;
}
ULARGE_INTEGER idle, kernel, user;
idle.LowPart = idleTime.dwLowDateTime;
idle.HighPart = idleTime.dwHighDateTime;
kernel.LowPart = kernelTime.dwLowDateTime;
kernel.HighPart = kernelTime.dwHighDateTime;
user.LowPart = userTime.dwLowDateTime;
user.HighPart = userTime.dwHighDateTime;
ULARGE_INTEGER prevIdle, prevKernel, prevUser;
prevIdle.LowPart = prevIdleTime.dwLowDateTime;
prevIdle.HighPart = prevIdleTime.dwHighDateTime;
prevKernel.LowPart = prevKernelTime.dwLowDateTime;
prevKernel.HighPart = prevKernelTime.dwHighDateTime;
prevUser.LowPart = prevUserTime.dwLowDateTime;
prevUser.HighPart = prevUserTime.dwHighDateTime;
ULONGLONG idleDiff = idle.QuadPart - prevIdle.QuadPart;
ULONGLONG kernelDiff = kernel.QuadPart - prevKernel.QuadPart;
ULONGLONG userDiff = user.QuadPart - prevUser.QuadPart;
ULONGLONG totalDiff = kernelDiff + userDiff;
prevIdleTime = idleTime;
prevKernelTime = kernelTime;
prevUserTime = userTime;
if (totalDiff == 0) return 0.0;
double cpuUsage = (totalDiff - idleDiff) * 100.0 / totalDiff;
return cpuUsage;
}
}