Skip to content

Commit 1e58e3d

Browse files
committed
move event handling to native
1 parent a05ffea commit 1e58e3d

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"
@@ -105,6 +106,25 @@ type Config struct {
105106
DefaultLogLevel string `json:"default_log_level"`
106107
}
107108

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

110130
var defaultConfig = &Config{

display.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,6 @@ func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool) {
195195
func updateStaticContents() {
196196
//contents that never change
197197
nativeInstance.UpdateLabelIfChanged("home_info_mac_addr", networkState.MACString())
198-
systemVersion, appVersion, err := GetLocalVersion()
199-
if err == nil {
200-
nativeInstance.UpdateLabelIfChanged("boot_screen_version", systemVersion.String())
201-
nativeInstance.UpdateLabelIfChanged("boot_screen_app_version", appVersion.String())
202-
nativeInstance.UpdateLabelAndChangeVisibility("system_version", systemVersion.String())
203-
nativeInstance.UpdateLabelAndChangeVisibility("app_version", appVersion.String())
204-
}
205198

206199
// get cpu info
207200
cpuInfo, err := os.ReadFile("/proc/cpuinfo")
@@ -308,34 +301,6 @@ func wakeDisplay(force bool) {
308301
backlightState = 0
309302
}
310303

311-
// watchTsEvents monitors the touchscreen for events and simply calls wakeDisplay() to ensure the
312-
// touchscreen interface still works even with LCD dimming/off.
313-
// TODO: This is quite a hack, really we should be getting an event from jetkvm_native, or the whole display backlight
314-
// control should be hoisted up to jetkvm_native.
315-
func watchTsEvents() {
316-
ts, err := os.OpenFile(touchscreenDevice, os.O_RDONLY, 0666)
317-
if err != nil {
318-
displayLogger.Warn().Err(err).Msg("failed to open touchscreen device")
319-
return
320-
}
321-
322-
defer ts.Close()
323-
324-
// This buffer is set to 24 bytes as that's the normal size of events on /dev/input
325-
// Reference: https://www.kernel.org/doc/Documentation/input/input.txt
326-
// This could potentially be set higher, to require multiple events to wake the display.
327-
buf := make([]byte, 24)
328-
for {
329-
_, err := ts.Read(buf)
330-
if err != nil {
331-
displayLogger.Warn().Err(err).Msg("failed to read from touchscreen device")
332-
return
333-
}
334-
335-
wakeDisplay(false)
336-
}
337-
}
338-
339304
// startBacklightTickers starts the two tickers for dimming and switching off the display
340305
// if they're not already set. This is done separately to the init routine as the "never dim"
341306
// option has the value set to zero, but time.NewTicker only accept positive values.
@@ -389,14 +354,11 @@ func initDisplay() {
389354
go func() {
390355
displayLogger.Info().Msg("setting initial display contents")
391356
time.Sleep(500 * time.Millisecond)
392-
_, _ = nativeInstance.DisplaySetRotation(config.DisplayRotation)
393357
updateStaticContents()
394358
displayInited = true
395359
displayLogger.Info().Msg("display inited")
396360
startBacklightTickers()
397361
wakeDisplay(true)
398362
requestDisplayUpdate(true)
399363
}()
400-
401-
go watchTsEvents()
402364
}

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)