Commit a787392b authored by Prince Gupta's avatar Prince Gupta 💬 Committed by Jean-Baptiste Kempf
Browse files

qt: move CSD handling to interface_window_handler

only interface_window_handler knows correct root window

fixes CSD settings not updating and aero snap not working with
win7 compositor
parent d118f1d0
......@@ -844,7 +844,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
QObject::connect( ui.intfScaleFactorSpinBox, QOverload<int>::of(&QSpinBox::valueChanged)
, p_intf->p_sys->p_mi , updateIntfUserScaleFactorFromControls );
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
CONFIG_BOOL( "qt-titlebar", titleBarCheckBox );
#else
ui.titleBarCheckBox->hide();
......
......@@ -192,8 +192,6 @@ MainInterface* CompositorWin7::makeMainInterface()
m_qmlView->setColor(QColor(Qt::transparent));
m_qmlView->setGeometry(m_rootWindow->geometry());
m_qmlView->setMinimumSize( m_rootWindow->minimumSize() );
if (m_rootWindow->useClientSideDecoration())
m_qmlView->setFlag(Qt::FramelessWindowHint);
m_qmlView->installEventFilter(this);
Win7NativeEventFilter* m_nativeEventFilter = new Win7NativeEventFilter(this);
......
......@@ -75,6 +75,11 @@ InterfaceWindowHandler::InterfaceWindowHandler(intf_thread_t *_p_intf, MainInter
connect(this, &InterfaceWindowHandler::incrementIntfUserScaleFactor,
m_mainInterface, &MainInterface::incrementIntfUserScaleFactor);
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
connect( m_mainInterface, &MainInterface::useClientSideDecorationChanged,
this, &InterfaceWindowHandler::updateCSDWindowSettings );
#endif
m_window->installEventFilter(this);
}
......@@ -85,7 +90,7 @@ InterfaceWindowHandler::~InterfaceWindowHandler()
WindowStateHolder::holdFullscreen( m_window, WindowStateHolder::INTERFACE, false );
}
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
bool InterfaceWindowHandler::CSDSetCursor(QMouseEvent* mouseEvent)
{
if (!m_mainInterface->useClientSideDecoration())
......@@ -137,6 +142,13 @@ bool InterfaceWindowHandler::CSDHandleClick(QMouseEvent* mouseEvent)
}
return false;
}
void InterfaceWindowHandler::updateCSDWindowSettings()
{
m_window->hide(); // some window managers don't like to change frame window hint on visible window
m_window->setFlag(Qt::FramelessWindowHint, m_mainInterface->useClientSideDecoration());
m_window->show();
}
#endif
bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
......@@ -206,7 +218,7 @@ bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
}
break;
}
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
//Handle CSD edge behaviors
case QEvent::MouseMove:
{
......
......@@ -55,9 +55,10 @@ signals:
void incrementIntfUserScaleFactor(bool increment);
private:
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
bool CSDSetCursor(QMouseEvent* mouseEvent);
bool CSDHandleClick(QMouseEvent* mouseEvent);
virtual void updateCSDWindowSettings();
#endif
protected:
......
......@@ -163,7 +163,7 @@ MainInterface::MainInterface(intf_thread_t *_p_intf , QWidget* parent, Qt::Windo
/* Should the UI stays on top of other windows */
b_interfaceOnTop = var_InheritBool( p_intf, "video-on-top" );
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
m_clientSideDecoration = ! var_InheritBool( p_intf, "qt-titlebar" );
#endif
m_hasToolbarMenu = var_InheritBool( p_intf, "qt-menubar" );
......@@ -305,12 +305,11 @@ void MainInterface::reloadPrefs()
emit hasToolbarMenuChanged();
}
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
if (m_clientSideDecoration != (! var_InheritBool( p_intf, "qt-titlebar" )))
{
m_clientSideDecoration = !m_clientSideDecoration;
emit useClientSideDecorationChanged();
updateClientSideDecorations();
}
#endif
}
......@@ -720,13 +719,6 @@ void MainInterface::closeEvent( QCloseEvent *e )
}
}
void MainInterface::updateClientSideDecorations()
{
hide(); // some window managers don't like to change frame window hint on visible window
setWindowFlag(Qt::FramelessWindowHint, useClientSideDecoration());
show();
}
void MainInterface::setInterfaceFullScreen( bool fs )
{
b_interfaceFullScreen = fs;
......
......@@ -226,7 +226,6 @@ protected:
void dragMoveEvent( QDragMoveEvent * ) Q_DECL_OVERRIDE;
void dragLeaveEvent( QDragLeaveEvent * ) Q_DECL_OVERRIDE;
void closeEvent( QCloseEvent *) Q_DECL_OVERRIDE;
virtual void updateClientSideDecorations();
protected:
/* Systray */
......
......@@ -27,6 +27,7 @@
#include "main_interface_win32.hpp"
#include "maininterface/compositor.hpp"
#include "player/player_controller.hpp"
#include "playlist/playlist_controller.hpp"
#include "dialogs/dialogs_provider.hpp"
......@@ -93,6 +94,77 @@ HWND WinId( QWindow *windowHandle )
return 0;
}
class CSDWin32EventHandler : public QObject, public QAbstractNativeEventFilter
{
public:
CSDWin32EventHandler(const bool useClientSideDecoration, const bool isWin7Compositor, QWindow *window, QObject *parent)
: QObject {parent}
, m_useClientSideDecoration {useClientSideDecoration}
, m_window {window}
, m_isWin7Compositor {isWin7Compositor}
{
QApplication::instance()->installNativeEventFilter(this);
updateCSDSettings();
}
bool nativeEventFilter(const QByteArray &, void *message, long *result) override
{
MSG* msg = static_cast<MSG*>( message );
if ( (msg->message == WM_NCCALCSIZE) && (msg->hwnd == WinId(m_window)) )
{
/* This is used to remove the decoration instead of using FramelessWindowHint because
* frameless window don't support areo snapping
*/
if (m_useClientSideDecoration) {
*result = WVR_REDRAW;
return true;
}
}
return false;
}
void setUseClientSideDecoration(bool useClientSideDecoration)
{
m_useClientSideDecoration = useClientSideDecoration;
updateCSDSettings();
}
private:
void updateCSDSettings()
{
HWND winId = WinId(m_window);
if (m_isWin7Compositor)
{
// special case for win7 compositor
// removing CSD borders with win7 compositor works with Qt::FramelessWindowHint
// but with that the shadows don't work, so manually remove WS_CAPTION style
DWORD style = m_nonCSDGwlStyle == 0 ? GetWindowLong(winId, GWL_STYLE) : m_nonCSDGwlStyle;
if (m_nonCSDGwlStyle == 0)
m_nonCSDGwlStyle = style;
if (m_useClientSideDecoration)
{
style &= ~WS_CAPTION;
style |= (WS_MAXIMIZEBOX | WS_THICKFRAME);
}
SetWindowLong (winId, GWL_STYLE, style);
}
SetWindowPos(winId, NULL, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS |
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION |
SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER);
}
DWORD m_nonCSDGwlStyle = 0;
bool m_useClientSideDecoration;
QWindow *m_window;
const bool m_isWin7Compositor;
};
}
WinTaskbarWidget::WinTaskbarWidget(intf_thread_t *_p_intf, QWindow* windowHandle, QObject* parent)
......@@ -340,19 +412,6 @@ bool MainInterfaceWin32::nativeEvent(const QByteArray &eventType, void *message,
short cmd;
switch( msg->message )
{
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
case WM_NCCALCSIZE:
{
/* This is used to remove the decoration instead of using FramelessWindowHint because
* frameless window don't support areo snapping
*/
if (useClientSideDecoration()) {
*result = 0;
return true;
}
break;
}
#endif
case WM_APPCOMMAND:
cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
......@@ -425,6 +484,13 @@ bool MainInterfaceWin32::nativeEvent(const QByteArray &eventType, void *message,
InterfaceWindowHandlerWin32::InterfaceWindowHandlerWin32(intf_thread_t *_p_intf, MainInterface* mainInterface, QWindow* window, QObject *parent)
: InterfaceWindowHandler(_p_intf, mainInterface, window, parent)
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
, m_CSDWindowEventHandler(new CSDWin32EventHandler(mainInterface->useClientSideDecoration(),
_p_intf->p_sys->p_compositor->type() == vlc::Compositor::Win7Compositor,
window, window))
#endif
{
}
......@@ -434,15 +500,6 @@ void MainInterfaceWin32::reloadPrefs()
MainInterface::reloadPrefs();
}
void MainInterfaceWin32::updateClientSideDecorations()
{
HWND winId = WinId(windowHandle());
SetWindowPos(winId, NULL, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS |
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION |
SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER);
}
void InterfaceWindowHandlerWin32::toggleWindowVisiblity()
{
......@@ -530,3 +587,10 @@ bool InterfaceWindowHandlerWin32::eventFilter(QObject* obj, QEvent* ev)
return ret;
}
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
void InterfaceWindowHandlerWin32::updateCSDWindowSettings()
{
static_cast<CSDWin32EventHandler *>(m_CSDWindowEventHandler)->setUseClientSideDecoration(m_mainInterface->useClientSideDecoration());
}
#endif
......@@ -67,9 +67,6 @@ private:
public slots:
virtual void reloadPrefs() override;
protected:
void updateClientSideDecorations() Q_DECL_OVERRIDE;
};
class InterfaceWindowHandlerWin32 : public InterfaceWindowHandler
......@@ -81,6 +78,12 @@ public:
virtual void toggleWindowVisiblity() override;
virtual bool eventFilter(QObject*, QEvent* event) override;
private:
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
void updateCSDWindowSettings() override;
QObject *m_CSDWindowEventHandler {};
#endif
};
#endif // MAIN_INTERFACE_WIN32_HPP
......@@ -333,7 +333,7 @@ vlc_module_begin ()
false /* advanced mode only */)
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
add_bool( "qt-titlebar",
#ifdef _WIN32
false /* use CSD by default on windows */,
......
......@@ -169,4 +169,6 @@ static inline QString QVLCUserDir( vlc_userdir_t type )
*/
#define QT_XMAS_JOKE_DAY 354
#define QT_CLIENT_SIDE_DECORATION_AVAILABLE (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment