app/display: Remove keyboard grab

Remove `gimp_display_shell_keyboard_grab()` and ...ungrab(), as there
doesn't seem to be any good reason to grab the keyboard away from the
compositor. More annoyingly, in some systems it will pop up a dialog
on each first click whether the user is okay with inhibiting shortcuts.
This commit is contained in:
Niels De Graef 2021-12-14 22:36:43 +01:00 committed by Jehan
parent 5e1dd03c52
commit 2b8ed6cfae
4 changed files with 9 additions and 140 deletions

View File

@ -59,34 +59,6 @@ get_associated_pointer (GdkDevice *device)
return device;
}
static GdkDevice *
get_associated_keyboard (GdkDevice *device)
{
switch (gdk_device_get_device_type (device))
{
case GDK_DEVICE_TYPE_SLAVE:
device = gdk_device_get_associated_device (device);
break;
case GDK_DEVICE_TYPE_FLOATING:
{
GdkDisplay *display = gdk_device_get_display (device);
GdkSeat *seat = gdk_display_get_default_seat (display);
device = gdk_seat_get_pointer (seat);
}
break;
default:
break;
}
if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
device = gdk_device_get_associated_device (device);
return device;
}
gboolean
gimp_display_shell_pointer_grab (GimpDisplayShell *shell,
const GdkEvent *event,
@ -144,63 +116,3 @@ gimp_display_shell_pointer_ungrab (GimpDisplayShell *shell,
shell->grab_pointer_source = NULL;
shell->grab_pointer_time = 0;
}
gboolean
gimp_display_shell_keyboard_grab (GimpDisplayShell *shell,
const GdkEvent *event)
{
GdkDevice *device;
GdkDevice *source_device;
GdkGrabStatus status;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
g_return_val_if_fail (shell->grab_keyboard == NULL, FALSE);
source_device = gimp_devices_get_from_event (shell->display->gimp,
event, &device);
if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
{
device = get_associated_keyboard (device);
source_device = NULL;
}
status = gdk_device_grab (device,
gtk_widget_get_window (shell->canvas),
GDK_OWNERSHIP_APPLICATION,
FALSE,
GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK |
GDK_FOCUS_CHANGE_MASK,
NULL, gdk_event_get_time (event));
if (status == GDK_GRAB_SUCCESS)
{
shell->grab_keyboard = device;
shell->grab_keyboard_source = source_device;
shell->grab_keyboard_time = gdk_event_get_time (event);
return TRUE;
}
g_printerr ("%s: gdk_device_grab(%s) failed with status %d\n",
G_STRFUNC, gdk_device_get_name (device), status);
return FALSE;
}
void
gimp_display_shell_keyboard_ungrab (GimpDisplayShell *shell,
const GdkEvent *event)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (event != NULL);
g_return_if_fail (shell->grab_keyboard != NULL);
gdk_device_ungrab (shell->grab_keyboard, shell->grab_keyboard_time);
shell->grab_keyboard = NULL;
shell->grab_keyboard_source = NULL;
shell->grab_keyboard_time = 0;
}

View File

@ -27,10 +27,5 @@ gboolean gimp_display_shell_pointer_grab (GimpDisplayShell *shell,
void gimp_display_shell_pointer_ungrab (GimpDisplayShell *shell,
const GdkEvent *event);
gboolean gimp_display_shell_keyboard_grab (GimpDisplayShell *shell,
const GdkEvent *event);
void gimp_display_shell_keyboard_ungrab (GimpDisplayShell *shell,
const GdkEvent *event);
#endif /* __GIMP_DISPLAY_SHELL_GRAB_H__ */

View File

@ -532,13 +532,6 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
GDK_BUTTON_RELEASE_MASK))
return TRUE;
if (! shell->space_release_pending)
if (! gimp_display_shell_keyboard_grab (shell, event))
{
gimp_display_shell_pointer_ungrab (shell, event);
return TRUE;
}
if (gimp_display_shell_initialize_tool (shell,
&image_coords, state))
{
@ -670,9 +663,6 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
if (! shell->grab_pointer || shell->scrolling)
return TRUE;
if (! shell->space_release_pending)
gimp_display_shell_keyboard_ungrab (shell, event);
if (active_tool &&
(! gimp_image_is_empty (image) ||
gimp_tool_control_get_handle_empty_image (active_tool->control)))
@ -1453,24 +1443,17 @@ gimp_display_shell_ruler_button_press (GtkWidget *widget,
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK))
{
if (gimp_display_shell_keyboard_grab (shell, (GdkEvent *) event))
if (event->state & gimp_get_toggle_behavior_mask ())
{
if (event->state & gimp_get_toggle_behavior_mask ())
{
gimp_sample_point_tool_start_new (active_tool, display);
}
else
{
gimp_guide_tool_start_new (active_tool, display,
orientation);
}
return TRUE;
gimp_sample_point_tool_start_new (active_tool, display);
}
else
{
gimp_display_shell_pointer_ungrab (shell, (GdkEvent *) event);
gimp_guide_tool_start_new (active_tool, display,
orientation);
}
return TRUE;
}
}
}
@ -1581,21 +1564,9 @@ gimp_display_shell_check_device (GimpDisplayShell *shell,
/* While we have a grab, ignore all events from all other devices
* of the same type
*/
if (event->type == GDK_KEY_PRESS ||
event->type == GDK_KEY_RELEASE ||
event->type == GDK_FOCUS_CHANGE)
{
if ((shell->grab_keyboard && (shell->grab_keyboard != grab_device)) ||
(shell->grab_keyboard_source && (shell->grab_keyboard_source != device)))
{
GIMP_LOG (TOOL_EVENTS,
"ignoring key event from '%s' while waiting for event from '%s'\n",
gdk_device_get_name (device),
gdk_device_get_name (shell->grab_keyboard_source));
return TRUE;
}
}
else
if (event->type != GDK_KEY_PRESS &&
event->type != GDK_KEY_RELEASE &&
event->type != GDK_FOCUS_CHANGE)
{
if ((shell->grab_pointer && (shell->grab_pointer != grab_device)) ||
(shell->grab_pointer_source && (shell->grab_pointer_source != device)))
@ -1816,9 +1787,6 @@ gimp_display_shell_space_pressed (GimpDisplayShell *shell,
if (shell->space_release_pending || shell->scrolling)
return;
if (! gimp_display_shell_keyboard_grab (shell, event))
return;
switch (shell->display->config->space_bar_action)
{
case GIMP_SPACE_BAR_ACTION_NONE:
@ -1916,8 +1884,6 @@ gimp_display_shell_released (GimpDisplayShell *shell,
break;
}
gimp_display_shell_keyboard_ungrab (shell, event);
shell->space_release_pending = FALSE;
shell->button1_release_pending = FALSE;
}

View File

@ -197,10 +197,6 @@ struct _GimpDisplayShell
GdkDevice *grab_pointer_source;
guint32 grab_pointer_time;
GdkDevice *grab_keyboard;
GdkDevice *grab_keyboard_source;
guint32 grab_keyboard_time;
/* the state of gimp_display_shell_zoom_gesture_*() */
gdouble last_zoom_scale;
gboolean zoom_gesture_active;