From 995191c16e14980603d062af7774d8db81517ac9 Mon Sep 17 00:00:00 2001 From: youdiansaodongxi Date: Fri, 6 Dec 2024 14:39:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(src/windows):=20=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=BC=B9=E5=87=BA=E4=BD=8D=E7=BD=AE=E9=80=82?= =?UTF-8?q?=E9=85=8D=E4=B8=89=E5=B2=9B=E4=BB=BB=E5=8A=A1=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- src/windows/menu-main-window.cpp | 217 ++++++++++++++++++++++++++----- src/windows/menu-main-window.h | 21 +++ 3 files changed, 208 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e4216..23eb9fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,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 ukui-search kysdk-datacollect) +set(UKUI_MENU_PC_PKGS gsettings-qt ukui-search kysdk-datacollect gio-2.0) foreach(external_lib IN ITEMS ${UKUI_MENU_PC_PKGS}) pkg_check_modules(${external_lib} REQUIRED ${external_lib}) diff --git a/src/windows/menu-main-window.cpp b/src/windows/menu-main-window.cpp index 657e92e..de54287 100644 --- a/src/windows/menu-main-window.cpp +++ b/src/windows/menu-main-window.cpp @@ -16,6 +16,9 @@ * */ +#include +#include + #include "menu-main-window.h" #include "settings.h" #include "context-menu-manager.h" @@ -30,10 +33,15 @@ #include #include #include +#include -#define UKUI_PANEL_SETTING "org.ukui.panel.settings" -#define UKUI_PANEL_POSITION_KEY "panelposition" -#define UKUI_PANEL_SIZE_KEY "panelsize" +#define UKUI_PANEL_SETTING "org.ukui.panel.settings" +#define UKUI_PANEL_POSITION_KEY "panelposition" +#define UKUI_PANEL_SIZE_KEY "panelsize" +#define UKUI_PANEL_TYPE_KEY "paneltype" +#define UKUI_DATA_ISLAND_POSITION_KEY "dataislandposition" +#define UKUI_TOPBAR_SIZE_KEY "topbarsize" +#define UKUI_PANEL_LENGTH_KEY "panellength" namespace UkuiMenu { @@ -74,6 +82,97 @@ void WindowHelper::setRegion(QWindow *window, qreal x, qreal y, qreal w, qreal h windowBlur(window, true, QRegion(path.toFillPolygon().toPolygon())); } +// ====== PanelSettings ====== // +static std::once_flag onceFlag; +static PanelGSettings* g_instance = nullptr; +static GSettings * m_settings = nullptr; +static GSettingsSchema * m_schema = nullptr; +static const char *m_panelLengthKey = "panellength"; +PanelGSettings *PanelGSettings::instance() +{ + std::call_once(onceFlag, [ & ] { + g_instance = new PanelGSettings(); + }); + return g_instance; +} + +int PanelGSettings::getPanelLength(QString screenName) +{ + if (!m_settings || !m_schema) return -1; + if (!isKeysContain(m_panelLengthKey)) return -1; + + QMap map = getPanelLengthMap(); + if (!map.contains(screenName)) { + return -1; + } + return map.value(screenName).toInt(); +} + +PanelGSettings::~PanelGSettings() +{ + if (m_settings) { + g_object_unref(m_settings); + } + if (m_schema) { + g_settings_schema_unref(m_schema); + } + g_instance = nullptr; +} + +PanelGSettings::PanelGSettings(QObject *parent) : QObject(parent) +{ + GSettingsSchemaSource *source; + + source = g_settings_schema_source_get_default(); + m_schema = g_settings_schema_source_lookup(source, "org.ukui.panel.settings", true); + g_settings_schema_source_unref(source); + + if (!m_schema) { + m_settings = nullptr; + return; + } + + m_settings = g_settings_new_with_path("org.ukui.panel.settings", "/org/ukui/panel/settings/"); +} + +bool PanelGSettings::isKeysContain(const char *key) +{ + if (!m_settings || !m_schema) return false; + + gchar **keys = g_settings_schema_list_keys(m_schema); + if (g_strv_contains(keys, key)) { + g_strfreev(keys); + return true; + } else { + g_strfreev(keys); + return false; + } +} + +QMap PanelGSettings::getPanelLengthMap() +{ + GVariant *gvalue = g_settings_get_value(m_settings, m_panelLengthKey); + + GVariantIter iter; + QMap map; + const gchar *key; + size_t str_len; + GVariant *val = NULL; + g_variant_iter_init (&iter, gvalue); + QVariant qvar; + + while (g_variant_iter_next (&iter, "{&sv}", &key, &val)) { + if (g_variant_is_of_type(val, G_VARIANT_TYPE_UINT32)) { + qvar = QVariant::fromValue(static_cast(g_variant_get_uint32(val))); + map.insert(key, qvar); + } + } + + g_variant_unref(gvalue); + + return map; +} + // ====== WindowGeometryHelper ====== // WindowGeometryHelper::WindowGeometryHelper(QObject *parent) : QObject(parent) { @@ -293,6 +392,20 @@ void MenuWindow::initPanelSetting() m_panelSize = m_setting->get(UKUI_PANEL_SIZE_KEY).toInt(); } + if (keys.contains(UKUI_PANEL_TYPE_KEY)) { + m_panelType = m_setting->get(UKUI_PANEL_TYPE_KEY).toInt(); + } else { + m_panelType = 0; + } + + if (keys.contains(UKUI_DATA_ISLAND_POSITION_KEY)) { + m_dataIslandPosition = m_setting->get(UKUI_DATA_ISLAND_POSITION_KEY).toInt(); + } + + if (keys.contains(UKUI_TOPBAR_SIZE_KEY)) { + m_topbarSize = m_setting->get(UKUI_TOPBAR_SIZE_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(); @@ -300,6 +413,17 @@ void MenuWindow::initPanelSetting() } else if (key == UKUI_PANEL_SIZE_KEY) { m_panelSize = m_setting->get(key).toInt(); updateGeometry(); + } else if (key == UKUI_PANEL_TYPE_KEY) { + m_panelType = m_setting->get(UKUI_PANEL_TYPE_KEY).toInt(); + updateGeometry(); + } else if (key == UKUI_DATA_ISLAND_POSITION_KEY) { + m_dataIslandPosition = m_setting->get(UKUI_DATA_ISLAND_POSITION_KEY).toInt(); + updateGeometry(); + } else if (key == UKUI_TOPBAR_SIZE_KEY) { + m_topbarSize = m_setting->get(UKUI_TOPBAR_SIZE_KEY).toInt(); + updateGeometry(); + } else if (key == UKUI_PANEL_LENGTH_KEY) { + updateGeometry(); } }); } @@ -437,24 +561,73 @@ void MenuWindow::updateCurrentScreenGeometry() UkuiQuick::WindowProxy::SlideFromEdge slideFromEdge; bool isMirrored = qGuiApp->layoutDirection() == Qt::LayoutDirection::RightToLeft; - //上: 1, 下: 0, 左: 2, 右: 3 - switch (m_panelPos) { - default: - case 0: { + if (m_panelType == 0) { + //经典任务栏 + //上: 1, 下: 0, 左: 2, 右: 3 + switch (m_panelPos) { + default: + case 0: { + fullRect.adjust(0, 0, 0, -m_panelSize); + + QSize normalSize(qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)); + if (isMirrored) { + normalMaskRect.setTopLeft({fullRect.width() - margin - width, fullRect.height() - normalSize.height() - margin}); + } else { + normalMaskRect.setTopLeft({margin, fullRect.height() - normalSize.height() - margin}); + } + normalMaskRect.setSize(normalSize); + slideFromEdge = UkuiQuick::WindowProxy::BottomEdge; + break; + } + case 1: { + fullRect.adjust(0, m_panelSize, 0, 0); + + QSize normalSize(qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)); + if (isMirrored) { + normalMaskRect.setTopLeft({fullRect.width() - margin - width, margin}); + } else { + normalMaskRect.setTopLeft({margin, margin}); + } + normalMaskRect.setSize(normalSize); + slideFromEdge = UkuiQuick::WindowProxy::TopEdge; + break; + } + case 2: { + fullRect.adjust(m_panelSize, 0, 0, 0); + + normalMaskRect.setTopLeft({margin, margin}); + normalMaskRect.setSize({qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)}); + slideFromEdge = UkuiQuick::WindowProxy::LeftEdge; + break; + } + case 3: { + fullRect.adjust(0, 0, -m_panelSize, 0); + + 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); + slideFromEdge = UkuiQuick::WindowProxy::RightEdge; + break; + } + } + } else if (m_panelType == 1) { + //三岛任务栏 + if (m_dataIslandPosition == 0) { fullRect.adjust(0, 0, 0, -m_panelSize); QSize normalSize(qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)); if (isMirrored) { - normalMaskRect.setTopLeft({fullRect.width() - margin - width, fullRect.height() - normalSize.height() - margin}); + normalMaskRect.setTopLeft({fullRect.width() - + (fullRect.width() - PanelGSettings::instance()->getPanelLength(screen()->name())) / 2 - width , + fullRect.height() - normalSize.height() - margin}); } else { - normalMaskRect.setTopLeft({margin, fullRect.height() - normalSize.height() - margin}); + normalMaskRect.setTopLeft({(fullRect.width() - PanelGSettings::instance()->getPanelLength(screen()->name())) / 2, + fullRect.height() - normalSize.height() - margin}); } normalMaskRect.setSize(normalSize); slideFromEdge = UkuiQuick::WindowProxy::BottomEdge; - break; - } - case 1: { - fullRect.adjust(0, m_panelSize, 0, 0); + } else if (m_dataIslandPosition == 1) { + fullRect.adjust(0, m_topbarSize, 0, 0); QSize normalSize(qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)); if (isMirrored) { @@ -464,24 +637,6 @@ void MenuWindow::updateCurrentScreenGeometry() } normalMaskRect.setSize(normalSize); slideFromEdge = UkuiQuick::WindowProxy::TopEdge; - break; - } - case 2: { - fullRect.adjust(m_panelSize, 0, 0, 0); - - normalMaskRect.setTopLeft({margin, margin}); - normalMaskRect.setSize({qMin(fullRect.width() - margin*2, width), qMin(fullRect.height() - margin*2, height)}); - slideFromEdge = UkuiQuick::WindowProxy::LeftEdge; - break; - } - case 3: { - fullRect.adjust(0, 0, -m_panelSize, 0); - - 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); - slideFromEdge = UkuiQuick::WindowProxy::RightEdge; - break; } } diff --git a/src/windows/menu-main-window.h b/src/windows/menu-main-window.h index fb78152..77963bf 100644 --- a/src/windows/menu-main-window.h +++ b/src/windows/menu-main-window.h @@ -42,6 +42,24 @@ public: static void setRegion(QWindow *window, qreal x, qreal y, qreal w, qreal h, qreal radius); }; +class PanelGSettings : public QObject +{ + Q_OBJECT +public: + static PanelGSettings *instance(); + + int getPanelLength(QString screenName); + + ~PanelGSettings(); + +private: + PanelGSettings(QObject *parent = nullptr); + + bool isKeysContain(const char* key); + + QMap getPanelLengthMap(); +}; + class WindowGeometryHelper final : public QObject { Q_OBJECT @@ -130,6 +148,9 @@ private: // 任务栏位置与屏幕:上: 1, 下: 0, 左: 2, 右: 3, 如果为其他值,则说明任务栏不存在 int m_panelPos{4}; int m_panelSize{48}; + int m_panelType{0}; + int m_dataIslandPosition{0}; + int m_topbarSize{0}; bool m_editMode {false}; bool m_isFullScreen{false}; QRect m_maskGeometry = QRect(0,0,0,0); -- Gitee