Skip to content

Commit b707596

Browse files
committed
move event handling to native
1 parent b3243b2 commit b707596

26 files changed

+58222
-804
lines changed

config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"os"
7+
"strconv"
78
"sync"
89

910
"github.com/jetkvm/kvm/internal/logging"
@@ -102,6 +103,25 @@ type Config struct {
102103
DefaultLogLevel string `json:"default_log_level"`
103104
}
104105

106+
func (c *Config) GetDisplayRotation() uint16 {
107+
rotationInt, err := strconv.ParseUint(c.DisplayRotation, 10, 16)
108+
if err != nil {
109+
logger.Warn().Err(err).Msg("invalid display rotation, using default")
110+
return 270
111+
}
112+
return uint16(rotationInt)
113+
}
114+
115+
func (c *Config) SetDisplayRotation(rotation string) error {
116+
_, err := strconv.ParseUint(rotation, 10, 16)
117+
if err != nil {
118+
logger.Warn().Err(err).Msg("invalid display rotation, using default")
119+
return err
120+
}
121+
c.DisplayRotation = rotation
122+
return nil
123+
}
124+
105125
const configPath = "/userdata/kvm_config.json"
106126

107127
var defaultConfig = &Config{

display.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,6 @@ func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool) {
153153
func updateStaticContents() {
154154
//contents that never change
155155
nativeInstance.UpdateLabelIfChanged("home_info_mac_addr", networkState.MACString())
156-
systemVersion, appVersion, err := GetLocalVersion()
157-
if err == nil {
158-
nativeInstance.UpdateLabelIfChanged("boot_screen_version", systemVersion.String())
159-
nativeInstance.UpdateLabelIfChanged("boot_screen_app_version", appVersion.String())
160-
nativeInstance.UpdateLabelAndChangeVisibility("system_version", systemVersion.String())
161-
nativeInstance.UpdateLabelAndChangeVisibility("app_version", appVersion.String())
162-
}
163156

164157
// get cpu info
165158
cpuInfo, err := os.ReadFile("/proc/cpuinfo")
@@ -266,34 +259,6 @@ func wakeDisplay(force bool) {
266259
backlightState = 0
267260
}
268261

269-
// watchTsEvents monitors the touchscreen for events and simply calls wakeDisplay() to ensure the
270-
// touchscreen interface still works even with LCD dimming/off.
271-
// TODO: This is quite a hack, really we should be getting an event from jetkvm_native, or the whole display backlight
272-
// control should be hoisted up to jetkvm_native.
273-
func watchTsEvents() {
274-
ts, err := os.OpenFile(touchscreenDevice, os.O_RDONLY, 0666)
275-
if err != nil {
276-
displayLogger.Warn().Err(err).Msg("failed to open touchscreen device")
277-
return
278-
}
279-
280-
defer ts.Close()
281-
282-
// This buffer is set to 24 bytes as that's the normal size of events on /dev/input
283-
// Reference: https://www.kernel.org/doc/Documentation/input/input.txt
284-
// This could potentially be set higher, to require multiple events to wake the display.
285-
buf := make([]byte, 24)
286-
for {
287-
_, err := ts.Read(buf)
288-
if err != nil {
289-
displayLogger.Warn().Err(err).Msg("failed to read from touchscreen device")
290-
return
291-
}
292-
293-
wakeDisplay(false)
294-
}
295-
}
296-
297262
// startBacklightTickers starts the two tickers for dimming and switching off the display
298263
// if they're not already set. This is done separately to the init routine as the "never dim"
299264
// option has the value set to zero, but time.NewTicker only accept positive values.
@@ -347,14 +312,11 @@ func initDisplay() {
347312
go func() {
348313
displayLogger.Info().Msg("setting initial display contents")
349314
time.Sleep(500 * time.Millisecond)
350-
_, _ = nativeInstance.DisplaySetRotation(config.DisplayRotation)
351315
updateStaticContents()
352316
displayInited = true
353317
displayLogger.Info().Msg("display inited")
354318
startBacklightTickers()
355319
wakeDisplay(true)
356320
requestDisplayUpdate(true)
357321
}()
358-
359-
go watchTsEvents()
360322
}

internal/native/cgo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build
2+
deps
23
ui_index.c

0 commit comments

Comments
 (0)