Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
42 changes: 22 additions & 20 deletions shell/platform/linux/fl_mouse_cursor_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ static constexpr char kBadArgumentsError[] = "Bad Arguments";
static constexpr char kActivateSystemCursorMethod[] = "activateSystemCursor";
static constexpr char kKindKey[] = "kind";

static GHashTable* systemCursorTable = nullptr;

bool define_system_cursor(const gchar *key, const gchar *value) {
return g_hash_table_insert(systemCursorTable, (gpointer)key, (gpointer)value);
}

struct _FlMouseCursorPlugin {
GObject parent_instance;

Expand All @@ -37,26 +43,22 @@ FlMethodResponse* activate_system_cursor(FlMouseCursorPlugin* self,
if (fl_value_get_type(kind_value) == FL_VALUE_TYPE_STRING)
kind = fl_value_get_string(kind_value);

const gchar* cursor_name = nullptr;
if (g_strcmp0(kind, "none") == 0)
cursor_name = "none";
else if (g_strcmp0(kind, "basic") == 0)
cursor_name = "default";
else if (g_strcmp0(kind, "click") == 0)
cursor_name = "pointer";
else if (g_strcmp0(kind, "text") == 0)
cursor_name = "text";
else if (g_strcmp0(kind, "forbidden") == 0)
cursor_name = "not-allowed";
else if (g_strcmp0(kind, "grab") == 0)
cursor_name = "grab";
else if (g_strcmp0(kind, "grabbing") == 0)
cursor_name = "grabbing";
else if (g_strcmp0(kind, "resizeLeftRight") == 0)
cursor_name = "ew-resize";
else if (g_strcmp0(kind, "resizeUpDown") == 0)
cursor_name = "ns-resize";
else
if (systemCursorTable == nullptr) {
systemCursorTable = g_hash_table_new(g_str_hash, g_str_equal);

// The following mapping must be kept in sync with Flutter framework's
// mouse_cursor.dart
define_system_cursor("none", "none");
define_system_cursor("click", "pointer");
define_system_cursor("text", "text");
define_system_cursor("forbidden", "not-allowed");
define_system_cursor("grab", "grabbing");
define_system_cursor("resizeLeftRight", "ew-resize");
define_system_cursor("resizeUpDown", "ns-resize");
}

const gchar* cursor_name = (const gchar*)g_hash_table_lookup(systemCursorTable, kind);
if (cursor_name == nullptr) // Including "basic" kind
cursor_name = "default";

GdkWindow* window =
Expand Down