From c6e1af995e3b2af2044faf1b815dc5323af7c691 Mon Sep 17 00:00:00 2001 From: Manuel Stoeckl Date: Sun, 10 Oct 2021 21:29:15 -0400 Subject: demos: port to Gtk3 GTK2 has reached end of life, and GTK3 has been available for a almost a decade. Signed-off-by: Manuel Stoeckl Reviewed-by: Simon Ser --- configure.ac | 4 ++-- demos/dither.c | 36 +++++++++++++++++------------------- demos/gtk-utils.c | 10 +++------- demos/scale.c | 28 +++++++++++++--------------- meson.build | 2 +- 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/configure.ac b/configure.ac index 9db0131..4b12898 100644 --- a/configure.ac +++ b/configure.ac @@ -892,7 +892,7 @@ PKG_PROG_PKG_CONFIG if test $enable_gtk = yes ; then AC_CHECK_LIB([pixman-1], [pixman_version_string]) - PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.16 pixman-1]) + PKG_CHECK_MODULES(GTK, [gtk+-3.0 pixman-1]) fi if test $enable_gtk = auto ; then @@ -900,7 +900,7 @@ if test $enable_gtk = auto ; then fi if test $enable_gtk = auto ; then - PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.16 pixman-1], [enable_gtk=yes], [enable_gtk=no]) + PKG_CHECK_MODULES(GTK, [gtk+-3.0 pixman-1], [enable_gtk=yes], [enable_gtk=no]) fi AM_CONDITIONAL(HAVE_GTK, [test "x$enable_gtk" = xyes]) diff --git a/demos/dither.c b/demos/dither.c index d72c250..2ab8270 100644 --- a/demos/dither.c +++ b/demos/dither.c @@ -103,48 +103,46 @@ rescale (GtkWidget *may_be_null, app_t *app) } static gboolean -on_expose (GtkWidget *da, GdkEvent *event, gpointer data) +on_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) { - app_t *app = data; - GdkRectangle *area = &event->expose.area; + app_t *app = user_data; + GdkRectangle area; cairo_surface_t *surface; pixman_image_t *tmp, *final; - cairo_t *cr; uint32_t *pixels; + gdk_cairo_get_clip_rectangle(cr, &area); + tmp = pixman_image_create_bits ( - app->format, area->width, area->height, NULL, 0); + app->format, area.width, area.height, NULL, 0); pixman_image_set_dither (tmp, app->dither); pixman_image_composite ( PIXMAN_OP_SRC, app->original, NULL, tmp, - area->x, area->y, 0, 0, 0, 0, - app->width - area->x, - app->height - area->y); + area.x, area.y, 0, 0, 0, 0, + app->width - area.x, + app->height - area.y); - pixels = calloc (1, area->width * area->height * 4); + pixels = calloc (1, area.width * area.height * 4); final = pixman_image_create_bits ( - PIXMAN_a8r8g8b8, area->width, area->height, pixels, area->width * 4); + PIXMAN_a8r8g8b8, area.width, area.height, pixels, area.width * 4); pixman_image_composite ( PIXMAN_OP_SRC, tmp, NULL, final, - area->x, area->y, 0, 0, 0, 0, - app->width - area->x, - app->height - area->y); + area.x, area.y, 0, 0, 0, 0, + app->width - area.x, + app->height - area.y); surface = cairo_image_surface_create_for_data ( (uint8_t *)pixels, CAIRO_FORMAT_ARGB32, - area->width, area->height, area->width * 4); - - cr = gdk_cairo_create (da->window); + area.width, area.height, area.width * 4); - cairo_set_source_surface (cr, surface, area->x, area->y); + cairo_set_source_surface (cr, surface, area.x, area.y); cairo_paint (cr); - cairo_destroy (cr); cairo_surface_destroy (surface); free (pixels); pixman_image_unref (final); @@ -211,7 +209,7 @@ app_new (pixman_image_t *original) g_error ("Could not read file dither.ui: %s", err->message); widget = get_widget (app, "drawing_area"); - g_signal_connect (widget, "expose_event", G_CALLBACK (on_expose), app); + g_signal_connect (widget, "draw", G_CALLBACK (on_draw), app); set_up_combo_box (app, "target_format_combo_box", G_N_ELEMENTS (formats), formats); diff --git a/demos/gtk-utils.c b/demos/gtk-utils.c index 32d4aec..b3a60ff 100644 --- a/demos/gtk-utils.c +++ b/demos/gtk-utils.c @@ -93,15 +93,14 @@ pixbuf_from_argb32 (uint32_t *bits, } static gboolean -on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data) +on_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) { - pixman_image_t *pimage = data; + pixman_image_t *pimage = user_data; int width = pixman_image_get_width (pimage); int height = pixman_image_get_height (pimage); int stride = pixman_image_get_stride (pimage); cairo_surface_t *cimage; cairo_format_t format; - cairo_t *cr; if (pixman_image_get_format (pimage) == PIXMAN_x8r8g8b8) format = CAIRO_FORMAT_RGB24; @@ -111,14 +110,11 @@ on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data) cimage = cairo_image_surface_create_for_data ( (uint8_t *)pixman_image_get_data (pimage), format, width, height, stride); - - cr = gdk_cairo_create (widget->window); cairo_rectangle (cr, 0, 0, width, height); cairo_set_source_surface (cr, cimage, 0, 0); cairo_fill (cr); - cairo_destroy (cr); cairo_surface_destroy (cimage); return TRUE; @@ -170,7 +166,7 @@ show_image (pixman_image_t *image) break; } - g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), copy); + g_signal_connect (window, "draw", G_CALLBACK (on_draw), copy); g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show (window); diff --git a/demos/scale.c b/demos/scale.c index 0995ad0..7459a5c 100644 --- a/demos/scale.c +++ b/demos/scale.c @@ -278,39 +278,37 @@ rescale (GtkWidget *may_be_null, app_t *app) } static gboolean -on_expose (GtkWidget *da, GdkEvent *event, gpointer data) +on_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) { - app_t *app = data; - GdkRectangle *area = &event->expose.area; + app_t *app = user_data; + GdkRectangle area; cairo_surface_t *surface; pixman_image_t *tmp; - cairo_t *cr; uint32_t *pixels; - pixels = calloc (1, area->width * area->height * 4); + gdk_cairo_get_clip_rectangle(cr, &area); + + pixels = calloc (1, area.width * area.height * 4); tmp = pixman_image_create_bits ( - PIXMAN_a8r8g8b8, area->width, area->height, pixels, area->width * 4); + PIXMAN_a8r8g8b8, area.width, area.height, pixels, area.width * 4); - if (area->x < app->scaled_width && area->y < app->scaled_height) + if (area.x < app->scaled_width && area.y < app->scaled_height) { pixman_image_composite ( PIXMAN_OP_SRC, app->original, NULL, tmp, - area->x, area->y, 0, 0, 0, 0, - app->scaled_width - area->x, app->scaled_height - area->y); + area.x, area.y, 0, 0, 0, 0, + app->scaled_width - area.x, app->scaled_height - area.y); } surface = cairo_image_surface_create_for_data ( (uint8_t *)pixels, CAIRO_FORMAT_ARGB32, - area->width, area->height, area->width * 4); - - cr = gdk_cairo_create (da->window); + area.width, area.height, area.width * 4); - cairo_set_source_surface (cr, surface, area->x, area->y); + cairo_set_source_surface (cr, surface, area.x, area.y); cairo_paint (cr); - cairo_destroy (cr); cairo_surface_destroy (surface); free (pixels); pixman_image_unref (tmp); @@ -400,7 +398,7 @@ app_new (pixman_image_t *original) gtk_scale_add_mark (GTK_SCALE (widget), 0.0, GTK_POS_LEFT, NULL); widget = get_widget (app, "drawing_area"); - g_signal_connect (widget, "expose_event", G_CALLBACK (on_expose), app); + g_signal_connect (widget, "draw", G_CALLBACK (on_draw), app); set_up_filter_box (app, "reconstruct_x_combo_box"); set_up_filter_box (app, "reconstruct_y_combo_box"); diff --git a/meson.build b/meson.build index 831f9eb..6ab6a97 100644 --- a/meson.build +++ b/meson.build @@ -412,7 +412,7 @@ else dep_openmp = null_dep endif -dep_gtk = dependency('gtk+-2.0', version : '>= 2.16', required : get_option('gtk')) +dep_gtk = dependency('gtk+-3.0', required : get_option('gtk')) dep_glib = dependency('glib-2.0', required : get_option('gtk')) dep_png = null_dep -- cgit v1.2.1