Browse Source

Refactor a lot of code in the clock plugin.

Each clock widget now handles it's own timeout using a
new automatic sync timeout function.

Properly bind the properties using exo bindings for the
dialog and xfconf bindings for the objects.

Use g_timeout_add_seconds for all updates since we don't
care about nano seconds and the seconds timeout stays
much better in sync over time.
upstream/xfce4-panel-4.10.1
Nick Schermer 13 years ago
parent
commit
121d9b0400
  1. 2
      plugins/clock/Makefile.am
  2. 67
      plugins/clock/clock-analog.c
  3. 6
      plugins/clock/clock-analog.h
  4. 52
      plugins/clock/clock-binary.c
  5. 6
      plugins/clock/clock-binary.h
  6. 92
      plugins/clock/clock-digital.c
  7. 6
      plugins/clock/clock-digital.h
  8. 63
      plugins/clock/clock-fuzzy.c
  9. 6
      plugins/clock/clock-fuzzy.h
  10. 80
      plugins/clock/clock-lcd.c
  11. 4
      plugins/clock/clock-lcd.h
  12. 867
      plugins/clock/clock.c
  13. 39
      plugins/clock/clock.h

2
plugins/clock/Makefile.am

@ -35,6 +35,7 @@ libclock_la_CFLAGS = \
$(CAIRO_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
$(PLATFORM_CFLAGS) \
$(EXO_CFLAGS) \
$(XFCONF_CFLAGS)
libclock_la_LDFLAGS = \
@ -51,6 +52,7 @@ libclock_la_LIBADD = \
$(CAIRO_LIBS) \
$(LIBXFCE4UTIL_LIBS) \
$(LIBXFCE4UI_LIBS) \
$(EXO_LIBS) \
$(XFCONF_LIBS)
libclock_la_DEPENDENCIES = \

67
plugins/clock/clock-analog.c

@ -34,17 +34,12 @@
#include "clock.h"
#include "clock-analog.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define CLOCK_SCALE 0.1
#define TICKS_TO_RADIANS(x) (M_PI - (M_PI / 30.0) * (x))
#define HOURS_TO_RADIANS(x,y) (M_PI - (M_PI / 6.0) * (((x) > 12 ? (x) - 12 : (x)) + (y) / 60.0))
#define TICKS_TO_RADIANS(x) (G_PI - (G_PI / 30.0) * (x))
#define HOURS_TO_RADIANS(x,y) (G_PI - (G_PI / 6.0) * (((x) > 12 ? (x) - 12 : (x)) + (y) / 60.0))
/* prototypes */
static void xfce_clock_analog_set_property (GObject *object,
guint prop_id,
const GValue *value,
@ -53,8 +48,9 @@ static void xfce_clock_analog_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfce_clock_analog_finalize (GObject *object);
static void xfce_clock_analog_size_request (GtkWidget *widget,
GtkRequisition *requisition);
GtkRequisition *requisition);
static gboolean xfce_clock_analog_expose_event (GtkWidget *widget,
GdkEventExpose *event);
static void xfce_clock_analog_draw_ticks (cairo_t *cr,
@ -68,6 +64,7 @@ static void xfce_clock_analog_draw_pointer (cairo_t *cr,
gdouble angle,
gdouble scale,
gboolean line);
static gboolean xfce_clock_analog_update (gpointer user_data);
@ -86,8 +83,9 @@ struct _XfceClockAnalog
{
GtkImage __parent__;
/* draw seconds */
guint show_seconds : 1;
ClockPluginTimeout *timeout;
guint show_seconds : 1;
};
@ -105,6 +103,7 @@ xfce_clock_analog_class_init (XfceClockAnalogClass *klass)
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = xfce_clock_analog_set_property;
gobject_class->get_property = xfce_clock_analog_get_property;
gobject_class->finalize = xfce_clock_analog_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->size_request = xfce_clock_analog_size_request;
@ -115,7 +114,7 @@ xfce_clock_analog_class_init (XfceClockAnalogClass *klass)
g_param_spec_boolean ("show-seconds", NULL, NULL,
FALSE,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
}
@ -123,8 +122,10 @@ xfce_clock_analog_class_init (XfceClockAnalogClass *klass)
static void
xfce_clock_analog_init (XfceClockAnalog *analog)
{
/* init */
analog->show_seconds = FALSE;
analog->timeout = clock_plugin_timeout_new (CLOCK_INTERVAL_MINUTE,
xfce_clock_analog_update,
analog);
}
@ -147,6 +148,11 @@ xfce_clock_analog_set_property (GObject *object,
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
/* reschedule the timeout and redraw */
clock_plugin_timeout_set_interval (analog->timeout,
analog->show_seconds ? CLOCK_INTERVAL_SECOND : CLOCK_INTERVAL_MINUTE);
xfce_clock_analog_update (analog);
}
@ -173,6 +179,17 @@ xfce_clock_analog_get_property (GObject *object,
static void
xfce_clock_analog_finalize (GObject *object)
{
/* stop the timeout */
clock_plugin_timeout_free (XFCE_CLOCK_ANALOG (object)->timeout);
(*G_OBJECT_CLASS (xfce_clock_analog_parent_class)->finalize) (object);
}
static void
xfce_clock_analog_size_request (GtkWidget *widget,
GtkRequisition *requisition)
@ -270,7 +287,7 @@ xfce_clock_analog_draw_ticks (cairo_t *cr,
/* draw arc */
cairo_move_to (cr, x, y);
cairo_arc (cr, x, y, radius * CLOCK_SCALE, 0, 2 * M_PI);
cairo_arc (cr, x, y, radius * CLOCK_SCALE, 0, 2 * G_PI);
cairo_close_path (cr);
}
@ -308,12 +325,12 @@ xfce_clock_analog_draw_pointer (cairo_t *cr,
else
{
/* calculate start position */
xs = xc + sin (angle - 0.5 * M_PI) * radius * CLOCK_SCALE;
ys = yc + cos (angle - 0.5 * M_PI) * radius * CLOCK_SCALE;
xs = xc + sin (angle - 0.5 * G_PI) * radius * CLOCK_SCALE;
ys = yc + cos (angle - 0.5 * G_PI) * radius * CLOCK_SCALE;
/* draw the pointer */
cairo_move_to (cr, xs, ys);
cairo_arc (cr, xc, yc, radius * CLOCK_SCALE, -angle + M_PI, -angle);
cairo_arc (cr, xc, yc, radius * CLOCK_SCALE, -angle + G_PI, -angle);
cairo_line_to (cr, xt, yt);
cairo_close_path (cr);
@ -324,15 +341,7 @@ xfce_clock_analog_draw_pointer (cairo_t *cr,
GtkWidget *
xfce_clock_analog_new (void)
{
return g_object_new (XFCE_CLOCK_TYPE_ANALOG, NULL);
}
gboolean
static gboolean
xfce_clock_analog_update (gpointer user_data)
{
GtkWidget *widget = GTK_WIDGET (user_data);
@ -348,10 +357,8 @@ xfce_clock_analog_update (gpointer user_data)
guint
xfce_clock_analog_interval (XfceClockAnalog *analog)
GtkWidget *
xfce_clock_analog_new (void)
{
panel_return_val_if_fail (XFCE_CLOCK_IS_ANALOG (analog), CLOCK_INTERVAL_SECOND);
return analog->show_seconds ? CLOCK_INTERVAL_SECOND : CLOCK_INTERVAL_MINUTE;
return g_object_new (XFCE_CLOCK_TYPE_ANALOG, NULL);
}

6
plugins/clock/clock-analog.h

@ -34,14 +34,10 @@ typedef struct _XfceClockAnalog XfceClockAnalog;
GType xfce_clock_analog_get_type (void) G_GNUC_CONST;
void xfce_clock_analog_register_type (GTypeModule *type_module);
void xfce_clock_analog_register_type (GTypeModule *type_module);
GtkWidget *xfce_clock_analog_new (void) G_GNUC_MALLOC;
gboolean xfce_clock_analog_update (gpointer user_data);
guint xfce_clock_analog_interval (XfceClockAnalog *analog);
G_END_DECLS
#endif /* !__CLOCK_ANALOG_H__ */

52
plugins/clock/clock-binary.c

@ -48,10 +48,13 @@ static void xfce_clock_binary_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfce_clock_binary_finalize (GObject *object);
static void xfce_clock_binary_size_request (GtkWidget *widget,
GtkRequisition *requisition);
GtkRequisition *requisition);
static gboolean xfce_clock_binary_expose_event (GtkWidget *widget,
GdkEventExpose *event);
static gboolean xfce_clock_binary_update (gpointer user_data);
enum
@ -70,10 +73,9 @@ struct _XfceClockBinary
{
GtkImage __parent__;
/* whether we draw seconds */
guint show_seconds : 1;
ClockPluginTimeout *timeout;
/* if this is a true binary clock */
guint show_seconds : 1;
guint true_binary : 1;
};
@ -92,6 +94,7 @@ xfce_clock_binary_class_init (XfceClockBinaryClass *klass)
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = xfce_clock_binary_set_property;
gobject_class->get_property = xfce_clock_binary_get_property;
gobject_class->finalize = xfce_clock_binary_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->size_request = xfce_clock_binary_size_request;
@ -102,14 +105,14 @@ xfce_clock_binary_class_init (XfceClockBinaryClass *klass)
g_param_spec_boolean ("show-seconds", NULL, NULL,
FALSE,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_TRUE_BINARY,
g_param_spec_boolean ("true-binary", NULL, NULL,
FALSE,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
}
@ -120,6 +123,9 @@ xfce_clock_binary_init (XfceClockBinary *binary)
/* init */
binary->show_seconds = FALSE;
binary->true_binary = FALSE;
binary->timeout = clock_plugin_timeout_new (CLOCK_INTERVAL_MINUTE,
xfce_clock_binary_update,
binary);
}
@ -146,6 +152,11 @@ xfce_clock_binary_set_property (GObject *object,
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
/* reschedule the timeout and resize */
clock_plugin_timeout_set_interval (binary->timeout,
binary->show_seconds ? CLOCK_INTERVAL_SECOND : CLOCK_INTERVAL_MINUTE);
gtk_widget_queue_resize (GTK_WIDGET (binary));
}
@ -176,6 +187,17 @@ xfce_clock_binary_get_property (GObject *object,
static void
xfce_clock_binary_finalize (GObject *object)
{
/* stop the timeout */
clock_plugin_timeout_free (XFCE_CLOCK_BINARY (object)->timeout);
(*G_OBJECT_CLASS (xfce_clock_binary_parent_class)->finalize) (object);
}
static void
xfce_clock_binary_size_request (GtkWidget *widget,
GtkRequisition *requisition)
@ -336,15 +358,7 @@ xfce_clock_binary_expose_event (GtkWidget *widget,
GtkWidget *
xfce_clock_binary_new (void)
{
return g_object_new (XFCE_CLOCK_TYPE_BINARY, NULL);
}
gboolean
static gboolean
xfce_clock_binary_update (gpointer user_data)
{
GtkWidget *widget = GTK_WIDGET (user_data);
@ -360,10 +374,8 @@ xfce_clock_binary_update (gpointer user_data)
guint
xfce_clock_binary_interval (XfceClockBinary *binary)
GtkWidget *
xfce_clock_binary_new (void)
{
panel_return_val_if_fail (XFCE_CLOCK_IS_BINARY (binary), CLOCK_INTERVAL_SECOND);
return binary->show_seconds ? CLOCK_INTERVAL_SECOND : CLOCK_INTERVAL_MINUTE;
return g_object_new (XFCE_CLOCK_TYPE_BINARY, NULL);
}

6
plugins/clock/clock-binary.h

@ -34,14 +34,10 @@ typedef struct _XfceClockBinary XfceClockBinary;
GType xfce_clock_binary_get_type (void) G_GNUC_CONST;
void xfce_clock_binary_register_type (GTypeModule *type_module);
void xfce_clock_binary_register_type (GTypeModule *type_module);
GtkWidget *xfce_clock_binary_new (void) G_GNUC_MALLOC;
gboolean xfce_clock_binary_update (gpointer user_data);
guint xfce_clock_binary_interval (XfceClockBinary *binary);
G_END_DECLS
#endif /* !__CLOCK_BINARY_H__ */

92
plugins/clock/clock-digital.c

@ -30,17 +30,20 @@
#include "clock.h"
#include "clock-digital.h"
#define DEFAULT_DIGITAL_FORMAT "%R"
static void xfce_clock_digital_finalize (GObject *object);
static void xfce_clock_digital_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void xfce_clock_digital_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfce_clock_digital_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void xfce_clock_digital_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfce_clock_digital_finalize (GObject *object);
static gboolean xfce_clock_digital_update (gpointer user_data);
@ -59,7 +62,8 @@ struct _XfceClockDigital
{
GtkLabel __parent__;
/* clock format */
ClockPluginTimeout *timeout;
gchar *format;
};
@ -82,9 +86,9 @@ xfce_clock_digital_class_init (XfceClockDigitalClass *klass)
g_object_class_install_property (gobject_class,
PROP_DIGITAL_FORMAT,
g_param_spec_string ("digital-format", NULL, NULL,
NULL,
DEFAULT_DIGITAL_FORMAT,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
}
@ -92,28 +96,16 @@ xfce_clock_digital_class_init (XfceClockDigitalClass *klass)
static void
xfce_clock_digital_init (XfceClockDigital *digital)
{
/* init */
digital->format = NULL;
digital->format = g_strdup (DEFAULT_DIGITAL_FORMAT);
digital->timeout = clock_plugin_timeout_new (clock_plugin_interval_from_format (digital->format),
xfce_clock_digital_update,
digital);
/* center text */
gtk_label_set_justify (GTK_LABEL (digital), GTK_JUSTIFY_CENTER);
}
static void
xfce_clock_digital_finalize (GObject *object)
{
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (object);
/* cleanup */
g_free (digital->format);
(*G_OBJECT_CLASS (xfce_clock_digital_parent_class)->finalize) (object);
}
static void
xfce_clock_digital_set_property (GObject *object,
guint prop_id,
@ -125,20 +117,19 @@ xfce_clock_digital_set_property (GObject *object,
switch (prop_id)
{
case PROP_DIGITAL_FORMAT:
/* cleanup */
g_free (digital->format);
/* set new format */
digital->format = g_value_dup_string (value);
/* update the widget */
xfce_clock_digital_update (digital);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
/* reschedule the timeout and redraw */
clock_plugin_timeout_set_interval (digital->timeout,
clock_plugin_interval_from_format (digital->format));
xfce_clock_digital_update (digital);
}
@ -165,15 +156,22 @@ xfce_clock_digital_get_property (GObject *object,
GtkWidget *
xfce_clock_digital_new (void)
static void
xfce_clock_digital_finalize (GObject *object)
{
return g_object_new (XFCE_CLOCK_TYPE_DIGITAL, NULL);
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (object);
/* stop the timeout */
clock_plugin_timeout_free (digital->timeout);
g_free (digital->format);
(*G_OBJECT_CLASS (xfce_clock_digital_parent_class)->finalize) (object);
}
gboolean
static gboolean
xfce_clock_digital_update (gpointer user_data)
{
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (user_data);
@ -185,14 +183,9 @@ xfce_clock_digital_update (gpointer user_data)
/* get the local time */
clock_plugin_get_localtime (&tm);
/* get the string */
string = clock_plugin_strdup_strftime (digital->format ? digital->format :
DEFAULT_DIGITAL_FORMAT, &tm);
/* set the new label */
/* set time string */
string = clock_plugin_strdup_strftime (digital->format, &tm);
gtk_label_set_markup (GTK_LABEL (digital), string);
/* cleanup */
g_free (string);
return TRUE;
@ -200,11 +193,8 @@ xfce_clock_digital_update (gpointer user_data)
guint
xfce_clock_digital_interval (XfceClockDigital *digital)
GtkWidget *
xfce_clock_digital_new (void)
{
panel_return_val_if_fail (XFCE_CLOCK_IS_DIGITAL (digital), CLOCK_INTERVAL_SECOND);
return clock_plugin_interval_from_format (digital->format ? digital->format :
DEFAULT_DIGITAL_FORMAT);
return g_object_new (XFCE_CLOCK_TYPE_DIGITAL, NULL);
}

6
plugins/clock/clock-digital.h

@ -34,14 +34,10 @@ typedef struct _XfceClockDigital XfceClockDigital;
GType xfce_clock_digital_get_type (void) G_GNUC_CONST;
void xfce_clock_digital_register_type (GTypeModule *type_module);
void xfce_clock_digital_register_type (GTypeModule *type_module);
GtkWidget *xfce_clock_digital_new (void) G_GNUC_MALLOC;
gboolean xfce_clock_digital_update (gpointer user_data);
guint xfce_clock_digital_interval (XfceClockDigital *digital);
G_END_DECLS
#endif /* !__CLOCK_DIGITAL_H__ */

63
plugins/clock/clock-fuzzy.c

@ -32,14 +32,17 @@
static void xfce_clock_fuzzy_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void xfce_clock_fuzzy_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfce_clock_fuzzy_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void xfce_clock_fuzzy_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfce_clock_fuzzy_finalize (GObject *object);
static gboolean xfce_clock_fuzzy_update (gpointer user_data);
enum
@ -68,8 +71,9 @@ struct _XfceClockFuzzy
{
GtkLabel __parent__;
/* fuzziness */
guint fuzziness;
ClockPluginTimeout *timeout;
guint fuzziness;
};
const gchar *i18n_day_sectors[] =
@ -114,14 +118,16 @@ xfce_clock_fuzzy_class_init (XfceClockFuzzyClass *klass)
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = xfce_clock_fuzzy_set_property;
gobject_class->get_property = xfce_clock_fuzzy_get_property;
gobject_class->finalize = xfce_clock_fuzzy_finalize;
g_object_class_install_property (gobject_class,
PROP_FUZZINESS,
g_param_spec_uint ("fuzziness", NULL, NULL,
FUZZINESS_MIN, FUZZINESS_MAX,
FUZZINESS_MIN,
FUZZINESS_MAX,
FUZZINESS_DEFAULT,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
}
@ -129,10 +135,11 @@ xfce_clock_fuzzy_class_init (XfceClockFuzzyClass *klass)
static void
xfce_clock_fuzzy_init (XfceClockFuzzy *fuzzy)
{
/* init */
fuzzy->fuzziness = FUZZINESS_DEFAULT;
fuzzy->timeout = clock_plugin_timeout_new (CLOCK_INTERVAL_MINUTE,
xfce_clock_fuzzy_update,
fuzzy);
/* center text */
gtk_label_set_justify (GTK_LABEL (fuzzy), GTK_JUSTIFY_CENTER);
}
@ -145,11 +152,17 @@ xfce_clock_fuzzy_set_property (GObject *object,
GParamSpec *pspec)
{
XfceClockFuzzy *fuzzy = XFCE_CLOCK_FUZZY (object);
guint fuzziness;
switch (prop_id)
{
case PROP_FUZZINESS:
fuzzy->fuzziness = MIN (g_value_get_uint (value), FUZZINESS_MAX);
fuzziness = g_value_get_uint (value);
if (G_LIKELY (fuzzy->fuzziness != fuzziness))
{
fuzzy->fuzziness = fuzziness;
xfce_clock_fuzzy_update (fuzzy);
}
break;
default:
@ -182,15 +195,18 @@ xfce_clock_fuzzy_get_property (GObject *object,
GtkWidget *
xfce_clock_fuzzy_new (void)
static void
xfce_clock_fuzzy_finalize (GObject *object)
{
return g_object_new (XFCE_CLOCK_TYPE_FUZZY, NULL);
/* stop the timeout */
clock_plugin_timeout_free (XFCE_CLOCK_FUZZY (object)->timeout);
(*G_OBJECT_CLASS (xfce_clock_fuzzy_parent_class)->finalize) (object);
}
gboolean
static gboolean
xfce_clock_fuzzy_update (gpointer user_data)
{
XfceClockFuzzy *fuzzy = XFCE_CLOCK_FUZZY (user_data);
@ -236,10 +252,9 @@ xfce_clock_fuzzy_update (gpointer user_data)
guint
xfce_clock_fuzzy_interval (XfceClockFuzzy *fuzzy)
{
panel_return_val_if_fail (XFCE_CLOCK_IS_FUZZY (fuzzy), CLOCK_INTERVAL_MINUTE);
return CLOCK_INTERVAL_MINUTE;
GtkWidget *
xfce_clock_fuzzy_new (void)
{
return g_object_new (XFCE_CLOCK_TYPE_FUZZY, NULL);
}

6
plugins/clock/clock-fuzzy.h

@ -34,14 +34,10 @@ typedef struct _XfceClockFuzzy XfceClockFuzzy;
GType xfce_clock_fuzzy_get_type (void) G_GNUC_CONST;
void xfce_clock_fuzzy_register_type (GTypeModule *type_module);
void xfce_clock_fuzzy_register_type (GTypeModule *type_module);
GtkWidget *xfce_clock_fuzzy_new (void) G_GNUC_MALLOC;
gboolean xfce_clock_fuzzy_update (gpointer user_data);
guint xfce_clock_fuzzy_interval (XfceClockFuzzy *fuzzy);
G_END_DECLS
#endif /* !__CLOCK_FUZZY_H__ */

80
plugins/clock/clock-lcd.c

@ -36,7 +36,7 @@
#define RELATIVE_DOTS (3 * RELATIVE_SPACE)
/* prototypes */
static void xfce_clock_lcd_set_property (GObject *object,
guint prop_id,
const GValue *value,
@ -45,6 +45,7 @@ static void xfce_clock_lcd_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfce_clock_lcd_finalize (GObject *object);
static void xfce_clock_lcd_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static gboolean xfce_clock_lcd_expose_event (GtkWidget *widget,
@ -59,7 +60,7 @@ static gdouble xfce_clock_lcd_draw_digit (cairo_t *cr,
gdouble size,
gdouble offset_x,
gdouble offset_y);
static gboolean xfce_clock_lcd_update (gpointer user_data);
enum
@ -80,17 +81,12 @@ struct _XfceClockLcd
{
GtkImage __parent__;
/* whether we show seconds */
guint show_seconds : 1;
/* whether it's a 24h clock */
guint show_military : 1;
/* whether we display am/pm */
guint show_meridiem : 1;
ClockPluginTimeout *timeout;
/* whether to flash the separators */
guint flash_separators : 1;
guint show_seconds : 1;
guint show_military : 1;
guint show_meridiem : 1;
guint flash_separators : 1;
};
@ -108,6 +104,7 @@ xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = xfce_clock_lcd_set_property;
gobject_class->get_property = xfce_clock_lcd_get_property;
gobject_class->finalize = xfce_clock_lcd_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->size_request = xfce_clock_lcd_size_request;
@ -121,7 +118,7 @@ xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
g_param_spec_boolean ("show-seconds", NULL, NULL,
FALSE,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
/**
* Whether we show a 24h clock
@ -131,7 +128,7 @@ xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
g_param_spec_boolean ("show-military", NULL, NULL,
FALSE,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
/**
* Whether we show am or pm
@ -141,7 +138,7 @@ xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
g_param_spec_boolean ("show-meridiem", NULL, NULL,
TRUE,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
/**
* Whether to flash the time separators
@ -151,7 +148,7 @@ xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
g_param_spec_boolean ("flash-separators", NULL, NULL,
FALSE,
G_PARAM_READWRITE
| G_PARAM_STATIC_BLURB));
| G_PARAM_STATIC_STRINGS));
}
@ -159,11 +156,13 @@ xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
static void
xfce_clock_lcd_init (XfceClockLcd *lcd)
{
/* init */
lcd->show_seconds = FALSE;
lcd->show_meridiem = FALSE;
lcd->show_military = TRUE;
lcd->flash_separators = FALSE;
lcd->timeout = clock_plugin_timeout_new (CLOCK_INTERVAL_MINUTE,
xfce_clock_lcd_update,
lcd);
}
@ -175,6 +174,7 @@ xfce_clock_lcd_set_property (GObject *object,
GParamSpec *pspec)
{
XfceClockLcd *lcd = XFCE_CLOCK_LCD (object);
gboolean show_seconds;
switch (prop_id)
{
@ -198,6 +198,12 @@ xfce_clock_lcd_set_property (GObject *object,
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
/* reschedule the timeout and resize */
show_seconds = lcd->show_seconds || lcd->flash_separators;
clock_plugin_timeout_set_interval (lcd->timeout,
show_seconds ? CLOCK_INTERVAL_SECOND : CLOCK_INTERVAL_MINUTE);
gtk_widget_queue_resize (GTK_WIDGET (lcd));
}
@ -236,6 +242,17 @@ xfce_clock_lcd_get_property (GObject *object,
static void
xfce_clock_lcd_finalize (GObject *object)
{
/* stop the timeout */
clock_plugin_timeout_free (XFCE_CLOCK_LCD (object)->timeout);
(*G_OBJECT_CLASS (xfce_clock_lcd_parent_class)->finalize) (object);
}
static void
xfce_clock_lcd_size_request (GtkWidget *widget,
GtkRequisition *requisition)
@ -317,8 +334,12 @@ xfce_clock_lcd_expose_event (GtkWidget *widget,
if (!lcd->show_military && ticks > 12)
ticks -= 12;
/* queue a resize when the number of hour digits changed */
if (G_UNLIKELY ((ticks == 10 || ticks == 0) && tm.tm_min == 0 && tm.tm_sec == 0))
/* 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) && tm.tm_min == 0
&& (!lcd->show_seconds || tm.tm_sec < 3))
gtk_widget_queue_resize (widget);
if (ticks >= 10)
@ -542,15 +563,7 @@ xfce_clock_lcd_draw_digit (cairo_t *cr,
GtkWidget *
xfce_clock_lcd_new (void)
{
return g_object_new (XFCE_CLOCK_TYPE_LCD, NULL);
}
gboolean
static gboolean
xfce_clock_lcd_update (gpointer user_data)
{
GtkWidget *widget = GTK_WIDGET (user_data);
@ -566,13 +579,8 @@ xfce_clock_lcd_update (gpointer user_data)
guint
xfce_clock_lcd_interval (XfceClockLcd *lcd)
GtkWidget *
xfce_clock_lcd_new (void)
{
panel_return_val_if_fail (XFCE_CLOCK_IS_LCD (lcd), CLOCK_INTERVAL_SECOND);
if (lcd->show_seconds || lcd->flash_separators)
return CLOCK_INTERVAL_SECOND;
else
return CLOCK_INTERVAL_MINUTE;
return g_object_new (XFCE_CLOCK_TYPE_LCD, NULL);
}

4
plugins/clock/clock-lcd.h

@ -38,10 +38,6 @@ void xfce_clock_lcd_register_type (GTypeModule *type_module);
GtkWidget *xfce_clock_lcd_new (void) G_GNUC_MALLOC;
gboolean xfce_clock_lcd_update (gpointer user_data);
guint xfce_clock_lcd_interval (XfceClockLcd *lcd);
G_END_DECLS
#endif /* !__CLOCK_LCD_H__ */

867
plugins/clock/clock.c

File diff suppressed because it is too large

39
plugins/clock/clock.h

@ -26,19 +26,13 @@
G_BEGIN_DECLS
#define CLOCK_INTERVAL_SECOND (1000)
#define CLOCK_INTERVAL_MINUTE (60 * 1000)
#define CLOCK_INTERVAL_HOUR (3600 * 1000)
#define CLOCK_INTERVAL_SECOND (1)
#define CLOCK_INTERVAL_MINUTE (60)
#define CLOCK_INTERVAL_HOUR (3600)
#define BUFFER_SIZE 256
#define DEFAULT_TOOLTIP_FORMAT "%A %d %B %Y"
#define DEFAULT_DIGITAL_FORMAT "%R"
typedef struct _ClockPlugin ClockPlugin;
typedef struct _ClockPluginClass ClockPluginClass;
typedef enum _ClockPluginMode ClockPluginMode;
typedef struct _ClockPlugin ClockPlugin;
typedef struct _ClockPluginClass ClockPluginClass;
typedef struct _ClockPluginTimeout ClockPluginTimeout;
#define XFCE_TYPE_CLOCK_PLUGIN (clock_plugin_get_type ())
#define XFCE_CLOCK_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_CLOCK_PLUGIN, ClockPlugin))
@ -49,16 +43,25 @@ typedef enum _ClockPluginMode ClockPluginMode;
GType clock_plugin_get_type (void) G_GNUC_CONST;
GType clock_plugin_get_type (void) G_GNUC_CONST;
void clock_plugin_register_type (GTypeModule *type_module);
ClockPluginTimeout *clock_plugin_timeout_new (guint interval,
GSourceFunc function,
gpointer data);
void clock_plugin_timeout_set_interval (ClockPluginTimeout *timeout,
guint interval);
void clock_plugin_register_type (GTypeModule *type_module);
void clock_plugin_timeout_free (ClockPluginTimeout *timeout);
void clock_plugin_get_localtime (struct tm *tm);
void clock_plugin_get_localtime (struct tm *tm);
gchar *clock_plugin_strdup_strftime (const gchar *format,
const struct tm *tm);
gchar *clock_plugin_strdup_strftime (const gchar *format,
const struct tm *tm);
guint clock_plugin_interval_from_format (const gchar *format);
guint clock_plugin_interval_from_format (const gchar *format);
G_END_DECLS

Loading…
Cancel
Save