forked from github_mirror/framelesshelper
Minor improvement.
It turns out that the final title bar height contains the border height as well. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
1822333268
commit
9cd7e368de
|
@ -7,9 +7,27 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>423</width>
|
<width>423</width>
|
||||||
<height>26</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>31</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>31</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">#iconButton, #minimizeButton, #maximizeButton, #closeButton {
|
<string notr="true">#iconButton, #minimizeButton, #maximizeButton, #closeButton {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
@ -44,7 +62,7 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
@ -127,13 +145,13 @@
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>26</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>26</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
|
@ -152,7 +170,7 @@
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>30</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -168,13 +186,13 @@
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>26</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>26</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
|
@ -194,7 +212,7 @@
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>30</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
|
@ -213,13 +231,13 @@
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>26</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>26</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
|
@ -238,7 +256,7 @@
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
<size>
|
<size>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>30</height>
|
<height>31</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -199,7 +199,7 @@ void Widget::setupUi()
|
||||||
sizePolicy1.setVerticalStretch(0);
|
sizePolicy1.setVerticalStretch(0);
|
||||||
sizePolicy1.setHeightForWidth(minimizeButton->sizePolicy().hasHeightForWidth());
|
sizePolicy1.setHeightForWidth(minimizeButton->sizePolicy().hasHeightForWidth());
|
||||||
minimizeButton->setSizePolicy(sizePolicy1);
|
minimizeButton->setSizePolicy(sizePolicy1);
|
||||||
const QSize systemButtonSize = {45, 30};
|
const QSize systemButtonSize = {qRound(titleBarHeight * 1.5), titleBarHeight};
|
||||||
minimizeButton->setMinimumSize(systemButtonSize);
|
minimizeButton->setMinimumSize(systemButtonSize);
|
||||||
minimizeButton->setMaximumSize(systemButtonSize);
|
minimizeButton->setMaximumSize(systemButtonSize);
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
|
|
|
@ -2181,6 +2181,7 @@ int WinNativeEventFilter::getSystemMetric(void *handle,
|
||||||
Q_ASSERT(handle);
|
Q_ASSERT(handle);
|
||||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||||
const qreal dpr = dpiAware ? GetDevicePixelRatioForWindow(hwnd) : m_defaultDevicePixelRatio;
|
const qreal dpr = dpiAware ? GetDevicePixelRatioForWindow(hwnd) : m_defaultDevicePixelRatio;
|
||||||
|
int ret = 0;
|
||||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||||
createUserData(hwnd);
|
createUserData(hwnd);
|
||||||
const auto userData = reinterpret_cast<WINDOWDATA *>(
|
const auto userData = reinterpret_cast<WINDOWDATA *>(
|
||||||
|
@ -2189,7 +2190,7 @@ int WinNativeEventFilter::getSystemMetric(void *handle,
|
||||||
case SystemMetric::BorderWidth: {
|
case SystemMetric::BorderWidth: {
|
||||||
const int bw = userData->borderWidth;
|
const int bw = userData->borderWidth;
|
||||||
if (bw > 0) {
|
if (bw > 0) {
|
||||||
return qRound(bw * dpr);
|
ret = qRound(bw * dpr);
|
||||||
} else {
|
} else {
|
||||||
const int result_nondpi
|
const int result_nondpi
|
||||||
= WNEF_EXECUTE_WINAPI_RETURN(GetSystemMetrics, 0, SM_CXSIZEFRAME)
|
= WNEF_EXECUTE_WINAPI_RETURN(GetSystemMetrics, 0, SM_CXSIZEFRAME)
|
||||||
|
@ -2197,13 +2198,13 @@ int WinNativeEventFilter::getSystemMetric(void *handle,
|
||||||
const int result_dpi = GetSystemMetricsForWindow(hwnd, SM_CXSIZEFRAME)
|
const int result_dpi = GetSystemMetricsForWindow(hwnd, SM_CXSIZEFRAME)
|
||||||
+ GetSystemMetricsForWindow(hwnd, SM_CXPADDEDBORDER);
|
+ GetSystemMetricsForWindow(hwnd, SM_CXPADDEDBORDER);
|
||||||
const int result = dpiAware ? result_dpi : result_nondpi;
|
const int result = dpiAware ? result_dpi : result_nondpi;
|
||||||
return result > 0 ? result : qRound(m_defaultBorderWidth * dpr);
|
ret = result > 0 ? result : qRound(m_defaultBorderWidth * dpr);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
case SystemMetric::BorderHeight: {
|
case SystemMetric::BorderHeight: {
|
||||||
const int bh = userData->borderHeight;
|
const int bh = userData->borderHeight;
|
||||||
if (bh > 0) {
|
if (bh > 0) {
|
||||||
return qRound(bh * dpr);
|
ret = qRound(bh * dpr);
|
||||||
} else {
|
} else {
|
||||||
const int result_nondpi
|
const int result_nondpi
|
||||||
= WNEF_EXECUTE_WINAPI_RETURN(GetSystemMetrics, 0, SM_CYSIZEFRAME)
|
= WNEF_EXECUTE_WINAPI_RETURN(GetSystemMetrics, 0, SM_CYSIZEFRAME)
|
||||||
|
@ -2211,45 +2212,61 @@ int WinNativeEventFilter::getSystemMetric(void *handle,
|
||||||
const int result_dpi = GetSystemMetricsForWindow(hwnd, SM_CYSIZEFRAME)
|
const int result_dpi = GetSystemMetricsForWindow(hwnd, SM_CYSIZEFRAME)
|
||||||
+ GetSystemMetricsForWindow(hwnd, SM_CXPADDEDBORDER);
|
+ GetSystemMetricsForWindow(hwnd, SM_CXPADDEDBORDER);
|
||||||
const int result = dpiAware ? result_dpi : result_nondpi;
|
const int result = dpiAware ? result_dpi : result_nondpi;
|
||||||
return result > 0 ? result : qRound(m_defaultBorderHeight * dpr);
|
ret = result > 0 ? result : qRound(m_defaultBorderHeight * dpr);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
case SystemMetric::TitleBarHeight: {
|
case SystemMetric::TitleBarHeight: {
|
||||||
const int tbh = userData->titleBarHeight;
|
const int tbh = userData->titleBarHeight;
|
||||||
if (tbh > 0) {
|
if (tbh > 0) {
|
||||||
return qRound(tbh * dpr);
|
ret = qRound(tbh * dpr);
|
||||||
} else {
|
} else {
|
||||||
const int result_nondpi = WNEF_EXECUTE_WINAPI_RETURN(GetSystemMetrics,
|
const int result_nondpi = WNEF_EXECUTE_WINAPI_RETURN(GetSystemMetrics,
|
||||||
0,
|
0,
|
||||||
SM_CYCAPTION);
|
SM_CYCAPTION);
|
||||||
const int result_dpi = GetSystemMetricsForWindow(hwnd, SM_CYCAPTION);
|
const int result_dpi = GetSystemMetricsForWindow(hwnd, SM_CYCAPTION);
|
||||||
const int result = dpiAware ? result_dpi : result_nondpi;
|
const int result = dpiAware ? result_dpi : result_nondpi;
|
||||||
return result > 0 ? result : qRound(m_defaultTitleBarHeight * dpr);
|
ret = result > 0 ? result : qRound(m_defaultTitleBarHeight * dpr);
|
||||||
}
|
}
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
// When dpr = 1.0 (DPI = 96):
|
||||||
|
// SM_CXSIZEFRAME = SM_CYSIZEFRAME = 4px
|
||||||
|
// SM_CXPADDEDBORDER = 4px
|
||||||
|
// SM_CYCAPTION = 23px
|
||||||
|
// Border Width = Border Height = SM_C(X|Y)SIZEFRAME + SM_CXPADDEDBORDER = 8px
|
||||||
|
// Title Bar Height = Border Height + SM_CYCAPTION = 31px
|
||||||
|
// dpr = 1.25 --> Title Bar Height = 38px
|
||||||
|
// dpr = 1.5 --> Title Bar Height = 45px
|
||||||
|
// dpr = 1.75 --> Title Bar Height = 51px
|
||||||
|
ret += (metric == SystemMetric::TitleBarHeight)
|
||||||
|
? getSystemMetric(handle, SystemMetric::BorderHeight, dpiAware)
|
||||||
|
: 0;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
switch (metric) {
|
switch (metric) {
|
||||||
case SystemMetric::BorderWidth:
|
case SystemMetric::BorderWidth: {
|
||||||
if (coreData()->m_borderWidth > 0) {
|
if (coreData()->m_borderWidth > 0) {
|
||||||
return qRound(coreData()->m_borderWidth * dpr);
|
ret = qRound(coreData()->m_borderWidth * dpr);
|
||||||
} else {
|
} else {
|
||||||
return qRound(m_defaultBorderWidth * dpr);
|
ret = qRound(m_defaultBorderWidth * dpr);
|
||||||
}
|
}
|
||||||
case SystemMetric::BorderHeight:
|
} break;
|
||||||
|
case SystemMetric::BorderHeight: {
|
||||||
if (coreData()->m_borderHeight > 0) {
|
if (coreData()->m_borderHeight > 0) {
|
||||||
return qRound(coreData()->m_borderHeight * dpr);
|
ret = qRound(coreData()->m_borderHeight * dpr);
|
||||||
} else {
|
} else {
|
||||||
return qRound(m_defaultBorderHeight * dpr);
|
ret = qRound(m_defaultBorderHeight * dpr);
|
||||||
}
|
}
|
||||||
case SystemMetric::TitleBarHeight:
|
} break;
|
||||||
|
case SystemMetric::TitleBarHeight: {
|
||||||
if (coreData()->m_titleBarHeight > 0) {
|
if (coreData()->m_titleBarHeight > 0) {
|
||||||
return qRound(coreData()->m_titleBarHeight * dpr);
|
ret = qRound(coreData()->m_titleBarHeight * dpr);
|
||||||
} else {
|
} else {
|
||||||
return qRound(m_defaultTitleBarHeight * dpr);
|
ret = qRound(m_defaultTitleBarHeight * dpr);
|
||||||
}
|
}
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinNativeEventFilter::setWindowGeometry(
|
void WinNativeEventFilter::setWindowGeometry(
|
||||||
|
|
Loading…
Reference in New Issue