[Xfce4-commits] <xfce4-panel:nick/gtk3> Clock plugin: ported to Gtk3

Andrzej noreply at xfce.org
Wed Apr 10 00:36:01 CEST 2013


Updating branch refs/heads/nick/gtk3
         to 23ea8921e879d9a48e217fabea5d25566ac96db3 (commit)
       from 132029185b6c70bebbee84d905ce4e635594d1f4 (commit)

commit 23ea8921e879d9a48e217fabea5d25566ac96db3
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Tue Apr 9 23:35:05 2013 +0100

    Clock plugin: ported to Gtk3
    
    Not tested. Potential problems with gdk_device_grab.
    Code for selecting light and dark background colors in clock-binary.c
    copied from panel-base-window.c.

 plugins/clock/clock-analog.c |   87 ++++++-------
 plugins/clock/clock-binary.c |  287 +++++++++++++++++++++++-----------------
 plugins/clock/clock-lcd.c    |  160 +++++++++++------------
 plugins/clock/clock-time.c   |    5 +-
 plugins/clock/clock.c        |  303 ++++++------------------------------------
 5 files changed, 323 insertions(+), 519 deletions(-)

diff --git a/plugins/clock/clock-analog.c b/plugins/clock/clock-analog.c
index 2e96a09..8ed2304 100644
--- a/plugins/clock/clock-analog.c
+++ b/plugins/clock/clock-analog.c
@@ -46,8 +46,8 @@ static void      xfce_clock_analog_get_property  (GObject              *object,
                                                   GValue               *value,
                                                   GParamSpec           *pspec);
 static void      xfce_clock_analog_finalize      (GObject              *object);
-static gboolean  xfce_clock_analog_expose_event  (GtkWidget            *widget,
-                                                  GdkEventExpose       *event);
+static gboolean  xfce_clock_analog_draw          (GtkWidget            *widget,
+                                                  cairo_t              *cr);
 static void      xfce_clock_analog_draw_ticks    (cairo_t              *cr,
                                                   gdouble               xc,
                                                   gdouble               yc,
@@ -106,7 +106,7 @@ xfce_clock_analog_class_init (XfceClockAnalogClass *klass)
   gobject_class->finalize = xfce_clock_analog_finalize;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
-  gtkwidget_class->expose_event = xfce_clock_analog_expose_event;
+  gtkwidget_class->draw = xfce_clock_analog_draw;
 
   g_object_class_install_property (gobject_class,
                                    PROP_SIZE_RATIO,
@@ -209,65 +209,60 @@ xfce_clock_analog_finalize (GObject *object)
 
 
 static gboolean
-xfce_clock_analog_expose_event (GtkWidget      *widget,
-                                GdkEventExpose *event)
+xfce_clock_analog_draw (GtkWidget *widget,
+                        cairo_t   *cr)
 {
   XfceClockAnalog *analog = XFCE_CLOCK_ANALOG (widget);
   gdouble          xc, yc;
   gdouble          angle, radius;
-  cairo_t         *cr;
   GDateTime       *time;
+  GtkAllocation    allocation;
+  GtkStyleContext *ctx;
+  GdkRGBA          fg_rgba;
 
   panel_return_val_if_fail (XFCE_CLOCK_IS_ANALOG (analog), FALSE);
+  panel_return_val_if_fail (cr != NULL, FALSE);
 
   /* get center of the widget and the radius */
-  xc = (widget->allocation.width / 2.0);
-  yc = (widget->allocation.height / 2.0);
+  gtk_widget_get_allocation (widget, &allocation);
+  xc = (allocation.width / 2.0);
+  yc = (allocation.height / 2.0);
   radius = MIN (xc, yc);
 
   /* add the window offset */
-  xc += widget->allocation.x;
-  yc += widget->allocation.y;
+  xc += allocation.x;
+  yc += allocation.y;
 
-  /* get the cairo context */
-  cr = gdk_cairo_create (widget->window);
+  /* get the local time */
+  time = clock_time_get_time (analog->time);
 
-  if (G_LIKELY (cr != NULL))
+  /* set the line properties */
+  cairo_set_line_width (cr, 1);
+  ctx = gtk_widget_get_style_context (widget);
+  gtk_style_context_get_color (ctx, gtk_widget_get_state_flags (widget), &fg_rgba);
+  gdk_cairo_set_source_rgba (cr, &fg_rgba);
+
+  /* draw the ticks */
+  xfce_clock_analog_draw_ticks (cr, xc, yc, radius);
+
+  if (analog->show_seconds)
     {
-      /* clip the drawing region */
-      gdk_cairo_rectangle (cr, &event->area);
-      cairo_clip (cr);
-
-      /* get the local time */
-      time = clock_time_get_time (analog->time);
-
-      /* set the line properties */
-      cairo_set_line_width (cr, 1);
-      gdk_cairo_set_source_color (cr, &widget->style->fg[GTK_WIDGET_STATE (widget)]);
-
-      /* draw the ticks */
-      xfce_clock_analog_draw_ticks (cr, xc, yc, radius);
-
-      if (analog->show_seconds)
-        {
-          /* second pointer */
-          angle = TICKS_TO_RADIANS (g_date_time_get_second (time));
-          xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.7, TRUE);
-        }
-
-      /* minute pointer */
-      angle = TICKS_TO_RADIANS (g_date_time_get_minute (time));
-      xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.8, FALSE);
-
-      /* hour pointer */
-      angle = HOURS_TO_RADIANS (g_date_time_get_hour (time), g_date_time_get_minute (time));
-      xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.5, FALSE);
-
-      /* cleanup */
-      g_date_time_unref (time);
-      cairo_destroy (cr);
+      /* second pointer */
+      angle = TICKS_TO_RADIANS (g_date_time_get_second (time));
+      xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.7, TRUE);
     }
 
+  /* minute pointer */
+  angle = TICKS_TO_RADIANS (g_date_time_get_minute (time));
+  xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.8, FALSE);
+
+  /* hour pointer */
+  angle = HOURS_TO_RADIANS (g_date_time_get_hour (time), g_date_time_get_minute (time));
+  xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.5, FALSE);
+
+  /* cleanup */
+  g_date_time_unref (time);
+
   return FALSE;
 }
 
@@ -355,7 +350,7 @@ xfce_clock_analog_update (XfceClockAnalog *analog,
   panel_return_val_if_fail (XFCE_IS_CLOCK_TIME (time), FALSE);
 
   /* update if the widget if visible */
-  if (G_LIKELY (GTK_WIDGET_VISIBLE (widget)))
+  if (G_LIKELY (gtk_widget_get_visible (widget)))
     gtk_widget_queue_draw (widget);
 
   return TRUE;
diff --git a/plugins/clock/clock-binary.c b/plugins/clock/clock-binary.c
index 4751c51..8ab9480 100644
--- a/plugins/clock/clock-binary.c
+++ b/plugins/clock/clock-binary.c
@@ -42,8 +42,8 @@ static void      xfce_clock_binary_get_property  (GObject              *object,
                                                   GValue               *value,
                                                   GParamSpec           *pspec);
 static void      xfce_clock_binary_finalize      (GObject              *object);
-static gboolean  xfce_clock_binary_expose_event  (GtkWidget            *widget,
-                                                  GdkEventExpose       *event);
+static gboolean  xfce_clock_binary_draw          (GtkWidget            *widget,
+                                                  cairo_t              *cr);
 static gboolean  xfce_clock_binary_update        (XfceClockBinary      *binary,
                                                   ClockTime            *time);
 
@@ -98,7 +98,7 @@ xfce_clock_binary_class_init (XfceClockBinaryClass *klass)
   gobject_class->finalize = xfce_clock_binary_finalize;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
-  gtkwidget_class->expose_event = xfce_clock_binary_expose_event;
+  gtkwidget_class->draw = xfce_clock_binary_draw;
 
   g_object_class_install_property (gobject_class,
                                    PROP_SIZE_RATIO,
@@ -257,29 +257,51 @@ xfce_clock_binary_finalize (GObject *object)
 
 
 static void
-xfce_clock_binary_expose_event_true_binary (XfceClockBinary *binary,
-                                            cairo_t         *cr,
-                                            GtkAllocation   *alloc)
+xfce_clock_binary_draw_true_binary (XfceClockBinary *binary,
+                                    cairo_t         *cr,
+                                    GtkAllocation   *alloc)
 {
-  GdkColor    *active, *inactive;
-  GDateTime   *time;
-  gint         row, rows;
-  static gint  binary_table[] = { 32, 16, 8, 4, 2, 1 };
-  gint         col, cols = G_N_ELEMENTS (binary_table);
-  gint         remain_h, remain_w;
-  gint         offset_x, offset_y;
-  gint         w, h, x;
-  gint         ticks;
-
-  if (G_UNLIKELY (GTK_WIDGET_STATE (binary) == GTK_STATE_INSENSITIVE))
+  GDateTime        *time;
+  gint              row, rows;
+  static gint       binary_table[] = { 32, 16, 8, 4, 2, 1 };
+  gint              col, cols = G_N_ELEMENTS (binary_table);
+  gint              remain_h, remain_w;
+  gint              offset_x, offset_y;
+  gint              w, h, x;
+  gint              ticks;
+  GtkStyleContext  *ctx;
+  GdkRGBA           active_rgba, inactive_rgba;
+  GtkSymbolicColor *literal;
+  GtkSymbolicColor *shade;
+
+  ctx = gtk_widget_get_style_context (GTK_WIDGET (binary));
+
+  if (G_UNLIKELY (gtk_widget_get_state_flags (GTK_WIDGET (binary)) & GTK_STATE_INSENSITIVE))
     {
-      inactive = &(GTK_WIDGET (binary)->style->mid[GTK_STATE_INSENSITIVE]);
-      active = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_INSENSITIVE]);
+      gtk_style_context_get_background_color (ctx, GTK_STATE_INSENSITIVE, &inactive_rgba);
+      literal = gtk_symbolic_color_new_literal (&inactive_rgba);
+      shade = gtk_symbolic_color_new_shade (literal, 0.7);
+      gtk_symbolic_color_resolve (shade, NULL, &active_rgba);
+      gtk_symbolic_color_unref (shade);
+      gtk_symbolic_color_unref (literal);
     }
   else
     {
-      inactive = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_NORMAL]);
-      active = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_SELECTED]);
+      gtk_style_context_get_background_color (ctx, GTK_STATE_NORMAL, &inactive_rgba);
+      literal = gtk_symbolic_color_new_literal (&inactive_rgba);
+      shade = gtk_symbolic_color_new_shade (literal, 0.7);
+      gtk_symbolic_color_resolve (shade, NULL, &inactive_rgba);
+      gtk_symbolic_color_unref (shade);
+      gtk_symbolic_color_unref (literal);
+
+      gtk_style_context_get_background_color (ctx, GTK_STATE_SELECTED, &active_rgba);
+      literal = gtk_symbolic_color_new_literal (&active_rgba);
+      shade = gtk_symbolic_color_new_shade (literal, 0.7);
+      gtk_symbolic_color_resolve (shade, NULL, &active_rgba);
+      gtk_symbolic_color_unref (shade);
+      gtk_symbolic_color_unref (literal);
+      gtk_style_context_get_color (ctx, GTK_STATE_NORMAL, &inactive_rgba);
+      gtk_style_context_get_color (ctx, GTK_STATE_SELECTED, &active_rgba);
     }
 
   time = clock_time_get_time (binary->time);
@@ -315,12 +337,12 @@ xfce_clock_binary_expose_event_true_binary (XfceClockBinary *binary,
 
           if (ticks >= binary_table[col])
             {
-              gdk_cairo_set_source_color (cr, active);
+              gdk_cairo_set_source_rgba (cr, &active_rgba);
               ticks -= binary_table[col];
             }
           else if (binary->show_inactive)
             {
-              gdk_cairo_set_source_color (cr, inactive);
+              gdk_cairo_set_source_rgba (cr, &inactive_rgba);
             }
           else
             {
@@ -342,30 +364,52 @@ xfce_clock_binary_expose_event_true_binary (XfceClockBinary *binary,
 
 
 static void
-xfce_clock_binary_expose_event_binary (XfceClockBinary *binary,
-                                       cairo_t         *cr,
-                                       GtkAllocation   *alloc)
+xfce_clock_binary_draw_binary (XfceClockBinary *binary,
+                                     cairo_t         *cr,
+                                     GtkAllocation   *alloc)
 {
-  GdkColor    *active, *inactive;
-  static gint  binary_table[] = { 80, 40, 20, 10, 8, 4, 2, 1 };
-  GDateTime   *time;
-  gint         row, rows = G_N_ELEMENTS (binary_table) / 2;
-  gint         col, cols;
-  gint         digit;
-  gint         remain_h, remain_w;
-  gint         offset_x, offset_y;
-  gint         w, h, y;
-  gint         ticks = 0;
-
-  if (G_UNLIKELY (GTK_WIDGET_STATE (binary) == GTK_STATE_INSENSITIVE))
+  static gint       binary_table[] = { 80, 40, 20, 10, 8, 4, 2, 1 };
+  GDateTime        *time;
+  gint              row, rows = G_N_ELEMENTS (binary_table) / 2;
+  gint              col, cols;
+  gint              digit;
+  gint              remain_h, remain_w;
+  gint              offset_x, offset_y;
+  gint              w, h, y;
+  gint              ticks = 0;
+  GtkStyleContext  *ctx;
+  GdkRGBA           active_rgba, inactive_rgba;
+  GtkSymbolicColor *literal;
+  GtkSymbolicColor *shade;
+
+  ctx = gtk_widget_get_style_context (GTK_WIDGET (binary));
+
+  if (G_UNLIKELY (gtk_widget_get_state_flags (GTK_WIDGET (binary)) & GTK_STATE_INSENSITIVE))
     {
-      inactive = &(GTK_WIDGET (binary)->style->mid[GTK_STATE_INSENSITIVE]);
-      active = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_INSENSITIVE]);
+      gtk_style_context_get_background_color (ctx, GTK_STATE_INSENSITIVE, &inactive_rgba);
+      literal = gtk_symbolic_color_new_literal (&inactive_rgba);
+      shade = gtk_symbolic_color_new_shade (literal, 0.7);
+      gtk_symbolic_color_resolve (shade, NULL, &active_rgba);
+      gtk_symbolic_color_unref (shade);
+      gtk_symbolic_color_unref (literal);
     }
   else
     {
-      inactive = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_NORMAL]);
-      active = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_SELECTED]);
+      gtk_style_context_get_background_color (ctx, GTK_STATE_NORMAL, &inactive_rgba);
+      literal = gtk_symbolic_color_new_literal (&inactive_rgba);
+      shade = gtk_symbolic_color_new_shade (literal, 0.7);
+      gtk_symbolic_color_resolve (shade, NULL, &inactive_rgba);
+      gtk_symbolic_color_unref (shade);
+      gtk_symbolic_color_unref (literal);
+
+      gtk_style_context_get_background_color (ctx, GTK_STATE_SELECTED, &active_rgba);
+      literal = gtk_symbolic_color_new_literal (&active_rgba);
+      shade = gtk_symbolic_color_new_shade (literal, 0.7);
+      gtk_symbolic_color_resolve (shade, NULL, &active_rgba);
+      gtk_symbolic_color_unref (shade);
+      gtk_symbolic_color_unref (literal);
+      gtk_style_context_get_color (ctx, GTK_STATE_NORMAL, &inactive_rgba);
+      gtk_style_context_get_color (ctx, GTK_STATE_SELECTED, &active_rgba);
     }
 
   time = clock_time_get_time (binary->time);
@@ -402,12 +446,12 @@ xfce_clock_binary_expose_event_binary (XfceClockBinary *binary,
           digit = row + (4 * (col % 2));
           if (ticks >= binary_table[digit])
             {
-              gdk_cairo_set_source_color (cr, active);
+              gdk_cairo_set_source_rgba (cr, &active_rgba);
               ticks -= binary_table[digit];
             }
           else if (binary->show_inactive)
             {
-              gdk_cairo_set_source_color (cr, inactive);
+              gdk_cairo_set_source_rgba (cr, &inactive_rgba);
             }
           else
             {
@@ -427,92 +471,93 @@ xfce_clock_binary_expose_event_binary (XfceClockBinary *binary,
 
 
 static gboolean
-xfce_clock_binary_expose_event (GtkWidget      *widget,
-                                GdkEventExpose *event)
+xfce_clock_binary_draw (GtkWidget *widget,
+                        cairo_t   *cr)
 {
-  XfceClockBinary *binary = XFCE_CLOCK_BINARY (widget);
-  cairo_t         *cr;
-  GdkColor        *color;
-  gint             col, cols;
-  gint             row, rows;
-  GtkAllocation    alloc;
-  gdouble          remain_w, x;
-  gdouble          remain_h, y;
-  gint             w, h;
-  gint             pad_x, pad_y;
-  gint             diff;
+  XfceClockBinary  *binary = XFCE_CLOCK_BINARY (widget);
+  gint              col, cols;
+  gint              row, rows;
+  GtkAllocation     alloc;
+  gdouble           remain_w, x;
+  gdouble           remain_h, y;
+  gint              w, h;
+  gint              pad_x, pad_y;
+  gint              diff;
+  GtkStyleContext  *ctx;
+  GdkRGBA           bg_rgba, light_rgba;
+  GtkSymbolicColor *literal;
+  GtkSymbolicColor *shade;
 
   panel_return_val_if_fail (XFCE_CLOCK_IS_BINARY (binary), FALSE);
-  panel_return_val_if_fail (GDK_IS_WINDOW (widget->window), FALSE);
-
-  cr = gdk_cairo_create (widget->window);
-  if (G_LIKELY (cr != NULL))
+  panel_return_val_if_fail (gtk_widget_get_has_window (widget), FALSE);
+  panel_return_val_if_fail (cr != NULL, FALSE);
+
+  gtk_misc_get_padding (GTK_MISC (widget), &pad_x, &pad_y);
+
+  gtk_widget_get_allocation (widget, &alloc);
+  alloc.width -= 1 + 2 * pad_x;
+  alloc.height -= 1 + 2 * pad_y;
+  alloc.x += pad_x + 1;
+  alloc.y += pad_y + 1;
+
+  /* align columns and fix rounding */
+  cols = binary->true_binary ? 6 : (binary->show_seconds ? 6 : 4);
+  diff = alloc.width - (floor ((gdouble) alloc.width / cols) * cols);
+  alloc.width -= diff;
+  alloc.x += diff / 2;
+
+  /* align rows and fix rounding */
+  rows = binary->true_binary ? (binary->show_seconds ? 3 : 2) : 4;
+  diff = alloc.height - (floor ((gdouble) alloc.height / rows) * rows);
+  alloc.height -= diff;
+  alloc.y += diff / 2;
+
+  if (binary->show_grid)
     {
-      /* clip the drawing region */
-      gdk_cairo_rectangle (cr, &event->area);
-      cairo_clip (cr);
-
-      gtk_misc_get_padding (GTK_MISC (widget), &pad_x, &pad_y);
-
-      alloc = widget->allocation;
-      alloc.width -= 1 + 2 * pad_x;
-      alloc.height -= 1 + 2 * pad_y;
-      alloc.x += pad_x + 1;
-      alloc.y += pad_y + 1;
-
-      /* align columns and fix rounding */
-      cols = binary->true_binary ? 6 : (binary->show_seconds ? 6 : 4);
-      diff = alloc.width - (floor ((gdouble) alloc.width / cols) * cols);
-      alloc.width -= diff;
-      alloc.x += diff / 2;
-
-      /* align rows and fix rounding */
-      rows = binary->true_binary ? (binary->show_seconds ? 3 : 2) : 4;
-      diff = alloc.height - (floor ((gdouble) alloc.height / rows) * rows);
-      alloc.height -= diff;
-      alloc.y += diff / 2;
-
-      if (binary->show_grid)
+      ctx = gtk_widget_get_style_context (widget);
+      gtk_style_context_get_background_color (ctx, GTK_STATE_SELECTED, &bg_rgba);
+      /* make the bg color lighter */
+      literal = gtk_symbolic_color_new_literal (&bg_rgba);
+      shade = gtk_symbolic_color_new_shade (literal, 1.3);
+      gtk_symbolic_color_resolve (shade, NULL, &light_rgba);
+      gtk_symbolic_color_unref (shade);
+      gtk_symbolic_color_unref (literal);
+
+      gdk_cairo_set_source_rgba (cr, &light_rgba);
+      cairo_set_line_width (cr, 1);
+
+      remain_w = alloc.width;
+      remain_h = alloc.height;
+      x = alloc.x - 0.5;
+      y = alloc.y - 0.5;
+
+      cairo_rectangle (cr, x, y, alloc.width, alloc.height);
+      cairo_stroke (cr);
+
+      for (col = 0; col < cols - 1; col++)
         {
-          color = &(GTK_WIDGET (binary)->style->light[GTK_STATE_SELECTED]);
-          gdk_cairo_set_source_color (cr, color);
-          cairo_set_line_width (cr, 1);
-
-          remain_w = alloc.width;
-          remain_h = alloc.height;
-          x = alloc.x - 0.5;
-          y = alloc.y - 0.5;
-
-          cairo_rectangle (cr, x, y, alloc.width, alloc.height);
+          w = remain_w / (cols - col);
+          x += w; remain_w -= w;
+          cairo_move_to (cr, x, alloc.y);
+          cairo_rel_line_to (cr, 0, alloc.height);
           cairo_stroke (cr);
-
-          for (col = 0; col < cols - 1; col++)
-            {
-              w = remain_w / (cols - col);
-              x += w; remain_w -= w;
-              cairo_move_to (cr, x, alloc.y);
-              cairo_rel_line_to (cr, 0, alloc.height);
-              cairo_stroke (cr);
-            }
-
-          for (row = 0; row < rows - 1; row++)
-            {
-              h = remain_h / (rows - row);
-              y += h; remain_h -= h;
-              cairo_move_to (cr, alloc.x, y);
-              cairo_rel_line_to (cr, alloc.width, 0);
-              cairo_stroke (cr);
-            }
         }
 
-      if (binary->true_binary)
-        xfce_clock_binary_expose_event_true_binary (binary, cr, &alloc);
-      else
-        xfce_clock_binary_expose_event_binary (binary, cr, &alloc);
-
-      cairo_destroy (cr);
+      for (row = 0; row < rows - 1; row++)
+        {
+          h = remain_h / (rows - row);
+          y += h; remain_h -= h;
+          cairo_move_to (cr, alloc.x, y);
+          cairo_rel_line_to (cr, alloc.width, 0);
+          cairo_stroke (cr);
+        }
     }
 
+  if (binary->true_binary)
+    xfce_clock_binary_draw_true_binary (binary, cr, &alloc);
+  else
+    xfce_clock_binary_draw_binary (binary, cr, &alloc);
+
   return FALSE;
 }
 
@@ -527,7 +572,7 @@ xfce_clock_binary_update (XfceClockBinary     *binary,
   panel_return_val_if_fail (XFCE_CLOCK_IS_BINARY (binary), FALSE);
 
   /* update if the widget if visible */
-  if (G_LIKELY (GTK_WIDGET_VISIBLE (widget)))
+  if (G_LIKELY (gtk_widget_get_visible (widget)))
     gtk_widget_queue_draw (widget);
 
   return TRUE;
diff --git a/plugins/clock/clock-lcd.c b/plugins/clock/clock-lcd.c
index 84e74e6..92c0189 100644
--- a/plugins/clock/clock-lcd.c
+++ b/plugins/clock/clock-lcd.c
@@ -46,8 +46,8 @@ static void      xfce_clock_lcd_get_property (GObject           *object,
                                               GValue            *value,
                                               GParamSpec        *pspec);
 static void      xfce_clock_lcd_finalize     (GObject           *object);
-static gboolean  xfce_clock_lcd_expose_event (GtkWidget         *widget,
-                                              GdkEventExpose    *event);
+static gboolean  xfce_clock_lcd_draw         (GtkWidget         *widget,
+                                              cairo_t           *cr);
 static gdouble   xfce_clock_lcd_get_ratio    (XfceClockLcd      *lcd);
 static gdouble   xfce_clock_lcd_draw_dots    (cairo_t           *cr,
                                               gdouble            size,
@@ -119,7 +119,7 @@ xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
   gobject_class->finalize = xfce_clock_lcd_finalize;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
-  gtkwidget_class->expose_event = xfce_clock_lcd_expose_event;
+  gtkwidget_class->draw = xfce_clock_lcd_draw;
 
   g_object_class_install_property (gobject_class,
                                    PROP_SIZE_RATIO,
@@ -276,123 +276,115 @@ xfce_clock_lcd_finalize (GObject *object)
 
 
 static gboolean
-xfce_clock_lcd_expose_event (GtkWidget      *widget,
-                             GdkEventExpose *event)
+xfce_clock_lcd_draw (GtkWidget *widget,
+                     cairo_t   *cr)
 {
   XfceClockLcd *lcd = XFCE_CLOCK_LCD (widget);
-  cairo_t      *cr;
   gdouble       offset_x, offset_y;
   gint          ticks, i;
   gdouble       size;
   gdouble       ratio;
   GDateTime    *time;
+  GtkAllocation allocation;
 
   panel_return_val_if_fail (XFCE_CLOCK_IS_LCD (lcd), FALSE);
+  panel_return_val_if_fail (cr != NULL, FALSE);
 
   /* get the width:height ratio */
   ratio = xfce_clock_lcd_get_ratio (XFCE_CLOCK_LCD (widget));
 
   /* make sure we also fit on small vertical panels */
-  size = MIN ((gdouble) widget->allocation.width / ratio, widget->allocation.height);
+  gtk_widget_get_allocation (widget, &allocation);
+  size = MIN ((gdouble) allocation.width / ratio, allocation.height);
 
   /* begin offsets */
-  offset_x = rint ((widget->allocation.width - (size * ratio)) / 2.00);
-  offset_y = rint ((widget->allocation.height - size) / 2.00);
+  offset_x = rint ((allocation.width - (size * ratio)) / 2.00);
+  offset_y = rint ((allocation.height - size) / 2.00);
 
   /* only allow positive values from the base point */
-  offset_x = widget->allocation.x + MAX (0.00, offset_x);
-  offset_y = widget->allocation.y + MAX (0.00, offset_y);
+  offset_x = allocation.x + MAX (0.00, offset_x);
+  offset_y = allocation.y + MAX (0.00, offset_y);
 
-  /* get the cairo context */
-  cr = gdk_cairo_create (widget->window);
+  cairo_push_group (cr);
 
-  if (G_LIKELY (cr != NULL))
-    {
-      gdk_cairo_set_source_color (cr, &widget->style->fg[GTK_WIDGET_STATE (widget)]);
-      gdk_cairo_rectangle (cr, &event->area);
-      cairo_clip (cr);
-      cairo_push_group (cr);
+  /* width of the clear line */
+  cairo_set_line_width (cr, MAX (size * 0.05, 1.5));
 
-      /* width of the clear line */
-      cairo_set_line_width (cr, MAX (size * 0.05, 1.5));
+  /* get the local time */
+  time = clock_time_get_time (lcd->time);
 
-      /* get the local time */
-      time = clock_time_get_time (lcd->time);
+  /* draw the hours */
+  ticks = g_date_time_get_hour (time);
+
+  /* convert 24h clock to 12h clock */
+  if (!lcd->show_military && ticks > 12)
+    ticks -= 12;
 
-      /* draw the hours */
-      ticks = g_date_time_get_hour (time);
+  if (ticks == 1 || (ticks >= 10 && ticks < 20))
+    offset_x -= size * (RELATIVE_SPACE * 4);
 
-      /* convert 24h clock to 12h clock */
-      if (!lcd->show_military && ticks > 12)
-        ticks -= 12;
+  /* queue a resize when the number of hour digits changed,
+   * because we might miss the exact second (due to slightly delayed
+   * timeout) we queue a resize the first 3 seconds or anything in
+   * the first minute */
+  if ((ticks == 10 || ticks == 0) && g_date_time_get_minute (time) == 0
+      && (!lcd->show_seconds || g_date_time_get_second (time) < 3))
+    g_object_notify (G_OBJECT (lcd), "size-ratio");
 
-      if (ticks == 1 || (ticks >= 10 && ticks < 20))
-        offset_x -= size * (RELATIVE_SPACE * 4);
+  if (ticks >= 10)
+    {
+      /* draw the number and increase the offset */
+      offset_x = xfce_clock_lcd_draw_digit (cr, ticks >= 20 ? 2 : 1, size, offset_x, offset_y);
+    }
 
-      /* queue a resize when the number of hour digits changed,
-       * because we might miss the exact second (due to slightly delayed
-       * timeout) we queue a resize the first 3 seconds or anything in
-       * the first minute */
-      if ((ticks == 10 || ticks == 0) && g_date_time_get_minute (time) == 0
-          && (!lcd->show_seconds || g_date_time_get_second (time) < 3))
-        g_object_notify (G_OBJECT (lcd), "size-ratio");
+  /* draw the other number of the hour and increase the offset */
+  offset_x = xfce_clock_lcd_draw_digit (cr, ticks % 10, size, offset_x, offset_y);
 
-      if (ticks >= 10)
+  for (i = 0; i < 2; i++)
+    {
+      /* get the time */
+      if (i == 0)
         {
-          /* draw the number and increase the offset */
-          offset_x = xfce_clock_lcd_draw_digit (cr, ticks >= 20 ? 2 : 1, size, offset_x, offset_y);
+          /* get the minutes */
+          ticks = g_date_time_get_minute (time);
         }
-
-      /* draw the other number of the hour and increase the offset */
-      offset_x = xfce_clock_lcd_draw_digit (cr, ticks % 10, size, offset_x, offset_y);
-
-      for (i = 0; i < 2; i++)
+      else
         {
-          /* get the time */
-          if (i == 0)
-            {
-              /* get the minutes */
-              ticks = g_date_time_get_minute (time);
-            }
-          else
-            {
-              /* leave when we don't want seconds */
-              if (!lcd->show_seconds)
-                break;
-
-              /* get the seconds */
-              ticks = g_date_time_get_second (time);
-            }
-
-          /* draw the dots */
-          if (lcd->flash_separators && (g_date_time_get_second (time) % 2) == 1)
-            offset_x += size * RELATIVE_SPACE * 2;
-          else
-            offset_x = xfce_clock_lcd_draw_dots (cr, size, offset_x, offset_y);
-
-          /* draw the first digit */
-          offset_x = xfce_clock_lcd_draw_digit (cr, (ticks - (ticks % 10)) / 10, size, offset_x, offset_y);
+          /* leave when we don't want seconds */
+          if (!lcd->show_seconds)
+            break;
 
-          /* draw the second digit */
-          offset_x = xfce_clock_lcd_draw_digit (cr, ticks % 10, size, offset_x, offset_y);
+          /* get the seconds */
+          ticks = g_date_time_get_second (time);
         }
 
-      if (lcd->show_meridiem)
-        {
-          /* am or pm? */
-          ticks = g_date_time_get_hour (time) >= 12 ? 11 : 10;
+      /* draw the dots */
+      if (lcd->flash_separators && (g_date_time_get_second (time) % 2) == 1)
+        offset_x += size * RELATIVE_SPACE * 2;
+      else
+        offset_x = xfce_clock_lcd_draw_dots (cr, size, offset_x, offset_y);
 
-          /* draw the digit */
-          offset_x = xfce_clock_lcd_draw_digit (cr, ticks, size, offset_x, offset_y);
-        }
+      /* draw the first digit */
+      offset_x = xfce_clock_lcd_draw_digit (cr, (ticks - (ticks % 10)) / 10, size, offset_x, offset_y);
+
+      /* draw the second digit */
+      offset_x = xfce_clock_lcd_draw_digit (cr, ticks % 10, size, offset_x, offset_y);
+    }
 
-      /* drop the pushed group */
-      g_date_time_unref (time);
-      cairo_pop_group_to_source (cr);
-      cairo_paint (cr);
-      cairo_destroy (cr);
+  if (lcd->show_meridiem)
+    {
+      /* am or pm? */
+      ticks = g_date_time_get_hour (time) >= 12 ? 11 : 10;
+
+      /* draw the digit */
+      offset_x = xfce_clock_lcd_draw_digit (cr, ticks, size, offset_x, offset_y);
     }
 
+  /* drop the pushed group */
+  g_date_time_unref (time);
+  cairo_pop_group_to_source (cr);
+  cairo_paint (cr);
+
   return FALSE;
 }
 
@@ -591,7 +583,7 @@ xfce_clock_lcd_update (XfceClockLcd *lcd,
   panel_return_val_if_fail (XFCE_CLOCK_IS_LCD (lcd), FALSE);
 
   /* update if the widget if visible */
-  if (G_LIKELY (GTK_WIDGET_VISIBLE (widget)))
+  if (G_LIKELY (gtk_widget_get_visible (widget)))
     gtk_widget_queue_draw (widget);
 
   return TRUE;
diff --git a/plugins/clock/clock-time.c b/plugins/clock/clock-time.c
index 16b0f89..f737cad 100644
--- a/plugins/clock/clock-time.c
+++ b/plugins/clock/clock-time.c
@@ -18,7 +18,6 @@
 
 
 #include <glib.h>
-#include <exo/exo.h>
 
 #include "clock-time.h"
 #include "clock.h"
@@ -93,7 +92,7 @@ clock_time_class_init (ClockTimeClass *klass)
                                    g_param_spec_string ("timezone",
                                                         NULL, NULL,
                                                         DEFAULT_TIMEZONE,
-                                                        EXO_PARAM_READWRITE));
+                                                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   clock_time_signals[TIME_CHANGED] =
     g_signal_new (g_intern_static_string ("time-changed"),
@@ -232,7 +231,7 @@ clock_time_interval_from_format (const gchar *format)
 {
   const gchar *p;
 
-  if (G_UNLIKELY (exo_str_is_empty (format)))
+  if (G_UNLIKELY (panel_str_is_empty (format)))
       return CLOCK_INTERVAL_MINUTE;
 
   for (p = format; *p != '\0'; ++p)
diff --git a/plugins/clock/clock.c b/plugins/clock/clock.c
index 699184e..db6678f 100644
--- a/plugins/clock/clock.c
+++ b/plugins/clock/clock.c
@@ -152,7 +152,6 @@ struct _ClockPlugin
   ClockTimeTimeout   *tooltip_timeout;
 
   GdkGrabStatus       grab_pointer;
-  GdkGrabStatus       grab_keyboard;
 
   gchar              *time_config_tool;
   ClockTime          *time;
@@ -919,8 +918,6 @@ clock_plugin_configure_zoneinfo_model (gpointer data)
   GtkListStore       *store;
   GObject            *object;
 
-  GDK_THREADS_ENTER ();
-
   dialog->zonecompletion_idle = 0;
 
   object = gtk_builder_get_object (dialog->builder, "timezone-name");
@@ -941,8 +938,6 @@ clock_plugin_configure_zoneinfo_model (gpointer data)
 
   g_object_unref (G_OBJECT (completion));
 
-  GDK_THREADS_LEAVE ();
-
   return FALSE;
 }
 
@@ -987,7 +982,7 @@ clock_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
   /* idle add the zone completion */
-  dialog->zonecompletion_idle = g_idle_add (clock_plugin_configure_zoneinfo_model, dialog);
+  dialog->zonecompletion_idle = gdk_threads_add_idle (clock_plugin_configure_zoneinfo_model, dialog);
 
   object = gtk_builder_get_object (builder, "mode");
   g_signal_connect_data (G_OBJECT (object), "changed",
@@ -1134,10 +1129,18 @@ static void
 clock_plugin_pointer_ungrab (ClockPlugin *plugin,
                              GtkWidget   *widget)
 {
+  GdkDisplay       *display;
+  GdkDevice        *pointer;
+  GdkDeviceManager *device_manager;
+
+  panel_return_if_fail (GTK_IS_WIDGET (widget));
+
+  display = gtk_widget_get_display (widget);
+  device_manager = gdk_display_get_device_manager (display);
+  pointer = gdk_device_manager_get_client_pointer (device_manager);
+
   if (plugin->grab_pointer == GDK_GRAB_SUCCESS)
-    gdk_pointer_ungrab (GDK_CURRENT_TIME);
-  if (plugin->grab_keyboard == GDK_GRAB_SUCCESS)
-    gdk_keyboard_ungrab (GDK_CURRENT_TIME);
+    gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
 }
 
 
@@ -1147,28 +1150,31 @@ clock_plugin_pointer_grab (ClockPlugin *plugin,
                            GtkWidget   *widget,
                            gboolean     keep)
 {
-  GdkWindow     *window;
-  gboolean       grab_succeed = FALSE;
-  guint          i;
-  GdkEventMask   pointer_mask = GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
-                                | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
-                                | GDK_POINTER_MOTION_MASK;
-
-  window = widget->window;
+  GdkWindow        *window;
+  gboolean          grab_succeed = FALSE;
+  guint             i;
+  GdkDisplay       *display;
+  GdkDevice        *pointer;
+  GdkDeviceManager *device_manager;
+  GdkEventMask      pointer_mask = GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+                                 | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
+                                 | GDK_POINTER_MOTION_MASK
+                                 | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK;
+
+  window = gtk_widget_get_parent_window (widget);
+  display = gtk_widget_get_display (widget);
+  device_manager = gdk_display_get_device_manager (display);
+  pointer = gdk_device_manager_get_client_pointer (device_manager);
 
   /* don't try to get the grab for longer then 1/4 second */
   for (i = 0; i < (G_USEC_PER_SEC / 100 / 4); i++)
     {
-      plugin->grab_keyboard = gdk_keyboard_grab (window, TRUE, GDK_CURRENT_TIME);
-      if (plugin->grab_keyboard == GDK_GRAB_SUCCESS)
+      plugin->grab_pointer = gdk_device_grab (pointer, window, GDK_OWNERSHIP_NONE, TRUE, pointer_mask,
+                                              NULL, GDK_CURRENT_TIME);
+      if (plugin->grab_pointer == GDK_GRAB_SUCCESS)
         {
-          plugin->grab_pointer = gdk_pointer_grab (window, TRUE, pointer_mask,
-                                                   NULL, NULL, GDK_CURRENT_TIME);
-          if (plugin->grab_pointer == GDK_GRAB_SUCCESS)
-            {
-              grab_succeed = TRUE;
-              break;
-            }
+          grab_succeed = TRUE;
+          break;
         }
 
       g_usleep (100);
@@ -1196,13 +1202,16 @@ clock_plugin_calendar_pointed (GtkWidget *calendar_window,
                                gdouble    y_root)
 {
   gint          window_x, window_y;
+  GtkAllocation allocation;
 
   if (gtk_widget_get_mapped (calendar_window))
     {
-      gdk_window_get_position (calendar_window->window, &window_x, &window_y);
+      gdk_window_get_position (gtk_widget_get_parent_window (calendar_window), &window_x, &window_y);
 
-      if (x_root >= window_x && x_root < window_x + calendar_window->allocation.width &&
-          y_root >= window_y && y_root < window_y + calendar_window->allocation.height)
+      gtk_widget_get_allocation (calendar_window, &allocation);
+
+      if (x_root >= window_x && x_root < window_x + allocation.width &&
+          y_root >= window_y && y_root < window_y + allocation.height)
         return TRUE;
     }
 
@@ -1316,239 +1325,3 @@ clock_plugin_tooltip (gpointer user_data)
   /* keep the timeout running */
   return TRUE;
 }
-<<<<<<< HEAD
-=======
-
-
-
-static gboolean
-clock_plugin_timeout_running (gpointer user_data)
-{
-  ClockPluginTimeout *timeout = user_data;
-  gboolean            result;
-  struct tm           tm;
-
-  GDK_THREADS_ENTER ();
-  result = (timeout->function) (timeout->data);
-  GDK_THREADS_LEAVE ();
-
-  /* check if the timeout still runs in time if updating once a minute */
-  if (result && timeout->interval == CLOCK_INTERVAL_MINUTE)
-    {
-      /* sync again when we don't run on time */
-      clock_plugin_get_localtime (&tm);
-      timeout->restart = tm.tm_sec != 0;
-    }
-
-  return result && !timeout->restart;
-}
-
-
-
-static void
-clock_plugin_timeout_destroyed (gpointer user_data)
-{
-  ClockPluginTimeout *timeout = user_data;
-
-  timeout->timeout_id = 0;
-
-  if (G_UNLIKELY (timeout->restart))
-    clock_plugin_timeout_set_interval (timeout, timeout->interval);
-}
-
-
-
-static gboolean
-clock_plugin_timeout_sync (gpointer user_data)
-{
-  ClockPluginTimeout *timeout = user_data;
-
-  /* run the user function */
-  if ((timeout->function) (timeout->data))
-    {
-      /* start the real timeout */
-      timeout->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, timeout->interval,
-                                                        clock_plugin_timeout_running, timeout,
-                                                        clock_plugin_timeout_destroyed);
-    }
-  else
-    {
-      timeout->timeout_id = 0;
-    }
-
-  /* stop the sync timeout */
-  return FALSE;
-}
-
-
-
-ClockPluginTimeout *
-clock_plugin_timeout_new (guint       interval,
-                          GSourceFunc function,
-                          gpointer    data)
-{
-  ClockPluginTimeout *timeout;
-
-  panel_return_val_if_fail (interval > 0, NULL);
-  panel_return_val_if_fail (function != NULL, NULL);
-
-  timeout = g_slice_new0 (ClockPluginTimeout);
-  timeout->interval = 0;
-  timeout->function = function;
-  timeout->data = data;
-  timeout->timeout_id = 0;
-  timeout->restart = FALSE;
-
-  clock_plugin_timeout_set_interval (timeout, interval);
-
-  return timeout;
-}
-
-
-
-void
-clock_plugin_timeout_set_interval (ClockPluginTimeout *timeout,
-                                   guint               interval)
-{
-  struct tm tm;
-  guint     next_interval;
-  gboolean  restart = timeout->restart;
-
-  panel_return_if_fail (timeout != NULL);
-  panel_return_if_fail (interval > 0);
-
-  /* leave if nothing changed and we're not restarting */
-  if (!restart && timeout->interval == interval)
-    return;
-  timeout->interval = interval;
-  timeout->restart = FALSE;
-
-  /* stop running timeout */
-  if (G_LIKELY (timeout->timeout_id != 0))
-    g_source_remove (timeout->timeout_id);
-  timeout->timeout_id = 0;
-
-  /* run function when not restarting, leave if it returns false */
-  if (!restart && !(timeout->function) (timeout->data))
-    return;
-
-  /* get the seconds to the next internal */
-  if (interval == CLOCK_INTERVAL_MINUTE)
-    {
-      clock_plugin_get_localtime (&tm);
-      next_interval = 60 - tm.tm_sec;
-    }
-  else
-    {
-      next_interval = 0;
-    }
-
-  if (next_interval > 0)
-    {
-      /* start the sync timeout */
-      timeout->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, next_interval,
-                                                        clock_plugin_timeout_sync,
-                                                        timeout, NULL);
-    }
-  else
-    {
-      /* directly start running the normal timeout */
-      timeout->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, interval,
-                                                        clock_plugin_timeout_running, timeout,
-                                                        clock_plugin_timeout_destroyed);
-    }
-}
-
-
-
-void
-clock_plugin_timeout_free (ClockPluginTimeout *timeout)
-{
-  panel_return_if_fail (timeout != NULL);
-
-  timeout->restart = FALSE;
-  if (G_LIKELY (timeout->timeout_id != 0))
-    g_source_remove (timeout->timeout_id);
-  g_slice_free (ClockPluginTimeout, timeout);
-}
-
-
-
-void
-clock_plugin_get_localtime (struct tm *tm)
-{
-  time_t now = time (NULL);
-
-#ifndef HAVE_LOCALTIME_R
-  struct tm *tmbuf;
-
-  tmbuf = localtime (&now);
-  *tm = *tmbuf;
-#else
-  localtime_r (&now, tm);
-#endif
-}
-
-
-
-gchar *
-clock_plugin_strdup_strftime (const gchar     *format,
-                              const struct tm *tm)
-{
-  gchar *converted, *result;
-  gsize  length;
-  gchar  buffer[1024];
-
-  /* leave when format is null */
-  if (G_UNLIKELY (panel_str_is_empty (format)))
-    return NULL;
-
-  /* convert to locale, because that's what strftime uses */
-  converted = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
-  if (G_UNLIKELY (converted == NULL))
-    return NULL;
-
-  /* parse the time string */
-  length = strftime (buffer, sizeof (buffer), converted, tm);
-  if (G_UNLIKELY (length == 0))
-    buffer[0] = '\0';
-
-  /* convert the string back to utf-8 */
-  result = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
-
-  /* cleanup */
-  g_free (converted);
-
-  return result;
-}
-
-
-
-guint
-clock_plugin_interval_from_format (const gchar *format)
-{
-  const gchar *p;
-
-  if (G_UNLIKELY (panel_str_is_empty (format)))
-      return CLOCK_INTERVAL_MINUTE;
-
-  for (p = format; *p != '\0'; ++p)
-    {
-      if (p[0] == '%' && p[1] != '\0')
-        {
-          switch (*++p)
-            {
-            case 'c':
-            case 'N':
-            case 'r':
-            case 's':
-            case 'S':
-            case 'T':
-            case 'X':
-              return CLOCK_INTERVAL_SECOND;
-            }
-        }
-    }
-
-  return CLOCK_INTERVAL_MINUTE;
-}


More information about the Xfce4-commits mailing list