Skip to content

Commit

Permalink
Replace goibus with upstream ibus library
Browse files Browse the repository at this point in the history
  • Loading branch information
luongthanhlam committed Dec 2, 2023
1 parent 12df73a commit 1661620
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@master
with:
fetch-depth: 1
- run: sudo apt-get update && sudo apt-get install -y make libx11-dev libxtst-dev libgtk-3-dev osc
- run: sudo apt-get update && sudo apt-get install -y make libibus-1.0-dev libx11-dev libxtst-dev libgtk-3-dev osc
- run: make t && make build
- shell: bash
env:
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ xml:
glib-compile-resources --generate-source setup-ui/keyboard.gresource.xml

build:
GOPATH=$(CURDIR) GO111MODULE=off go build $(GOLDFLAGS) -o $(ibus_e_name) ibus-$(engine_name)
GOPATH=$(CURDIR) GO111MODULE=off CGO_ENABLED=1 go build $(GOLDFLAGS) -o $(ibus_e_name) ibus-$(engine_name)
gcc -o $(keyboard_shortcut_editor) setup-ui/$(keyboard_shortcut_editor).c `pkg-config --libs --cflags gtk+-3.0`
gcc -rdynamic -o $(macro_editor) setup-ui/$(macro_editor).c `pkg-config --libs --cflags gtk+-3.0`

t:
GOPATH=$(CURDIR) GO111MODULE=off go test ./src/ibus-bamboo/...
GOPATH=$(CURDIR) GO111MODULE=off go test ./src/github.com/BambooEngine/bamboo-core/...
GOPATH=$(CURDIR) GO111MODULE=off CGO_ENABLED=1 go test ./src/ibus-bamboo/...
GOPATH=$(CURDIR) GO111MODULE=off CGO_ENABLED=1 go test ./src/github.com/BambooEngine/bamboo-core/...

clean:
rm -f ibus-engine-* *_linux *_cover.html go_test_* go_build_* test *.gz test
Expand Down
2 changes: 1 addition & 1 deletion archlinux/PKGBUILD-git
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ arch=(any)
license=(GPL3)
url="https://github.com/BambooEngine/ibus-bamboo"
optdepends=('ibus')
makedepends=('go' 'libx11' 'gtk3' 'libxtst')
makedepends=('go' 'ibus-devel' 'libx11' 'gtk3' 'libxtst')
source=("$pkgname"::git+'https://github.com/BambooEngine/ibus-bamboo.git')
md5sums=('SKIP')
options=('!strip')
Expand Down
2 changes: 1 addition & 1 deletion archlinux/PKGBUILD-obs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ arch=(any)
license=(GPL3)
url="https://github.com/BambooEngine/ibus-bamboo"
optdepends=('ibus')
makedepends=('go' 'libx11' 'gtk3' 'libxtst')
makedepends=('go' 'ibus-devel' 'libx11' 'gtk3' 'libxtst')
source=("$pkgname-$pkgver.tar.gz")
md5sums=('SKIP')
options=('!strip')
Expand Down
2 changes: 1 addition & 1 deletion archlinux/PKGBUILD-release
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ arch=(any)
license=(GPL3)
url="https://github.com/BambooEngine/ibus-bamboo"
optdepends=('ibus')
makedepends=('go' 'libx11' 'gtk3' 'libxtst')
makedepends=('go' 'ibus-devel' 'libx11' 'gtk3' 'libxtst')
source=("$pkgname-$pkgver.tar.gz"::"https://github.com/BambooEngine/$pkgname/archive/v$pkgver.tar.gz")
md5sums=('SKIP')
options=('!strip')
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Source: ibus-bamboo
Section: utils
Priority: extra
Maintainer: Luong Thanh Lam <ltlam93@gmail.com>
Build-Depends: debhelper, golang, libx11-dev, libxtst-dev, libgtk-3-dev
Build-Depends: debhelper, golang, libibus-1.0-dev, libx11-dev, libxtst-dev, libgtk-3-dev
Standards-Version: 0.8.3
Homepage: https://github.com/BambooEngine/ibus-bamboo

Expand Down
2 changes: 1 addition & 1 deletion ibus-bamboo.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Architecture: any
Version: 0.8.3-0
Maintainer: Luong Thanh Lam <ltlam93@gmail.com>
Homepage: https://github.com/BambooEngine/ibus-bamboo
Build-Depends: debhelper (>= 9), golang, libx11-dev, libgtk-3-dev, libxt-dev, libxtst-dev
Build-Depends: debhelper (>= 9), golang, libibus-1.0-dev, libx11-dev, libgtk-3-dev, libxt-dev, libxtst-dev
Files:
0 0 ibus-bamboo-0.8.3.tar.gz
DEBTRANSFORM-TAR:
Expand Down
2 changes: 1 addition & 1 deletion ibus-bamboo.spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ License: GPL-3.0+
URL: https://github.com/BambooEngine/ibus-bamboo
Source0: %{name}-%{version}.tar.gz

BuildRequires: go, libX11-devel, libXtst-devel, gtk3-devel
BuildRequires: go, ibus-devel, libX11-devel, libXtst-devel, gtk3-devel
Requires: ibus, gtk3

%description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package ibus

/*
#cgo pkg-config: ibus-1.0
#include <ibus.h>
#include <stdlib.h>
*/
import "C"
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"unsafe"
"strings"

"github.com/godbus/dbus"
)
Expand All @@ -25,8 +21,8 @@ const (

IBUS_IFACE_PANEL = "org.freedesktop.IBus.Panel"
IBUS_IFACE_CONFIG = "org.freedesktop.IBus.Config"
IBUS_IFACE_ENGINE = "org.freedesktop.IBus.Engine"
IBUS_IFACE_SERVICE = "org.freedesktop.IBus.Service"
IBUS_IFACE_ENGINE = "org.freedesktop.IBus.Engine"
IBUS_IFACE_ENGINE_FACTORY = "org.freedesktop.IBus.Factory"
IBUS_IFACE_INPUT_CONTEXT = "org.freedesktop.IBus.InputContext"
IBUS_IFACE_NOTIFICATIONS = "org.freedesktop.IBus.Notifications"
Expand Down Expand Up @@ -61,16 +57,85 @@ const (
)

func GetAddress() string {
cString := (*C.char)(unsafe.Pointer(C.ibus_get_address()))
// defer C.free(unsafe.Pointer(cString))
return C.GoString(cString)
address := os.Getenv("IBUS_ADDRESS")
if address != "" {
return address
}
data, err := ioutil.ReadFile(GetSocketPath(true))
if err != nil {
data, err = ioutil.ReadFile(GetSocketPath(false))
if err != nil {
panic(err)
}
}

for _, line := range strings.Split(string(data), "\n") {
if strings.Index(line, "IBUS_ADDRESS=") == 0 {
address = line[13:]
}
}
return address
}

func GetSocketPath(useWayland bool) string {
path := os.Getenv("IBUS_ADDRESS_FILE")
if path != "" {
return path
}
display := os.Getenv("WAYLAND_DISPLAY")
if display != "" && useWayland {
return GetWaylandSocketPath(display)
}
return GetX11SocketPath()
}

func GetX11SocketPath() string {
display := os.Getenv("DISPLAY")
if display == "" {
fmt.Fprintf(os.Stderr, "DISPLAY is empty! We use default DISPLAY (:0.0)")
display = ":0.0"
}
hostname := "unix"
displayNumber := ""
// format is {hostname}:{displaynumber}.{screennumber}
HDS := strings.SplitN(display, ":", 2)
DS := strings.SplitN(HDS[1], ".", 2)

if HDS[0] != "" {
hostname = HDS[0]
}
displayNumber = DS[0]
p := fmt.Sprintf("%s-%s-%s", GetLocalMachineId(), hostname, displayNumber)
return GetUserConfigDir() + "/ibus/bus/" + p
}

func GetSocketPath() string {
cString := (*C.char)(unsafe.Pointer(C.ibus_get_socket_path()))
// defer C.free(unsafe.Pointer(cString))
return C.GoString(cString)
func GetWaylandSocketPath(display string) string {
hostname := "unix"
p := fmt.Sprintf("%s-%s-%s", GetLocalMachineId(), hostname, display)
return GetUserConfigDir() + "/ibus/bus/" + p
}

func GetLocalMachineId() string {
var mID []byte
var err error
mID, err = ioutil.ReadFile("/var/lib/dbus/machine-id")
if err != nil {
mID, err = ioutil.ReadFile("/etc/machine-id")
if err != nil {
panic(err)
}
}
return strings.TrimSpace(string(mID))
}

func GetUserConfigDir() string {
dir := os.Getenv("XDG_CONFIG_HOME")
if dir == "" {
return os.Getenv("HOME") + "/.config"
}
return dir
}

func GetUserAuth() []dbus.Auth {
uid := os.Getenv("DBUS_AUTH_UID")
if uid == "" {
Expand Down
95 changes: 15 additions & 80 deletions src/github.com/BambooEngine/goibus/ibus/common.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package ibus

/*
#cgo pkg-config: ibus-1.0
#include <ibus.h>
#include <stdlib.h>
*/
import "C"
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"unsafe"

"github.com/godbus/dbus"
)
Expand All @@ -21,8 +25,8 @@ const (

IBUS_IFACE_PANEL = "org.freedesktop.IBus.Panel"
IBUS_IFACE_CONFIG = "org.freedesktop.IBus.Config"
IBUS_IFACE_SERVICE = "org.freedesktop.IBus.Service"
IBUS_IFACE_ENGINE = "org.freedesktop.IBus.Engine"
IBUS_IFACE_SERVICE = "org.freedesktop.IBus.Service"
IBUS_IFACE_ENGINE_FACTORY = "org.freedesktop.IBus.Factory"
IBUS_IFACE_INPUT_CONTEXT = "org.freedesktop.IBus.InputContext"
IBUS_IFACE_NOTIFICATIONS = "org.freedesktop.IBus.Notifications"
Expand Down Expand Up @@ -57,85 +61,16 @@ const (
)

func GetAddress() string {
address := os.Getenv("IBUS_ADDRESS")
if address != "" {
return address
}
data, err := ioutil.ReadFile(GetSocketPath(true))
if err != nil {
data, err = ioutil.ReadFile(GetSocketPath(false))
if err != nil {
panic(err)
}
}

for _, line := range strings.Split(string(data), "\n") {
if strings.Index(line, "IBUS_ADDRESS=") == 0 {
address = line[13:]
}
}
return address
}

func GetSocketPath(useWayland bool) string {
path := os.Getenv("IBUS_ADDRESS_FILE")
if path != "" {
return path
}
display := os.Getenv("WAYLAND_DISPLAY")
if display != "" && useWayland {
return GetWaylandSocketPath(display)
}
return GetX11SocketPath()
}

func GetX11SocketPath() string {
display := os.Getenv("DISPLAY")
if display == "" {
fmt.Fprintf(os.Stderr, "DISPLAY is empty! We use default DISPLAY (:0.0)")
display = ":0.0"
}
hostname := "unix"
displayNumber := ""
// format is {hostname}:{displaynumber}.{screennumber}
HDS := strings.SplitN(display, ":", 2)
DS := strings.SplitN(HDS[1], ".", 2)

if HDS[0] != "" {
hostname = HDS[0]
}
displayNumber = DS[0]
p := fmt.Sprintf("%s-%s-%s", GetLocalMachineId(), hostname, displayNumber)
return GetUserConfigDir() + "/ibus/bus/" + p
cString := (*C.char)(unsafe.Pointer(C.ibus_get_address()))
// defer C.free(unsafe.Pointer(cString))
return C.GoString(cString)
}

func GetWaylandSocketPath(display string) string {
hostname := "unix"
p := fmt.Sprintf("%s-%s-%s", GetLocalMachineId(), hostname, display)
return GetUserConfigDir() + "/ibus/bus/" + p
func GetSocketPath() string {
cString := (*C.char)(unsafe.Pointer(C.ibus_get_socket_path()))
// defer C.free(unsafe.Pointer(cString))
return C.GoString(cString)
}

func GetLocalMachineId() string {
var mID []byte
var err error
mID, err = ioutil.ReadFile("/var/lib/dbus/machine-id")
if err != nil {
mID, err = ioutil.ReadFile("/etc/machine-id")
if err != nil {
panic(err)
}
}
return strings.TrimSpace(string(mID))
}

func GetUserConfigDir() string {
dir := os.Getenv("XDG_CONFIG_HOME")
if dir == "" {
return os.Getenv("HOME") + "/.config"
}
return dir
}

func GetUserAuth() []dbus.Auth {
uid := os.Getenv("DBUS_AUTH_UID")
if uid == "" {
Expand Down

0 comments on commit 1661620

Please sign in to comment.