Skip to content

Gtk4 Click Through Widgets #254

Open
@BluewyDiamond

Description

@BluewyDiamond

I have some widgets, and I want to be able to click through them to interact with the window below.

A quick search suggests the following approach might work. I tried implementing it in JavaScript, but I ran into an issue because I couldn’t create a region from a rectangle — I couldn't find the equivalent method or maybe there wasn't one for it yet. This might work in Vala, but I don't have experience or knowledge to write it or test it in Vala.

static void toggle_mouse_input(GtkWidget *area)
{
    GdkSurface *surface = gtk_native_get_surface(gtk_widget_get_native(area));
    static gboolean enabled = TRUE;
    if (enabled) {
        cairo_region_t *region = cairo_region_create();
        gdk_surface_set_input_region(surface, region);
        enabled = FALSE;
    } else {
        int width = gtk_widget_get_width(area);
        int height = gtk_widget_get_width(area);
        cairo_rectangle_int_t rectangle = {.x = 0, .y = 0, .width = width, .height = height};
        cairo_region_t *region = cairo_region_create_rectangle(&rectangle);
        gdk_surface_set_input_region(surface, region);
        enabled = TRUE;
    }
    gtk_widget_queue_draw(area);
}

static gboolean key_pressed(GtkEventControllerKey *controller_key, guint keyval, guint keycode,
                            GdkModifierType state, GtkWidget *area)
{
    if (keyval == GDK_KEY_F1) {
        toggle_mouse_input(area);
        g_print("Hello toggle input\n");
    } else {
        // Forward the key event to the underlying window.
    }
    return TRUE;
}

source: https://discourse.gnome.org/t/how-to-release-input-gtk4/22821

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions