set screen size using struct.

This commit is contained in:
Miroslav Šedivý 2021-01-15 17:30:19 +01:00
parent 0e09609c67
commit 3bbe3781c8
8 changed files with 30 additions and 21 deletions

View File

@ -3,15 +3,16 @@ package room
import (
"net/http"
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
"demodesk/neko/internal/utils"
)
type ScreenConfigurationPayload struct {
Width int `json:"width"`
Height int `json:"height"`
Rate int `json:"rate"`
Width int `json:"width"`
Height int `json:"height"`
Rate int16 `json:"rate"`
}
func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request) {
@ -25,7 +26,7 @@ func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request
utils.HttpSuccess(w, ScreenConfigurationPayload{
Width: size.Width,
Height: size.Height,
Rate: int(size.Rate),
Rate: size.Rate,
})
}
@ -35,7 +36,11 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
return
}
if err := h.desktop.ChangeScreenSize(data.Width, data.Height, data.Rate); err != nil {
if err := h.desktop.SetScreenSize(types.ScreenSize{
Width: data.Width,
Height: data.Height,
Rate: data.Rate,
}); err != nil {
utils.HttpUnprocessableEntity(w, err)
return
}
@ -60,7 +65,7 @@ func (h *RoomHandler) screenConfigurationsList(w http.ResponseWriter, r *http.Re
list = append(list, ScreenConfigurationPayload{
Width: size.Width,
Height: size.Height,
Rate: int(fps),
Rate: fps,
})
}
}

View File

@ -11,7 +11,7 @@ import (
type Desktop struct {
ScreenWidth int
ScreenHeight int
ScreenRate int
ScreenRate int16
}
func (Desktop) Init(cmd *cobra.Command) error {
@ -39,7 +39,7 @@ func (s *Desktop) Set() {
if err1 == nil && err2 == nil && err3 == nil {
s.ScreenWidth = int(width)
s.ScreenHeight = int(height)
s.ScreenRate = int(rate)
s.ScreenRate = int16(rate)
}
}
}

View File

@ -40,11 +40,7 @@ func (manager *DesktopManagerCtx) ScreenConfigurations() map[int]types.ScreenCon
return xorg.ScreenConfigurations
}
func (manager *DesktopManagerCtx) GetScreenSize() *types.ScreenSize {
return xorg.GetScreenSize()
}
func (manager *DesktopManagerCtx) ChangeScreenSize(width int, height int, rate int) error {
func (manager *DesktopManagerCtx) SetScreenSize(size types.ScreenSize) error {
mu.Lock()
manager.emmiter.Emit("before_screen_size_change")
@ -53,7 +49,11 @@ func (manager *DesktopManagerCtx) ChangeScreenSize(width int, height int, rate i
mu.Unlock()
}()
return xorg.ChangeScreenSize(width, height, rate)
return xorg.ChangeScreenSize(size.Width, size.Height, size.Rate)
}
func (manager *DesktopManagerCtx) GetScreenSize() *types.ScreenSize {
return xorg.GetScreenSize()
}
func (manager *DesktopManagerCtx) SetKeyboardMap(kbd types.KeyboardMap) error {

View File

@ -167,14 +167,14 @@ func CheckKeys(duration time.Duration) {
}
}
func ChangeScreenSize(width int, height int, rate int) error {
func ChangeScreenSize(width int, height int, rate int16) error {
mu.Lock()
defer mu.Unlock()
for index, size := range ScreenConfigurations {
if size.Width == width && size.Height == height {
for _, fps := range size.Rates {
if int16(rate) == fps {
if rate == fps {
C.XSetScreenConfiguration(C.int(index), C.short(fps))
return nil
}

View File

@ -38,7 +38,6 @@ type DesktopManager interface {
OnAfterScreenSizeChange(listener func())
// xorg
ChangeScreenSize(width int, height int, rate int) error
Move(x, y int)
Scroll(x, y int)
ButtonDown(code int) error
@ -47,6 +46,7 @@ type DesktopManager interface {
KeyUp(code uint64) error
ResetKeys()
ScreenConfigurations() map[int]ScreenConfiguration
SetScreenSize(ScreenSize) error
GetScreenSize() *ScreenSize
SetKeyboardMap(KeyboardMap) error
GetKeyboardMap() (*KeyboardMap, error)

View File

@ -116,7 +116,7 @@ type ScreenSize struct {
Event string `json:"event,omitempty"`
Width int `json:"width"`
Height int `json:"height"`
Rate int `json:"rate"`
Rate int16 `json:"rate"`
}
/////////////////////////////

View File

@ -12,7 +12,11 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
return nil
}
if err := h.desktop.ChangeScreenSize(payload.Width, payload.Height, payload.Rate); err != nil {
if err := h.desktop.SetScreenSize(types.ScreenSize{
Width: payload.Width,
Height: payload.Height,
Rate: payload.Rate,
}); err != nil {
return err
}

View File

@ -55,7 +55,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
ScreenSize: message.ScreenSize{
Width: size.Width,
Height: size.Height,
Rate: int(size.Rate),
Rate: size.Rate,
},
Members: members,
ImplicitHosting: h.sessions.ImplicitHosting(),
@ -70,7 +70,7 @@ func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
screenSizesList = append(screenSizesList, message.ScreenSize{
Width: size.Width,
Height: size.Height,
Rate: int(fps),
Rate: fps,
})
}
}