ui/gtk/draw_cairo.c

changeset 431
bb7da585debc
parent 300
2f924f7ca901
--- a/ui/gtk/draw_cairo.c	Sun May 23 09:44:43 2021 +0200
+++ b/ui/gtk/draw_cairo.c	Sat Jan 04 16:38:48 2025 +0100
@@ -33,12 +33,19 @@
 
 #include "draw_cairo.h"
 
-#ifdef UI_GTK3
-gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) {
+
+#if GTK_MAJOR_VERSION >= 3
+static void ui_drawingarea_draw(
+        GtkDrawingArea *area,
+        cairo_t *cr,
+        int width,
+        int height,
+        gpointer data)
+{
     UiCairoGraphics g;
-    g.g.width = gtk_widget_get_allocated_width(w);
-    g.g.height = gtk_widget_get_allocated_height(w);
-    g.widget = w;
+    g.g.width = width;
+    g.g.height = height;
+    g.widget = GTK_WIDGET(area);
     g.cr = cr;
     
     UiDrawEvent *event = data;
@@ -48,10 +55,18 @@
     ev.document = event->obj->ctx->document;
     
     event->callback(&ev, &g.g, event->userdata);
-    
+}
+#endif
+
+#if UI_GTK3
+gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) {
+    int width = gtk_widget_get_allocated_width(w);
+    int height = gtk_widget_get_allocated_height(w);
+    ui_drawingarea_draw(GTK_DRAWING_AREA(w), cr, width, height, data);
     return FALSE;
 }
-#else
+#endif
+#ifdef UI_GTK2
 gboolean ui_canvas_expose(GtkWidget *w, GdkEventExpose *e, void *data) {
     UiCairoGraphics g;
     g.g.width = w->allocation.width;
@@ -74,7 +89,9 @@
 // function from graphics.h
 
 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) {
-#ifdef UI_GTK3
+#if GTK_MAJOR_VERSION >= 4
+    gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), ui_drawingarea_draw, event, NULL);
+#elif GTK_MAJOR_VERSION == 3
     g_signal_connect(G_OBJECT(widget),
             "draw",
             G_CALLBACK(ui_drawingarea_expose),

mercurial