From 14b04451bfd27147f068285e44f4946e8d5733c1 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Sun, 21 Dec 2014 14:29:52 -0500 Subject: [PATCH] Add allocation width/height macro for Gtk+-3 support Directly accessing allocation structure is no more allowed in Gtk+-3. --- src/clock.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/clock.c b/src/clock.c index cdce025..5615d56 100644 --- a/src/clock.c +++ b/src/clock.c @@ -82,11 +82,15 @@ /* Starting mode is clock mode */ static int hvclock_mode = CLOCK_MODE; +/* In preparation for Gtk+-3 support. */ +#define gtk_widget_get_allocated_width(_widget_) _widget_->allocation.width +#define gtk_widget_get_allocated_height(_widget_) _widget_->allocation.height + static double get_clock_face_radius(GtkWidget *clock) { /* Compute clock face radius */ - return (MIN(clock->allocation.width, clock->allocation.height) / 2) - 3; + return (MIN(gtk_widget_get_allocated_width(clock), gtk_widget_get_allocated_height(clock)) / 2) - 3; } static struct tm * @@ -109,8 +113,8 @@ draw_clock_background(GtkWidget *clock, cairo_t *cr) double radius, radius_numbers, radius_dots; int digit; - center_x = clock->allocation.width / 2; - center_y = clock->allocation.height / 2; + center_x = gtk_widget_get_allocated_width(clock) / 2; + center_y = gtk_widget_get_allocated_height(clock) / 2; radius = get_clock_face_radius(clock); @@ -221,8 +225,8 @@ draw_clock_hand_common(GtkWidget *clock, cairo_t *cr, double angle, radius = get_clock_face_radius(clock); - center_x = clock->allocation.width / 2; - center_y = clock->allocation.height / 2; + center_x = gtk_widget_get_allocated_width(clock) / 2; + center_y = gtk_widget_get_allocated_height(clock) / 2; sin_x = sin(angle); cos_y = cos(angle); @@ -254,8 +258,8 @@ draw_clock_hands(GtkWidget *clock, cairo_t *cr) ts = clock_get_time(); - center_x = clock->allocation.width / 2; - center_y = clock->allocation.height / 2; + center_x = gtk_widget_get_allocated_width(clock) / 2; + center_y = gtk_widget_get_allocated_height(clock) / 2; radius = get_clock_face_radius(clock); @@ -325,8 +329,8 @@ calendar_display_test(GtkWidget *clock, struct tm *ts, cairo_t *cr, char str[32]; diameter = 2 * get_clock_face_radius(clock); - center_x = (clock->allocation.width / 2) - 2; - start_y = (clock->allocation.height / 2) - (diameter / 2); + center_x = (gtk_widget_get_allocated_width(clock) / 2) - 2; + start_y = (gtk_widget_get_allocated_height(clock) / 2) - (diameter / 2); cairo_set_font_size(cr, diameter * font_ratio); -- 2.20.1