widget: [API] change Decorations to leave the user in control of window state

As suggested by ~egonelbre, Decorations should not be the source of truth
for the windows state, because external gestures may also change state.

This breaking change removes Decorations.Perform and exposes Maximized
as a bool which is the user's responsibility to set.

Fixes: https://todo.sr.ht/~eliasnaur/gio/600
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2024-07-31 18:39:30 +02:00
parent 97044e53b5
commit 6722c7960a
3 changed files with 8 additions and 25 deletions
+1 -1
View File
@@ -656,6 +656,7 @@ func (w *Window) processEvent(e event.Event) bool {
}
w.coalesced.view = &e2
case ConfigEvent:
w.decorations.Decorations.Maximized = e2.Config.Mode == Maximized
wasFocused := w.decorations.Config.Focused
w.decorations.Config = e2.Config
e2.Config = w.effectiveConfig()
@@ -801,7 +802,6 @@ func (w *Window) decorate(e FrameEvent, o *op.Ops) image.Point {
default:
panic(fmt.Errorf("unknown WindowMode %v", m))
}
deco.Perform(actions)
gtx := layout.Context{
Ops: o,
Now: e.Now,
+6 -23
View File
@@ -11,8 +11,11 @@ import (
// Decorations handles the states of window decorations.
type Decorations struct {
// Maximized controls the look and behaviour of the maximize
// button. It is the user's responsibility to set Maximized
// according to the window state reported through [app.ConfigEvent].
Maximized bool
clicks map[int]*Clickable
maximized bool
}
// LayoutMove lays out the widget that makes a window movable.
@@ -40,17 +43,6 @@ func (d *Decorations) Clickable(action system.Action) *Clickable {
return click
}
// Perform updates the decorations as if the specified actions were
// performed by the user.
func (d *Decorations) Perform(actions system.Action) {
if actions&system.ActionMaximize != 0 {
d.maximized = true
}
if actions&(system.ActionUnmaximize|system.ActionMinimize|system.ActionFullscreen) != 0 {
d.maximized = false
}
}
// Update the state and return the set of actions activated by the user.
func (d *Decorations) Update(gtx layout.Context) system.Action {
var actions system.Action
@@ -60,21 +52,12 @@ func (d *Decorations) Update(gtx layout.Context) system.Action {
}
action := system.Action(1 << idx)
switch {
case action == system.ActionMaximize && d.maximized:
case action == system.ActionMaximize && d.Maximized:
action = system.ActionUnmaximize
case action == system.ActionUnmaximize && !d.maximized:
case action == system.ActionUnmaximize && !d.Maximized:
action = system.ActionMaximize
}
switch action {
case system.ActionMaximize, system.ActionUnmaximize:
d.maximized = !d.maximized
}
actions |= action
}
return actions
}
// Maximized returns whether the window is maximized.
func (d *Decorations) Maximized() bool {
return d.maximized
}
+1 -1
View File
@@ -75,7 +75,7 @@ func (d DecorationsStyle) layoutDecorations(gtx layout.Context) layout.Dimension
case system.ActionMinimize:
w = minimizeWindow
case system.ActionMaximize:
if d.Decorations.Maximized() {
if d.Decorations.Maximized {
w = maximizedWindow
} else {
w = maximizeWindow