io/system: add ActionInputOp to register window move gesture areas

The app.Window.Perform(ActionMove) is the wrong abstraction for
initiating a move gesture: Windows needs to know the move gesture
area at pointer move, and macOS needs to know the pointer button
down event that triggers the move gesture. This change replaces
Perform(ActionMove) with a new system.ActionInputOp that marks an
area movable.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-06-25 19:03:50 +02:00
parent b53cdfef8d
commit 3f38e67ce0
10 changed files with 85 additions and 35 deletions
+1
View File
@@ -113,6 +113,7 @@ const (
HWND_TOPMOST = ^(uint32(1) - 1) // -1
HTCAPTION = 2
HTCLIENT = 1
HTLEFT = 10
HTRIGHT = 11
+14 -21
View File
@@ -232,9 +232,8 @@ type window struct {
displayLink *displayLink
// redraw is a single entry channel for making sure only one
// display link redraw request is in flight.
redraw chan struct{}
cursor pointer.Cursor
lastPress C.CFTypeRef
redraw chan struct{}
cursor pointer.Cursor
scale float32
config Config
@@ -413,12 +412,6 @@ func (w *window) Perform(acts system.Action) {
C.setScreenFrame(w.window, C.CGFloat(x), C.CGFloat(y), C.CGFloat(sz.X), C.CGFloat(sz.Y))
case system.ActionRaise:
C.raiseWindow(w.window)
case system.ActionMove:
if w.lastPress != 0 {
C.performWindowDragWithEvent(w.window, w.lastPress)
C.CFRelease(w.lastPress)
w.lastPress = 0
}
}
})
if acts&system.ActionClose != 0 {
@@ -500,6 +493,10 @@ func gio_onText(view, cstr C.CFTypeRef) {
//export gio_onMouse
func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy C.CGFloat, ti C.double, mods C.NSUInteger) {
w := mustView(view)
t := time.Duration(float64(ti)*float64(time.Second) + .5)
xf, yf := float32(x)*w.scale, float32(y)*w.scale
dxf, dyf := float32(dx)*w.scale, float32(dy)*w.scale
pos := f32.Point{X: xf, Y: yf}
var typ pointer.Type
switch cdir {
case C.MOUSE_MOVE:
@@ -508,11 +505,14 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx
typ = pointer.Release
case C.MOUSE_DOWN:
typ = pointer.Press
if w.lastPress != 0 {
C.CFRelease(w.lastPress)
w.lastPress = 0
act, ok := w.w.ActionAt(pos)
if ok && w.config.Mode != Fullscreen {
switch act {
case system.ActionMove:
C.performWindowDragWithEvent(w.window, evt)
return
}
}
w.lastPress = C.CFRetain(evt)
case C.MOUSE_SCROLL:
typ = pointer.Scroll
default:
@@ -528,15 +528,12 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx
if cbtns&(1<<2) != 0 {
btns |= pointer.ButtonTertiary
}
t := time.Duration(float64(ti)*float64(time.Second) + .5)
xf, yf := float32(x)*w.scale, float32(y)*w.scale
dxf, dyf := float32(dx)*w.scale, float32(dy)*w.scale
w.w.Event(pointer.Event{
Type: typ,
Source: pointer.Mouse,
Time: t,
Buttons: btns,
Position: f32.Point{X: xf, Y: yf},
Position: pos,
Scroll: f32.Point{X: dxf, Y: dyf},
Modifiers: convertMods(mods),
})
@@ -768,10 +765,6 @@ func gio_onClose(view C.CFTypeRef) {
w.w.Event(ViewEvent{})
deleteView(view)
w.w.Event(system.DestroyEvent{})
if w.lastPress != 0 {
C.CFRelease(w.lastPress)
w.lastPress = 0
}
w.displayLink.Close()
C.CFRelease(w.view)
C.CFRelease(w.window)
+12 -6
View File
@@ -879,6 +879,14 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
w.resize(serial, edge)
return
}
act, ok := w.w.ActionAt(w.lastPos)
if ok && w.config.Mode == Windowed {
switch act {
case system.ActionMove:
w.move(serial)
return
}
}
case BTN_RIGHT:
btn = pointer.ButtonSecondary
case BTN_MIDDLE:
@@ -1073,19 +1081,17 @@ func (w *window) Perform(actions system.Action) {
// https://wayland.app/protocols/xdg-shell#xdg_toplevel:request:set_minimized
walkActions(actions, func(action system.Action) {
switch action {
case system.ActionMove:
w.move()
case system.ActionClose:
w.dead = true
}
})
}
func (w *window) move() {
if !w.inCompositor && w.seat != nil {
func (w *window) move(serial C.uint32_t) {
s := w.seat
if !w.inCompositor && s != nil {
w.inCompositor = true
s := w.seat
C.xdg_toplevel_move(w.topLvl, s.seat, s.serial)
C.xdg_toplevel_move(w.topLvl, s.seat, serial)
}
}
+5
View File
@@ -437,6 +437,11 @@ func (w *window) hitTest(x, y int) uintptr {
default:
fallthrough
case !top && !bottom && !left && !right:
p := f32.Pt(float32(x), float32(y))
switch a, _ := w.w.ActionAt(p); a {
case system.ActionMove:
return windows.HTCAPTION
}
return windows.HTCLIENT
case top && left:
return windows.HTTOPLEFT
+4
View File
@@ -567,6 +567,10 @@ func (c *callbacks) ClickFocus() {
c.w.updateAnimation(c.d)
}
func (c *callbacks) ActionAt(p f32.Point) (system.Action, bool) {
return c.w.queue.q.ActionAt(p)
}
func (e *editorState) Replace(r key.Range, text string) {
if r.Start > r.End {
r.Start, r.End = r.End, r.Start