From c2b945687c1fda9c218c3b2a3bfb1c91b3d65f04 Mon Sep 17 00:00:00 2001
From: meizhigang <meizhigang@kylinsec.com.cn>
Date: Fri, 14 Apr 2023 09:28:34 +0800
Subject: [PATCH] fix(keyboard):Add modifier lock window tips enable key with
 gsettings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

 - 使用gsettings配置添加修饰锁按键提示窗口开关

 Related #67766

Signed-off-by: meizhigang <meizhigang@kylinsec.com.cn>
---
 data/schemas/com.kylinsec.kiran.keyboard.gschema.xml.in | 5 +++++
 plugins/inputdevices/keyboard/keyboard-manager.cpp      | 9 ++++++++-
 plugins/inputdevices/keyboard/keyboard-manager.h        | 1 +
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/data/schemas/com.kylinsec.kiran.keyboard.gschema.xml.in b/data/schemas/com.kylinsec.kiran.keyboard.gschema.xml.in
index ffea7cf..05e948a 100644
--- a/data/schemas/com.kylinsec.kiran.keyboard.gschema.xml.in
+++ b/data/schemas/com.kylinsec.kiran.keyboard.gschema.xml.in
@@ -1,6 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <schemalist gettext-domain="@PROJECT_NAME@">
     <schema id="com.kylinsec.kiran.keyboard" path="/com/kylinsec/kiran/keyboard/">
+        <key name="modifier-lock-enabled" type="b">
+            <default>false</default>
+            <description>Whether enable capslock and numlock windows tips.</description>
+        </key>
+
         <key name="repeat-enabled" type="b">
             <default>true</default>
             <description>Whether repeat to trigger KeyPress and KeyRelease event when key is pressed.</description>
diff --git a/plugins/inputdevices/keyboard/keyboard-manager.cpp b/plugins/inputdevices/keyboard/keyboard-manager.cpp
index 0b1bcc4..2318a9e 100644
--- a/plugins/inputdevices/keyboard/keyboard-manager.cpp
+++ b/plugins/inputdevices/keyboard/keyboard-manager.cpp
@@ -25,6 +25,7 @@
 namespace Kiran
 {
 #define KEYBOARD_SCHEMA_ID "com.kylinsec.kiran.keyboard"
+#define KEYBOARD_SCHEMA_MODIFIER_LOCK_ENABLED "modifier-lock-enabled"
 #define KEYBOARD_SCHEMA_REPEAT_ENABLED "repeat-enabled"
 #define KEYBOARD_SCHEMA_REPEAT_DELAY "repeat-delay"
 #define KEYBOARD_SCHEMA_REPEAT_INTERVAL "repeat-interval"
@@ -41,6 +42,7 @@ namespace Kiran
 
 KeyboardManager::KeyboardManager() : dbus_connect_id_(0),
                                      object_register_id_(0),
+                                     modifier_lock_enabled_(false),
                                      repeat_enabled_(true),
                                      repeat_delay_(500),
                                      repeat_interval_(30)
@@ -291,7 +293,11 @@ void KeyboardManager::init()
     this->load_from_settings();
     this->load_xkb_rules();
     this->set_all_props();
-    this->modifier_lock_manager_->init();
+
+    if (this->modifier_lock_enabled_)
+    {
+        this->modifier_lock_manager_->init();
+    }
 
     this->keyboard_settings_->signal_changed().connect(sigc::mem_fun(this, &KeyboardManager::settings_changed));
 
@@ -308,6 +314,7 @@ void KeyboardManager::load_from_settings()
 
     if (this->keyboard_settings_)
     {
+        this->modifier_lock_enabled_ = this->keyboard_settings_->get_boolean(KEYBOARD_SCHEMA_MODIFIER_LOCK_ENABLED);
         this->repeat_enabled_ = this->keyboard_settings_->get_boolean(KEYBOARD_SCHEMA_REPEAT_ENABLED);
         this->repeat_delay_ = this->keyboard_settings_->get_int(KEYBOARD_SCHEMA_REPEAT_DELAY);
         this->repeat_interval_ = this->keyboard_settings_->get_int(KEYBOARD_SCHEMA_REPEAT_INTERVAL);
diff --git a/plugins/inputdevices/keyboard/keyboard-manager.h b/plugins/inputdevices/keyboard/keyboard-manager.h
index 5015b1d..b213169 100644
--- a/plugins/inputdevices/keyboard/keyboard-manager.h
+++ b/plugins/inputdevices/keyboard/keyboard-manager.h
@@ -98,6 +98,7 @@ private:
     Glib::RefPtr<Gio::Settings> keyboard_settings_;
     std::map<Glib::ustring, Glib::ustring> valid_layouts_;
 
+    bool modifier_lock_enabled_;
     bool repeat_enabled_;
     int32_t repeat_delay_;
     int32_t repeat_interval_;
-- 
2.27.0

