[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: properly handle clicking on csd buttons on windows
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Oct 29 06:04:05 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
9dbb3612 by Fatih Uzunoglu at 2024-10-29T05:35:35+00:00
qt: properly handle clicking on csd buttons on windows
Although it depends on the platform whether press or
release triggers the click action, on Windows press
has never been considered as click.
It is not clear why `WM_NCLBUTTONDOWN` was used to
click here. `WM_NCLBUTTONUP` should have been used
to trigger the click action.
- - - - -
89273dbb by Fatih Uzunoglu at 2024-10-29T05:35:35+00:00
qt: fix hover handling of csd buttons on windows
- WM_NCHITTEST handler should not unconditionally unset
hover status of all buttons. It does not make sense to
alter hover status during hit testing.
- WM_NCMOUSEMOVE should set the hover status of the
hovered button, and unset/reset the hover status of
rest of the buttons.
- - - - -
5 changed files:
- modules/gui/qt/maininterface/mainctx_win32.cpp
- modules/gui/qt/util/csdbuttonmodel.cpp
- modules/gui/qt/util/csdbuttonmodel.hpp
- modules/gui/qt/widgets/qml/CSDWindowButton.qml
- modules/gui/qt/widgets/qml/CSDWindowButtonSet.qml
Changes:
=====================================
modules/gui/qt/maininterface/mainctx_win32.cpp
=====================================
@@ -319,8 +319,6 @@ public:
// handle it to relay if mouse is on the CSD buttons
// required for snap layouts menu (WINDOWS 11)
- setAllUnhovered();
-
// Get the point in screen coordinates.
POINT point = { GET_X_LPARAM(msg->lParam), GET_Y_LPARAM(msg->lParam) };
@@ -369,13 +367,21 @@ public:
{
case HTCLOSE:
setHovered(CSDButton::Close);
+ setHovered(CSDButton::Minimize, false);
+ setHovered(CSDButton::MaximizeRestore, false);
break;
case HTMINBUTTON:
setHovered(CSDButton::Minimize);
+ setHovered(CSDButton::Close, false);
+ setHovered(CSDButton::MaximizeRestore, false);
break;
case HTMAXBUTTON:
setHovered(CSDButton::MaximizeRestore);
+ setHovered(CSDButton::Close, false);
+ setHovered(CSDButton::Minimize, false);
break;
+ default:
+ setAllUnhovered();
}
// If we haven't previously asked for mouse tracking, request mouse
@@ -402,22 +408,57 @@ public:
break;
}
+ case WM_NCLBUTTONUP:
case WM_NCLBUTTONDOWN:
{
+ void (CSDButton::*function)();
+ void (CSDButton::*functionForOthers)() = nullptr;
+
+ if (msg->message == WM_NCLBUTTONDOWN)
+ function = &CSDButton::externalPress;
+ else if (msg->message == WM_NCLBUTTONUP)
+ {
+ function = &CSDButton::externalRelease;
+ functionForOthers = &CSDButton::unsetExternalPressed;
+ }
+ else
+ Q_UNREACHABLE();
// manually trigger button here, UI will never get click
// signal because we have captured the mouse in non client area
switch ( msg->wParam )
{
case HTCLOSE:
- trigger(CSDButton::Close);
+ trigger(CSDButton::Close, function);
+ if (functionForOthers)
+ {
+ trigger(CSDButton::Minimize, functionForOthers);
+ trigger(CSDButton::MaximizeRestore, functionForOthers);
+ }
break;
case HTMINBUTTON:
- trigger(CSDButton::Minimize);
+ trigger(CSDButton::Minimize, function);
+ if (functionForOthers)
+ {
+ trigger(CSDButton::Close, functionForOthers);
+ trigger(CSDButton::MaximizeRestore, functionForOthers);
+ }
break;
case HTMAXBUTTON:
- trigger(CSDButton::MaximizeRestore);
+ trigger(CSDButton::MaximizeRestore, function);
+ if (functionForOthers)
+ {
+ trigger(CSDButton::Close, functionForOthers);
+ trigger(CSDButton::Minimize, functionForOthers);
+ }
break;
+ default:
+ if (functionForOthers)
+ {
+ trigger(CSDButton::Close, functionForOthers);
+ trigger(CSDButton::Minimize, functionForOthers);
+ trigger(CSDButton::MaximizeRestore, functionForOthers);
+ }
}
@@ -494,11 +535,11 @@ private:
return nullptr;
}
- void setHovered(CSDButton::ButtonType type)
+ void setHovered(CSDButton::ButtonType type, bool hovered = true)
{
for (auto button : m_buttonmodel->windowCSDButtons()) {
if (button->type() == type) {
- button->setShowHovered(true);
+ button->setShowHovered(hovered);
return ;
}
}
@@ -506,11 +547,11 @@ private:
vlc_assert_unreachable();
}
- void trigger(CSDButton::ButtonType type)
+ void trigger(CSDButton::ButtonType type, void (CSDButton::*function)())
{
for (auto button : m_buttonmodel->windowCSDButtons()) {
if (button->type() == type) {
- button->click();
+ (button->*function)();
return ;
}
}
=====================================
modules/gui/qt/util/csdbuttonmodel.cpp
=====================================
@@ -62,6 +62,40 @@ void CSDButton::setRect(const QRect &newRect)
emit rectChanged();
}
+bool CSDButton::externalPressed() const
+{
+ return m_externalPressed;
+}
+
+void CSDButton::setExternalPressed()
+{
+ if (m_externalPressed)
+ return;
+ m_externalPressed = true;
+ emit externalPressedChanged();
+}
+
+void CSDButton::unsetExternalPressed()
+{
+ if (!m_externalPressed)
+ return;
+ m_externalPressed = false;
+ emit externalPressedChanged();
+};
+
+void CSDButton::externalPress()
+{
+ setExternalPressed();
+}
+
+void CSDButton::externalRelease()
+{
+ if (!m_externalPressed)
+ return;
+ unsetExternalPressed();
+ click();
+}
+
void CSDButton::click()
{
emit clicked();
=====================================
modules/gui/qt/util/csdbuttonmodel.hpp
=====================================
@@ -33,6 +33,7 @@ class CSDButton : public QObject
Q_PROPERTY(ButtonType type READ type CONSTANT)
Q_PROPERTY(bool showHovered READ showHovered WRITE setShowHovered NOTIFY showHoveredChanged)
Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY rectChanged)
+ Q_PROPERTY(bool externalPressed READ externalPressed NOTIFY externalPressedChanged FINAL)
public:
enum ButtonType
@@ -63,6 +64,12 @@ public:
const QRect &rect() const;
void setRect(const QRect &newRect);
+ bool externalPressed() const;
+ void setExternalPressed();
+ void unsetExternalPressed();
+ void externalPress();
+ void externalRelease();
+
public slots:
// signals to perfrom action associated with button
// actions are dependent on implmentation
@@ -74,11 +81,13 @@ signals:
void rectChanged();
void clicked();
void doubleClicked();
+ void externalPressedChanged();
private:
const ButtonType m_type;
bool m_showHovered = false;
QRect m_rect;
+ bool m_externalPressed = false;
};
=====================================
modules/gui/qt/widgets/qml/CSDWindowButton.qml
=====================================
@@ -33,6 +33,7 @@ T.Button {
property string iconTxt: ""
property bool showHovered: false
property bool isThemeDark: false
+ property bool externalPressed: false
readonly property bool _paintHovered: control.hovered || showHovered
@@ -50,7 +51,7 @@ T.Button {
height: control.height
width: control.width
color: {
- if (control.pressed)
+ if (control.pressed || (control.externalPressed && control._paintHovered))
return control.isThemeDark ? Qt.lighter(control.hoverColor, 1.2)
: Qt.darker(control.hoverColor, 1.2)
=====================================
modules/gui/qt/widgets/qml/CSDWindowButtonSet.qml
=====================================
@@ -62,6 +62,8 @@ Row {
showHovered: modelData.showHovered
+ externalPressed: modelData.externalPressed
+
color: (modelData.type === CSDButton.Close && (hovered || modelData.showHovered))
? "white"
: windowButtonGroup.color
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/456d7c92575dd226c8b967d312d5a67b4fa8fb55...89273dbb3a446a00c55c1696d7db651ccb681bf9
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/456d7c92575dd226c8b967d312d5a67b4fa8fb55...89273dbb3a446a00c55c1696d7db651ccb681bf9
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list