gtk: Stop using modifier intents

Reviewing the existing settings, the only backend with
some differences in the modifier intent settings is OS X,
and we would rather have that implemented by interpreting
the existing modifiers in the appropriate way.

                X11      Wayland  Win32    OS X

primary         ctrl     ctrl     ctrl     mod2
mnemonic        alt      alt      alt      alt
context menu    -        -        -        ctrl
extend sel      shift    shift    shift    shift
modify sel      ctrl     ctrl     ctrl     mod2
no text         alt|ctrl alt|ctrl alt|ctrl mod2|ctrl
shift group     varies   -        -        alt

GTK now uses the following modifiers:

primary         ctrl
mnemonic        alt
extend sel      shift
modify sel      ctrl
no text         alt|ctrl

The context menu and shift group intents were not used
in GTK at all.

Update tests to no longer expect <Primary> to roundtrip
through the accelerator parsing and formatting code.
This commit is contained in:
Matthias Clasen 2020-04-05 19:52:25 -04:00
parent dce8d251c6
commit c297d45b8a
14 changed files with 45 additions and 143 deletions

View File

@ -43,7 +43,12 @@
*/
/* --- variables --- */
static guint default_accel_mod_mask = 0;
static guint default_accel_mod_mask = GDK_CONTROL_MASK|
GDK_SHIFT_MASK|
GDK_ALT_MASK|
GDK_SUPER_MASK|
GDK_HYPER_MASK|
GDK_META_MASK;
/* --- functions --- */
@ -276,7 +281,6 @@ gtk_accelerator_parse_with_keycode (const gchar *accelerator,
GdkModifierType mods;
gint len;
gboolean error;
GdkModifierType primary;
if (accelerator_key)
*accelerator_key = 0;
@ -290,9 +294,6 @@ gtk_accelerator_parse_with_keycode (const gchar *accelerator,
if (!display)
display = gdk_display_get_default ();
primary = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
error = FALSE;
keyval = 0;
mods = 0;
@ -305,7 +306,7 @@ gtk_accelerator_parse_with_keycode (const gchar *accelerator,
{
accelerator += 9;
len -= 9;
mods |= primary;
mods |= GDK_CONTROL_MASK;
}
else if (len >= 9 && is_control (accelerator))
{
@ -578,7 +579,6 @@ gchar*
gtk_accelerator_name (guint accelerator_key,
GdkModifierType accelerator_mods)
{
static const gchar text_primary[] = "<Primary>";
static const gchar text_shift[] = "<Shift>";
static const gchar text_control[] = "<Control>";
static const gchar text_alt[] = "<Alt>";
@ -589,10 +589,6 @@ gtk_accelerator_name (guint accelerator_key,
guint l;
const char *keyval_name;
gchar *accelerator;
GdkModifierType primary;
primary = gdk_display_get_modifier_mask (gdk_display_get_default (),
GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
accelerator_mods &= GDK_MODIFIER_MASK;
@ -602,11 +598,6 @@ gtk_accelerator_name (guint accelerator_key,
saved_mods = accelerator_mods;
l = 0;
if (accelerator_mods & primary)
{
l += sizeof (text_primary) - 1;
accelerator_mods &= ~primary; /* consume the default accel */
}
if (accelerator_mods & GDK_SHIFT_MASK)
l += sizeof (text_shift) - 1;
if (accelerator_mods & GDK_CONTROL_MASK)
@ -625,12 +616,6 @@ gtk_accelerator_name (guint accelerator_key,
accelerator_mods = saved_mods;
l = 0;
accelerator[l] = 0;
if (accelerator_mods & primary)
{
strcpy (accelerator + l, text_primary);
l += sizeof (text_primary) - 1;
accelerator_mods &= ~primary; /* consume the default accel */
}
if (accelerator_mods & GDK_SHIFT_MASK)
{
strcpy (accelerator + l, text_shift);
@ -1045,19 +1030,5 @@ gtk_accelerator_set_default_mod_mask (GdkModifierType default_mod_mask)
GdkModifierType
gtk_accelerator_get_default_mod_mask (void)
{
if (!default_accel_mod_mask)
{
GdkDisplay *display;
display = gdk_display_get_default ();
if (!display)
return GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_ALT_MASK;
default_accel_mod_mask =
gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_DEFAULT_MOD_MASK);
}
return default_accel_mod_mask;
}

View File

@ -142,10 +142,10 @@ get_current_selection_modifiers (GtkWidget *widget,
if (gtk_get_current_event_state (&state))
{
mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
mask = GDK_CONTROL_MASK;
if ((state & mask) == mask)
*modify = TRUE;
mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
mask = GDK_SHIFT_MASK;
if ((state & mask) == mask)
*extend = TRUE;
}
@ -2992,19 +2992,9 @@ gtk_flow_box_add_move_binding (GtkWidgetClass *widget_class,
GtkMovementStep step,
gint count)
{
GdkDisplay *display;
GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
display = gdk_display_get_default ();
if (display != NULL)
{
extend_mod_mask = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
}
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",

View File

@ -2125,7 +2125,7 @@ gtk_icon_view_button_press (GtkGestureClick *gesture,
GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
int button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
GdkEventSequence *sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
GdkEventButton *event = (GdkEventButton *)gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
GdkEvent *event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
GdkModifierType state;
if (!gtk_widget_has_focus (widget))
@ -2133,15 +2133,10 @@ gtk_icon_view_button_press (GtkGestureClick *gesture,
if (button == GDK_BUTTON_PRIMARY)
{
GdkModifierType extend_mod_mask;
GdkModifierType modify_mod_mask;
GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
state = gdk_event_get_modifier_state ((GdkEvent *)event);
extend_mod_mask =
gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask =
gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
state = gdk_event_get_modifier_state (event);
item = _gtk_icon_view_get_item_at_widget_coords (icon_view,
x, y,
@ -3468,15 +3463,8 @@ gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
if (gtk_get_current_event_state (&state))
{
GdkModifierType extend_mod_mask;
GdkModifierType modify_mod_mask;
extend_mod_mask =
gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask =
gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
if ((state & modify_mod_mask) == modify_mod_mask)
icon_view->priv->modify_selection_pressed = TRUE;

View File

@ -1034,7 +1034,6 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
GtkIMContextSimplePrivate *priv = context_simple->priv;
GdkSurface *surface = gdk_event_get_surface ((GdkEvent *) event);
GdkDisplay *display = gdk_surface_get_display (surface);
GSList *tmp_list;
int n_compose = 0;
GdkModifierType hex_mod_mask;
@ -1100,8 +1099,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
if (keyval == gtk_compose_ignore[i])
return FALSE;
hex_mod_mask = gdk_display_get_modifier_mask (display, GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
hex_mod_mask |= GDK_SHIFT_MASK;
hex_mod_mask = GDK_CONTROL_MASK|GDK_SHIFT_MASK;
if (priv->in_hex_sequence && priv->modifiers_dropped)
have_hex_mods = TRUE;
@ -1132,7 +1130,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
{
GdkModifierType no_text_input_mask;
no_text_input_mask = gdk_display_get_modifier_mask (display, GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
no_text_input_mask = GDK_ALT_MASK|GDK_CONTROL_MASK;
if (state & no_text_input_mask ||
(priv->in_hex_sequence && priv->modifiers_dropped &&

View File

@ -361,16 +361,12 @@ gtk_im_multicontext_filter_keypress (GtkIMContext *context,
}
else
{
GdkDisplay *display;
GdkModifierType no_text_input_mask;
keyval = gdk_key_event_get_keyval (event);
state = gdk_event_get_modifier_state (event);
display = gdk_event_get_display (event);
no_text_input_mask =
gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
no_text_input_mask = GDK_ALT_MASK|GDK_CONTROL_MASK;
if (gdk_event_get_event_type (event) == GDK_KEY_PRESS &&
(state & no_text_input_mask) == 0)

View File

@ -1425,19 +1425,9 @@ gtk_list_box_add_move_binding (GtkWidgetClass *widget_class,
GtkMovementStep step,
gint count)
{
GdkDisplay *display;
GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
display = gdk_display_get_default ();
if (display)
{
extend_mod_mask = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
}
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
@ -1786,10 +1776,10 @@ get_current_selection_modifiers (GtkWidget *widget,
if (gtk_get_current_event_state (&state))
{
mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
mask = GDK_CONTROL_MASK;
if ((state & mask) == mask)
*modify = TRUE;
mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
mask = GDK_SHIFT_MASK;
if ((state & mask) == mask)
*extend = TRUE;
}

View File

@ -158,22 +158,6 @@ _gtk_single_string_accumulator (GSignalInvocationHint *ihint,
return continue_emission;
}
GdkModifierType
_gtk_get_primary_accel_mod (void)
{
static GdkModifierType primary = 0;
if (! primary)
{
GdkDisplay *display = gdk_display_get_default ();
primary = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
}
return primary;
}
static gpointer
register_resources (gpointer data)
{

View File

@ -82,8 +82,6 @@ gboolean _gtk_single_string_accumulator (GSignalInvocationHint *ihint,
const GValue *handler_return,
gpointer dummy);
GdkModifierType _gtk_get_primary_accel_mod (void);
gboolean gtk_propagate_event_internal (GtkWidget *widget,
GdkEvent *event,
GtkWidget *topmost);

View File

@ -2657,7 +2657,6 @@ gtk_text_click_gesture_pressed (GtkGestureClick *gesture,
gboolean have_selection;
gboolean is_touchscreen, extend_selection;
GdkDevice *source;
guint state;
sel_start = priv->selection_bound;
sel_end = priv->current_pos;
@ -2673,12 +2672,7 @@ gtk_text_click_gesture_pressed (GtkGestureClick *gesture,
priv->select_words = FALSE;
priv->select_lines = FALSE;
state = gdk_event_get_modifier_state (event);
extend_selection =
(state &
gtk_widget_get_modifier_mask (widget,
GDK_MODIFIER_INTENT_EXTEND_SELECTION));
extend_selection = GDK_SHIFT_MASK;
/* Always emit reset when preedit is shown */
priv->need_im_reset = TRUE;

View File

@ -5373,9 +5373,7 @@ gtk_text_view_click_gesture_pressed (GtkGestureClick *gesture,
state = gdk_event_get_modifier_state (event);
if (state &
gtk_widget_get_modifier_mask (GTK_WIDGET (text_view),
GDK_MODIFIER_INTENT_EXTEND_SELECTION))
if (state & GDK_SHIFT_MASK)
extends = TRUE;
switch (n_press)

View File

@ -2791,10 +2791,10 @@ get_current_selection_modifiers (GtkWidget *widget,
if (gtk_get_current_event_state (&state))
{
mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
mask = GDK_CONTROL_MASK;
if ((state & mask) == mask)
*modify = TRUE;
mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
mask = GDK_SHIFT_MASK;
if ((state & mask) == mask)
*extend = TRUE;
}
@ -7966,13 +7966,8 @@ gtk_tree_view_real_move_cursor (GtkTreeView *tree_view,
GdkModifierType extend_mod_mask;
GdkModifierType modify_mod_mask;
extend_mod_mask =
gtk_widget_get_modifier_mask (GTK_WIDGET (tree_view),
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask =
gtk_widget_get_modifier_mask (GTK_WIDGET (tree_view),
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
extend_mod_mask = GDK_SHIFT_MASK;
modify_mod_mask = GDK_CONTROL_MASK;
if ((state & modify_mod_mask) == modify_mod_mask)
tree_view->modify_selection_pressed = TRUE;
@ -9990,9 +9985,7 @@ gtk_tree_view_real_select_cursor_parent (GtkTreeView *tree_view)
{
GdkModifierType modify_mod_mask;
modify_mod_mask =
gtk_widget_get_modifier_mask (GTK_WIDGET (tree_view),
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
modify_mod_mask = GDK_CONTROL_MASK;
if ((state & modify_mod_mask) == modify_mod_mask)
tree_view->modify_selection_pressed = TRUE;
@ -13686,8 +13679,7 @@ gtk_tree_view_search_key_pressed (GtkEventControllerKey *key,
return TRUE;
}
default_accel = gtk_widget_get_modifier_mask (widget,
GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
default_accel = GDK_CONTROL_MASK;
/* select previous matching iter */
if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)

View File

@ -742,7 +742,7 @@ key_pressed (GtkEventController *controller,
gboolean search_started;
search_started = gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (wt->priv->search_bar));
default_accel = gtk_widget_get_modifier_mask (GTK_WIDGET (wt), GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
default_accel = GDK_CONTROL_MASK;
if (search_started &&
(keyval == GDK_KEY_Return ||

View File

@ -407,7 +407,7 @@ key_pressed (GtkEventController *controller,
gboolean search_started;
search_started = gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (sl->priv->search_bar));
default_accel = gtk_widget_get_modifier_mask (GTK_WIDGET (sl), GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
default_accel = GDK_CONTROL_MASK;
if (search_started &&
(keyval == GDK_KEY_Return ||

View File

@ -18,9 +18,11 @@
#include <locale.h>
static void
test_one_accel (const char *accel,
const char *exp_label,
gboolean has_keysym)
test_one_accel (const char *accel,
GdkModifierType exp_mods,
guint exp_key,
const char *exp_label,
gboolean has_keysym)
{
guint accel_key;
GdkModifierType mods;
@ -47,7 +49,8 @@ test_one_accel (const char *accel,
}
if (has_keysym)
g_assert (accel_key != 0);
g_assert (accel_key == exp_key);
g_assert (mods == exp_mods);
g_assert (keycodes);
g_assert (keycodes[0] != 0);
@ -72,49 +75,49 @@ test_one_accel (const char *accel,
static void
accel1 (void)
{
test_one_accel ("0xb3", "0xb3", FALSE);
test_one_accel ("0xb3", 0, 0xb3, "0xb3", FALSE);
}
static void
accel2 (void)
{
test_one_accel ("<Primary><Alt>z", "Ctrl+Alt+Z", TRUE);
test_one_accel ("<Control><Alt>z", GDK_CONTROL_MASK|GDK_ALT_MASK, GDK_KEY_z, "Ctrl+Alt+Z", TRUE);
}
static void
accel3 (void)
{
test_one_accel ("KP_7", "7", TRUE);
test_one_accel ("KP_7", 0, GDK_KEY_KP_7, "7", TRUE);
}
static void
accel4 (void)
{
test_one_accel ("<Primary>KP_7", "Ctrl+7", TRUE);
test_one_accel ("<Control>KP_7", GDK_CONTROL_MASK, GDK_KEY_KP_7, "Ctrl+7", TRUE);
}
static void
accel5 (void)
{
test_one_accel ("<Shift>exclam", "Shift+!", TRUE);
test_one_accel ("<Shift>exclam", GDK_SHIFT_MASK, GDK_KEY_exclam, "Shift+!", TRUE);
}
static void
accel6 (void)
{
test_one_accel ("<Hyper>x", "Hyper+X", TRUE);
test_one_accel ("<Hyper>x", GDK_HYPER_MASK, GDK_KEY_x, "Hyper+X", TRUE);
}
static void
accel7 (void)
{
test_one_accel ("<Super>x", "Super+X", TRUE);
test_one_accel ("<Super>x", GDK_SUPER_MASK, GDK_KEY_x, "Super+X", TRUE);
}
static void
accel8 (void)
{
test_one_accel ("<Meta>x", "Meta+X", TRUE);
test_one_accel ("<Meta>x", GDK_META_MASK, GDK_KEY_x, "Meta+X", TRUE);
}
static void