diff --git a/qml/main.qml b/qml/main.qml index dcc4a94..7768584 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -71,6 +71,7 @@ Item { Component.onCompleted: mainWindow.changeWindowBlurRegion(x, y, width, height, radius) onRadiusChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius) onWidthChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius) + onHeightChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius) ParallelAnimation { id: enterFullScreenAnimation diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp index 1956968..7ba955c 100644 --- a/src/ukui-menu-application.cpp +++ b/src/ukui-menu-application.cpp @@ -142,19 +142,19 @@ void UkuiMenuApplication::execCommand(Command command) switch (command) { case Active: { if (m_mainWindow) { - m_mainWindow->setVisible(!m_mainWindow->isVisible()); + m_mainWindow->activeMenuWindow(!m_mainWindow->isVisible()); } break; } case Show: { if (m_mainWindow) { - m_mainWindow->setVisible(true); + m_mainWindow->activeMenuWindow(true); } break; } case Quit: { if (m_mainWindow) { - m_mainWindow->setVisible(false); + m_mainWindow->activeMenuWindow(false); m_engine->quit(); } QCoreApplication::quit(); @@ -162,7 +162,7 @@ void UkuiMenuApplication::execCommand(Command command) } case Hide: { if (m_mainWindow) { - m_mainWindow->setVisible(false); + m_mainWindow->activeMenuWindow(false); } break; } diff --git a/src/windows/menu-main-window.cpp b/src/windows/menu-main-window.cpp index dc5829e..872e369 100644 --- a/src/windows/menu-main-window.cpp +++ b/src/windows/menu-main-window.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -31,6 +30,7 @@ #include #include #include +#include #define UKUI_PANEL_SETTING "org.ukui.panel.settings" #define UKUI_PANEL_POSITION_KEY "panelposition" @@ -212,19 +212,28 @@ const int WindowGeometryHelper::getPanelPos() } //======MenuWindow======// -MenuWindow::MenuWindow(QWindow *parent) : QQuickView(parent), m_geometryHelper(new WindowGeometryHelper(this)) +MenuWindow::MenuWindow(QWindow *parent) : QQuickView(parent) { init(); } MenuWindow::MenuWindow(QQmlEngine *engine, QWindow *parent) - : QQuickView(engine, parent), m_geometryHelper(new WindowGeometryHelper(this)) + : QQuickView(engine, parent) { init(); } void MenuWindow::init() { + initPanelSetting(); + + connect(MenuSetting::instance(), &MenuSetting::changed, this, [this] (const QString& key) { + if (key == MENU_WIDTH || key == MENU_HEIGHT) { + updateGeometry(); + } + }); + setScreen(QGuiApplication::primaryScreen()); + setTitle(QCoreApplication::applicationName()); setResizeMode(SizeRootObjectToView); setColor("transparent"); @@ -237,13 +246,6 @@ void MenuWindow::init() // 访问窗口api rootContext()->setContextProperty("mainWindow", this); - connect(m_geometryHelper, &WindowGeometryHelper::geometryChanged, this, [this] { - QEvent event(QEvent::Move); - QCoreApplication::sendEvent(this, &event); - Q_EMIT panelPosChanged(); - Q_EMIT normalRectChanged(); - }); - rootContext()->setContextProperty("isLiteMode", GlobalSetting::instance()->get(GlobalSetting::IsLiteMode)); connect(GlobalSetting::instance(), &GlobalSetting::styleChanged, this , [this] (const GlobalSetting::Key& key) { if (key == GlobalSetting::EffectEnabled) { @@ -260,9 +262,34 @@ void MenuWindow::init() ContextMenuManager::instance()->setMainWindow(this); } +void MenuWindow::initPanelSetting() +{ + if (!MenuSetting::instance()->get(FOLLOW_UKUI_PANEL).toBool()) { + return; + } + + const QByteArray id(UKUI_PANEL_SETTING); + if (QGSettings::isSchemaInstalled(id)) { + m_setting = new QGSettings(id, QByteArray(), this); + + QStringList keys = m_setting->keys(); + if (keys.contains(UKUI_PANEL_POSITION_KEY)) { + m_panelPos = m_setting->get(UKUI_PANEL_POSITION_KEY).toInt(); + } + + connect(m_setting, &QGSettings::changed, this, [this] (const QString& key) { + if (key == UKUI_PANEL_POSITION_KEY) { + m_panelPos = m_setting->get(UKUI_PANEL_POSITION_KEY).toInt(); + updateGeometry(); + } + }); + } +} + void MenuWindow::updateGeometry() { - UkuiQuick::WindowProxy::setWindowGeometry(this, m_geometryHelper->fullScreenGeometry()); + updateCurrentScreenGeometry(); + UkuiQuick::WindowProxy::setWindowGeometry(this, m_fullScreenGeometry); setMinimumSize(geometry().size()); setMaximumSize(geometry().size()); @@ -320,11 +347,6 @@ void MenuWindow::focusOutEvent(QFocusEvent *event) bool MenuWindow::event(QEvent *event) { - if (event->type() == QEvent::Move) { - updateGeometry(); - return true; - } - if (event->type() == QEvent::Show) { KWindowSystem::setType(winId(), NET::SystemWindow); updateGeometry(); @@ -350,7 +372,7 @@ double MenuWindow::transparency() const int MenuWindow::panelPos() const { - return m_geometryHelper->getPanelPos(); + return m_panelPos; } bool MenuWindow::editMode() const @@ -371,17 +393,85 @@ void MenuWindow::setEditMode(bool mode) void MenuWindow::updateGeometryOfMask() { if (m_isFullScreen) { - m_maskGeometry = QRect(0, 0, m_geometryHelper->fullScreenGeometry().width(), m_geometryHelper->fullScreenGeometry().height()); + m_maskGeometry = QRect(0, 0, m_fullScreenGeometry.width(), m_fullScreenGeometry.height()); } else { - m_maskGeometry = m_geometryHelper->normalGeometry(); + m_maskGeometry = m_normalGeometry; } setMask(m_maskGeometry); } +void MenuWindow::updateCurrentScreenGeometry() +{ + if (!screen()) { + if (!QGuiApplication::primaryScreen()) { + return; + } + setScreen(QGuiApplication::primaryScreen()); + } + + QRect normalMaskRect, fullRect = screen()->availableGeometry(); + int width = MenuSetting::instance()->get(MENU_WIDTH).toInt(); + int height = MenuSetting::instance()->get(MENU_HEIGHT).toInt(); + int margin = MenuSetting::instance()->get(MENU_MARGIN).toInt(); + + //上: 1, 下: 0, 左: 2, 右: 3 + switch (m_panelPos) { + default: + case 0: { + QSize normalSize(qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)); + normalMaskRect.setTopLeft({margin, fullRect.height() - normalSize.height() - margin}); + normalMaskRect.setSize(normalSize); + break; + } + case 1: { + normalMaskRect.setTopLeft({margin, margin}); + normalMaskRect.setSize({qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)}); + break; + } + case 2: { + normalMaskRect.setTopLeft({margin, margin}); + normalMaskRect.setSize({qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)}); + break; + } + case 3: { + QSize normalSize(qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)); + normalMaskRect.setTopLeft({fullRect.width() - normalSize.width() - margin, margin}); + normalMaskRect.setSize(normalSize); + break; + } + } + + m_normalGeometry = normalMaskRect; + m_fullScreenGeometry = fullRect; + + Q_EMIT panelPosChanged(); + Q_EMIT normalRectChanged(); +} + QRect MenuWindow::normalRect() const { - return m_geometryHelper->normalGeometry(); + return m_normalGeometry; +} + +void MenuWindow::activeMenuWindow(bool active) +{ + if (active == isVisible()) { + return; + } + + if (active) { + QScreen* currrentScreen = nullptr; + for (const auto& screen : QGuiApplication::screens()) { + if (screen->geometry().contains(QCursor::pos())) { + currrentScreen = screen; + break; + } + } + this->setScreen(currrentScreen ? currrentScreen : QGuiApplication::primaryScreen()); + } + + setVisible(active); } } // UkuiMenu diff --git a/src/windows/menu-main-window.h b/src/windows/menu-main-window.h index 6d7c775..8844d5e 100644 --- a/src/windows/menu-main-window.h +++ b/src/windows/menu-main-window.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace UkuiMenu { @@ -96,10 +97,13 @@ public: int panelPos() const; QRect normalRect() const; + void activeMenuWindow(bool active); + Q_INVOKABLE void changeWindowBlurRegion(qreal x, qreal y, qreal w, qreal h, qreal radius = 8); Q_INVOKABLE void exitFullScreen(); Q_SIGNALS: + void geometryChanged(); void effectEnabledChanged(); void transparencyChanged(); void fullScreenChanged(); @@ -116,14 +120,20 @@ protected: private: void init(); + void initPanelSetting(); void updateGeometry(); void updateGeometryOfMask(); + void updateCurrentScreenGeometry(); private: + // 任务栏位置与屏幕:上: 1, 下: 0, 左: 2, 右: 3, 如果为其他值,则说明任务栏不存在 + int m_panelPos{4}; bool m_editMode {false}; bool m_isFullScreen{false}; - WindowGeometryHelper *m_geometryHelper{nullptr}; QRect m_maskGeometry = QRect(0,0,0,0); + QRect m_normalGeometry = QRect(0,0,0,0); + QRect m_fullScreenGeometry = QRect(0,0,0,0); + QGSettings *m_setting {nullptr}; }; } // UkuiMenu