summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Expósito <jose.exposito89@gmail.com>2021-07-29 18:07:32 +0200
committerJosé Expósito <jose.exposito89@gmail.com>2021-08-03 16:52:39 +0000
commit895e866da642f381e4cbfbea9703ab1843561f8e (patch)
tree02800965e2be06b759eb8417243ab3cb9e34cfc2
parent55889adeff3fe5dd666709bdbc006e1905b4dd3c (diff)
downloadlibinput-895e866da642f381e4cbfbea9703ab1843561f8e.tar.gz
debug-gui: migrate to GTK4
Global: - Stop passing commandline arguments to gtk_init: https://docs.gtk.org/gtk4/migrating-3to4.html#stop-passing-commandline-arguments-to-gtk_init window_init function: - gtk_window_new doesn't require a type anymore - gtk_window_iconify has been renamed to gtk_window_minimize - gtk_container_add has been removed in favor of container specific APIs. Use gtk_window_set_child in this case. - gtk_widget_show_all has been removed, widgets are now visible by default: https://docs.gtk.org/gtk4/migrating-3to4.html#widgets-are-now-visible-by-default - gtk_widget_set_events to NULL is no longer required, widgets must set their event handlers explicitly now: https://blog.gtk.org/2020/04/29/custom-widgets-in-gtk-4-input/ window_delete_event_cb function: - Use the new close-request event: https://docs.gtk.org/gtk4/migrating-3to4.html#stop-using-gtkwidget-event-signals map_event_cb function: - gtk_widget_set_cursor_from_name instead of gdk_window_set_cursor - Wait until the draw area is resized to use the whole window to start calculating sizes window_place_ui_elements function: - Use gtk_widget_get_width and gtk_widget_get_height instead of gtk_window_get_size Drawing: - Use gtk_drawing_area_set_draw_func instead of the GtkWidget::draw signal: https://docs.gtk.org/gtk4/migrating-3to4.html#adapt-to-drawing-model-changes Signed-off-by: José Expósito <jose.exposito89@gmail.com>
-rw-r--r--meson.build8
-rw-r--r--tools/libinput-debug-gui.c83
2 files changed, 86 insertions, 5 deletions
diff --git a/meson.build b/meson.build
index e78fafd1..9db3283f 100644
--- a/meson.build
+++ b/meson.build
@@ -550,7 +550,13 @@ executable('libinput-record',
)
if get_option('debug-gui')
- dep_gtk = dependency('gtk+-3.0', version : '>= 3.20')
+ dep_gtk = dependency('gtk4', version : '>= 4.0', required : false)
+ config_h.set10('HAVE_GTK4', dep_gtk.found())
+ if not dep_gtk.found()
+ dep_gtk = dependency('gtk+-3.0', version : '>= 3.20')
+ config_h.set10('HAVE_GTK3', dep_gtk.found())
+ endif
+
dep_cairo = dependency('cairo')
dep_glib = dependency('glib-2.0')
diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c
index 5bcf8a36..22afa6a8 100644
--- a/tools/libinput-debug-gui.c
+++ b/tools/libinput-debug-gui.c
@@ -792,10 +792,27 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data)
return TRUE;
}
+#if HAVE_GTK4
+static void
+draw_gtk4(GtkDrawingArea *widget,
+ cairo_t *cr,
+ int width,
+ int height,
+ gpointer data)
+{
+ draw(GTK_WIDGET(widget), cr, data);
+}
+#endif
+
static void
window_place_ui_elements(GtkWidget *widget, struct window *w)
{
+#if HAVE_GTK4
+ w->width = gtk_widget_get_width(w->area);
+ w->height = gtk_widget_get_height(w->area);
+#else
gtk_window_get_size(GTK_WINDOW(widget), &w->width, &w->height);
+#endif
w->pointer.x = w->width/2;
w->pointer.y = w->height/2;
@@ -821,6 +838,22 @@ window_place_ui_elements(GtkWidget *widget, struct window *w)
w->pinch.y = w->height/2;
}
+#if HAVE_GTK4
+static void
+map_event_cb(GtkDrawingArea *widget, int width, int height, gpointer data)
+{
+ struct window *w = data;
+
+ window_place_ui_elements(GTK_WIDGET(widget), w);
+
+ gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(w->area),
+ draw_gtk4,
+ w,
+ NULL);
+
+ gtk_widget_set_cursor_from_name(w->win, "none");
+}
+#else
static void
map_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
@@ -851,6 +884,7 @@ map_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
NULL /* prepare_func_data */
);
}
+#endif
static void
window_quit(struct window *w)
@@ -858,6 +892,17 @@ window_quit(struct window *w)
g_main_loop_quit(w->event_loop);
}
+#if HAVE_GTK4
+static gboolean
+window_delete_event_cb(GtkWindow *window, gpointer data)
+{
+ struct window *w = data;
+
+ window_quit(w);
+
+ return TRUE;
+}
+#else
static void
window_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
@@ -865,28 +910,51 @@ window_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
window_quit(w);
}
+#endif
static void
window_init(struct window *w)
{
list_init(&w->evdev_devices);
+#if HAVE_GTK4
+ w->win = gtk_window_new();
+#else
w->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- if (getenv("LIBINPUT_RUNNING_TEST_SUITE"))
+#endif
+
+ if (getenv("LIBINPUT_RUNNING_TEST_SUITE")) {
+#if HAVE_GTK4
+ gtk_window_minimize(GTK_WINDOW(w->win));
+#else
gtk_window_iconify(GTK_WINDOW(w->win));
- gtk_widget_set_events(w->win, 0);
+#endif
+ }
+
gtk_window_set_title(GTK_WINDOW(w->win), "libinput debugging tool");
gtk_window_set_default_size(GTK_WINDOW(w->win), 1024, 768);
gtk_window_maximize(GTK_WINDOW(w->win));
gtk_window_set_resizable(GTK_WINDOW(w->win), TRUE);
gtk_widget_realize(w->win);
+
+ w->area = gtk_drawing_area_new();
+
+#if HAVE_GTK4
+ g_signal_connect(G_OBJECT(w->area), "resize", G_CALLBACK(map_event_cb), w);
+ g_signal_connect(G_OBJECT(w->win), "close-request", G_CALLBACK(window_delete_event_cb), w);
+
+ gtk_window_set_child(GTK_WINDOW(w->win), w->area);
+ gtk_widget_show(w->win);
+#else
g_signal_connect(G_OBJECT(w->win), "map-event", G_CALLBACK(map_event_cb), w);
g_signal_connect(G_OBJECT(w->win), "delete-event", G_CALLBACK(window_delete_event_cb), w);
- w->area = gtk_drawing_area_new();
+ gtk_widget_set_events(w->win, 0);
gtk_widget_set_events(w->area, 0);
+
gtk_container_add(GTK_CONTAINER(w->win), w->area);
gtk_widget_show_all(w->win);
+#endif
w->pad.ring.position = -1;
w->pad.strip.position = -1;
@@ -1618,8 +1686,15 @@ main(int argc, char **argv)
enum tools_backend backend = BACKEND_NONE;
const char *seat_or_device[2] = {"seat0", NULL};
bool verbose = false;
+ bool gtk_init = false;
+
+#if HAVE_GTK4
+ gtk_init = gtk_init_check();
+#else
+ gtk_init = gtk_init_check(&argc, &argv);
+#endif
- if (!gtk_init_check(&argc, &argv))
+ if (!gtk_init)
return 77;
tools_init_options(&options);