inspector: fix incorrect usage of g_flags_get_first_value

g_flags_get_first_value gets the value for the first bit set in the
bitflags passed to it. It expects a bitflag passed to it, but previously
add_tool iterated from GDK_AXIS_X up to GDK_AXIS_LAST and passed i into
get_first_value. This is obviously incorrect, as i isn't a bitflag
array.

While it could have been fixed by simply passing (1 << i) into
get_first_value, the new implementation is better, as we only iterate as
many times as necessary over axes instead of GDK_AXIS_LAST times.
This commit is contained in:
Florian "sp1rit"​
2024-10-10 14:10:23 +02:00
parent 067688684f
commit cbbf741f4b

View File

@@ -469,7 +469,7 @@ init_gl (GtkInspectorGeneral *gen)
gdk_gl_context_make_current (context);
gdk_gl_context_get_version (context, &major, &minor);
s = g_strdup_printf ("%s %u.%u",
gdk_gl_context_get_use_es (context) ? "GLES " : "OpenGL ",
gdk_gl_context_get_use_es (context) ? "GLES " : "OpenGL ",
major, minor);
gtk_label_set_text (GTK_LABEL (gen->gl_version), s);
g_free (s);
@@ -952,7 +952,6 @@ add_tool (GtkInspectorGeneral *gen,
GdkAxisFlags axes;
GString *str;
char *val;
int i;
GEnumClass *eclass;
GEnumValue *evalue;
GFlagsClass *fclass;
@@ -970,15 +969,12 @@ add_tool (GtkInspectorGeneral *gen,
fclass = g_type_class_ref (GDK_TYPE_AXIS_FLAGS);
str = g_string_new ("");
axes = gdk_device_tool_get_axes (tool);
for (i = GDK_AXIS_X; i < GDK_AXIS_LAST; i++)
while ((fvalue = g_flags_get_first_value (fclass, axes)))
{
if ((axes & (1 << i)) != 0)
{
fvalue = g_flags_get_first_value (fclass, i);
if (str->len > 0)
g_string_append (str, ", ");
g_string_append (str, fvalue->value_nick);
}
if (str->len > 0)
g_string_append (str, ", ");
g_string_append (str, fvalue->value_nick);
axes &= ~fvalue->value;
}
g_type_class_unref (fclass);