From b845b0829f3512d78ee0e41df8ce637c8b9a236c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 10 May 2021 17:24:16 +0300 Subject: [PATCH 49/49] gtk3x: Get rid of remaining gtk_widget_get_surface() calls See osdn #42215 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/cityrep.c | 2 +- client/gui-gtk-4.0/gtkcompat.h | 5 +++++ client/gui-gtk-4.0/mapctrl.c | 7 ++++--- client/gui-gtk-4.0/mapview.c | 17 ++++++++++++----- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/client/gui-gtk-4.0/cityrep.c b/client/gui-gtk-4.0/cityrep.c index 91ecbafb7f..d84174979e 100644 --- a/client/gui-gtk-4.0/cityrep.c +++ b/client/gui-gtk-4.0/cityrep.c @@ -1431,7 +1431,7 @@ static void city_activated_callback(GtkTreeView *view, GtkTreePath *path, return; } - win = gtk_widget_get_surface(GTK_WIDGET(view)); + win = gtk_native_get_surface(gtk_widget_get_native(GTK_WIDGET(view))); seat = gdk_display_get_default_seat(gdk_surface_get_display(win)); gdk_surface_get_device_position(win, gdk_seat_get_pointer(seat), diff --git a/client/gui-gtk-4.0/gtkcompat.h b/client/gui-gtk-4.0/gtkcompat.h index 9411b2db21..cfab3f996f 100644 --- a/client/gui-gtk-4.0/gtkcompat.h +++ b/client/gui-gtk-4.0/gtkcompat.h @@ -31,6 +31,11 @@ GdkModifierType gdk_event_get_modifier_state(GdkEvent *ev); guint gdk_button_event_get_button(GdkEvent *ev); #define gdk_event_get_position(_ev_, _x_, _y_) gdk_event_get_coords(_ev_, _x_, _y_) +/* Wrap GtkNative away */ +#define GtkNative GtkWidget +#define gtk_widget_get_native(_wdg_) (_wdg_) +#define gtk_native_get_surface(_nat_) gtk_widget_get_surface(_nat_) + #endif /* GTK version < 3.98 */ #endif /* FC__GTKCOMPAT_H */ diff --git a/client/gui-gtk-4.0/mapctrl.c b/client/gui-gtk-4.0/mapctrl.c index 80b0b44736..f9d9173548 100644 --- a/client/gui-gtk-4.0/mapctrl.c +++ b/client/gui-gtk-4.0/mapctrl.c @@ -311,9 +311,9 @@ void create_line_at_mouse_pos(void) window = gdk_device_get_surface_at_position(pointer, &x, &y); if (window) { - if (window == gtk_widget_get_surface(map_canvas)) { + if (window == gtk_native_get_surface(gtk_widget_get_native(map_canvas))) { update_line(x, y); - } else if (window == gtk_widget_get_surface(overview_canvas)) { + } else if (window == gtk_native_get_surface(gtk_widget_get_native(overview_canvas))) { overview_update_line(x, y); } } @@ -337,7 +337,8 @@ void update_rect_at_mouse_pos(void) } window = gdk_device_get_surface_at_position(pointer, &x, &y); - if (window && window == gtk_widget_get_surface(map_canvas)) { + if (window + && window == gtk_native_get_surface(gtk_widget_get_native(map_canvas))) { gdk_device_get_state(pointer, window, NULL, &mask); if (mask & GDK_BUTTON3_MASK) { update_selection_rectangle(x, y); diff --git a/client/gui-gtk-4.0/mapview.c b/client/gui-gtk-4.0/mapview.c index 9de2432019..7c2f4d4140 100644 --- a/client/gui-gtk-4.0/mapview.c +++ b/client/gui-gtk-4.0/mapview.c @@ -324,9 +324,10 @@ struct canvas *get_overview_window(void) { #if 0 static struct canvas store; + GtkNative *nat = gtk_widget_get_native(overview_canvas); store.surface = NULL; - store.drawable = gdk_cairo_create(gtk_widget_get_surface(overview_canvas)); + store.drawable = gdk_cairo_create(gtk_native_get_surface(nat)); return &store; #endif /* 0 */ @@ -420,7 +421,9 @@ void dirty_rect(int canvas_x, int canvas_y, // GdkRectangle rectangle = {canvas_x, canvas_y, pixel_width, pixel_height}; if (gtk_widget_get_realized(map_canvas)) { - // gdk_surface_invalidate_rect(gtk_widget_get_surface(map_canvas), &rectangle); + // GtkNative *nat = gtk_widget_get_native(map_canvas); + + // gdk_surface_invalidate_rect(gtk_native_get_surface(nat), &rectangle); } } @@ -430,7 +433,9 @@ void dirty_rect(int canvas_x, int canvas_y, void dirty_all(void) { if (gtk_widget_get_realized(map_canvas)) { - // gdk_surface_invalidate_rect(gtk_widget_get_surface(map_canvas), NULL); + // GtkNative *nat = gtk_widget_get_native(map_canvas); + + // gdk_surface_invalidate_rect(gtk_native_get_surface(nat), NULL); } } @@ -618,7 +623,9 @@ void put_cross_overlay_tile(struct tile *ptile) float canvas_x, canvas_y; if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) { - pixmap_put_overlay_tile(gtk_widget_get_surface(map_canvas), map_zoom, + GtkNative *nat = gtk_widget_get_native(map_canvas); + + pixmap_put_overlay_tile(gtk_native_get_surface(nat), map_zoom, canvas_x / map_zoom, canvas_y / map_zoom, get_attention_crosshair_sprite(tileset)); } @@ -737,7 +744,7 @@ void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h) return; } - wndw = gtk_widget_get_surface(map_canvas); + wndw = gtk_native_get_surface(gtk_widget_get_native(map_canvas)); ctx = gdk_window_begin_draw_frame(wndw, NULL, gdk_window_get_clip_region(wndw)); cr = gdk_drawing_context_get_cairo_context(ctx); -- 2.30.2