Skip to content

Commit

Permalink
Add unicode in option and make it disable by default to fix issue #258
Browse files Browse the repository at this point in the history
  • Loading branch information
binhtran432k committed Jul 25, 2021
1 parent cd0aa9f commit 4d4f003
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/ibus-bamboo/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions src/ibus-bamboo/prop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/ibus-bamboo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ const (
IBimQuickSwitchEnabled
IBrestoreKeyStrokesEnabled
IBmouseCapturing
IBhexadecimalDisabled
IBstdFlags = IBspellCheckEnabled | IBspellCheckWithRules | IBautoNonVnRestore | IBddFreeStyle |
IBemojiDisabled | IBinputModeLookupTableEnabled | IBmouseCapturing | IBautoCapitalizeMacro
IBemojiDisabled | IBinputModeLookupTableEnabled | IBmouseCapturing | IBautoCapitalizeMacro | IBhexadecimalDisabled
)

const (
Expand Down

0 comments on commit 4d4f003

Please sign in to comment.