From 4789475b519b87f5be433f6387799da2266baa99 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Mon, 20 Feb 2023 11:34:27 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E5=B8=A6=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C2.=E9=80=82=E9=85=8D=E7=AA=97=E7=AE=A1?= =?UTF-8?q?=E6=97=A0=E8=BE=B9=E6=A1=86=E5=8F=8A=E7=AA=97=E5=8F=A3=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 1 + src/windows/menu-main-window.cpp | 60 ++++++++++++++++++++++++++++++-- src/windows/menu-main-window.h | 2 ++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 94dd86e..446d649 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,7 @@ int main(int argc, char *argv[]) } UkuiMenu::UkuiMenuApplication menuApplication(&messageProcessor); + messageProcessor.processMessage(app.instanceId(), SingleApplication::arguments().join(" ").toUtf8()); QObject::connect(&app, &SingleApplication::receivedMessage, &messageProcessor, &UkuiMenu::MenuMessageProcessor::processMessage); diff --git a/src/windows/menu-main-window.cpp b/src/windows/menu-main-window.cpp index 3e3e4ed..19e758c 100644 --- a/src/windows/menu-main-window.cpp +++ b/src/windows/menu-main-window.cpp @@ -26,9 +26,14 @@ #include #include #include +#include -#include +// kysdk #include +#include + +// x11 +#include #define UKUI_PANEL_SETTING "org.ukui.panel.settings" #define UKUI_PANEL_POSITION_KEY "panelposition" @@ -36,6 +41,19 @@ namespace UkuiMenu { +struct MotifWmHints { + ulong flags = 0; + ulong functions = 0; + ulong decorations = 0; + long input_mode = 0; + ulong status = 0; +}; + +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_FUNC_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) + void WindowModule::defineModule(const char *uri, int versionMajor, int versionMinor) { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) @@ -90,6 +108,36 @@ void WindowHelper::setWindowAttribute(QWindow *window) } } +void WindowHelper::removeHeaderBar(QWindow *window) +{ + if (!window) { + return; + } + + if (QX11Info::isPlatformX11()) { + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + + unsigned long atom = XInternAtom(QX11Info::display(), "_MOTIF_WM_HINTS", true); + XChangeProperty(QX11Info::display(), window->winId(), atom, atom, 32, XCB_PROP_MODE_REPLACE, + (const unsigned char *)&hints, sizeof(MotifWmHints) / sizeof(const unsigned char)); + + } else { + UKUIDecorationManager::getInstance()->removeHeaderBar(window); + } +} + +void WindowHelper::windowBlur(QWindow *window, bool enable) +{ + if (!window) { + return; + } + //use KWindowEffects + KWindowEffects::enableBlurBehind(window->winId(), enable); +} + //======MenuMainWindow======// MenuMainWindow::MenuMainWindow(QWindow *parent) : QQuickWindow(parent), m_geometryHelper(new WindowGeometryHelper(this)) { @@ -334,13 +382,19 @@ void MenuWindow::init() setResizeMode(SizeRootObjectToView); setColor("transparent"); - // TODO 使用窗管接口设置无边框 - setFlags(Qt::FramelessWindowHint); +// setFlags(Qt::FramelessWindowHint); WindowHelper::setWindowAttribute(this); + WindowHelper::removeHeaderBar(this); + WindowHelper::windowBlur(this, true); // 访问窗口api rootContext()->setContextProperty("mainWindow", this); connect(this, &QQuickView::activeFocusItemChanged, this, &MenuWindow::onActiveFocusItemChanged); + + connect(m_geometryHelper, &WindowGeometryHelper::geometryChanged, this, [this] { + QEvent event(QEvent::Move); + QCoreApplication::sendEvent(this, &event); + }); } void MenuWindow::updateGeometry() diff --git a/src/windows/menu-main-window.h b/src/windows/menu-main-window.h index c45a72f..37c649f 100644 --- a/src/windows/menu-main-window.h +++ b/src/windows/menu-main-window.h @@ -38,6 +38,8 @@ class WindowHelper final public: static void setWindowGeometry(QWindow *window, const QRect &rect); static void setWindowAttribute(QWindow *window); + static void removeHeaderBar(QWindow *window); + static void windowBlur(QWindow *window, bool enable); }; class WindowGeometryHelper final : public QObject