[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: refactor setting hover for windows CSD
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Nov 15 14:43:51 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
04e6d55c by Prince Gupta at 2024-11-15T13:28:06+00:00
qt: refactor setting hover for windows CSD
- - - - -
91b84e08 by Prince Gupta at 2024-11-15T13:28:06+00:00
qt: refactor press handling for windows CSD
- - - - -
e8069e64 by Prince Gupta at 2024-11-15T13:28:06+00:00
qt: improve comments
- - - - -
1 changed file:
- modules/gui/qt/maininterface/mainctx_win32.cpp
Changes:
=====================================
modules/gui/qt/maininterface/mainctx_win32.cpp
=====================================
@@ -325,7 +325,7 @@ public:
// Map the point to client coordinates.
::MapWindowPoints(nullptr, msg->hwnd, &point, 1);
- // excluse resize handle area
+ // exclude resize handle area
if ((m_window->windowState() != Qt::WindowFullScreen)
&& (point.y < resizeBorderHeight(m_window)
|| point.x > (m_window->width() * m_window->devicePixelRatio() - resizeBorderWidth(m_window))))
@@ -366,19 +366,13 @@ public:
switch ( msg->wParam )
{
case HTCLOSE:
- setHovered(CSDButton::Close);
- setHovered(CSDButton::Minimize, false);
- setHovered(CSDButton::MaximizeRestore, false);
+ hoverExclusive(CSDButton::Close);
break;
case HTMINBUTTON:
- setHovered(CSDButton::Minimize);
- setHovered(CSDButton::Close, false);
- setHovered(CSDButton::MaximizeRestore, false);
+ hoverExclusive(CSDButton::Minimize);
break;
case HTMAXBUTTON:
- setHovered(CSDButton::MaximizeRestore);
- setHovered(CSDButton::Close, false);
- setHovered(CSDButton::Minimize, false);
+ hoverExclusive(CSDButton::MaximizeRestore);
break;
default:
setAllUnhovered();
@@ -411,54 +405,24 @@ public:
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();
+ const bool pressed = (msg->message == WM_NCLBUTTONDOWN);
// 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, function);
- if (functionForOthers)
- {
- trigger(CSDButton::Minimize, functionForOthers);
- trigger(CSDButton::MaximizeRestore, functionForOthers);
- }
+ handleButtonActionExclusive(CSDButton::Close, pressed);
break;
case HTMINBUTTON:
- trigger(CSDButton::Minimize, function);
- if (functionForOthers)
- {
- trigger(CSDButton::Close, functionForOthers);
- trigger(CSDButton::MaximizeRestore, functionForOthers);
- }
+ handleButtonActionExclusive(CSDButton::Minimize, pressed);
break;
case HTMAXBUTTON:
- trigger(CSDButton::MaximizeRestore, function);
- if (functionForOthers)
- {
- trigger(CSDButton::Close, functionForOthers);
- trigger(CSDButton::Minimize, functionForOthers);
- }
+ handleButtonActionExclusive(CSDButton::MaximizeRestore, pressed);
break;
default:
- if (functionForOthers)
- {
- trigger(CSDButton::Close, functionForOthers);
- trigger(CSDButton::Minimize, functionForOthers);
- trigger(CSDButton::MaximizeRestore, functionForOthers);
- }
+ resetPressedState();
+ break;
}
@@ -503,7 +467,7 @@ private:
// that somehow breaks snaplayouts menu with WS_CAPTION style ^_____^
//
// warning2: if you set negative margin, the window will start painting
- // default CSD button underneath the qml layer, you won't be able to see
+ // server-side buttons underneath the qml layer, you won't be able to see
// it but those will capture all your CSD events.
margin.cxLeftWidth = (m_useClientSideDecoration ? 1 : 0);
@@ -535,28 +499,36 @@ private:
return nullptr;
}
- void setHovered(CSDButton::ButtonType type, bool hovered = true)
+ void hoverExclusive(CSDButton::ButtonType type)
{
for (auto button : m_buttonmodel->windowCSDButtons()) {
- if (button->type() == type) {
- button->setShowHovered(hovered);
- return ;
- }
+ button->setShowHovered(button->type() == type);
}
-
- vlc_assert_unreachable();
}
- void trigger(CSDButton::ButtonType type, void (CSDButton::*function)())
+ void handleButtonActionExclusive(CSDButton::ButtonType type, bool pressed)
{
- for (auto button : m_buttonmodel->windowCSDButtons()) {
- if (button->type() == type) {
- (button->*function)();
- return ;
+ for (auto button : m_buttonmodel->windowCSDButtons())
+ {
+ if (pressed)
+ {
+ if (button->type() == type)
+ button->externalPress();
+ }
+ else
+ {
+ if (button->type() == type)
+ button->externalRelease();
+ else
+ button->unsetExternalPressed();
}
}
+ }
- vlc_assert_unreachable();
+ void resetPressedState()
+ {
+ for (auto button : m_buttonmodel->windowCSDButtons())
+ button->unsetExternalPressed();
}
void setAllUnhovered()
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/127ac893dcab9598b0dfb2c3962b08485f2fa0fa...e8069e644ba244acf8913969f8054ef068555513
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/127ac893dcab9598b0dfb2c3962b08485f2fa0fa...e8069e644ba244acf8913969f8054ef068555513
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