feat(overlay): add position customization for overlay placement
- Introduce PositionX and PositionY fields in OverlaySettings to allow manual positioning of the overlay. - Update validation to ensure PositionX and PositionY are not less than -1. - Modify diskConfig to include new position fields for JSON serialization. - Implement functionality to save overlay position during drag events in the GUI. - Enhance overlay placement logic to respect user-defined positions while ensuring proper display behavior.
This commit is contained in:
+16
-1
@@ -143,13 +143,16 @@ func (a *Application) activate() {
|
||||
a.buildWindow()
|
||||
a.installActions()
|
||||
a.subscribeModels()
|
||||
overlay.SetPositionSaver(a.saveOverlayPosition)
|
||||
if a.launch.Warning != nil {
|
||||
a.log.Add(diagnostics.Warning, "configuration", fmt.Sprintf("%v; using built-in defaults", a.launch.Warning))
|
||||
}
|
||||
// Show the main window before creating the overlay so a Layer Shell /
|
||||
// display failure cannot leave the user with a silent no-GUI launch.
|
||||
a.window.Present()
|
||||
if err := a.configureOutputs(a.config, true); err != nil {
|
||||
a.log.Add(diagnostics.Error, "outputs", err.Error())
|
||||
}
|
||||
a.window.Present()
|
||||
a.applyAlwaysOnTop(a.config.GUI.MainWindowAlwaysOnTop)
|
||||
if a.config.GUI.StartCaptions {
|
||||
a.startCaptions()
|
||||
@@ -395,6 +398,18 @@ func (a *Application) restartCaptions() {
|
||||
}()
|
||||
}
|
||||
|
||||
func (a *Application) saveOverlayPosition(x, y int) {
|
||||
a.config.Overlay.PositionX = x
|
||||
a.config.Overlay.PositionY = y
|
||||
a.applied.Overlay.PositionX = x
|
||||
a.applied.Overlay.PositionY = y
|
||||
if err := config.Save(a.launch.Path, a.config); err != nil {
|
||||
a.log.Add(diagnostics.Error, "configuration", fmt.Sprintf("Save overlay position: %v", err))
|
||||
return
|
||||
}
|
||||
a.log.Add(diagnostics.Info, "overlay", fmt.Sprintf("Saved caption position (%d, %d)", x, y))
|
||||
}
|
||||
|
||||
func (a *Application) configureOutputs(next config.AppConfig, initial bool) error {
|
||||
var outputErr error
|
||||
a.history.SetEnabled(next.Outputs.History)
|
||||
|
||||
Reference in New Issue
Block a user