feat(src/windows): 开始菜单适配多屏任务栏

This commit is contained in:
youdiansaodongxi 2024-04-07 09:38:21 +08:00 committed by iaom
parent 598758c28d
commit 7a52fc5d45
4 changed files with 126 additions and 25 deletions

View File

@ -71,6 +71,7 @@ Item {
Component.onCompleted: mainWindow.changeWindowBlurRegion(x, y, width, height, radius) Component.onCompleted: mainWindow.changeWindowBlurRegion(x, y, width, height, radius)
onRadiusChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius) onRadiusChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius)
onWidthChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius) onWidthChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius)
onHeightChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius)
ParallelAnimation { ParallelAnimation {
id: enterFullScreenAnimation id: enterFullScreenAnimation

View File

@ -142,19 +142,19 @@ void UkuiMenuApplication::execCommand(Command command)
switch (command) { switch (command) {
case Active: { case Active: {
if (m_mainWindow) { if (m_mainWindow) {
m_mainWindow->setVisible(!m_mainWindow->isVisible()); m_mainWindow->activeMenuWindow(!m_mainWindow->isVisible());
} }
break; break;
} }
case Show: { case Show: {
if (m_mainWindow) { if (m_mainWindow) {
m_mainWindow->setVisible(true); m_mainWindow->activeMenuWindow(true);
} }
break; break;
} }
case Quit: { case Quit: {
if (m_mainWindow) { if (m_mainWindow) {
m_mainWindow->setVisible(false); m_mainWindow->activeMenuWindow(false);
m_engine->quit(); m_engine->quit();
} }
QCoreApplication::quit(); QCoreApplication::quit();
@ -162,7 +162,7 @@ void UkuiMenuApplication::execCommand(Command command)
} }
case Hide: { case Hide: {
if (m_mainWindow) { if (m_mainWindow) {
m_mainWindow->setVisible(false); m_mainWindow->activeMenuWindow(false);
} }
break; break;
} }

View File

@ -23,7 +23,6 @@
#include <window-helper.h> #include <window-helper.h>
#include <QGuiApplication> #include <QGuiApplication>
#include <QQuickItem> #include <QQuickItem>
#include <QGSettings>
#include <QX11Info> #include <QX11Info>
#include <QQmlContext> #include <QQmlContext>
#include <QPoint> #include <QPoint>
@ -31,6 +30,7 @@
#include <KWindowEffects> #include <KWindowEffects>
#include <QPainterPath> #include <QPainterPath>
#include <QTimer> #include <QTimer>
#include <QCursor>
#define UKUI_PANEL_SETTING "org.ukui.panel.settings" #define UKUI_PANEL_SETTING "org.ukui.panel.settings"
#define UKUI_PANEL_POSITION_KEY "panelposition" #define UKUI_PANEL_POSITION_KEY "panelposition"
@ -212,19 +212,28 @@ const int WindowGeometryHelper::getPanelPos()
} }
//======MenuWindow======// //======MenuWindow======//
MenuWindow::MenuWindow(QWindow *parent) : QQuickView(parent), m_geometryHelper(new WindowGeometryHelper(this)) MenuWindow::MenuWindow(QWindow *parent) : QQuickView(parent)
{ {
init(); init();
} }
MenuWindow::MenuWindow(QQmlEngine *engine, QWindow *parent) MenuWindow::MenuWindow(QQmlEngine *engine, QWindow *parent)
: QQuickView(engine, parent), m_geometryHelper(new WindowGeometryHelper(this)) : QQuickView(engine, parent)
{ {
init(); init();
} }
void MenuWindow::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()); setTitle(QCoreApplication::applicationName());
setResizeMode(SizeRootObjectToView); setResizeMode(SizeRootObjectToView);
setColor("transparent"); setColor("transparent");
@ -237,13 +246,6 @@ void MenuWindow::init()
// 访问窗口api // 访问窗口api
rootContext()->setContextProperty("mainWindow", this); 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)); rootContext()->setContextProperty("isLiteMode", GlobalSetting::instance()->get(GlobalSetting::IsLiteMode));
connect(GlobalSetting::instance(), &GlobalSetting::styleChanged, this , [this] (const GlobalSetting::Key& key) { connect(GlobalSetting::instance(), &GlobalSetting::styleChanged, this , [this] (const GlobalSetting::Key& key) {
if (key == GlobalSetting::EffectEnabled) { if (key == GlobalSetting::EffectEnabled) {
@ -260,9 +262,34 @@ void MenuWindow::init()
ContextMenuManager::instance()->setMainWindow(this); 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() void MenuWindow::updateGeometry()
{ {
UkuiQuick::WindowProxy::setWindowGeometry(this, m_geometryHelper->fullScreenGeometry()); updateCurrentScreenGeometry();
UkuiQuick::WindowProxy::setWindowGeometry(this, m_fullScreenGeometry);
setMinimumSize(geometry().size()); setMinimumSize(geometry().size());
setMaximumSize(geometry().size()); setMaximumSize(geometry().size());
@ -320,11 +347,6 @@ void MenuWindow::focusOutEvent(QFocusEvent *event)
bool MenuWindow::event(QEvent *event) bool MenuWindow::event(QEvent *event)
{ {
if (event->type() == QEvent::Move) {
updateGeometry();
return true;
}
if (event->type() == QEvent::Show) { if (event->type() == QEvent::Show) {
KWindowSystem::setType(winId(), NET::SystemWindow); KWindowSystem::setType(winId(), NET::SystemWindow);
updateGeometry(); updateGeometry();
@ -350,7 +372,7 @@ double MenuWindow::transparency() const
int MenuWindow::panelPos() const int MenuWindow::panelPos() const
{ {
return m_geometryHelper->getPanelPos(); return m_panelPos;
} }
bool MenuWindow::editMode() const bool MenuWindow::editMode() const
@ -371,17 +393,85 @@ void MenuWindow::setEditMode(bool mode)
void MenuWindow::updateGeometryOfMask() void MenuWindow::updateGeometryOfMask()
{ {
if (m_isFullScreen) { 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 { } else {
m_maskGeometry = m_geometryHelper->normalGeometry(); m_maskGeometry = m_normalGeometry;
} }
setMask(m_maskGeometry); 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<int>(fullRect.width() - margin*2, width), qMin<int>(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<int>(fullRect.width() - margin*2, width), qMin<int>(fullRect.height() - margin*2, height)});
break;
}
case 2: {
normalMaskRect.setTopLeft({margin, margin});
normalMaskRect.setSize({qMin<int>(fullRect.width() - margin*2, width), qMin<int>(fullRect.height() - margin*2, height)});
break;
}
case 3: {
QSize normalSize(qMin<int>(fullRect.width() - margin*2, width), qMin<int>(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 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 } // UkuiMenu

View File

@ -24,6 +24,7 @@
#include <QScreen> #include <QScreen>
#include <QQuickView> #include <QQuickView>
#include <QQuickWindow> #include <QQuickWindow>
#include <QGSettings>
namespace UkuiMenu { namespace UkuiMenu {
@ -96,10 +97,13 @@ public:
int panelPos() const; int panelPos() const;
QRect normalRect() 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 changeWindowBlurRegion(qreal x, qreal y, qreal w, qreal h, qreal radius = 8);
Q_INVOKABLE void exitFullScreen(); Q_INVOKABLE void exitFullScreen();
Q_SIGNALS: Q_SIGNALS:
void geometryChanged();
void effectEnabledChanged(); void effectEnabledChanged();
void transparencyChanged(); void transparencyChanged();
void fullScreenChanged(); void fullScreenChanged();
@ -116,14 +120,20 @@ protected:
private: private:
void init(); void init();
void initPanelSetting();
void updateGeometry(); void updateGeometry();
void updateGeometryOfMask(); void updateGeometryOfMask();
void updateCurrentScreenGeometry();
private: private:
// 任务栏位置与屏幕:上: 1, 下: 0, 左: 2, 右: 3, 如果为其他值,则说明任务栏不存在
int m_panelPos{4};
bool m_editMode {false}; bool m_editMode {false};
bool m_isFullScreen{false}; bool m_isFullScreen{false};
WindowGeometryHelper *m_geometryHelper{nullptr};
QRect m_maskGeometry = QRect(0,0,0,0); 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 } // UkuiMenu