Skip to content

Commit

Permalink
io/system: remove resize actions
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
eliasnaur committed Jun 25, 2022
1 parent b34dc63 commit b53cdfe
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 108 deletions.
6 changes: 1 addition & 5 deletions app/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 0 additions & 59 deletions io/system/decoration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package system

import (
"strings"

"gioui.org/io/pointer"
)

// Action is a set of window decoration actions.
Expand Down Expand Up @@ -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 {
Expand All @@ -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 ""
}
41 changes: 0 additions & 41 deletions widget/decorations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions widget/material/decorations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit b53cdfe

Please sign in to comment.