2020-11-04 12:27:47 +13:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2021-03-12 05:44:49 +13:00
|
|
|
"os"
|
2020-11-04 12:27:47 +13:00
|
|
|
"regexp"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
2023-08-18 02:14:59 +12:00
|
|
|
|
|
|
|
"github.com/demodesk/neko/pkg/types"
|
2020-11-04 12:27:47 +13:00
|
|
|
)
|
|
|
|
|
|
|
|
type Desktop struct {
|
2021-03-12 05:44:49 +13:00
|
|
|
Display string
|
|
|
|
|
2023-08-18 02:14:59 +12:00
|
|
|
ScreenSize types.ScreenSize
|
2023-04-23 03:06:35 +12:00
|
|
|
|
2023-08-18 02:14:59 +12:00
|
|
|
UseInputDriver bool
|
|
|
|
InputSocket string
|
|
|
|
|
2023-11-24 22:39:09 +13:00
|
|
|
Unminimize bool
|
|
|
|
FileChooserDialog bool
|
2020-11-04 12:27:47 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
func (Desktop) Init(cmd *cobra.Command) error {
|
2021-03-17 03:24:58 +13:00
|
|
|
cmd.PersistentFlags().String("desktop.screen", "1280x720@30", "default screen size and framerate")
|
|
|
|
if err := viper.BindPFlag("desktop.screen", cmd.PersistentFlags().Lookup("desktop.screen")); err != nil {
|
2020-11-04 12:27:47 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-18 02:14:59 +12:00
|
|
|
cmd.PersistentFlags().Bool("desktop.input.enabled", true, "whether custom xf86 input driver should be used to handle touchscreen")
|
|
|
|
if err := viper.BindPFlag("desktop.input.enabled", cmd.PersistentFlags().Lookup("desktop.input.enabled")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().String("desktop.input.socket", "/tmp/xf86-input-neko.sock", "socket path for custom xf86 input driver connection")
|
|
|
|
if err := viper.BindPFlag("desktop.input.socket", cmd.PersistentFlags().Lookup("desktop.input.socket")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-04-23 03:06:35 +12:00
|
|
|
cmd.PersistentFlags().Bool("desktop.unminimize", true, "automatically unminimize window when it is minimized")
|
|
|
|
if err := viper.BindPFlag("desktop.unminimize", cmd.PersistentFlags().Lookup("desktop.unminimize")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-11-24 22:39:09 +13:00
|
|
|
cmd.PersistentFlags().Bool("desktop.file_chooser_dialog", false, "whether to handle file chooser dialog externally")
|
|
|
|
if err := viper.BindPFlag("desktop.file_chooser_dialog", cmd.PersistentFlags().Lookup("desktop.file_chooser_dialog")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-04 12:27:47 +13:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Desktop) Set() {
|
2021-03-12 05:44:49 +13:00
|
|
|
// Display is provided by env variable
|
|
|
|
s.Display = os.Getenv("DISPLAY")
|
|
|
|
|
2023-08-18 02:14:59 +12:00
|
|
|
s.ScreenSize = types.ScreenSize{
|
|
|
|
Width: 1280,
|
|
|
|
Height: 720,
|
|
|
|
Rate: 30,
|
|
|
|
}
|
2020-11-04 12:27:47 +13:00
|
|
|
|
|
|
|
r := regexp.MustCompile(`([0-9]{1,4})x([0-9]{1,4})@([0-9]{1,3})`)
|
2021-03-17 03:24:58 +13:00
|
|
|
res := r.FindStringSubmatch(viper.GetString("desktop.screen"))
|
2020-11-04 12:27:47 +13:00
|
|
|
|
|
|
|
if len(res) > 0 {
|
|
|
|
width, err1 := strconv.ParseInt(res[1], 10, 64)
|
|
|
|
height, err2 := strconv.ParseInt(res[2], 10, 64)
|
|
|
|
rate, err3 := strconv.ParseInt(res[3], 10, 64)
|
|
|
|
|
|
|
|
if err1 == nil && err2 == nil && err3 == nil {
|
2023-08-18 02:14:59 +12:00
|
|
|
s.ScreenSize.Width = int(width)
|
|
|
|
s.ScreenSize.Height = int(height)
|
|
|
|
s.ScreenSize.Rate = int16(rate)
|
2020-11-04 12:27:47 +13:00
|
|
|
}
|
|
|
|
}
|
2023-08-18 02:14:59 +12:00
|
|
|
|
|
|
|
s.UseInputDriver = viper.GetBool("desktop.input.enabled")
|
|
|
|
s.InputSocket = viper.GetString("desktop.input.socket")
|
|
|
|
s.Unminimize = viper.GetBool("desktop.unminimize")
|
2023-11-24 22:39:09 +13:00
|
|
|
s.FileChooserDialog = viper.GetBool("desktop.file_chooser_dialog")
|
2020-11-04 12:27:47 +13:00
|
|
|
}
|