Browse Source

* Fix problems with the lcd clock (Bug #3960). Also

use new tooltip api when available.


(Old svn revision: 27440)
upstream/xfce4-panel-4.10.1
Nick Schermer 14 years ago
parent
commit
b7e7def078
  1. 25
      plugins/clock/clock-analog.c
  2. 25
      plugins/clock/clock-binary.c
  3. 6
      plugins/clock/clock-dialog.c
  4. 25
      plugins/clock/clock-digital.c
  5. 58
      plugins/clock/clock-lcd.c
  6. 24
      plugins/clock/clock.c

25
plugins/clock/clock-analog.c

@ -95,28 +95,7 @@ struct _XfceClockAnalog
static GObjectClass *xfce_clock_analog_parent_class;
GType
xfce_clock_analog_get_type (void)
{
static GType type = G_TYPE_INVALID;
if (G_UNLIKELY (type == G_TYPE_INVALID))
{
type = g_type_register_static_simple (GTK_TYPE_IMAGE,
I_("XfceClockAnalog"),
sizeof (XfceClockAnalogClass),
(GClassInitFunc) xfce_clock_analog_class_init,
sizeof (XfceClockAnalog),
(GInstanceInitFunc) xfce_clock_analog_init,
0);
}
return type;
}
G_DEFINE_TYPE (XfceClockAnalog, xfce_clock_analog, GTK_TYPE_IMAGE);
@ -126,8 +105,6 @@ xfce_clock_analog_class_init (XfceClockAnalogClass *klass)
GObjectClass *gobject_class;
GtkWidgetClass *gtkwidget_class;
xfce_clock_analog_parent_class = g_type_class_peek_parent (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = xfce_clock_analog_finalize;
gobject_class->set_property = xfce_clock_analog_set_property;

25
plugins/clock/clock-binary.c

@ -83,28 +83,7 @@ struct _XfceClockBinary
static GObjectClass *xfce_clock_binary_parent_class;
GType
xfce_clock_binary_get_type (void)
{
static GType type = G_TYPE_INVALID;
if (G_UNLIKELY (type == G_TYPE_INVALID))
{
type = g_type_register_static_simple (GTK_TYPE_IMAGE,
I_("XfceClockBinary"),
sizeof (XfceClockBinaryClass),
(GClassInitFunc) xfce_clock_binary_class_init,
sizeof (XfceClockBinary),
(GInstanceInitFunc) xfce_clock_binary_init,
0);
}
return type;
}
G_DEFINE_TYPE (XfceClockBinary, xfce_clock_binary, GTK_TYPE_IMAGE);
@ -114,8 +93,6 @@ xfce_clock_binary_class_init (XfceClockBinaryClass *klass)
GObjectClass *gobject_class;
GtkWidgetClass *gtkwidget_class;
xfce_clock_binary_parent_class = g_type_class_peek_parent (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = xfce_clock_binary_finalize;
gobject_class->set_property = xfce_clock_binary_set_property;

6
plugins/clock/clock-dialog.c

@ -454,7 +454,8 @@ xfce_clock_dialog_options (ClockPlugin *clock)
g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (xfce_clock_dialog_digital_format_changed), clock);
gtk_widget_show (combo);
entry = gtk_entry_new_with_max_length (BUFFER_SIZE-1);
entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry), BUFFER_SIZE - 1);
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
g_object_set_data (G_OBJECT (combo), I_("entry"), entry);
if (!has_active)
@ -538,7 +539,8 @@ xfce_clock_dialog_show (ClockPlugin *clock)
g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (xfce_clock_dialog_tooltip_format_changed), clock);
gtk_widget_show (combo);
entry = gtk_entry_new_with_max_length (BUFFER_SIZE-1);
entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry), BUFFER_SIZE - 1);
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
g_object_set_data (G_OBJECT (combo), I_("entry"), entry);
if (!has_active)

25
plugins/clock/clock-digital.c

@ -68,28 +68,7 @@ struct _XfceClockDigital
static GObjectClass *xfce_clock_digital_parent_class;
GType
xfce_clock_digital_get_type (void)
{
static GType type = G_TYPE_INVALID;
if (G_UNLIKELY (type == G_TYPE_INVALID))
{
type = g_type_register_static_simple (GTK_TYPE_LABEL,
I_("XfceClockDigital"),
sizeof (XfceClockDigitalClass),
(GClassInitFunc) xfce_clock_digital_class_init,
sizeof (XfceClockDigital),
(GInstanceInitFunc) xfce_clock_digital_init,
0);
}
return type;
}
G_DEFINE_TYPE (XfceClockDigital, xfce_clock_digital, GTK_TYPE_LABEL);
@ -98,8 +77,6 @@ xfce_clock_digital_class_init (XfceClockDigitalClass *klass)
{
GObjectClass *gobject_class;
xfce_clock_digital_parent_class = g_type_class_peek_parent (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = xfce_clock_digital_finalize;
gobject_class->set_property = xfce_clock_digital_set_property;

58
plugins/clock/clock-lcd.c

@ -21,7 +21,9 @@
#include <config.h>
#endif
#ifdef HAVE_MATH_H
#include <math.h>
#endif
#include <gtk/gtk.h>
#include <cairo/cairo.h>
@ -95,28 +97,7 @@ struct _XfceClockLcd
static GObjectClass *xfce_clock_lcd_parent_class;
GType
xfce_clock_lcd_get_type (void)
{
static GType type = G_TYPE_INVALID;
if (G_UNLIKELY (type == G_TYPE_INVALID))
{
type = g_type_register_static_simple (GTK_TYPE_IMAGE,
I_("XfceClockLcd"),
sizeof (XfceClockLcdClass),
(GClassInitFunc) xfce_clock_lcd_class_init,
sizeof (XfceClockLcd),
(GInstanceInitFunc) xfce_clock_lcd_init,
0);
}
return type;
}
G_DEFINE_TYPE (XfceClockLcd, xfce_clock_lcd, GTK_TYPE_IMAGE);
@ -126,8 +107,6 @@ xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
GObjectClass *gobject_class;
GtkWidgetClass *gtkwidget_class;
xfce_clock_lcd_parent_class = g_type_class_peek_parent (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = xfce_clock_lcd_finalize;
gobject_class->set_property = xfce_clock_lcd_set_property;
@ -291,9 +270,6 @@ xfce_clock_lcd_size_request (GtkWidget *widget,
requisition->height = height;
requisition->width = height * ratio;
}
/* increase the width with 1 px for rounding errors */
requisition->width++;
}
@ -312,15 +288,22 @@ xfce_clock_lcd_expose_event (GtkWidget *widget,
g_return_val_if_fail (XFCE_CLOCK_IS_LCD (clock), FALSE);
/* get the width:height ratio */
ratio = xfce_clock_lcd_get_ratio (XFCE_CLOCK_LCD (widget));
/* size of a digit should be a fraction of 10 */
size = widget->allocation.height - widget->allocation.height % 10;
/* 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 (floor ((gdouble) widget->allocation.width / ratio), size);
/* begin offsets */
offset_x = widget->allocation.x + (widget->allocation.width - (size * ratio)) / 2;
offset_y = widget->allocation.y + (widget->allocation.height - size) / 2;
offset_x = rint ((widget->allocation.width - (size * ratio)) / 2.00);
offset_y = rint ((widget->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);
/* get the cairo context */
cr = gdk_cairo_create (widget->window);
@ -511,11 +494,18 @@ xfce_clock_lcd_draw_digit (cairo_t *cr,
x = segments_x[segment][j] * size + offset_x;
y = segments_y[segment][j] * size + offset_y;
/* when 0.01 * size is larger then 1, round the numbers */
if (size >= 10)
{
x = floor (x);
y = floor (y);
}
/* leave when there are no valid coordinates */
if (x < 0 || y < 0)
if (x < offset_x || y < offset_y)
break;
if (j == 0)
if (G_UNLIKELY (j == 0))
cairo_move_to (cr, x, y);
else
cairo_line_to (cr, x, y);

24
plugins/clock/clock.c

@ -228,15 +228,17 @@ xfce_clock_tooltip_update (gpointer user_data)
{
ClockPlugin *clock = (ClockPlugin *) user_data;
gchar *string;
static GtkTooltips *tooltips = NULL;
struct tm tm;
if (G_UNLIKELY (clock->tooltip_format == NULL))
return TRUE;
#if !GTK_CHECK_VERSION (2,12,0)
static GtkTooltips *tooltips = NULL;
/* allocate the tooltip on-demand */
if (G_UNLIKELY (tooltips == NULL))
tooltips = gtk_tooltips_new ();
#endif
if (G_UNLIKELY (clock->tooltip_format == NULL))
return TRUE;
/* get the local time */
xfce_clock_util_get_localtime (&tm);
@ -245,7 +247,11 @@ xfce_clock_tooltip_update (gpointer user_data)
string = xfce_clock_util_strdup_strftime (clock->tooltip_format, &tm);
/* set the tooltip */
#if GTK_CHECK_VERSION (2,12,0)
gtk_widget_set_tooltip_text (clock->ebox, string);
#else
gtk_tooltips_set_tip (tooltips, clock->ebox, string, NULL);
#endif
/* cleanup */
g_free (string);
@ -536,6 +542,15 @@ xfce_clock_plugin_set_size (ClockPlugin *clock,
static void
xfce_clock_plugin_set_orientation (ClockPlugin *clock)
{
/* do a size request */
xfce_clock_plugin_set_size (clock, xfce_panel_plugin_get_size (clock->plugin));
}
static void
xfce_clock_plugin_read (ClockPlugin *clock)
{
@ -663,5 +678,6 @@ xfce_clock_plugin_construct (XfcePanelPlugin *plugin)
g_signal_connect_swapped (G_OBJECT (plugin), "save", G_CALLBACK (xfce_clock_plugin_write), clock);
g_signal_connect_swapped (G_OBJECT (plugin), "free-data", G_CALLBACK (xfce_clock_plugin_free), clock);
g_signal_connect_swapped (G_OBJECT (plugin), "configure-plugin", G_CALLBACK (xfce_clock_dialog_show), clock);
g_signal_connect_swapped (G_OBJECT (plugin), "orientation-changed", G_CALLBACK (xfce_clock_plugin_set_orientation), clock);
}

Loading…
Cancel
Save