Repository: libsdl-org/SDL
File: src/video/wayland/SDL_waylandevents.c (C)

Code before:
    d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, SDL_min(3, version));

    if (d->input) {
        Wayland_create_data_device(d);
    }
}

void Wayland_add_primary_selection_device_manager(SDL_VideoData *d, uint32_t id, uint32_t version)
{
    d->primary_selection_device_manager = wl_registry_bind(d->registry, id, &zwp_primary_selection_device_manager_v1_interface, 1);

    if (d->input) {
        Wayland_create_primary_selection_device(d);
    }
}

void Wayland_add_text_input_manager(SDL_VideoData *d, uint32_t id, uint32_t version)
{
#ifdef HAVE_FCITX
    const char *im_module = SDL_getenv("SDL_IM_MODULE");
    if (im_module && SDL_strcmp(im_module, "fcitx") == 0) {
        /*
         * Override Wayland like how GTK_IM_MODULE does.
         * Fcitx wiki discourgaes SDL_IM_MODULE so its presence must be intentional because
         * a workaround is needed such as for fixing key repeat detection.
         */
        return;
    }
#endif

    d->text_input_manager = wl_registry_bind(d->registry, id, &zwp_text_input_manager_v3_interface, 1);

    if (d->input) {
        Wayland_create_text_input(d);
    }
}

static void tablet_tool_handle_type(void *data, struct zwp_tablet_tool_v2 *tool, uint32_t type)
{
    /* unimplemented */
}

static void tablet_tool_handle_hardware_serial(void *data, struct zwp_tablet_tool_v2 *tool, uint32_t serial_hi, uint32_t serial_lo)
{
    /* unimplemented */
}

static void tablet_tool_handle_hardware_id_wacom(void *data, struct zwp_tablet_tool_v2 *tool, uint32_t id_hi, uint32_t id_lo)
{
    /* unimplemented */
}

Review comment (suggestion):
```suggestion
        /* Override the Wayland text-input protocol when Fcitx is enabled, like how GTK_IM_MODULE does.
         *
         * The Fcitx wiki discourages enabling it under Wayland via SDL_IM_MODULE, so its presence must be intentional,
         * and this workaround is needed for fixing key repeat detection.
         */
```

Let's make the reasoning for this a bit more clear in the comment, but otherwise this makes sense and LGTM.

Code after:
    d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, SDL_min(3, version));

    if (d->input) {
        Wayland_create_data_device(d);
    }
}

void Wayland_add_primary_selection_device_manager(SDL_VideoData *d, uint32_t id, uint32_t version)
{
    d->primary_selection_device_manager = wl_registry_bind(d->registry, id, &zwp_primary_selection_device_manager_v1_interface, 1);

    if (d->input) {
        Wayland_create_primary_selection_device(d);
    }
}

void Wayland_add_text_input_manager(SDL_VideoData *d, uint32_t id, uint32_t version)
{
#ifdef HAVE_FCITX
    const char *im_module = SDL_getenv("SDL_IM_MODULE");
    if (im_module && SDL_strcmp(im_module, "fcitx") == 0) {
        /* Override the Wayland text-input protocol when Fcitx is enabled, like how GTK_IM_MODULE does.
         *
         * The Fcitx wiki discourages enabling it under Wayland via SDL_IM_MODULE, so its presence must
         * be intentional, and this workaround is needed for fixing key repeat detection.
         */
        return;
    }
#endif

    d->text_input_manager = wl_registry_bind(d->registry, id, &zwp_text_input_manager_v3_interface, 1);

    if (d->input) {
        Wayland_create_text_input(d);
    }
}

static void tablet_tool_handle_type(void *data, struct zwp_tablet_tool_v2 *tool, uint32_t type)
{
    /* unimplemented */
}

static void tablet_tool_handle_hardware_serial(void *data, struct zwp_tablet_tool_v2 *tool, uint32_t serial_hi, uint32_t serial_lo)
{
    /* unimplemented */
}

static void tablet_tool_handle_hardware_id_wacom(void *data, struct zwp_tablet_tool_v2 *tool, uint32_t id_hi, uint32_t id_lo)
{
    /* unimplemented */
}