From d8a63029d764c1c9b2a10883bbf37b87d8c44970 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Thu, 7 Mar 2024 20:29:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=93=E5=BC=80?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E8=8F=9C=E5=8D=95=E4=BC=9A=E5=9C=A8=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=A0=8F=E5=87=BA=E7=8E=B0=E5=9B=BE=E6=A0=87=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 +- qml/AppUI/Sidebar.qml | 2 +- qml/main.qml | 2 +- src/windows/menu-main-window.cpp | 121 +++++-------------------------- src/windows/menu-main-window.h | 4 - 5 files changed, 23 insertions(+), 110 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b74f3e7..37e4216 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ find_package(Qt${QT_VERSION_MAJOR} # see: https://api.kde.org/frameworks/index.html > KWindowSystem find_package(KF5WindowSystem REQUIRED) find_package(Qt5Xdg REQUIRED) +find_package(ukui-quick COMPONENTS platform REQUIRED) # 查找其他组件 # see: https://cmake.org/cmake/help/v3.16/module/FindPkgConfig.html @@ -29,7 +30,7 @@ find_package(PkgConfig REQUIRED) set(UKUI_MENU_EXTERNAL_LIBS "") # glib-2.0 gio-unix-2.0 gsettings-qt x11 kysdk-waylandhelper -set(UKUI_MENU_PC_PKGS gsettings-qt x11 kysdk-waylandhelper ukui-search kysdk-datacollect) +set(UKUI_MENU_PC_PKGS gsettings-qt ukui-search kysdk-datacollect) foreach(external_lib IN ITEMS ${UKUI_MENU_PC_PKGS}) pkg_check_modules(${external_lib} REQUIRED ${external_lib}) @@ -202,6 +203,7 @@ target_link_libraries(${PROJECT_NAME} ${SingleApplication} ${UKUI_MENU_EXTERNAL_LIBS} ${UKUI_MENU_LIBRARY_TARGET} + ukui-quick::platform ) # 安装ukui-menu diff --git a/qml/AppUI/Sidebar.qml b/qml/AppUI/Sidebar.qml index bc1a655..73600f7 100644 --- a/qml/AppUI/Sidebar.qml +++ b/qml/AppUI/Sidebar.qml @@ -153,7 +153,7 @@ Item { Layout.preferredHeight: 36 Layout.alignment: Qt.AlignHCenter - UkuiItems.ToolTip.text: qsTr("Applications System") + UkuiItems.ToolTip.text: qsTr("Control center") onEntered: { UkuiItems.ToolTip.show(setButton.mapToGlobal(0, setButton.height)); diff --git a/qml/main.qml b/qml/main.qml index 03b3a3a..dcc4a94 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -64,7 +64,7 @@ Item { width: mainWindow.isFullScreen ? root.width : normalGeometry.width radius: mainWindow.isFullScreen ? 0 : Platform.Theme.windowRadius - border.width: 1 + border.width: mainWindow.isFullScreen ? 0 : 1 borderColor: Platform.Theme.Text borderAlpha: 0.15 diff --git a/src/windows/menu-main-window.cpp b/src/windows/menu-main-window.cpp index 395ae24..21ae086 100644 --- a/src/windows/menu-main-window.cpp +++ b/src/windows/menu-main-window.cpp @@ -20,6 +20,7 @@ #include "settings.h" #include "context-menu-manager.h" +#include #include #include #include @@ -31,32 +32,12 @@ #include #include -// kysdk -#include -#include - -// x11 -#include - #define UKUI_PANEL_SETTING "org.ukui.panel.settings" #define UKUI_PANEL_POSITION_KEY "panelposition" #define UKUI_PANEL_SIZE_KEY "panelsize" 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, 5, 0) @@ -77,57 +58,6 @@ void WindowModule::defineModule(const char *uri, int versionMajor, int versionMi #endif } -void WindowHelper::setWindowGeometry(QWindow *window, const QRect &rect) -{ - if (!window) { - return; - } - - // 窗口系统不存在跟屏幕一样大的普通窗口? - window->setWindowState(Qt::WindowNoState); - if (QX11Info::isPlatformX11()) { - window->setGeometry(rect); - - } else { - kdk::WindowManager::setGeometry(window, rect); - } -} - -// 窗口管理器属性 -void WindowHelper::setWindowAttribute(QWindow *window) -{ - if (!window) { - return; - } - - // kwin - KWindowSystem::setType(window->winId(), NET::SystemWindow); - // 设置跳过多任务视图,设置跳过任务栏 - kdk::WindowManager::setSkipTaskBar(window, true); - kdk::WindowManager::setSkipSwitcher(window, true); -} - -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, const QRegion ®ion) { if (!window) { @@ -164,8 +94,8 @@ void WindowGeometryHelper::updateGeometry() if (!m_primaryScreen) { return; } - QRect screenRect = m_primaryScreen->geometry(), normalMaskRect, fullRect; + QRect screenRect = m_primaryScreen->geometry(), normalMaskRect, fullRect; int width = MenuSetting::instance()->get(MENU_WIDTH).toInt(); int height = MenuSetting::instance()->get(MENU_HEIGHT).toInt(); int margin = MenuSetting::instance()->get(MENU_MARGIN).toInt(); @@ -275,7 +205,7 @@ void WindowGeometryHelper::updatePrimaryScreen(QScreen *screen) } if (m_primaryScreen) { - disconnect(m_primaryScreen); + m_primaryScreen->disconnect(this); } m_primaryScreen = screen; @@ -315,10 +245,10 @@ void MenuWindow::init() setResizeMode(SizeRootObjectToView); setColor("transparent"); -// setFlags(Qt::FramelessWindowHint); - setFlags(Qt::Window); - WindowHelper::setWindowAttribute(this); - WindowHelper::removeHeaderBar(this); + //setWindowState(Qt::WindowMaximized); + setFlags(flags() | Qt::Window | Qt::FramelessWindowHint); + new UkuiQuick::WindowProxy(this, UkuiQuick::WindowProxy::SkipSwitcher | UkuiQuick::WindowProxy::SkipTaskBar); + KWindowSystem::setType(winId(), NET::SystemWindow); // 访问窗口api rootContext()->setContextProperty("mainWindow", this); @@ -348,12 +278,9 @@ void MenuWindow::init() void MenuWindow::updateGeometry() { - QRect rect = m_geometryHelper->fullScreenGeometry(); - if (rect != geometry()) { - WindowHelper::setWindowGeometry(this, rect); - setMinimumSize(geometry().size()); - setMaximumSize(geometry().size()); - } + UkuiQuick::WindowProxy::setWindowGeometry(this, m_geometryHelper->fullScreenGeometry()); + setMinimumSize(geometry().size()); + setMaximumSize(geometry().size()); updateGeometryOfMask(); WindowHelper::setRegion(this, m_maskGeometry.x(), m_maskGeometry.y(), m_maskGeometry.width(), m_maskGeometry.height(), 16); @@ -397,13 +324,6 @@ void MenuWindow::exitFullScreen() void MenuWindow::exposeEvent(QExposeEvent *event) { - if (isExposed()) { - if (QX11Info::isPlatformX11()) { - requestActivate(); - } -// WindowHelper::removeHeaderBar(this); - updateGeometry(); - } QQuickView::exposeEvent(event); } @@ -420,25 +340,20 @@ bool MenuWindow::event(QEvent *event) updateGeometry(); return true; } - if (event->type() == QEvent::UpdateRequest) { - WindowHelper::removeHeaderBar(this); - } - if (event->type() == QEvent::MouseButtonPress) { + + if (event->type() == QEvent::Show) { + KWindowSystem::setType(winId(), NET::SystemWindow); + updateGeometry(); + if (QX11Info::isPlatformX11()) { + requestActivate(); + } + } else if (event->type() == QEvent::MouseButtonPress) { ContextMenuManager::instance()->closeMenu(); } return QQuickView::event(event); } -void MenuWindow::showEvent(QShowEvent *event) -{ - //为了主动触发一次updaterequet事件 - update(); - QQuickView::showEvent(event); - QTimer::singleShot(1,this,[=](){WindowHelper::setWindowAttribute(this);}); - -} - bool MenuWindow::effectEnabled() const { return GlobalSetting::instance()->get(GlobalSetting::EffectEnabled).toBool(); diff --git a/src/windows/menu-main-window.h b/src/windows/menu-main-window.h index dc28bb7..6d7c775 100644 --- a/src/windows/menu-main-window.h +++ b/src/windows/menu-main-window.h @@ -36,9 +36,6 @@ public: 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, const QRegion ®ion = QRegion()); static void setRegion(QWindow *window, qreal x, qreal y, qreal w, qreal h, qreal radius); }; @@ -116,7 +113,6 @@ protected: void exposeEvent(QExposeEvent *event) override; void focusOutEvent(QFocusEvent *event) override; bool event(QEvent *event) override; - void showEvent(QShowEvent *event) override; private: void init();