Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk4 Click Through Widgets #254

Open
BluewyDiamond opened this issue Jan 23, 2025 · 0 comments
Open

Gtk4 Click Through Widgets #254

BluewyDiamond opened this issue Jan 23, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@BluewyDiamond
Copy link

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

@BluewyDiamond BluewyDiamond added the enhancement New feature or request label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant