Skip to content

Commit

Permalink
Drop deprecated gdk_cairo_create
Browse files Browse the repository at this point in the history
This fixes the regression of the test case `blink`.
  • Loading branch information
markuspg committed Mar 23, 2024
1 parent 0af285d commit 202efa5
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 56 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Version 2.2 (Work in Progress)

* Switch build system from Autotools to Meson
* Upgrade from GTK+ 2 to 3

Version 2.1

Expand Down
2 changes: 1 addition & 1 deletion callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ G_MODULE_EXPORT gboolean on_mainwin_draw_event(
gdk_window_set_background_rgba(gtk_widget_get_window(widget), bg_color);

if (current_test && current_test->draw)
current_test->draw(widget);
current_test->draw(widget, cr);
return TRUE;
}

Expand Down
2 changes: 1 addition & 1 deletion callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

struct test_ops {
void (*init)(GtkWidget *widget);
void (*draw)(GtkWidget *widget);
void (*draw)(GtkWidget *widget, cairo_t *cr);
void (*cycle)(GtkWidget *widget);
void (*close)(GtkWidget *widget);
};
Expand Down
7 changes: 1 addition & 6 deletions test_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ static void draw_boxes(cairo_t *cr, GdkRGBA *colors, gint ncols, gint x, gint y,
set_color_fg(cr);
}

static void basic_draw(GtkWidget *widget) {
cairo_t *cr;
static void basic_draw(GtkWidget *widget, cairo_t *cr) {
PangoLayout *pl;
GdkWindow *win = gtk_widget_get_window(widget);
gint w, h;
Expand All @@ -70,7 +69,6 @@ static void basic_draw(GtkWidget *widget) {
h = gdk_window_get_height(win);
w = gdk_window_get_width(win);

cr = gdk_cairo_create(gtk_widget_get_window(widget));
cairo_set_line_width(cr, 1.0);

pl = pango_cairo_create_layout(cr);
Expand Down Expand Up @@ -162,9 +160,6 @@ static void basic_draw(GtkWidget *widget) {
cairo_new_sub_path(cr);
cairo_arc(cr, w / 2, h / 2, d, 0, 2 * G_PI);
cairo_stroke(cr);

cairo_destroy(cr);
cr = NULL;
}

G_MODULE_EXPORT struct test_ops basic_ops = {
Expand Down
8 changes: 1 addition & 7 deletions test_blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ static gint blink_step;
void (*set_color1)(cairo_t *cr);
void (*set_color2)(cairo_t *cr);

static void blink_draw(GtkWidget *widget) {
cairo_t *cr;
static void blink_draw(GtkWidget *widget, cairo_t *cr) {
GdkWindow *win = gtk_widget_get_window(widget);
gint w, h;

Expand All @@ -48,8 +47,6 @@ static void blink_draw(GtkWidget *widget) {
set_color2 = set_color_bg;
}

cr = gdk_cairo_create(gtk_widget_get_window(widget));

set_color_fg(cr);
cairo_paint(cr);

Expand Down Expand Up @@ -78,9 +75,6 @@ static void blink_draw(GtkWidget *widget) {
cairo_rectangle(cr, 5, 2 * h / 3, w - 10, h / 3 - 5);
cairo_fill(cr);
}

cairo_destroy(cr);
cr = NULL;
}

static gboolean blink_timeout(gpointer data) {
Expand Down
8 changes: 1 addition & 7 deletions test_bright_pixels.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,12 @@ static void bright_pixels_cycle(G_GNUC_UNUSED GtkWidget *widget) {
current_color_idx = 0;
}

static void bright_pixels_draw(GtkWidget *widget) {
static void bright_pixels_draw(GtkWidget *widget, cairo_t *cr) {
GdkRGBA *col;
cairo_t *cr;

cr = gdk_cairo_create(gtk_widget_get_window(widget));

col = &fgcolors[color_cycle[current_color_idx]];
cairo_set_source_rgb(cr, col->red, col->green, col->blue);
cairo_paint(cr);

cairo_destroy(cr);
cr = NULL;
}

G_MODULE_EXPORT struct test_ops bright_pixels_ops = {.init = bright_pixels_init,
Expand Down
8 changes: 1 addition & 7 deletions test_grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ static void grid_cycle(G_GNUC_UNUSED GtkWidget *widget) {
grid_step = GRID_STEP;
}

static void grid_draw(GtkWidget *widget) {
cairo_t *cr;
static void grid_draw(GtkWidget *widget, cairo_t *cr) {
GdkWindow *win = gtk_widget_get_window(widget);
gint w, h;
gint i;

h = gdk_window_get_height(win);
w = gdk_window_get_width(win);

cr = gdk_cairo_create(gtk_widget_get_window(widget));

set_color_bg(cr);
cairo_paint(cr);

Expand All @@ -61,9 +58,6 @@ static void grid_draw(GtkWidget *widget) {
cairo_rectangle(cr, 0, i, w, 1);
}
cairo_fill(cr);

cairo_destroy(cr);
cr = NULL;
}

G_MODULE_EXPORT struct test_ops grid_ops = {
Expand Down
8 changes: 1 addition & 7 deletions test_horizontal.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ static void horizontal_cycle(G_GNUC_UNUSED GtkWidget *widget) {
horizontal_step = GRID_STEP;
}

static void horizontal_draw(GtkWidget *widget) {
cairo_t *cr;
static void horizontal_draw(GtkWidget *widget, cairo_t *cr) {
GdkWindow *win = gtk_widget_get_window(widget);
gint w, h;
gint i;

h = gdk_window_get_height(win);
w = gdk_window_get_width(win);

cr = gdk_cairo_create(gtk_widget_get_window(widget));

set_color_bg(cr);
cairo_paint(cr);

Expand All @@ -58,9 +55,6 @@ static void horizontal_draw(GtkWidget *widget) {
cairo_rectangle(cr, 0, i, w, 1);
}
cairo_fill(cr);

cairo_destroy(cr);
cr = NULL;
}

G_MODULE_EXPORT struct test_ops horizontal_ops = {.init = horizontal_init,
Expand Down
8 changes: 1 addition & 7 deletions test_lcdalign.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

#include "callbacks.h"

static void lcdalign_draw(GtkWidget *widget) {
cairo_t *cr;
static void lcdalign_draw(GtkWidget *widget, cairo_t *cr) {
GdkWindow *win = gtk_widget_get_window(widget);
gint w, h;
gint i;
Expand All @@ -33,8 +32,6 @@ static void lcdalign_draw(GtkWidget *widget) {
h = gdk_window_get_height(win);
w = gdk_window_get_width(win);

cr = gdk_cairo_create(gtk_widget_get_window(widget));

/* Background/Border */
set_color_fg(cr);
cairo_paint(cr);
Expand All @@ -54,9 +51,6 @@ static void lcdalign_draw(GtkWidget *widget) {
cairo_line_to(cr, w - 1, i + 0.5);
}
cairo_stroke(cr);

cairo_destroy(cr);
cr = NULL;
}

G_MODULE_EXPORT struct test_ops lcdalign_ops = {
Expand Down
7 changes: 1 addition & 6 deletions test_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ static gchar text[] =

static void text_init(GtkWidget *widget) { font_size_num = 1; }

static void text_draw(GtkWidget *widget) {
cairo_t *cr;
static void text_draw(GtkWidget *widget, cairo_t *cr) {
PangoFontDescription *pft;
PangoLayout *pl;
GdkWindow *win = gtk_widget_get_window(widget);
Expand All @@ -48,7 +47,6 @@ static void text_draw(GtkWidget *widget) {
h = gdk_window_get_height(win);
w = gdk_window_get_width(win);

cr = gdk_cairo_create(gtk_widget_get_window(widget));
cairo_set_line_width(cr, 1.0);

pft = pango_font_description_new();
Expand Down Expand Up @@ -79,9 +77,6 @@ static void text_draw(GtkWidget *widget) {
pango_layout_set_text(pl, dtext->str, -1);
pango_cairo_show_layout(cr, pl);

cairo_destroy(cr);
cr = NULL;

pango_font_description_free(pft);
pft = NULL;
}
Expand Down
8 changes: 1 addition & 7 deletions test_vertical.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ static void vertical_cycle(G_GNUC_UNUSED GtkWidget *widget) {
vertical_step = GRID_STEP;
}

static void vertical_draw(GtkWidget *widget) {
cairo_t *cr;
static void vertical_draw(GtkWidget *widget, cairo_t *cr) {
GdkWindow *win = gtk_widget_get_window(widget);
gint w, h;
gint i;

h = gdk_window_get_height(win);
w = gdk_window_get_width(win);

cr = gdk_cairo_create(gtk_widget_get_window(widget));

set_color_bg(cr);
cairo_paint(cr);

Expand All @@ -58,9 +55,6 @@ static void vertical_draw(GtkWidget *widget) {
cairo_rectangle(cr, i, 0, 1, h);
}
cairo_fill(cr);

cairo_destroy(cr);
cr = NULL;
}

G_MODULE_EXPORT struct test_ops vertical_ops = {.init = vertical_init,
Expand Down

0 comments on commit 202efa5

Please sign in to comment.