mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-16 23:24:16 +00:00
Improve enter/motion notify semantics
On X11 we receive enter notify and motion notify events for a window regardless of its focus state. On Mac OS X this is not the case. This commit improves the semantics to overcome this difference. It improves on my earlier patch that sent a motion notify event when a window became main. Instead of sending a motion notify when a window becomes main, we now send one when a window becomes key, which comes closest to a window getting focus in X11. This motion notify is needed because Mac OS X does not send motion events when an application is inactive (none of its windows have focus), these events are sent in X11. This dummy motion notify event (with current coordinates of the mouse cursor) allows an application to get its prelight and other state right when it gets focus and thus user attention. Another change is to send an enter notify event when updating the tracking rectangle of a GdkQuartView and the mouse cursor is currently in this rectangle. This rectangle is at least updated on window creation. This enter notify event is important for the case where a new window appears right below the mouse cursor. The window has to receive an enter notify event for the subsequent events to be processed correctly. Mac OS X does not send one in this case, so we generate it ourselves. Both of these synthesized events have to go through _gdk_windowing_got_event() for updating statekeeping, etc. append_event() has a boolean flag now to make this convenient.
This commit is contained in:
parent
453ac4a2ec
commit
a86bbf759f
@ -169,6 +169,15 @@
|
||||
owner:self
|
||||
userData:nil
|
||||
assumeInside:NO];
|
||||
|
||||
if (NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect))
|
||||
{
|
||||
/* When a new window (and thus view) has been created, and the mouse
|
||||
* is in the window area, we will not receive an NSMouseEntered
|
||||
* event. Therefore, we synthesize an enter notify event manually.
|
||||
*/
|
||||
_gdk_quartz_events_send_enter_notify_event (gdk_window);
|
||||
}
|
||||
}
|
||||
|
||||
-(void)viewDidMoveToWindow
|
||||
|
@ -43,7 +43,8 @@ static GdkWindow *current_keyboard_window;
|
||||
static GdkEventMask current_event_mask;
|
||||
static int current_button_state;
|
||||
|
||||
static void append_event (GdkEvent *event);
|
||||
static void append_event (GdkEvent *event,
|
||||
gboolean windowing);
|
||||
|
||||
NSEvent *
|
||||
gdk_quartz_event_get_nsevent (GdkEvent *event)
|
||||
@ -173,10 +174,16 @@ fixup_event (GdkEvent *event)
|
||||
}
|
||||
|
||||
static void
|
||||
append_event (GdkEvent *event)
|
||||
append_event (GdkEvent *event,
|
||||
gboolean windowing)
|
||||
{
|
||||
GList *node;
|
||||
|
||||
fixup_event (event);
|
||||
_gdk_event_queue_append (_gdk_display, event);
|
||||
node = _gdk_event_queue_append (_gdk_display, event);
|
||||
|
||||
if (windowing)
|
||||
_gdk_windowing_got_event (_gdk_display, node, event, 0);
|
||||
}
|
||||
|
||||
static gint
|
||||
@ -352,6 +359,53 @@ create_focus_event (GdkWindow *window,
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
generate_motion_event (GdkWindow *window)
|
||||
{
|
||||
NSPoint point;
|
||||
NSPoint screen_point;
|
||||
NSWindow *nswindow;
|
||||
GdkQuartzView *view;
|
||||
GdkWindowObject *private;
|
||||
GdkEvent *event;
|
||||
gint x, y, x_root, y_root;
|
||||
GdkDisplay *display;
|
||||
|
||||
event = gdk_event_new (GDK_MOTION_NOTIFY);
|
||||
event->any.window = NULL;
|
||||
event->any.send_event = TRUE;
|
||||
|
||||
private = (GdkWindowObject *)window;
|
||||
nswindow = ((GdkWindowImplQuartz *)private->impl)->toplevel;
|
||||
view = (GdkQuartzView *)[nswindow contentView];
|
||||
|
||||
display = gdk_drawable_get_display (window);
|
||||
|
||||
screen_point = [NSEvent mouseLocation];
|
||||
|
||||
_gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &x_root, &y_root);
|
||||
|
||||
point = [nswindow convertScreenToBase:screen_point];
|
||||
|
||||
x = point.x;
|
||||
y = private->height - point.y;
|
||||
|
||||
event->any.type = GDK_MOTION_NOTIFY;
|
||||
event->motion.window = window;
|
||||
event->motion.time = GDK_CURRENT_TIME;
|
||||
event->motion.x = x;
|
||||
event->motion.y = y;
|
||||
event->motion.x_root = x_root;
|
||||
event->motion.y_root = y_root;
|
||||
/* FIXME event->axes */
|
||||
event->motion.state = 0;
|
||||
event->motion.is_hint = FALSE;
|
||||
event->motion.device = _gdk_display->core_pointer;
|
||||
|
||||
append_event (event, TRUE);
|
||||
}
|
||||
|
||||
/* Note: Used to both set a new focus window and to unset the old one. */
|
||||
void
|
||||
_gdk_quartz_events_update_focus_window (GdkWindow *window,
|
||||
@ -369,7 +423,7 @@ _gdk_quartz_events_update_focus_window (GdkWindow *window,
|
||||
if (!got_focus && window == current_keyboard_window)
|
||||
{
|
||||
event = create_focus_event (current_keyboard_window, FALSE);
|
||||
append_event (event);
|
||||
append_event (event, FALSE);
|
||||
g_object_unref (current_keyboard_window);
|
||||
current_keyboard_window = NULL;
|
||||
}
|
||||
@ -379,17 +433,64 @@ _gdk_quartz_events_update_focus_window (GdkWindow *window,
|
||||
if (current_keyboard_window)
|
||||
{
|
||||
event = create_focus_event (current_keyboard_window, FALSE);
|
||||
append_event (event);
|
||||
append_event (event, FALSE);
|
||||
g_object_unref (current_keyboard_window);
|
||||
current_keyboard_window = NULL;
|
||||
}
|
||||
|
||||
event = create_focus_event (window, TRUE);
|
||||
append_event (event);
|
||||
append_event (event, FALSE);
|
||||
current_keyboard_window = g_object_ref (window);
|
||||
|
||||
/* We just became the active window. Unlike X11, Mac OS X does
|
||||
* not send us motion events while the window does not have focus
|
||||
* ("is not key"). We send a dummy motion notify event now, so that
|
||||
* everything in the window is set to correct state.
|
||||
*/
|
||||
generate_motion_event (window);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_quartz_events_send_enter_notify_event (GdkWindow *window)
|
||||
{
|
||||
NSPoint point;
|
||||
NSPoint screen_point;
|
||||
NSWindow *nswindow;
|
||||
GdkWindowObject *private;
|
||||
GdkEvent *event;
|
||||
gint x, y, x_root, y_root;
|
||||
|
||||
event = gdk_event_new (GDK_ENTER_NOTIFY);
|
||||
event->any.window = NULL;
|
||||
event->any.send_event = FALSE;
|
||||
|
||||
private = (GdkWindowObject *)window;
|
||||
nswindow = ((GdkWindowImplQuartz *)private->impl)->toplevel;
|
||||
|
||||
screen_point = [NSEvent mouseLocation];
|
||||
|
||||
_gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &x_root, &y_root);
|
||||
|
||||
point = [nswindow convertScreenToBase:screen_point];
|
||||
|
||||
x = point.x;
|
||||
y = private->height - point.y;
|
||||
|
||||
event->crossing.window = window;
|
||||
event->crossing.subwindow = NULL;
|
||||
event->crossing.time = GDK_CURRENT_TIME;
|
||||
event->crossing.x = x;
|
||||
event->crossing.y = y;
|
||||
event->crossing.x_root = x_root;
|
||||
event->crossing.y_root = y_root;
|
||||
event->crossing.mode = GDK_CROSSING_NORMAL;
|
||||
event->crossing.detail = GDK_NOTIFY_ANCESTOR;
|
||||
event->crossing.state = 0;
|
||||
|
||||
append_event (event, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_quartz_events_send_map_event (GdkWindow *window)
|
||||
{
|
||||
|
@ -175,6 +175,8 @@ void _gdk_quartz_events_update_focus_window (GdkWindow *new_window,
|
||||
void _gdk_quartz_events_send_map_event (GdkWindow *window);
|
||||
GdkEventMask _gdk_quartz_events_get_current_event_mask (void);
|
||||
|
||||
void _gdk_quartz_events_send_enter_notify_event (GdkWindow *window);
|
||||
|
||||
/* Event loop */
|
||||
gboolean _gdk_quartz_event_loop_check_pending (void);
|
||||
NSEvent * _gdk_quartz_event_loop_get_pending (void);
|
||||
|
@ -782,74 +782,13 @@ _gdk_quartz_window_find_child (GdkWindow *window,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
generate_motion_event (GdkWindow *window)
|
||||
{
|
||||
NSPoint point;
|
||||
NSPoint screen_point;
|
||||
NSWindow *nswindow;
|
||||
GdkQuartzView *view;
|
||||
GdkWindowObject *private;
|
||||
GdkEvent *event;
|
||||
gint x, y, x_root, y_root;
|
||||
gdouble xx, yy;
|
||||
GList *node;
|
||||
GdkWindow *pointer_window;
|
||||
|
||||
event = gdk_event_new (GDK_MOTION_NOTIFY);
|
||||
event->any.window = NULL;
|
||||
event->any.send_event = TRUE;
|
||||
|
||||
private = (GdkWindowObject *)window;
|
||||
nswindow = ((GdkWindowImplQuartz *)private->impl)->toplevel;
|
||||
view = (GdkQuartzView *)[nswindow contentView];
|
||||
|
||||
screen_point = [NSEvent mouseLocation];
|
||||
|
||||
_gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &x_root, &y_root);
|
||||
|
||||
point = [nswindow convertScreenToBase:screen_point];
|
||||
|
||||
x = point.x;
|
||||
y = private->height - point.y;
|
||||
|
||||
pointer_window = _gdk_window_find_descendant_at (window, x, y,
|
||||
&xx, &yy);
|
||||
|
||||
event->any.type = GDK_MOTION_NOTIFY;
|
||||
event->motion.window = window;
|
||||
event->motion.time = GDK_CURRENT_TIME;
|
||||
event->motion.x = x;
|
||||
event->motion.y = y;
|
||||
event->motion.x_root = x_root;
|
||||
event->motion.y_root = y_root;
|
||||
/* FIXME event->axes */
|
||||
event->motion.state = 0;
|
||||
event->motion.is_hint = FALSE;
|
||||
event->motion.device = _gdk_display->core_pointer;
|
||||
|
||||
if (event->any.window)
|
||||
g_object_ref (event->any.window);
|
||||
|
||||
node = _gdk_event_queue_append (gdk_display_get_default (), event);
|
||||
_gdk_windowing_got_event (gdk_display_get_default (), node, event, 0);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_quartz_window_did_become_main (GdkWindow *window)
|
||||
{
|
||||
main_window_stack = g_slist_remove (main_window_stack, window);
|
||||
|
||||
if (GDK_WINDOW_OBJECT (window)->window_type != GDK_WINDOW_TEMP)
|
||||
{
|
||||
main_window_stack = g_slist_prepend (main_window_stack, window);
|
||||
|
||||
/* We just became the active window, send a motion-notify
|
||||
* event so things like highlights get set up correctly.
|
||||
* This motion-notify is sent to the key window.
|
||||
*/
|
||||
generate_motion_event (window);
|
||||
}
|
||||
main_window_stack = g_slist_prepend (main_window_stack, window);
|
||||
|
||||
clear_toplevel_order ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user