Skip to content

Commit

Permalink
Add setup GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
luongthanhlam committed Feb 12, 2022
1 parent a1703cb commit 3954499
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
PREFIX=/usr

engine_name=bamboo
engine_gui_name=ibus-setup-Bamboo.desktop
ibus_e_name=ibus-engine-$(engine_name)
keyboard_shortcut_editor=keyboard-shortcut-editor
macro_editor=macro-editor
Expand Down Expand Up @@ -60,6 +61,7 @@ install: build
mkdir -p $(DESTDIR)$(ibus_dir)/component/

cp -R -f icons data $(DESTDIR)$(engine_dir)
cp -f $(engine_gui_name) $(DESTDIR)$(PREFIX)/share/applications/
cp -f $(ibus_e_name) $(DESTDIR)$(PREFIX)/lib/ibus-${engine_name}/
cp -f $(keyboard_shortcut_editor) $(DESTDIR)$(PREFIX)/lib/ibus-$(engine_name)/
cp -f $(macro_editor) $(DESTDIR)$(PREFIX)/lib/ibus-$(engine_name)/
Expand All @@ -70,7 +72,7 @@ uninstall:
sudo rm -rf $(DESTDIR)$(engine_dir)
sudo rm -rf $(DESTDIR)$(PREFIX)/lib/ibus-$(engine_name)/
sudo rm -f $(DESTDIR)$(ibus_dir)/component/$(engine_name).xml
sudo rm -f $(DESTDIR)$(ibus_dir)/component/$(engine_name)-simple.xml
sudo rm -rf $(DESTDIR)$(PREFIX)/share/applications/$(engine_gui_name)


src: clean
Expand Down
17 changes: 12 additions & 5 deletions bamboo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<layout>default</layout>
<longname>Bamboo</longname>
<description>Vietnamese input method editor</description>
<setup>/usr/lib/ibus-bamboo/ibus-engine-bamboo -gui</setup>
<rank>1</rank>
</engine>
<engine>
Expand All @@ -51,6 +52,7 @@
<longname>Bamboo (US layout)</longname>
<description>Vietnamese input method editor with US keyboard layout</description>
<rank>1</rank>
<setup>/usr/lib/ibus-bamboo/ibus-engine-bamboo -gui</setup>
</engine>
<!-- Vietnamese Icons -->
<engine>
Expand All @@ -59,23 +61,25 @@
<language>vi</language>
<license>GPLv3</license>
<author>Tran Duc Binh &lt;[email protected]&gt;</author>
<icon>/usr/share/ibus-bamboo/icons/vi-candy.svg</icon>
<icon>/usr/share/ibus-bamboo/icons/vi-candy.svg</icon>
<layout>default</layout>
<longname>Bamboo Candy</longname>
<description>Vietnamese input method editor with US keyboard layout with Candy Icon</description>
<rank>1</rank>
<setup>/usr/lib/ibus-bamboo/ibus-engine-bamboo -gui</setup>
</engine>
<engine>
<symbol>vi</symbol>
<name>Bamboo::Flag</name>
<language>vi</language>
<license>GPLv3</license>
<author>Tran Duc Binh &lt;[email protected]&gt;</author>
<icon>/usr/share/ibus-bamboo/icons/vi-flag.svg</icon>
<icon>/usr/share/ibus-bamboo/icons/vi-flag.svg</icon>
<layout>default</layout>
<longname>Bamboo Flag</longname>
<description>Vietnamese input method editor with US keyboard layout with Flag Icon</description>
<rank>1</rank>
<setup>/usr/lib/ibus-bamboo/ibus-engine-bamboo -gui</setup>
</engine>
<!-- English (US) Icons -->
<engine>
Expand All @@ -84,35 +88,38 @@
<language>en</language>
<license>GPLv3</license>
<author>Tran Duc Binh &lt;[email protected]&gt;</author>
<icon>/usr/share/ibus-bamboo/icons/us.svg</icon>
<icon>/usr/share/ibus-bamboo/icons/us.svg</icon>
<layout>us</layout>
<longname>Bamboo English (US)</longname>
<description>Vietnamese input method editor with US keyboard layout with US Normal Icon</description>
<rank>2</rank>
<setup>/usr/lib/ibus-bamboo/ibus-engine-bamboo -gui</setup>
</engine>
<engine>
<symbol>en</symbol>
<name>BambooUs::Candy</name>
<language>en</language>
<license>GPLv3</license>
<author>Tran Duc Binh &lt;[email protected]&gt;</author>
<icon>/usr/share/ibus-bamboo/icons/us-candy.svg</icon>
<icon>/usr/share/ibus-bamboo/icons/us-candy.svg</icon>
<layout>us</layout>
<longname>Bamboo English (US) Candy</longname>
<description>Vietnamese input method editor with US keyboard layout with US Candy Icon</description>
<rank>2</rank>
<setup>/usr/lib/ibus-bamboo/ibus-engine-bamboo -gui</setup>
</engine>
<engine>
<symbol>en</symbol>
<name>BambooUs::Flag</name>
<language>en</language>
<license>GPLv3</license>
<author>Tran Duc Binh &lt;[email protected]&gt;</author>
<icon>/usr/share/ibus-bamboo/icons/us-flag.svg</icon>
<icon>/usr/share/ibus-bamboo/icons/us-flag.svg</icon>
<layout>us</layout>
<longname>Bamboo English (US) Flag</longname>
<description>Vietnamese input method editor with US keyboard layout with US Flag Icon</description>
<rank>2</rank>
<setup>/usr/lib/ibus-bamboo/ibus-engine-bamboo -gui</setup>
</engine>
</engines>
</component>
7 changes: 7 additions & 0 deletions ibus-setup-Bamboo.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Desktop Entry]
Name=IBus-Bamboo Setup
Type=Application
Exec=/usr/lib/ibus-bamboo/ibus-engine-bamboo -gui
Icon=/usr/share/ibus-bamboo/icons/vi.svg
NoDisplay=true
StartupNotify=true
17 changes: 1 addition & 16 deletions src/ibus-bamboo/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package main
import (
"fmt"
"log"
"os"
"os/exec"
"reflect"
"strconv"
Expand Down Expand Up @@ -244,21 +243,7 @@ func (e *IBusBambooEngine) PropertyActivate(propName string, propState uint32) *
return nil
}
if propName == PropKeyInputModeLookupTableShortcut {
cmd := exec.Command("/usr/lib/ibus-bamboo/keyboard-shortcut-editor", e.getShortcutString(), strconv.Itoa(e.config.DefaultInputMode))
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "GTK_IM_MODULE=gtk-im-context-simple")
out, err := cmd.Output()
if err != nil {
out, err = exec.Command("./keyboard-shortcut-editor", e.getShortcutString(), strconv.Itoa(e.config.DefaultInputMode)).Output()
if err != nil {
return nil
}
}
if len(out) > 0 {
e.parseShortcuts(string(out))
} else if err != nil {
fmt.Println("execute keyboard-shortcut-editor: ", err)
}
e.openShortcutsGUI()
}
if propName == PropKeyMacroTable {
OpenMactabFile(e.engineName)
Expand Down
25 changes: 25 additions & 0 deletions src/ibus-bamboo/engine_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package main

import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -52,6 +54,11 @@ func GetIBusEngineCreator() func(*dbus.Conn, string) dbus.ObjectPath {
engine.config = loadConfig(engineName)
engine.propList = GetPropListByConfig(config)
ibus.PublishEngine(conn, objectPath, engine)
if *gui {
engine.openShortcutsGUI()
saveConfig(engine.config, engine.engineName)
os.Exit(0)
}
go engine.init()

return objectPath
Expand Down Expand Up @@ -572,6 +579,24 @@ func notify(enMode bool) {
}
}

func (e *IBusBambooEngine) openShortcutsGUI() {
cmd := exec.Command("/usr/lib/ibus-bamboo/keyboard-shortcut-editor", e.getShortcutString(), strconv.Itoa(e.config.DefaultInputMode))
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "GTK_IM_MODULE=gtk-im-context-simple")
out, err := cmd.Output()
if err != nil {
out, err = exec.Command("./keyboard-shortcut-editor", e.getShortcutString(), strconv.Itoa(e.config.DefaultInputMode)).Output()
if err != nil {
return
}
}
if len(out) > 0 {
e.parseShortcuts(string(out))
} else if err != nil {
fmt.Println("execute keyboard-shortcut-editor: ", err)
}
}

func (e *IBusBambooEngine) parseShortcuts(s string) {
fmt.Printf("output=(%s)\n", s)
list := strings.Split(s, ",")
Expand Down
1 change: 1 addition & 0 deletions src/ibus-bamboo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (

var embedded = flag.Bool("ibus", false, "Run the embedded ibus component")
var version = flag.Bool("version", false, "Show version")
var gui = flag.Bool("gui", false, "Show GUI")
var isWayland = false
var isGnome = false

Expand Down

0 comments on commit 3954499

Please sign in to comment.