fix(electrobun): disable WebView during resize drag in C (prevents grab theft)

This commit is contained in:
Hibryda 2026-03-25 17:59:32 +01:00
parent 7af94fd4bd
commit 6d0a65eb65
2 changed files with 37 additions and 2 deletions

View file

@ -16,7 +16,9 @@
#include <stdio.h>
static GtkWindow *stored_window = NULL;
static GtkWidget *stored_webview = NULL;
static int border_width = 8;
static gboolean resize_active = FALSE;
/**
* Hit-test: determine which edge the pointer is on.
@ -86,10 +88,18 @@ static gboolean on_webview_button_press(GtkWidget *widget,
/* Clear min-size on entire tree BEFORE resize drag — allows shrinking */
clear_min_size(GTK_WIDGET(stored_window), 0);
/* Also set geometry hints with small minimum */
/* Set geometry hints with small minimum */
GdkGeometry geom = { .min_width = 400, .min_height = 300, .max_width = 32767, .max_height = 32767 };
gtk_window_set_geometry_hints(stored_window, NULL, &geom, GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE);
/* Disable WebView input to prevent it from stealing the WM's pointer grab.
* The WebView's GdkWindow won't interfere with events during the resize. */
if (stored_webview) {
gtk_widget_set_sensitive(stored_webview, FALSE);
resize_active = TRUE;
fprintf(stderr, "[agor-resize] WebView DISABLED for resize\n");
}
gtk_window_begin_resize_drag(
stored_window,
edge,
@ -142,13 +152,37 @@ static gboolean on_webview_motion(GtkWidget *widget,
return FALSE; /* Always let WebKit see motion events too */
}
static guint reenable_timer_id = 0;
/**
* Configure-event handler logs every window size change.
* Timer callback: re-enable WebView after resize drag ends.
* Runs 500ms after the last configure event.
*/
static gboolean reenable_webview(gpointer data)
{
if (stored_webview && resize_active) {
gtk_widget_set_sensitive(stored_webview, TRUE);
resize_active = FALSE;
fprintf(stderr, "[agor-resize] WebView RE-ENABLED (resize ended)\n");
}
reenable_timer_id = 0;
return G_SOURCE_REMOVE;
}
/**
* Configure-event handler logs window size changes.
* Resets the re-enable timer on each configure (resize still in progress).
*/
static gboolean on_configure(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
{
fprintf(stderr, "[agor-resize] CONFIGURE size=%dx%d pos=%d,%d\n",
event->width, event->height, event->x, event->y);
/* If resize is active, reset the re-enable timer */
if (resize_active) {
if (reenable_timer_id) g_source_remove(reenable_timer_id);
reenable_timer_id = g_timeout_add(500, reenable_webview, NULL);
}
return FALSE;
}
@ -174,6 +208,7 @@ void agor_resize_init(void *window_ptr, int border)
webview = child;
}
stored_webview = webview;
if (webview == GTK_WIDGET(stored_window)) {
fprintf(stderr, "[agor-resize] WARNING: no child widget found, connecting on window\n");
} else {

Binary file not shown.