From a01ffafba0fac94c539eca33528af20b3e02cec5 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 10 Apr 2014 18:52:43 -0400 Subject: [PATCH] Fixed Area mouse events being sent when something happens outside the Area itself. --- area_darwin.go | 1 + area_unix.go | 6 ++++++ area_windows.go | 3 +++ todo.md | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/area_darwin.go b/area_darwin.go index dcc6941..9cdda68 100644 --- a/area_darwin.go +++ b/area_darwin.go @@ -143,6 +143,7 @@ func areaMouseEvent(self C.id, e C.id, click bool, up bool) { s := getSysData(self) xp := C.getTranslatedEventPoint(self, e) me.Pos = image.Pt(int(xp.x), int(xp.y)) + // no need to check me.Pos; Cocoa won't send an event outside the Area me.Modifiers = parseModifiers(e) which := uint(C.objc_msgSend_intret_noargs(e, _buttonNumber)) + 1 if which == 3 { // swap middle and right button numbers diff --git a/area_unix.go b/area_unix.go index 926166f..fe67641 100644 --- a/area_unix.go +++ b/area_unix.go @@ -105,6 +105,8 @@ func makeModifiers(state C.guint, m Modifiers) Modifiers { // shared code for finishing up and sending a mouse event func finishMouseEvent(widget *C.GtkWidget, data C.gpointer, me MouseEvent, mb uint, x C.gdouble, y C.gdouble, state C.guint, gdkwindow *C.GdkWindow) { + var areawidth, areaheight C.gint + s := (*sysData)(unsafe.Pointer(data)) state = translateModifiers(state, gdkwindow) me.Modifiers = makeModifiers(state, 0) @@ -126,6 +128,10 @@ func finishMouseEvent(widget *C.GtkWidget, data C.gpointer, me MouseEvent, mb ui me.Held = append(me.Held, 5) } me.Pos = image.Pt(int(x), int(y)) + C.gtk_widget_get_size_request(widget, &areawidth, &areaheight) + if !me.Pos.In(image.Rect(0, 0, int(areawidth), int(areaheight))) { // outside the actual Area; no event + return + } repaint := s.handler.Mouse(me) if repaint { C.gtk_widget_queue_draw(widget) diff --git a/area_windows.go b/area_windows.go index a0b855d..d9497bf 100644 --- a/area_windows.go +++ b/area_windows.go @@ -358,6 +358,9 @@ func areaMouseEvent(s *sysData, button uint, up bool, count uint, wparam _WPARAM xpos += lparam._X() ypos += lparam._Y() me.Pos = image.Pt(int(xpos), int(ypos)) + if !me.Pos.In(image.Rect(0, 0, s.areawidth, s.areaheight)) { // outside the actual Area; no event + return + } if up { me.Up = button } else { diff --git a/todo.md b/todo.md index 9a97ea4..1e7d27a 100644 --- a/todo.md +++ b/todo.md @@ -16,7 +16,7 @@ important things: - make gcc (Unix)/clang (Mac OS X) pedantic about warnings/errors; also -Werror - problem: cgo-generated files trip -Werror up; I can't seem to turn off unused argument warnings with the -Wall/-Wextra/-pedantic options - consolidate scroll view code in GTK+ and Mac OS X -- make sure mouse events don't trigger if the control size is larger than the Area size and the mouse event happens outside the Area range on all platforms +- make sure mouse events trigger when we move the mouse over an Area with a button held on OS X - area test time label weirdness - does not show anything past the date on windows - does not show initially on OS X; it shows up once you resize, and even shows up after you resize back to the original size