From 4d4f003ed7f93b2ad03a5e7fce3693da9bda05e2 Mon Sep 17 00:00:00 2001 From: Tran Duc Binh Date: Mon, 26 Jul 2021 00:26:16 +0700 Subject: [PATCH] Add unicode in option and make it disable by default to fix issue #258 --- src/ibus-bamboo/engine.go | 10 ++++++++- src/ibus-bamboo/prop.go | 45 +++++++++++++++++++++++++++++++++++++++ src/ibus-bamboo/utils.go | 3 ++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/ibus-bamboo/engine.go b/src/ibus-bamboo/engine.go index 866edb08..772277ef 100644 --- a/src/ibus-bamboo/engine.go +++ b/src/ibus-bamboo/engine.go @@ -85,7 +85,7 @@ func (e *IBusBambooEngine) ProcessKeyEvent(keyVal uint32, keyCode uint32, state } return e.hexadecimalProcessKeyEvent(keyVal, keyCode, state) } - if e.isHexadecimalKeyPressed(keyVal, keyCode, state) { + if e.config.IBflags&IBhexadecimalDisabled == 0 && e.isHexadecimalKeyPressed(keyVal, keyCode, state) { if state&IBusReleaseMask != 0 { //Ignore key-up event return false, nil @@ -339,6 +339,14 @@ func (e *IBusBambooEngine) PropertyActivate(propName string, propState uint32) * } } + if propName == PropKeyHexadecimalEnabled { + if propState == ibus.PROP_STATE_CHECKED { + e.config.IBflags &= ^IBhexadecimalDisabled + } else { + e.config.IBflags |= IBhexadecimalDisabled + } + } + if propName == PropKeyStdToneStyle { if propState == ibus.PROP_STATE_CHECKED { e.config.Flags |= bamboo.EstdToneStyle diff --git a/src/ibus-bamboo/prop.go b/src/ibus-bamboo/prop.go index 1163d37a..c2507793 100644 --- a/src/ibus-bamboo/prop.go +++ b/src/ibus-bamboo/prop.go @@ -40,6 +40,7 @@ const ( PropKeyMacroEnabled = "macro_enabled" PropKeyMacroTable = "open_macro_table" PropKeyEmojiEnabled = "emoji_enabled" + PropKeyHexadecimalEnabled = "hexadecimal_enabled" PropKeyConfiguration = "configuration" PropKeyPreeditElimination = "preedit_elimination" PropKeyInputModeLookupTable = "input_mode_lookup_table" @@ -80,6 +81,18 @@ func GetPropListByConfig(c *Config) *ibus.PropList { Symbol: dbus.MakeVariant(ibus.NewText("")), SubProps: dbus.MakeVariant(*ibus.NewPropList()), }, + &ibus.Property{ + Name: "IBusProperty", + Key: "-", + Type: ibus.PROP_TYPE_MENU, + Label: dbus.MakeVariant(ibus.NewText("Phím tắt")), + Tooltip: dbus.MakeVariant(ibus.NewText("Shortcut Keys")), + Sensitive: true, + Visible: true, + Icon: "appointment", + Symbol: dbus.MakeVariant(ibus.NewText("")), + SubProps: dbus.MakeVariant(GetHotKeyPropListByConfig(c)), + }, ) } return ibus.NewPropList( @@ -452,6 +465,26 @@ func GetOptionsPropListByConfig(c *Config) *ibus.PropList { } func GetHotKeyPropListByConfig(c *Config) *ibus.PropList { + hexadecimalChecked := ibus.PROP_STATE_CHECKED + if c.IBflags&IBhexadecimalDisabled != 0 { + hexadecimalChecked = ibus.PROP_STATE_UNCHECKED + } + if c.DefaultInputMode == usIM { + return ibus.NewPropList( + &ibus.Property{ + Name: "IBusProperty", + Key: PropKeyHexadecimalEnabled, + Type: ibus.PROP_TYPE_TOGGLE, + Label: dbus.MakeVariant(ibus.NewText("Unicode [Ctrl + Shift + U]")), + Tooltip: dbus.MakeVariant(ibus.NewText("Unicode")), + Sensitive: true, + Visible: true, + State: hexadecimalChecked, + Symbol: dbus.MakeVariant(ibus.NewText("")), + SubProps: dbus.MakeVariant(*ibus.NewPropList()), + }, + ) + } imQuickSwitchChecked := ibus.PROP_STATE_UNCHECKED if c.IBflags&IBimQuickSwitchEnabled != 0 { imQuickSwitchChecked = ibus.PROP_STATE_CHECKED @@ -470,6 +503,18 @@ func GetHotKeyPropListByConfig(c *Config) *ibus.PropList { } return ibus.NewPropList( + &ibus.Property{ + Name: "IBusProperty", + Key: PropKeyHexadecimalEnabled, + Type: ibus.PROP_TYPE_TOGGLE, + Label: dbus.MakeVariant(ibus.NewText("Unicode [Ctrl + Shift + U]")), + Tooltip: dbus.MakeVariant(ibus.NewText("Unicode")), + Sensitive: true, + Visible: true, + State: hexadecimalChecked, + Symbol: dbus.MakeVariant(ibus.NewText("")), + SubProps: dbus.MakeVariant(*ibus.NewPropList()), + }, &ibus.Property{ Name: "IBusProperty", Key: PropKeyEmojiEnabled, diff --git a/src/ibus-bamboo/utils.go b/src/ibus-bamboo/utils.go index a7281516..bb3d6b72 100644 --- a/src/ibus-bamboo/utils.go +++ b/src/ibus-bamboo/utils.go @@ -86,8 +86,9 @@ const ( IBimQuickSwitchEnabled IBrestoreKeyStrokesEnabled IBmouseCapturing + IBhexadecimalDisabled IBstdFlags = IBspellCheckEnabled | IBspellCheckWithRules | IBautoNonVnRestore | IBddFreeStyle | - IBemojiDisabled | IBinputModeLookupTableEnabled | IBmouseCapturing | IBautoCapitalizeMacro + IBemojiDisabled | IBinputModeLookupTableEnabled | IBmouseCapturing | IBautoCapitalizeMacro | IBhexadecimalDisabled ) const (