From b53cdfef8dc29edfac07a7fbcd62c2eb847d755e Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 25 Jun 2022 18:31:04 +0200 Subject: [PATCH] io/system: remove resize actions Allowing clients to initiate resize gestures is a waste: macOS doesn't support them, and the only reason we added them was to implement client-side decorations for Wayland. Now all desktop platforms implement resize gestures as needed, and we no longer need the system.Action actions. Signed-off-by: Elias Naur --- app/window.go | 6 +--- io/system/decoration.go | 59 ---------------------------------- widget/decorations.go | 41 ----------------------- widget/material/decorations.go | 3 -- 4 files changed, 1 insertion(+), 108 deletions(-) diff --git a/app/window.go b/app/window.go index 84636eb8..1e0c067b 100644 --- a/app/window.go +++ b/app/window.go @@ -983,11 +983,7 @@ func (w *Window) decorate(d driver, e system.FrameEvent, o *op.Ops) (size, offse w.decorations.Decorations = deco } allActions := system.ActionMinimize | system.ActionMaximize | system.ActionUnmaximize | - system.ActionClose | system.ActionMove | - system.ActionResizeNorth | system.ActionResizeSouth | - system.ActionResizeWest | system.ActionResizeEast | - system.ActionResizeNorthWest | system.ActionResizeSouthWest | - system.ActionResizeNorthEast | system.ActionResizeSouthEast + system.ActionClose | system.ActionMove style := material.Decorations(theme, deco, allActions, w.decorations.Config.Title) // Update the decorations based on the current window mode. var actions system.Action diff --git a/io/system/decoration.go b/io/system/decoration.go index 40a61ba8..245e14e1 100644 --- a/io/system/decoration.go +++ b/io/system/decoration.go @@ -2,8 +2,6 @@ package system import ( "strings" - - "gioui.org/io/pointer" ) // Action is a set of window decoration actions. @@ -31,49 +29,8 @@ const ( ActionClose // ActionMove moves a window directed by the user. ActionMove - // ActionResizeNorth resizes the top border of a window (directed by the user). - ActionResizeNorth - // ActionResizeSouth resizes the bottom border of a window (directed by the user). - ActionResizeSouth - // ActionResizeWest resizes the right border of a window (directed by the user). - ActionResizeWest - // ActionResizeEast resizes the left border of a window (directed by the user). - ActionResizeEast - // ActionResizeNorthWest resizes the top-left corner of a window (directed by the user). - ActionResizeNorthWest - // ActionResizeSouthWest resizes the bottom-left corner of a window (directed by the user). - ActionResizeSouthWest - // ActionResizeNorthEast resizes the top-right corner of a window (directed by the user). - ActionResizeNorthEast - // ActionResizeSouthEast resizes the bottom-right corner of a window (directed by the user). - ActionResizeSouthEast ) -// Cursor returns the cursor for the action. -// It must be a single action otherwise the default -// cursor is returned. -func (a Action) Cursor() pointer.Cursor { - switch a { - case ActionResizeNorthWest: - return pointer.CursorNorthWestResize - case ActionResizeSouthEast: - return pointer.CursorSouthEastResize - case ActionResizeNorthEast: - return pointer.CursorNorthEastResize - case ActionResizeSouthWest: - return pointer.CursorSouthWestResize - case ActionResizeWest: - return pointer.CursorWestResize - case ActionResizeEast: - return pointer.CursorEastResize - case ActionResizeNorth: - return pointer.CursorNorthResize - case ActionResizeSouth: - return pointer.CursorSouthResize - } - return pointer.CursorDefault -} - func (a Action) String() string { var buf strings.Builder for b := Action(1); a != 0; b <<= 1 { @@ -100,22 +57,6 @@ func (a Action) string() string { return "ActionClose" case ActionMove: return "ActionMove" - case ActionResizeNorth: - return "ActionResizeNorth" - case ActionResizeSouth: - return "ActionResizeSouth" - case ActionResizeWest: - return "ActionResizeWest" - case ActionResizeEast: - return "ActionResizeEast" - case ActionResizeNorthWest: - return "ActionResizeNorthWest" - case ActionResizeSouthWest: - return "ActionResizeSouthWest" - case ActionResizeNorthEast: - return "ActionResizeNorthEast" - case ActionResizeSouthEast: - return "ActionResizeSouthEast" } return "" } diff --git a/widget/decorations.go b/widget/decorations.go index b20a2bff..8a7de226 100644 --- a/widget/decorations.go +++ b/widget/decorations.go @@ -2,11 +2,9 @@ package widget import ( "fmt" - "image" "math/bits" "gioui.org/gesture" - "gioui.org/io/pointer" "gioui.org/io/system" "gioui.org/layout" "gioui.org/op/clip" @@ -63,45 +61,6 @@ func (d *Decorations) Clickable(action system.Action) *Clickable { return click } -// LayoutResize lays out the resize actions. -func (d *Decorations) LayoutResize(gtx layout.Context, actions system.Action) { - cs := gtx.Constraints.Max - wh := gtx.Dp(10) - s := []struct { - system.Action - image.Rectangle - }{ - {system.ActionResizeNorth, image.Rect(0, 0, cs.X, wh)}, - {system.ActionResizeSouth, image.Rect(0, cs.Y-wh, cs.X, cs.Y)}, - {system.ActionResizeWest, image.Rect(cs.X-wh, 0, cs.X, cs.Y)}, - {system.ActionResizeEast, image.Rect(0, 0, wh, cs.Y)}, - {system.ActionResizeNorthWest, image.Rect(0, 0, wh, wh)}, - {system.ActionResizeNorthEast, image.Rect(cs.X-wh, 0, cs.X, wh)}, - {system.ActionResizeSouthWest, image.Rect(0, cs.Y-wh, wh, cs.Y)}, - {system.ActionResizeSouthEast, image.Rect(cs.X-wh, cs.Y-wh, cs.X, cs.Y)}, - } - for i, data := range s { - action := data.Action - if actions&action == 0 { - continue - } - rsz := &d.resize[i] - rsz.Events(gtx.Metric, gtx, gesture.Both) - if rsz.Drag.Dragging() { - d.actions |= action - } - st := clip.Rect(data.Rectangle).Push(gtx.Ops) - if rsz.Hover.Hovered(gtx) { - action.Cursor().Add(gtx.Ops) - } - rsz.Drag.Add(gtx.Ops) - pass := pointer.PassOp{}.Push(gtx.Ops) - rsz.Hover.Add(gtx.Ops) - pass.Pop() - st.Pop() - } -} - // Perform updates the decorations as if the specified actions were // performed by the user. func (d *Decorations) Perform(actions system.Action) { diff --git a/widget/material/decorations.go b/widget/material/decorations.go index 55211bbe..d327dbbc 100644 --- a/widget/material/decorations.go +++ b/widget/material/decorations.go @@ -45,9 +45,6 @@ func (d DecorationsStyle) Layout(gtx layout.Context) layout.Dimensions { r := clip.Rect{Max: dims.Size} paint.FillShape(gtx.Ops, d.Background, r.Op()) decos.Add(gtx.Ops) - if !d.Decorations.Maximized() { - d.Decorations.LayoutResize(gtx, d.Actions) - } return dims }