macos: fix in-app native shortcuts (again)

Popping an event of the queue in the IMContext handler
prevents it from being forwarded to the NSApp, in case the
(key) event was not handled by IMContext.

So I reverted to a mix of the original (4.13) and new (4.14.1) behavior
for fetching events: NSEvent lookup for IMContext uses loose matching,
so it can work with rewritten events. When sending events to NSApp, only
we're checking for an exact match.

Now in-app keyboard shortcuts (e.g. Ctrl-F2) work from within text
fields again.
This commit is contained in:
Arjan Molenaar 2024-04-23 08:57:09 +02:00
parent 8f15f6959c
commit f004f14b89
4 changed files with 22 additions and 9 deletions

View File

@ -161,7 +161,8 @@ void _gdk_macos_display_send_event (GdkMacosDisp
void _gdk_macos_display_warp_pointer (GdkMacosDisplay *self,
int x,
int y);
NSEvent *_gdk_macos_display_pop_nsevent (GdkEvent *event);
NSEvent *_gdk_macos_display_get_matching_nsevent (GdkEvent *event);
NSEvent *_gdk_macos_display_get_exact_nsevent (GdkEvent *event);
NSEvent *_gdk_macos_display_get_last_nsevent (void);
GdkDrag *_gdk_macos_display_find_drag (GdkMacosDisplay *self,
NSInteger sequence_number);

View File

@ -992,7 +992,7 @@ _gdk_macos_display_warp_pointer (GdkMacosDisplay *self,
}
NSEvent *
_gdk_macos_display_pop_nsevent (GdkEvent *event)
_gdk_macos_display_get_matching_nsevent (GdkEvent *event)
{
for (GList *iter = event_map.head; iter; iter = iter->next)
{
@ -1002,11 +1002,23 @@ _gdk_macos_display_pop_nsevent (GdkEvent *event)
map->gdk_event->device == event->device &&
map->gdk_event->time == event->time)
{
NSEvent *nsevent = map->nsevent;
g_queue_unlink (&event_map, iter);
gdk_event_unref (map->gdk_event);
g_free (map);
return nsevent;
return map->nsevent;
}
}
return NULL;
}
NSEvent *
_gdk_macos_display_get_exact_nsevent (GdkEvent *event)
{
for (GList *iter = event_map.head; iter; iter = iter->next)
{
GdkToNSEventMap *map = iter->data;
if (map->gdk_event == event)
{
return map->nsevent;
}
}

View File

@ -738,7 +738,7 @@ gdk_macos_event_source_dispatch (GSource *source,
if (!handled)
{
NSEvent *nsevent = _gdk_macos_display_pop_nsevent (event);
NSEvent *nsevent = _gdk_macos_display_get_exact_nsevent (event);
if (nsevent != NULL)
[NSApp sendEvent: nsevent];
}

View File

@ -185,7 +185,7 @@ quartz_filter_keypress (GtkIMContext *context,
keyval = gdk_key_event_get_keyval (event);
keycode = gdk_key_event_get_keycode (event);
NSEvent *nsevent = _gdk_macos_display_pop_nsevent ((GdkEvent *)event);
NSEvent *nsevent = _gdk_macos_display_get_matching_nsevent ((GdkEvent *)event);
if (!nsevent)
{