core: Get per-direction pad feature labels for rings/strips

Let the caller specify the directions, so that the pad OSD UI may
assign distinct labels to each direction, instead of showing an
unified one on both directions.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3005>
This commit is contained in:
Carlos Garnacho 2023-05-16 16:32:11 +02:00 committed by Marge Bot
parent 3e3660ae5f
commit cd39ba8baf
4 changed files with 47 additions and 89 deletions

View File

@ -2778,6 +2778,7 @@ char *
meta_display_get_pad_feature_label (MetaDisplay *display, meta_display_get_pad_feature_label (MetaDisplay *display,
ClutterInputDevice *pad, ClutterInputDevice *pad,
MetaPadFeatureType feature, MetaPadFeatureType feature,
MetaPadDirection direction,
int feature_number) int feature_number)
{ {
char *label; char *label;
@ -2785,6 +2786,7 @@ meta_display_get_pad_feature_label (MetaDisplay *display,
/* First, lookup the action, as imposed by settings */ /* First, lookup the action, as imposed by settings */
label = meta_pad_action_mapper_get_feature_label (display->pad_action_mapper, label = meta_pad_action_mapper_get_feature_label (display->pad_action_mapper,
pad, feature, pad, feature,
direction,
feature_number); feature_number);
if (label) if (label)
return label; return label;

View File

@ -44,14 +44,6 @@ struct _PadMappingInfo
guint *group_modes; guint *group_modes;
}; };
typedef enum
{
META_PAD_DIRECTION_UP = 0,
META_PAD_DIRECTION_DOWN,
META_PAD_DIRECTION_CW,
META_PAD_DIRECTION_CCW,
} MetaPadDirection;
struct _MetaPadActionMapper struct _MetaPadActionMapper
{ {
GObject parent_class; GObject parent_class;
@ -744,101 +736,54 @@ meta_pad_action_mapper_handle_event (MetaPadActionMapper *mapper,
} }
} }
static void
format_directional_action (GString *str,
MetaPadDirection direction,
const gchar *action)
{
switch (direction)
{
case META_PAD_DIRECTION_CW:
g_string_append_printf (str, "⭮ %s", action);
break;
case META_PAD_DIRECTION_CCW:
g_string_append_printf (str, "⭯ %s", action);
break;
case META_PAD_DIRECTION_UP:
g_string_append_printf (str, "↥ %s", action);
break;
case META_PAD_DIRECTION_DOWN:
g_string_append_printf (str, "↧ %s", action);
break;
}
}
static char *
compose_directional_action_label (MetaPadDirection direction1,
GSettings *value1,
MetaPadDirection direction2,
GSettings *value2)
{
g_autofree char *accel1 = NULL, *accel2 = NULL;
GString *str;
accel1 = g_settings_get_string (value1, "keybinding");
accel2 = g_settings_get_string (value2, "keybinding");
if ((!accel1 || !*accel1) && ((!accel2 || !*accel2)))
return NULL;
str = g_string_new (NULL);
if (accel1 && *accel1)
format_directional_action (str, direction1, accel1);
if (accel2 && *accel2)
{
if (str->len != 0)
g_string_append (str, " / ");
format_directional_action (str, direction2, accel2);
}
return g_string_free (str, FALSE);
}
static char * static char *
meta_pad_action_mapper_get_ring_label (MetaPadActionMapper *mapper, meta_pad_action_mapper_get_ring_label (MetaPadActionMapper *mapper,
ClutterInputDevice *pad, ClutterInputDevice *pad,
guint number, int number,
guint mode) unsigned int mode,
MetaPadDirection direction)
{ {
GSettings *settings1, *settings2; g_autoptr (GSettings) settings = NULL;
char *label; g_autofree char *action = NULL;
if (direction != META_PAD_DIRECTION_CW &&
direction != META_PAD_DIRECTION_CCW)
return NULL;
settings = lookup_pad_feature_settings (pad, META_PAD_FEATURE_RING,
number, direction, mode);
/* We only allow keybinding actions with those */ /* We only allow keybinding actions with those */
settings1 = lookup_pad_feature_settings (pad, META_PAD_FEATURE_RING, number, action = g_settings_get_string (settings, "keybinding");
META_PAD_DIRECTION_CW, mode); if (action && *action)
settings2 = lookup_pad_feature_settings (pad, META_PAD_FEATURE_RING, number, return g_steal_pointer (&action);
META_PAD_DIRECTION_CCW, mode);
label = compose_directional_action_label (META_PAD_DIRECTION_CW, settings1,
META_PAD_DIRECTION_CCW, settings2);
g_object_unref (settings1);
g_object_unref (settings2);
return label; return NULL;
} }
static char * static char *
meta_pad_action_mapper_get_strip_label (MetaPadActionMapper *mapper, meta_pad_action_mapper_get_strip_label (MetaPadActionMapper *mapper,
ClutterInputDevice *pad, ClutterInputDevice *pad,
guint number, int number,
guint mode) unsigned int mode,
MetaPadDirection direction)
{ {
GSettings *settings1, *settings2; g_autoptr (GSettings) settings = NULL;
char *label; g_autofree char *action = NULL;
if (direction != META_PAD_DIRECTION_UP &&
direction != META_PAD_DIRECTION_DOWN)
return NULL;
settings = lookup_pad_feature_settings (pad, META_PAD_FEATURE_STRIP,
number, direction, mode);
/* We only allow keybinding actions with those */ /* We only allow keybinding actions with those */
settings1 = lookup_pad_feature_settings (pad, META_PAD_FEATURE_STRIP, number, action = g_settings_get_string (settings, "keybinding");
META_PAD_DIRECTION_UP, mode); if (action && *action)
settings2 = lookup_pad_feature_settings (pad, META_PAD_FEATURE_STRIP, number, return g_steal_pointer (&action);
META_PAD_DIRECTION_DOWN, mode);
label = compose_directional_action_label (META_PAD_DIRECTION_UP, settings1,
META_PAD_DIRECTION_DOWN, settings2);
g_object_unref (settings1);
g_object_unref (settings2);
return label; return NULL;
} }
char * char *
@ -921,6 +866,7 @@ char *
meta_pad_action_mapper_get_feature_label (MetaPadActionMapper *mapper, meta_pad_action_mapper_get_feature_label (MetaPadActionMapper *mapper,
ClutterInputDevice *pad, ClutterInputDevice *pad,
MetaPadFeatureType feature, MetaPadFeatureType feature,
MetaPadDirection direction,
int number) int number)
{ {
unsigned int mode; unsigned int mode;
@ -929,10 +875,10 @@ meta_pad_action_mapper_get_feature_label (MetaPadActionMapper *mapper,
{ {
case META_PAD_FEATURE_RING: case META_PAD_FEATURE_RING:
mode = get_current_pad_mode (mapper, pad, feature, number); mode = get_current_pad_mode (mapper, pad, feature, number);
return meta_pad_action_mapper_get_ring_label (mapper, pad, number, mode); return meta_pad_action_mapper_get_ring_label (mapper, pad, number, mode, direction);
case META_PAD_FEATURE_STRIP: case META_PAD_FEATURE_STRIP:
mode = get_current_pad_mode (mapper, pad, feature, number); mode = get_current_pad_mode (mapper, pad, feature, number);
return meta_pad_action_mapper_get_strip_label (mapper, pad, number, mode); return meta_pad_action_mapper_get_strip_label (mapper, pad, number, mode, direction);
} }
return NULL; return NULL;

View File

@ -46,6 +46,7 @@ char * meta_pad_action_mapper_get_button_label (MetaPadActionMapper *mapper,
char * meta_pad_action_mapper_get_feature_label (MetaPadActionMapper *mapper, char * meta_pad_action_mapper_get_feature_label (MetaPadActionMapper *mapper,
ClutterInputDevice *pad, ClutterInputDevice *pad,
MetaPadFeatureType feature, MetaPadFeatureType feature,
MetaPadDirection direction,
int number); int number);
#endif /* META_PAD_ACTION_MAPPER_H */ #endif /* META_PAD_ACTION_MAPPER_H */

View File

@ -62,6 +62,14 @@ typedef enum
META_PAD_FEATURE_STRIP, META_PAD_FEATURE_STRIP,
} MetaPadFeatureType; } MetaPadFeatureType;
typedef enum
{
META_PAD_DIRECTION_UP = 1,
META_PAD_DIRECTION_DOWN,
META_PAD_DIRECTION_CW,
META_PAD_DIRECTION_CCW,
} MetaPadDirection;
typedef struct _MetaDisplayClass MetaDisplayClass; typedef struct _MetaDisplayClass MetaDisplayClass;
#define META_TYPE_DISPLAY (meta_display_get_type ()) #define META_TYPE_DISPLAY (meta_display_get_type ())
@ -200,6 +208,7 @@ META_EXPORT
char * meta_display_get_pad_feature_label (MetaDisplay *display, char * meta_display_get_pad_feature_label (MetaDisplay *display,
ClutterInputDevice *pad, ClutterInputDevice *pad,
MetaPadFeatureType feature, MetaPadFeatureType feature,
MetaPadDirection direction,
int feature_number); int feature_number);
META_EXPORT META_EXPORT