Changed Unix Area WM_ACTIVATE equivalent handling to use enter-notify-event and leave-notify-event instead of focus-in-event and focus-out-event as suggested by tristan in irc.gimp.net/#gtk+.
This commit is contained in:
parent
cb3a421a25
commit
e1f322dce0
22
area_unix.go
22
area_unix.go
|
@ -15,7 +15,7 @@ import (
|
|||
// extern gboolean our_area_button_press_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// extern gboolean our_area_button_release_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// extern gboolean our_area_motion_notify_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// extern gboolean our_area_focus_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// extern gboolean our_area_enterleave_notify_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// extern gboolean our_area_key_press_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// extern gboolean our_area_key_release_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// /* because cgo doesn't like ... */
|
||||
|
@ -33,16 +33,10 @@ func gtkAreaNew() *C.GtkWidget {
|
|||
// the Area's size will be set later
|
||||
// we need to explicitly subscribe to mouse events with GtkDrawingArea
|
||||
C.gtk_widget_add_events(drawingarea,
|
||||
C.GDK_BUTTON_PRESS_MASK | C.GDK_BUTTON_RELEASE_MASK | C.GDK_POINTER_MOTION_MASK | C.GDK_BUTTON_MOTION_MASK)
|
||||
C.GDK_BUTTON_PRESS_MASK | C.GDK_BUTTON_RELEASE_MASK | C.GDK_POINTER_MOTION_MASK | C.GDK_BUTTON_MOTION_MASK | C.GDK_ENTER_NOTIFY_MASK | C.GDK_LEAVE_NOTIFY_MASK)
|
||||
// and we need to allow focusing on a GtkDrawingArea to enable keyboard events
|
||||
C.gtk_widget_set_can_focus(drawingarea, C.TRUE)
|
||||
scrollarea := C.gtk_scrolled_window_new((*C.GtkAdjustment)(nil), (*C.GtkAdjustment)(nil))
|
||||
// see below about focus events
|
||||
// TODO can this be part of the gtk_widget_add_events() somehow?
|
||||
// TODO this doesn't work properly; it complains that this isn't actually a window (????)
|
||||
gdkwindow := C.gtk_widget_get_window(drawingarea)
|
||||
C.gdk_window_set_events(gdkwindow,
|
||||
C.gdk_window_get_events(gdkwindow) | C.GDK_FOCUS_CHANGE_MASK)
|
||||
// need a viewport because GtkDrawingArea isn't natively scrollable
|
||||
C.gtk_scrolled_window_add_with_viewport((*C.GtkScrolledWindow)(unsafe.Pointer(scrollarea)), drawingarea)
|
||||
return scrollarea
|
||||
|
@ -219,18 +213,18 @@ func our_area_motion_notify_event_callback(widget *C.GtkWidget, event *C.GdkEven
|
|||
|
||||
var area_motion_notify_event_callback = C.GCallback(C.our_area_motion_notify_event_callback)
|
||||
|
||||
// we want switching away from the control to reset the double-click counter, like with WM_ACTIVATE on Windows; from what I can gather about the Windows version of GDK this is correct
|
||||
// differentiating between focus-in-event and focus-out-event is unimportant
|
||||
// TODO check logs; there's a comment left by either tristan or Company suggesting I use a different event here
|
||||
// we want switching away from the control to reset the double-click counter, like with WM_ACTIVATE on Windows
|
||||
// according to tristan in irc.gimp.net/#gtk+, doing this on enter-notify-event and leave-notify-event is correct (and this seems to be true; I have issues verifying the double-click behavior [TODO] but the events DO get sent on program changes with alt-tab so)
|
||||
// differentiating between enter-notify-event and leave-notify-event is unimportant
|
||||
|
||||
//export our_area_focus_event_callback
|
||||
func our_area_focus_event_callback(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer) C.gboolean {
|
||||
//export our_area_enterleave_notify_event_callback
|
||||
func our_area_enterleave_notify_event_callback(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer) C.gboolean {
|
||||
s := (*sysData)(unsafe.Pointer(data))
|
||||
s.clickCounter.reset()
|
||||
return C.FALSE // TODO really false?
|
||||
}
|
||||
|
||||
var area_focus_event_callback = C.GCallback(C.our_area_focus_event_callback)
|
||||
var area_enterleave_notify_event_callback = C.GCallback(C.our_area_enterleave_notify_event_callback)
|
||||
|
||||
// shared code for doing a key event
|
||||
func doKeyEvent(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer, up bool) bool {
|
||||
|
|
|
@ -104,8 +104,8 @@ var classTypes = [nctypes]*classData{
|
|||
"button-press-event": area_button_press_event_callback,
|
||||
"button-release-event": area_button_release_event_callback,
|
||||
"motion-notify-event": area_motion_notify_event_callback,
|
||||
"focus-in-event": area_focus_event_callback,
|
||||
"focus-out-event": area_focus_event_callback,
|
||||
"enter-notify-event": area_enterleave_notify_event_callback,
|
||||
"leave-notify-event": area_enterleave_notify_event_callback,
|
||||
"key-press-event": area_key_press_event_callback,
|
||||
"key-release-event": area_key_release_event_callback,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue