@@ -8,13 +8,16 @@ import org.deepin.dtk 1.0 as D
88import org.deepin.dcc 1.0
99
1010DccObject {
11- readonly property var enumKeys: [" None" , " CTRL_SHIFT" , " ALT_SHIFT" ]
11+ readonly property var enumKeys: [" Ctrl+Shift" , " Alt+Shift" , " None" ]
12+ readonly property var triggerEnumKeys: [" Shift" , " Ctrl+Space" , " None" ]
1213 property var triggerKeys: dccData .fcitx5ConfigProxy .globalConfigOption (
1314 " Hotkey" , " TriggerKeys" )
1415 property int enumerateForwardKeys: calculateEnumerateForwardKeys (
1516 dccData .fcitx5ConfigProxy .globalConfigOption (
1617 " Hotkey" ,
1718 " EnumerateForwardKeys" ).value )
19+ property int currentTriggerKeys: calculateTriggerKeys (triggerKeys .value )
20+ property bool isUserChanging: false
1821
1922 function calculateEnumerateForwardKeys (value ) {
2023 for (var i = 0 ; i < value .length ; i++ ) {
@@ -24,9 +27,88 @@ DccObject {
2427 }
2528 }
2629 let formattedValue = value .length > 0 ? value .join (" _" ) : " "
30+
31+ if (formattedValue === " CTRL_SHIFT" ) formattedValue = " Ctrl+Shift"
32+ if (formattedValue === " ALT_SHIFT" ) formattedValue = " Alt+Shift"
33+ if (formattedValue === " " ) formattedValue = " None" // 空配置映射到 "None"
34+
2735 return enumKeys .indexOf (formattedValue)
2836 }
2937
38+ function calculateTriggerKeys (value ) {
39+ // 获取完整的TriggerKeys配置
40+ let triggerKeys0 = dccData .fcitx5ConfigProxy .globalConfigOption (" Hotkey" , " TriggerKeys" ).value
41+ let triggerKeys1 = []
42+ try {
43+ // 尝试获取第二个TriggerKey
44+ let triggerKeysObj = dccData .fcitx5ConfigProxy .globalConfigOption (" Hotkey" , " TriggerKeys" )
45+ if (triggerKeysObj && triggerKeysObj .hasOwnProperty (" 1" )) {
46+ triggerKeys1 = triggerKeysObj[" 1" ] || []
47+ }
48+ } catch (e) {
49+ console .warn (" Could not get TriggerKeys/1:" , e)
50+ }
51+
52+ // 检查是否是分别设置的左右Shift
53+ let hasShiftL = (triggerKeys0 && triggerKeys0 .includes && triggerKeys0 .includes (" Shift_L" )) ||
54+ (triggerKeys1 && triggerKeys1 .includes && triggerKeys1 .includes (" Shift_L" ))
55+ let hasShiftR = (triggerKeys0 && triggerKeys0 .includes && triggerKeys0 .includes (" Shift_R" )) ||
56+ (triggerKeys1 && triggerKeys1 .includes && triggerKeys1 .includes (" Shift_R" ))
57+
58+ if (hasShiftL || hasShiftR) {
59+ console .log (" CASE: Detected separate Shift keys, returning Shift (0)" )
60+ return 0 // "Shift"
61+ }
62+
63+ // 优先使用triggerKeys0的数据进行判断,而不是value参数
64+ let actualKeys = triggerKeys0 || []
65+
66+ // 如果TriggerKeys/0配置真正为空或未定义,这是初始状态,默认使用Shift
67+ if (! actualKeys || actualKeys .length === 0 ) {
68+ console .log (" CASE: Empty TriggerKeys/0, returning Shift (0)" )
69+ return 0 // "Shift" - 初始默认
70+ }
71+
72+ // 如果是用户主动设置的None(fcitx5格式为[""])
73+ if (actualKeys .length === 1 && actualKeys[0 ] === " " ) {
74+ console .warn (" CASE: User selected None, returning None (2)" )
75+ return 2 // "None" - 用户主动选择的None
76+ }
77+
78+ let keyStrings = actualKeys .map (key => String (key))
79+
80+ // 检查是否是Ctrl+Space组合
81+ let isCtrlSpace = keyStrings .length === 2 &&
82+ (keyStrings .includes (" Ctrl" ) || keyStrings .includes (" Control" ) || keyStrings .includes (" Control_L" )) &&
83+ (keyStrings .includes (" Space" ) || keyStrings .includes (" space" ))
84+ if (isCtrlSpace) {
85+ console .warn (" CASE: Detected Ctrl+Space, returning Ctrl+Space (1)" )
86+ return 1 // "Ctrl+Space"
87+ }
88+ return 2 // "None"
89+ }
90+
91+ function reverseTriggerKeys (index ) {
92+ console .warn (" === reverseTriggerKeys ===" )
93+ console .warn (" Input index:" , index)
94+ let result
95+ switch (index) {
96+ case 0 :
97+ result = " Shift_L Shift_R"
98+ break
99+ case 1 :
100+ result = [" Ctrl" , " Space" ]
101+ break
102+ case 2 :
103+ result = [" " ] // "None"
104+ break
105+ default :
106+ result = [" Shift_L" , " Shift_R" ]
107+ break
108+ }
109+ return result
110+ }
111+
30112 // title
31113 DccObject {
32114 name: " ShortcutsTitle"
@@ -63,9 +145,15 @@ DccObject {
63145
64146 Component .onCompleted : {
65147 dccData .fcitx5ConfigProxy .onRequestConfigFinished .connect (() => {
66- triggerKeys = dccData .fcitx5ConfigProxy .globalConfigOption (
67- " Hotkey" ,
68- " TriggerKeys" )
148+
149+ let fullTriggerKeys = dccData .fcitx5ConfigProxy .globalConfigOption (" Hotkey" , " TriggerKeys" )
150+
151+ if (! isUserChanging) {
152+ triggerKeys = fullTriggerKeys
153+ console .warn (" Updated triggerKeys:" , triggerKeys .value )
154+ } else {
155+ console .warn (" Skipping config update - user is changing" )
156+ }
69157 enumerateForwardKeys = calculateEnumerateForwardKeys (dccData .fcitx5ConfigProxy .globalConfigOption (" Hotkey" , " EnumerateForwardKeys" ).value )
70158 })
71159 }
@@ -75,6 +163,10 @@ DccObject {
75163 return " "
76164 }
77165 let value = enumKeys[index]
166+
167+ if (value === " Ctrl+Shift" ) value = " CTRL_SHIFT"
168+ if (value === " Alt+Shift" ) value = " ALT_SHIFT"
169+
78170 if (value === " None" ) {
79171 return " "
80172 }
@@ -131,16 +223,28 @@ DccObject {
131223 displayName: qsTr (" Turn on or off input methods" )
132224 weight: 231
133225 pageType: DccObject .Editor
134- page: D .KeySequenceEdit {
135- placeholderText: qsTr (" Please enter a new shortcut" )
136- keys: triggerKeys .value
137- background: null
226+ page: D .ComboBox {
227+ id: triggerComboBox
228+ flat: true
229+ model: triggerEnumKeys
230+ currentIndex: currentTriggerKeys
138231
139- onKeysChanged: {
140- if (keys .length > 0 ) {
141- dccData .fcitx5ConfigProxy .setValue (
142- " Hotkey/TriggerKeys/0" , keys, true )
232+ onCurrentIndexChanged: {
233+ isUserChanging = true
234+
235+ if (currentIndex === 0 ) {
236+ // Shift选项:分别设置左右Shift
237+ dccData .fcitx5ConfigProxy .setValue (" Hotkey/TriggerKeys/0" , [" Shift_L" ], true )
238+ dccData .fcitx5ConfigProxy .setValue (" Hotkey/TriggerKeys/1" , [" Shift_R" ], true )
239+ } else {
240+ let newKeys = reverseTriggerKeys (currentIndex)
241+ dccData .fcitx5ConfigProxy .setValue (" Hotkey/TriggerKeys/0" , newKeys, true )
242+ dccData .fcitx5ConfigProxy .setValue (" Hotkey/TriggerKeys/1" , [" " ], true )
143243 }
244+
245+ Qt .callLater (() => {
246+ isUserChanging = false
247+ })
144248 }
145249 }
146250 }
0 commit comments