Skip to content

Commit 5a4f176

Browse files
authored
feat: UI for changing display orientation
* Added UI for changing display orientation. * Fixed lint issue.
1 parent d79f359 commit 5a4f176

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type Config struct {
8989
KeyboardMacros []KeyboardMacro `json:"keyboard_macros"`
9090
EdidString string `json:"hdmi_edid_string"`
9191
ActiveExtension string `json:"active_extension"`
92+
DisplayRotation string `json:"display_rotation"`
9293
DisplayMaxBrightness int `json:"display_max_brightness"`
9394
DisplayDimAfterSec int `json:"display_dim_after_sec"`
9495
DisplayOffAfterSec int `json:"display_off_after_sec"`
@@ -107,6 +108,7 @@ var defaultConfig = &Config{
107108
AutoUpdateEnabled: true, // Set a default value
108109
ActiveExtension: "",
109110
KeyboardMacros: []KeyboardMacro{},
111+
DisplayRotation: "270",
110112
DisplayMaxBrightness: 64,
111113
DisplayDimAfterSec: 120, // 2 minutes
112114
DisplayOffAfterSec: 1800, // 30 minutes

display.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ func lvImgSetSrc(objName string, src string) (*CtrlResponse, error) {
7373
return CallCtrlAction("lv_img_set_src", map[string]interface{}{"obj": objName, "src": src})
7474
}
7575

76+
func lvDispSetRotation(rotation string) (*CtrlResponse, error) {
77+
return CallCtrlAction("lv_disp_set_rotation", map[string]interface{}{"rotation": rotation})
78+
}
79+
7680
func updateLabelIfChanged(objName string, newText string) {
7781
if newText != "" && newText != displayedTexts[objName] {
7882
_, _ = lvLabelSetText(objName, newText)
@@ -373,6 +377,7 @@ func init() {
373377
waitCtrlClientConnected()
374378
displayLogger.Info().Msg("setting initial display contents")
375379
time.Sleep(500 * time.Millisecond)
380+
_, _ = lvDispSetRotation(config.DisplayRotation)
376381
updateStaticContents()
377382
displayInited = true
378383
displayLogger.Info().Msg("display inited")

jsonrpc.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type JSONRPCEvent struct {
3838
Params interface{} `json:"params,omitempty"`
3939
}
4040

41+
type DisplayRotationSettings struct {
42+
Rotation string `json:"rotation"`
43+
}
44+
4145
type BacklightSettings struct {
4246
MaxBrightness int `json:"max_brightness"`
4347
DimAfter int `json:"dim_after"`
@@ -280,6 +284,24 @@ func rpcTryUpdate() error {
280284
return nil
281285
}
282286

287+
func rpcSetDisplayRotation(params DisplayRotationSettings) error {
288+
var err error
289+
_, err = lvDispSetRotation(params.Rotation)
290+
if err == nil {
291+
config.DisplayRotation = params.Rotation
292+
if err := SaveConfig(); err != nil {
293+
return fmt.Errorf("failed to save config: %w", err)
294+
}
295+
}
296+
return err
297+
}
298+
299+
func rpcGetDisplayRotation() (*DisplayRotationSettings, error) {
300+
return &DisplayRotationSettings{
301+
Rotation: config.DisplayRotation,
302+
}, nil
303+
}
304+
283305
func rpcSetBacklightSettings(params BacklightSettings) error {
284306
blConfig := params
285307

@@ -1012,6 +1034,8 @@ var rpcHandlers = map[string]RPCHandler{
10121034
"getWakeOnLanDevices": {Func: rpcGetWakeOnLanDevices},
10131035
"setWakeOnLanDevices": {Func: rpcSetWakeOnLanDevices, Params: []string{"params"}},
10141036
"resetConfig": {Func: rpcResetConfig},
1037+
"setDisplayRotation": {Func: rpcSetDisplayRotation, Params: []string{"params"}},
1038+
"getDisplayRotation": {Func: rpcGetDisplayRotation},
10151039
"setBacklightSettings": {Func: rpcSetBacklightSettings, Params: []string{"params"}},
10161040
"getBacklightSettings": {Func: rpcGetBacklightSettings},
10171041
"getDCPowerState": {Func: rpcGetDCPowerState},

ui/src/hooks/stores.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ interface SettingsState {
292292
developerMode: boolean;
293293
setDeveloperMode: (enabled: boolean) => void;
294294

295+
displayRotation: string;
296+
setDisplayRotation: (rotation: string) => void;
297+
295298
backlightSettings: BacklightSettings;
296299
setBacklightSettings: (settings: BacklightSettings) => void;
297300
}
@@ -312,6 +315,10 @@ export const useSettingsStore = create(
312315
developerMode: false,
313316
setDeveloperMode: enabled => set({ developerMode: enabled }),
314317

318+
displayRotation: "270",
319+
setDisplayRotation: (rotation: string) =>
320+
set({ displayRotation: rotation }),
321+
315322
backlightSettings: {
316323
max_brightness: 100,
317324
dim_after: 10000,

ui/src/routes/devices.$id.settings.hardware.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ export default function SettingsHardwareRoute() {
1515
const [send] = useJsonRpc();
1616
const settings = useSettingsStore();
1717

18+
const setDisplayRotation = useSettingsStore(state => state.setDisplayRotation);
19+
20+
const handleDisplayRotationChange = (rotation: string) => {
21+
setDisplayRotation(rotation);
22+
handleDisplayRotationSave();
23+
};
24+
25+
const handleDisplayRotationSave = () => {
26+
send("setDisplayRotation", { params: { rotation: settings.displayRotation } }, resp => {
27+
if ("error" in resp) {
28+
notifications.error(
29+
`Failed to set display orientation: ${resp.error.data || "Unknown error"}`,
30+
);
31+
return;
32+
}
33+
notifications.success("Display orientation updated successfully");
34+
});
35+
};
36+
1837
const setBacklightSettings = useSettingsStore(state => state.setBacklightSettings);
1938

2039
const handleBacklightSettingsChange = (settings: BacklightSettings) => {
@@ -59,6 +78,24 @@ export default function SettingsHardwareRoute() {
5978
description="Configure display settings and hardware options for your JetKVM device"
6079
/>
6180
<div className="space-y-4">
81+
<SettingsItem
82+
title="Display Orientation"
83+
description="Set the orientation of the display"
84+
>
85+
<SelectMenuBasic
86+
size="SM"
87+
label=""
88+
value={settings.displayRotation.toString()}
89+
options={[
90+
{ value: "270", label: "Normal" },
91+
{ value: "90", label: "Inverted" },
92+
]}
93+
onChange={e => {
94+
settings.displayRotation = e.target.value;
95+
handleDisplayRotationChange(settings.displayRotation);
96+
}}
97+
/>
98+
</SettingsItem>
6299
<SettingsItem
63100
title="Display Brightness"
64101
description="Set the brightness of the display"

0 commit comments

Comments
 (0)