Add allocation width/height macro for Gtk+-3 support
authorHugo Villeneuve <hugo@hugovil.com>
Sun, 21 Dec 2014 19:29:52 +0000 (14:29 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Sun, 24 Apr 2016 22:31:09 +0000 (18:31 -0400)
Directly accessing allocation structure is no more allowed in Gtk+-3.

src/clock.c

index cdce025..5615d56 100644 (file)
 /* 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);