Removed clock class
authorHugo Villeneuve <hugo@hugovil.com>
Fri, 31 May 2013 23:46:35 +0000 (19:46 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Fri, 31 May 2013 23:46:35 +0000 (19:46 -0400)
src/clock.c
src/clock.h
src/dockapp.c

index 0f808f3..19bb67b 100644 (file)
 #define CALENDAR_MONTH_Y_POSITION_RATIO      0.40
 #define CALENDAR_DAYOFMONTH_Y_POSITION_RATIO 0.92
 
-struct hvclock_gtk_t {
-       GtkDrawingArea parent;
-};
-
-struct hvclock_gtk_class_t {
-       GtkDrawingAreaClass parent_class;
-};
-
-typedef struct hvclock_gtk_t HvClock;
-typedef struct hvclock_gtk_class_t HvClockClass;
-
-#define HVCLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), hvclock_get_type(), \
-                                                HvClock))
-
-G_DEFINE_TYPE(HvClock, hvclock, GTK_TYPE_DRAWING_AREA);
-
 /* Starting mode is clock mode */
 static int hvclock_mode = CLOCK_MODE;
 
@@ -112,7 +96,7 @@ static double
 get_clock_face_radius(GtkWidget *clock)
 {
        /* Compute clock face radius */
-       return (MIN(clock->allocation.width, clock->allocation.height) / 2) - 1;
+       return (MIN(clock->allocation.width, clock->allocation.height) / 2) - 3;
 }
 
 static struct tm *
@@ -415,13 +399,10 @@ hvclock_expose(GtkWidget *clock, GdkEventExpose *event)
 }
 
 static void
-hvclock_redraw_canvas(HvClock *clock)
+hvclock_redraw_canvas(GtkWidget *widget)
 {
-       GtkWidget *widget;
        GdkRegion *region;
 
-       widget = GTK_WIDGET(clock);
-
        if (!widget->window)
                return;
 
@@ -451,52 +432,47 @@ hvclock_button_release(GtkWidget *clock, GdkEventButton *event)
        }
 
        /* Update clock/calendar... */
-       hvclock_redraw_canvas(HVCLOCK(clock));
+       hvclock_redraw_canvas(clock);
 
        return FALSE;
 }
 
-static void
-hvclock_class_init(struct hvclock_gtk_class_t *class)
-{
-       GObjectClass *obj_class;
-       GtkWidgetClass *widget_class;
-
-       obj_class = G_OBJECT_CLASS(class);
-       widget_class = GTK_WIDGET_CLASS(class);
-
-       /* GtkWidget signals */
-       widget_class->expose_event = hvclock_expose;
-       widget_class->button_release_event = hvclock_button_release;
-}
-
 static gboolean
 hvclock_update(gpointer data)
 {
-       HvClock *clock;
-
-       clock = HVCLOCK(data);
+       GtkWidget *clock = GTK_WIDGET(data);
 
        hvclock_redraw_canvas(clock);
 
        return TRUE; /* keep running this event */
 }
 
-static void
-hvclock_init(HvClock *clock)
+void
+hvclock_init(GtkWidget *dockwin, GtkWidget *iconwin)
 {
-       gtk_widget_add_events(GTK_WIDGET(clock), GDK_BUTTON_PRESS_MASK |
+       gtk_widget_add_events(dockwin, GDK_BUTTON_PRESS_MASK |
                              GDK_BUTTON_RELEASE_MASK |
                              GDK_POINTER_MOTION_MASK);
+       gtk_widget_add_events(iconwin, GDK_BUTTON_PRESS_MASK |
+                             GDK_BUTTON_RELEASE_MASK |
+                             GDK_POINTER_MOTION_MASK);
+
+       g_signal_connect(G_OBJECT(dockwin), "expose-event",
+                        G_CALLBACK(hvclock_expose), NULL);
+       g_signal_connect(G_OBJECT(iconwin), "expose-event",
+                        G_CALLBACK(hvclock_expose), NULL);
 
-       hvclock_update(clock);
+       g_signal_connect(G_OBJECT(dockwin), "button-press-event",
+                        G_CALLBACK(hvclock_button_release), NULL);
+       g_signal_connect(G_OBJECT(iconwin), "button-press-event",
+                        G_CALLBACK(hvclock_button_release), NULL);
+       g_signal_connect(G_OBJECT(dockwin), "button-release-event",
+                        G_CALLBACK(hvclock_button_release), NULL);
+       g_signal_connect(G_OBJECT(iconwin), "button-release-event",
+                        G_CALLBACK(hvclock_button_release), NULL);
 
        /* update the clock once a second */
-       g_timeout_add(1000, hvclock_update, clock);
-}
+       g_timeout_add(1000, hvclock_update, iconwin);
 
-GtkWidget *
-hvclock_widget_new(void)
-{
-       return g_object_new(hvclock_get_type(), NULL);
+       hvclock_redraw_canvas(iconwin);
 }
index e9e8cd0..a0e11b0 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <gtk/gtk.h>
 
-GtkWidget *hvclock_widget_new(void);
+void
+hvclock_init(GtkWidget *dockwin, GtkWidget *iconwin);
 
 #endif /* CLOCK_H */
index 7b977cc..59984c3 100644 (file)
@@ -64,11 +64,14 @@ dockapp_init(int argc, char *argv[], char *display_arg, char *geometry_arg)
        dockwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_default_size(GTK_WINDOW(dockwin), ICON_SIZE, ICON_SIZE);
 
-       iconwin = hvclock_widget_new();
-       gtk_container_add(GTK_CONTAINER(dockwin), iconwin);
-       gtk_container_set_border_width(GTK_CONTAINER(dockwin), BWIDTH);
+       iconwin = gtk_window_new(GTK_WINDOW_POPUP);
        g_signal_connect(dockwin, "destroy", G_CALLBACK(gtk_main_quit), NULL);
 
+       gtk_widget_realize(dockwin);
+       gtk_widget_realize(iconwin);
+
+       hvclock_init(dockwin, iconwin);
+
        gtk_widget_show_all(dockwin);
 
        if (hvclock_infos.dockapp_mode == true) {