From 144f78d8900c48ba361dc65342878f73709d1c05 Mon Sep 17 00:00:00 2001 From: MovingtoMars Date: Mon, 3 Nov 2014 19:57:11 +1300 Subject: [PATCH 1/4] Gdk Events additions -added representation of GdkEventType -added representation of GdkEventButton -added Type() method to EventKey to get its EventType --- gdk/gdk.go | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/gdk/gdk.go b/gdk/gdk.go index 6a16373..1bcb259 100644 --- a/gdk/gdk.go +++ b/gdk/gdk.go @@ -492,6 +492,56 @@ func (v *Display) NotifyStartupComplete(startupID string) { C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr)) } +// EventType is a representation of GDK's GdkEventType. +// Do not confuse these event types with the signals that GTK+ widgets emit +type EventType int + +const ( + EVENT_NOTHING EventType = C.GDK_NOTHING + EVENT_DELETE EventType = C.GDK_DELETE + EVENT_DESTROY EventType = C.GDK_DESTROY + EVENT_EXPOSE EventType = C.GDK_EXPOSE + EVENT_MOTION_NOTIFY EventType = C.GDK_MOTION_NOTIFY + EVENT_BUTTON_PRESS EventType = C.GDK_BUTTON_PRESS + EVENT_2BUTTON_PRESS EventType = C.GDK_2BUTTON_PRESS + EVENT_DOUBLE_BUTTON_PRESS EventType = C.GDK_DOUBLE_BUTTON_PRESS + EVENT_3BUTTON_PRESS EventType = C.GDK_3BUTTON_PRESS + EVENT_TRIPLE_BUTTON_PRESS EventType = C.GDK_TRIPLE_BUTTON_PRESS + EVENT_BUTTON_RELEASE EventType = C.GDK_BUTTON_RELEASE + EVENT_KEY_PRESS EventType = C.GDK_KEY_PRESS + EVENT_KEY_RELEASE EventType = C.GDK_KEY_RELEASE + EVENT_LEAVE_NOTIFY EventType = C.GDK_ENTER_NOTIFY + EVENT_FOCUS_CHANGE EventType = C.GDK_FOCUS_CHANGE + EVENT_CONFIGURE EventType = C.GDK_CONFIGURE + EVENT_MAP EventType = C.GDK_MAP + EVENT_UNMAP EventType = C.GDK_UNMAP + EVENT_PROPERTY_NOTIFY EventType = C.GDK_PROPERTY_NOTIFY + EVENT_SELECTION_CLEAR EventType = C.GDK_SELECTION_CLEAR + EVENT_SELECTION_REQUEST EventType = C.GDK_SELECTION_REQUEST + EVENT_SELECTION_NOTIFY EventType = C.GDK_SELECTION_NOTIFY + EVENT_PROXIMITY_IN EventType = C.GDK_PROXIMITY_IN + EVENT_PROXIMITY_OUT EventType = C.GDK_PROXIMITY_OUT + EVENT_DRAG_ENTER EventType = C.GDK_DRAG_ENTER + EVENT_DRAG_LEAVE EventType = C.GDK_DRAG_LEAVE + EVENT_DRAG_MOTION EventType = C.GDK_DRAG_MOTION + EVENT_DRAG_STATUS EventType = C.GDK_DRAG_STATUS + EVENT_DROP_START EventType = C.GDK_DROP_START + EVENT_DROP_FINISHED EventType = C.GDK_DROP_FINISHED + EVENT_CLIENT_EVENT EventType = C.GDK_CLIENT_EVENT + EVENT_VISIBILITY_NOTIFY EventType = C.GDK_VISIBILITY_NOTIFY + EVENT_SCROLL EventType = C.GDK_SCROLL + EVENT_WINDOW_STATE EventType = C.GDK_WINDOW_STATE + EVENT_SETTING EventType = C.GDK_SETTING + EVENT_OWNER_CHANGE EventType = C.GDK_OWNER_CHANGE + EVENT_GRAB_BROKEN EventType = C.GDK_GRAB_BROKEN + EVENT_DAMAGE EventType = C.GDK_DAMAGE + EVENT_TOUCH_BEGIN EventType = C.GDK_TOUCH_BEGIN + EVENT_TOUCH_UPDATE EventType = C.GDK_TOUCH_UPDATE + EVENT_TOUCH_END EventType = C.GDK_TOUCH_END + EVENT_TOUCH_CANCEL EventType = C.GDK_TOUCH_CANCEL + EVENT_LAST EventType = C.GDK_EVENT_LAST +) + /* * GdkEvent */ @@ -546,6 +596,72 @@ func (v *EventKey) KeyVal() uint { return uint(c) } +func (v *EventKey) Type() EventType { + c := v.native()._type + return EventType(c) +} + +/* + * GdkEventButton + */ + +// EventButton is a representation of GDK's GdkEventButton. +type EventButton struct { + *Event +} + +// Native returns a pointer to the underlying GdkEventButton. +func (v *EventButton) Native() uintptr { + return uintptr(unsafe.Pointer(v.native())) +} + +func (v *EventButton) native() *C.GdkEventButton { + return (*C.GdkEventButton)(unsafe.Pointer(v.Event.native())) +} + +func (v *EventButton) X() float64 { + c := v.native().x + return float64(c) +} + +func (v *EventButton) Y() float64 { + c := v.native().y + return float64(c) +} + +// XRoot returns the x coordinate of the pointer relative to the root of the screen. +func (v *EventButton) XRoot() float64 { + c := v.native().x_root + return float64(c) +} + +// YRoot returns the y coordinate of the pointer relative to the root of the screen. +func (v *EventButton) YRoot() float64 { + c := v.native().y_root + return float64(c) +} + +func (v *EventButton) Button() uint { + c := v.native().button + return uint(c) +} + +func (v *EventButton) State() uint { + c := v.native().state + return uint(c) +} + +// Time returns the time of the event in milliseconds. +func (v *EventButton) Time() uint32 { + c := v.native().time + return uint32(c) +} + +func (v *EventButton) Type() EventType { + c := v.native()._type + return EventType(c) +} + /* * GdkPixbuf */ From acbdbd2ae527762de378fbb36e8d0dc16520bc31 Mon Sep 17 00:00:00 2001 From: MovingtoMars Date: Wed, 12 Nov 2014 18:54:29 +1300 Subject: [PATCH 2/4] added EventType marshaler --- gdk/gdk.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gdk/gdk.go b/gdk/gdk.go index 1bcb259..1e6d695 100644 --- a/gdk/gdk.go +++ b/gdk/gdk.go @@ -34,6 +34,7 @@ func init() { tm := []glib.TypeMarshaler{ // Enums {glib.Type(C.gdk_colorspace_get_type()), marshalColorspace}, + {glib.Type(C.gdk_event_type_get_type()), marshalEventType}, {glib.Type(C.gdk_interp_type_get_type()), marshalInterpType}, {glib.Type(C.gdk_pixbuf_alpha_mode_get_type()), marshalPixbufAlphaMode}, @@ -542,6 +543,11 @@ const ( EVENT_LAST EventType = C.GDK_EVENT_LAST ) +func marshalEventType(p uintptr) (interface{}, error) { + c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) + return EventType(c), nil +} + /* * GdkEvent */ From 9c231d0153e1d096864a137f961d33fc220b2b7e Mon Sep 17 00:00:00 2001 From: MovingtoMars Date: Thu, 13 Nov 2014 22:35:33 +1300 Subject: [PATCH 3/4] move events additions to correct locations --- gdk/gdk.go | 156 ++++++++++++++++++++++++++--------------------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/gdk/gdk.go b/gdk/gdk.go index 1e6d695..cd288a2 100644 --- a/gdk/gdk.go +++ b/gdk/gdk.go @@ -493,56 +493,6 @@ func (v *Display) NotifyStartupComplete(startupID string) { C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr)) } -// EventType is a representation of GDK's GdkEventType. -// Do not confuse these event types with the signals that GTK+ widgets emit -type EventType int - -const ( - EVENT_NOTHING EventType = C.GDK_NOTHING - EVENT_DELETE EventType = C.GDK_DELETE - EVENT_DESTROY EventType = C.GDK_DESTROY - EVENT_EXPOSE EventType = C.GDK_EXPOSE - EVENT_MOTION_NOTIFY EventType = C.GDK_MOTION_NOTIFY - EVENT_BUTTON_PRESS EventType = C.GDK_BUTTON_PRESS - EVENT_2BUTTON_PRESS EventType = C.GDK_2BUTTON_PRESS - EVENT_DOUBLE_BUTTON_PRESS EventType = C.GDK_DOUBLE_BUTTON_PRESS - EVENT_3BUTTON_PRESS EventType = C.GDK_3BUTTON_PRESS - EVENT_TRIPLE_BUTTON_PRESS EventType = C.GDK_TRIPLE_BUTTON_PRESS - EVENT_BUTTON_RELEASE EventType = C.GDK_BUTTON_RELEASE - EVENT_KEY_PRESS EventType = C.GDK_KEY_PRESS - EVENT_KEY_RELEASE EventType = C.GDK_KEY_RELEASE - EVENT_LEAVE_NOTIFY EventType = C.GDK_ENTER_NOTIFY - EVENT_FOCUS_CHANGE EventType = C.GDK_FOCUS_CHANGE - EVENT_CONFIGURE EventType = C.GDK_CONFIGURE - EVENT_MAP EventType = C.GDK_MAP - EVENT_UNMAP EventType = C.GDK_UNMAP - EVENT_PROPERTY_NOTIFY EventType = C.GDK_PROPERTY_NOTIFY - EVENT_SELECTION_CLEAR EventType = C.GDK_SELECTION_CLEAR - EVENT_SELECTION_REQUEST EventType = C.GDK_SELECTION_REQUEST - EVENT_SELECTION_NOTIFY EventType = C.GDK_SELECTION_NOTIFY - EVENT_PROXIMITY_IN EventType = C.GDK_PROXIMITY_IN - EVENT_PROXIMITY_OUT EventType = C.GDK_PROXIMITY_OUT - EVENT_DRAG_ENTER EventType = C.GDK_DRAG_ENTER - EVENT_DRAG_LEAVE EventType = C.GDK_DRAG_LEAVE - EVENT_DRAG_MOTION EventType = C.GDK_DRAG_MOTION - EVENT_DRAG_STATUS EventType = C.GDK_DRAG_STATUS - EVENT_DROP_START EventType = C.GDK_DROP_START - EVENT_DROP_FINISHED EventType = C.GDK_DROP_FINISHED - EVENT_CLIENT_EVENT EventType = C.GDK_CLIENT_EVENT - EVENT_VISIBILITY_NOTIFY EventType = C.GDK_VISIBILITY_NOTIFY - EVENT_SCROLL EventType = C.GDK_SCROLL - EVENT_WINDOW_STATE EventType = C.GDK_WINDOW_STATE - EVENT_SETTING EventType = C.GDK_SETTING - EVENT_OWNER_CHANGE EventType = C.GDK_OWNER_CHANGE - EVENT_GRAB_BROKEN EventType = C.GDK_GRAB_BROKEN - EVENT_DAMAGE EventType = C.GDK_DAMAGE - EVENT_TOUCH_BEGIN EventType = C.GDK_TOUCH_BEGIN - EVENT_TOUCH_UPDATE EventType = C.GDK_TOUCH_UPDATE - EVENT_TOUCH_END EventType = C.GDK_TOUCH_END - EVENT_TOUCH_CANCEL EventType = C.GDK_TOUCH_CANCEL - EVENT_LAST EventType = C.GDK_EVENT_LAST -) - func marshalEventType(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return EventType(c), nil @@ -579,34 +529,6 @@ func (v *Event) free() { C.gdk_event_free(v.native()) } -/* - * GdkEventKey - */ - -// EventKey is a representation of GDK's GdkEventKey. -type EventKey struct { - *Event -} - -// Native returns a pointer to the underlying GdkEventKey. -func (v *EventKey) Native() uintptr { - return uintptr(unsafe.Pointer(v.native())) -} - -func (v *EventKey) native() *C.GdkEventKey { - return (*C.GdkEventKey)(unsafe.Pointer(v.Event.native())) -} - -func (v *EventKey) KeyVal() uint { - c := v.native().keyval - return uint(c) -} - -func (v *EventKey) Type() EventType { - c := v.native()._type - return EventType(c) -} - /* * GdkEventButton */ @@ -668,6 +590,84 @@ func (v *EventButton) Type() EventType { return EventType(c) } +/* + * GdkEventKey + */ + +// EventKey is a representation of GDK's GdkEventKey. +type EventKey struct { + *Event +} + +// Native returns a pointer to the underlying GdkEventKey. +func (v *EventKey) Native() uintptr { + return uintptr(unsafe.Pointer(v.native())) +} + +func (v *EventKey) native() *C.GdkEventKey { + return (*C.GdkEventKey)(unsafe.Pointer(v.Event.native())) +} + +func (v *EventKey) KeyVal() uint { + c := v.native().keyval + return uint(c) +} + +func (v *EventKey) Type() EventType { + c := v.native()._type + return EventType(c) +} + +// EventType is a representation of GDK's GdkEventType. +// Do not confuse these event types with the signals that GTK+ widgets emit +type EventType int + +const ( + EVENT_NOTHING EventType = C.GDK_NOTHING + EVENT_DELETE EventType = C.GDK_DELETE + EVENT_DESTROY EventType = C.GDK_DESTROY + EVENT_EXPOSE EventType = C.GDK_EXPOSE + EVENT_MOTION_NOTIFY EventType = C.GDK_MOTION_NOTIFY + EVENT_BUTTON_PRESS EventType = C.GDK_BUTTON_PRESS + EVENT_2BUTTON_PRESS EventType = C.GDK_2BUTTON_PRESS + EVENT_DOUBLE_BUTTON_PRESS EventType = C.GDK_DOUBLE_BUTTON_PRESS + EVENT_3BUTTON_PRESS EventType = C.GDK_3BUTTON_PRESS + EVENT_TRIPLE_BUTTON_PRESS EventType = C.GDK_TRIPLE_BUTTON_PRESS + EVENT_BUTTON_RELEASE EventType = C.GDK_BUTTON_RELEASE + EVENT_KEY_PRESS EventType = C.GDK_KEY_PRESS + EVENT_KEY_RELEASE EventType = C.GDK_KEY_RELEASE + EVENT_LEAVE_NOTIFY EventType = C.GDK_ENTER_NOTIFY + EVENT_FOCUS_CHANGE EventType = C.GDK_FOCUS_CHANGE + EVENT_CONFIGURE EventType = C.GDK_CONFIGURE + EVENT_MAP EventType = C.GDK_MAP + EVENT_UNMAP EventType = C.GDK_UNMAP + EVENT_PROPERTY_NOTIFY EventType = C.GDK_PROPERTY_NOTIFY + EVENT_SELECTION_CLEAR EventType = C.GDK_SELECTION_CLEAR + EVENT_SELECTION_REQUEST EventType = C.GDK_SELECTION_REQUEST + EVENT_SELECTION_NOTIFY EventType = C.GDK_SELECTION_NOTIFY + EVENT_PROXIMITY_IN EventType = C.GDK_PROXIMITY_IN + EVENT_PROXIMITY_OUT EventType = C.GDK_PROXIMITY_OUT + EVENT_DRAG_ENTER EventType = C.GDK_DRAG_ENTER + EVENT_DRAG_LEAVE EventType = C.GDK_DRAG_LEAVE + EVENT_DRAG_MOTION EventType = C.GDK_DRAG_MOTION + EVENT_DRAG_STATUS EventType = C.GDK_DRAG_STATUS + EVENT_DROP_START EventType = C.GDK_DROP_START + EVENT_DROP_FINISHED EventType = C.GDK_DROP_FINISHED + EVENT_CLIENT_EVENT EventType = C.GDK_CLIENT_EVENT + EVENT_VISIBILITY_NOTIFY EventType = C.GDK_VISIBILITY_NOTIFY + EVENT_SCROLL EventType = C.GDK_SCROLL + EVENT_WINDOW_STATE EventType = C.GDK_WINDOW_STATE + EVENT_SETTING EventType = C.GDK_SETTING + EVENT_OWNER_CHANGE EventType = C.GDK_OWNER_CHANGE + EVENT_GRAB_BROKEN EventType = C.GDK_GRAB_BROKEN + EVENT_DAMAGE EventType = C.GDK_DAMAGE + EVENT_TOUCH_BEGIN EventType = C.GDK_TOUCH_BEGIN + EVENT_TOUCH_UPDATE EventType = C.GDK_TOUCH_UPDATE + EVENT_TOUCH_END EventType = C.GDK_TOUCH_END + EVENT_TOUCH_CANCEL EventType = C.GDK_TOUCH_CANCEL + EVENT_LAST EventType = C.GDK_EVENT_LAST +) + /* * GdkPixbuf */ From 95424ec9038a2e0c95e59e64148f42c83c6ba4bd Mon Sep 17 00:00:00 2001 From: MovingtoMars Date: Thu, 13 Nov 2014 22:37:29 +1300 Subject: [PATCH 4/4] one more move --- gdk/gdk.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gdk/gdk.go b/gdk/gdk.go index cd288a2..4ba12c5 100644 --- a/gdk/gdk.go +++ b/gdk/gdk.go @@ -493,11 +493,6 @@ func (v *Display) NotifyStartupComplete(startupID string) { C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr)) } -func marshalEventType(p uintptr) (interface{}, error) { - c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) - return EventType(c), nil -} - /* * GdkEvent */ @@ -622,6 +617,11 @@ func (v *EventKey) Type() EventType { // Do not confuse these event types with the signals that GTK+ widgets emit type EventType int +func marshalEventType(p uintptr) (interface{}, error) { + c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) + return EventType(c), nil +} + const ( EVENT_NOTHING EventType = C.GDK_NOTHING EVENT_DELETE EventType = C.GDK_DELETE