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