Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ibus/_common.cgo → _common.cgo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ibus
package goibus

/*
#cgo pkg-config: ibus-1.0
Expand Down
4 changes: 2 additions & 2 deletions ibus/bus.go → bus.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ibus
package goibus

import "github.com/godbus/dbus"
import "github.com/godbus/dbus/v5"

type Bus struct {
dbusConn *dbus.Conn
Expand Down
31 changes: 21 additions & 10 deletions ibus/common.go → common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ibus
package goibus

import (
"fmt"
Expand All @@ -7,7 +7,7 @@ import (
"strconv"
"strings"

"github.com/godbus/dbus"
"github.com/godbus/dbus/v5"
)

const (
Expand Down Expand Up @@ -79,20 +79,31 @@ func GetSocketPath() string {
if path != "" {
return path
}
display := os.Getenv("DISPLAY")
display := os.Getenv("WAYLAND_DISPLAY")
isWayland := true
if display == "" {
isWayland = false
display = os.Getenv("DISPLAY")
}
if display == "" {
fmt.Fprintf(os.Stderr, "DISPLAY is empty! We use default DISPLAY (:0.0)")
display = ":0.0"
}
// format is {hostname}:{displaynumber}.{screennumber}
hostname := "unix"
HDS := strings.SplitN(display, ":", 2)
DS := strings.SplitN(HDS[1], ".", 2)

if HDS[0] != "" {
hostname = HDS[0]
displayNumber := ""
if isWayland {
displayNumber = display
} else {
// 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, DS[0])
p := fmt.Sprintf("%s-%s-%s", GetLocalMachineId(), hostname, displayNumber)
path = GetUserConfigDir() + "/ibus/bus/" + p

return path
Expand Down
5 changes: 3 additions & 2 deletions ibus/component.go → component.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ibus
package goibus

import (
"encoding/xml"
"fmt"
"github.com/godbus/dbus"
"io"

"github.com/godbus/dbus/v5"
)

type Component struct {
Expand Down
4 changes: 2 additions & 2 deletions ibus/engine.go → engine.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ibus
package goibus

import (
"github.com/godbus/dbus"
"github.com/godbus/dbus/v5"
)

type Engine struct {
Expand Down
4 changes: 2 additions & 2 deletions ibus/engineDesc.go → engineDesc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ibus
package goibus

import (
"github.com/godbus/dbus"
"github.com/godbus/dbus/v5"
)

type EngineDesc struct {
Expand Down
4 changes: 2 additions & 2 deletions ibus/factory.go → factory.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ibus
package goibus

import (
"github.com/godbus/dbus"
"github.com/godbus/dbus/v5"
)

type Factory struct {
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/BambooEngine/goibus

go 1.13

require github.com/godbus/dbus/v5 v5.1.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
39 changes: 0 additions & 39 deletions ibus/lookupTable.go

This file was deleted.

137 changes: 137 additions & 0 deletions lookupTable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package goibus

import (
"github.com/godbus/dbus/v5"
)

type LookupTable struct {
Name string
Attachments map[string]dbus.Variant
PageSize uint32
CursorPos uint32
CursorVisible bool
Round bool
Orientation int32
Candidates []dbus.Variant
Labels []dbus.Variant
}

func NewLookupTable() *LookupTable {
lt := &LookupTable{}
lt.Name = "IBusLookupTable"
lt.PageSize = 5
lt.CursorPos = 0
lt.CursorVisible = true
lt.Round = false
lt.Orientation = ORIENTATION_SYSTEM

return lt
}

func (lt *LookupTable) AppendCandidate(text string) {
t := NewText(text)
lt.Candidates = append(lt.Candidates, dbus.MakeVariant(*t))
}

func (lt *LookupTable) AppendLabel(label string) {
l := NewText(label)
lt.Labels = append(lt.Labels, dbus.MakeVariant(*l))
}

func (lt *LookupTable) SetCursorPos(pos uint32) bool {
if pos >= uint32(len(lt.Candidates)) || pos < 0 {
return false
}
lt.CursorPos = pos
return true
}

func (lt *LookupTable) GetCursorPos() uint32 {
return lt.CursorPos
}

func (lt *LookupTable) GetCursorPosInCurrentPage() uint32 {
return lt.CursorPos % lt.PageSize
}

func (lt *LookupTable) SetCursorPosInCurrentPage(pos uint32) bool {
if pos < 0 || pos >= lt.PageSize {
return false
}
pos += lt.GetCursorPosInCurrentPage()
if pos >= uint32(len(lt.Candidates)) {
return false
}
lt.CursorPos = pos
return true
}

func (lt *LookupTable) CursorUp() bool {
if lt.CursorPos == 0 {
if lt.Round {
lt.CursorPos = uint32(len(lt.Candidates)) - 1
return true
} else {
return false
}
}
lt.CursorPos -= 1
return true
}

func (lt *LookupTable) CursorDown() bool {
if lt.CursorPos == uint32(len(lt.Candidates)) {
if lt.Round {
lt.CursorPos = 0
return true
} else {
return false
}
}
lt.CursorPos += 1
return true
}

func (lt *LookupTable) PageUp() bool {
if lt.CursorPos < lt.PageSize {
if lt.Round {
var nrCandidates = uint32(len(lt.Candidates))
var maxPage = uint32(nrCandidates / lt.PageSize)
lt.CursorPos += maxPage * lt.PageSize
if lt.CursorPos > nrCandidates-1 {
lt.CursorPos = nrCandidates - 1
}
return true
} else {
return false
}
}
lt.CursorPos -= lt.PageSize
return true
}

func (lt *LookupTable) PageDown() bool {
var currentPage = lt.CursorPos / lt.PageSize
var nrCandidates = uint32(len(lt.Candidates))
var maxPage = nrCandidates / lt.PageSize
if currentPage >= maxPage {
if lt.Round {
lt.CursorPos %= lt.PageSize
return true
} else {
return false
}
}
var pos = lt.CursorPos + lt.PageSize
if pos >= nrCandidates {
pos = nrCandidates - 1
}
lt.CursorPos = pos
return true
}

func (lt *LookupTable) Clean() {
lt.Candidates = nil
lt.Labels = nil
lt.CursorPos = 0
}
4 changes: 2 additions & 2 deletions ibus/property.go → property.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ibus
package goibus

import (
"github.com/godbus/dbus"
"github.com/godbus/dbus/v5"
)

type PropList struct {
Expand Down
4 changes: 2 additions & 2 deletions ibus/text.go → text.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ibus
package goibus

import (
"github.com/godbus/dbus"
"github.com/godbus/dbus/v5"
)

type Attribute struct {
Expand Down