Commit 2fde0675 authored by Jonny Lamb's avatar Jonny Lamb
Browse files

clock: move into its own widget

parent 6852bd87
/*
* Copyright (C) 2013 Collabora Ltd.
* Copyright (C) 2014 Collabora Ltd.
*
* Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
* Author: Jonny Lamb <jonny.lamb@collabora.co.uk>
*/
#include "config.h"
#include "clock.h"
#include <gtk/gtk.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-wall-clock.h>
enum {
PROP_0,
};
struct WestonGtkClockPrivate {
GnomeWallClock *wall_clock;
GtkWidget *label;
};
G_DEFINE_TYPE(WestonGtkClock, weston_gtk_clock, GTK_TYPE_LABEL)
G_DEFINE_TYPE(WestonGtkClock, weston_gtk_clock, GTK_TYPE_WINDOW)
static void
update_clock (GnomeWallClock *wall_clock,
GParamSpec *pspec,
WestonGtkClock *self)
weston_gtk_clock_init (WestonGtkClock *self)
{
gtk_label_set_text (GTK_LABEL (self), gnome_wall_clock_get_clock (wall_clock));
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
WESTON_GTK_CLOCK_TYPE,
WestonGtkClockPrivate);
}
static void
weston_gtk_clock_dispose (GObject *object)
weston_gtk_clock_constructed (GObject *object)
{
WestonGtkClock *self = WESTON_GTK_CLOCK (object);
g_clear_object (&self->priv->wall_clock);
G_OBJECT_CLASS (weston_gtk_clock_parent_class)->constructed (object);
G_OBJECT_CLASS (weston_gtk_clock_parent_class)->dispose (object);
gtk_window_set_title (GTK_WINDOW (self), "gtk shell");
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
gtk_widget_realize (GTK_WIDGET (self));
gtk_style_context_add_class (
gtk_widget_get_style_context (GTK_WIDGET (self)),
"wgs-clock");
self->priv->label = gtk_label_new ("");
gtk_label_set_markup (GTK_LABEL (self->priv->label),
"<span font=\"Droid Sans 32\">11:47</span>\n"
"<span font=\"Droid Sans 12\">13/02/2014</span>");
gtk_label_set_justify (GTK_LABEL (self->priv->label), GTK_JUSTIFY_CENTER);
gtk_container_add (GTK_CONTAINER (self), self->priv->label);
}
static void
weston_gtk_clock_init (WestonGtkClock *self)
weston_gtk_clock_dispose (GObject *object)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
WESTON_GTK_CLOCK_TYPE,
WestonGtkClockPrivate);
WestonGtkClock *self = WESTON_GTK_CLOCK (object);
self->priv->wall_clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
g_signal_connect (self->priv->wall_clock, "notify::clock",
G_CALLBACK (update_clock), self);
update_clock (self->priv->wall_clock, NULL, self);
G_OBJECT_CLASS (weston_gtk_clock_parent_class)->dispose (object);
}
static void
......@@ -59,6 +58,7 @@ weston_gtk_clock_class_init (WestonGtkClockClass *klass)
{
GObjectClass *object_class = (GObjectClass *)klass;
object_class->constructed = weston_gtk_clock_constructed;
object_class->dispose = weston_gtk_clock_dispose;
g_type_class_add_private (object_class, sizeof (WestonGtkClockPrivate));
......@@ -68,5 +68,5 @@ GtkWidget *
weston_gtk_clock_new (void)
{
return g_object_new (WESTON_GTK_CLOCK_TYPE,
NULL);
NULL);
}
/*
* Copyright (C) 2013 Collabora Ltd.
* Copyright (C) 2014 Collabora Ltd.
*
* Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
* Author: Jonny Lamb <jonny.lamb@collabora.co.uk>
*/
#ifndef __WESTON_GTK_CLOCK_H__
......@@ -9,6 +9,8 @@
#include <gtk/gtk.h>
#include "panel.h"
#define WESTON_GTK_CLOCK_TYPE (weston_gtk_clock_get_type ())
#define WESTON_GTK_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WESTON_GTK_CLOCK_TYPE, WestonGtkClock))
#define WESTON_GTK_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WESTON_GTK_CLOCK_TYPE, WestonGtkClockClass))
......@@ -22,17 +24,21 @@ typedef struct WestonGtkClockPrivate WestonGtkClockPrivate;
struct WestonGtkClock
{
GtkLabel parent;
GtkWindow parent;
WestonGtkClockPrivate *priv;
};
struct WestonGtkClockClass
{
GtkLabelClass parent_class;
GtkWindowClass parent_class;
};
GType weston_gtk_clock_get_type (void) G_GNUC_CONST;
GtkWidget *weston_gtk_clock_new (void);
#define WESTON_GTK_CLOCK_WIDTH (WESTON_GTK_PANEL_WIDTH * 2.6)
#define WESTON_GTK_CLOCK_HEIGHT (WESTON_GTK_PANEL_WIDTH * 2)
GType weston_gtk_clock_get_type (void) G_GNUC_CONST;
GtkWidget * weston_gtk_clock_new (void);
#endif /* __WESTON_GTK_CLOCK_H__ */
......@@ -216,25 +216,12 @@ static GtkWidget *
clock_create (struct desktop *desktop)
{
struct element *clock;
GtkWidget *widget;
GdkWindow *gdk_window;
clock = malloc(sizeof *clock);
memset(clock, 0, sizeof *clock);
clock->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(clock->window), "gtk shell");
gtk_window_set_decorated(GTK_WINDOW(clock->window), FALSE);
gtk_widget_realize(clock->window);
gtk_style_context_add_class (gtk_widget_get_style_context (clock->window),
"wgs-clock");
widget = gtk_label_new ("");
gtk_label_set_markup (GTK_LABEL (widget), "<span font=\"Droid Sans 32\">11:47</span>\n"
"<span font=\"Droid Sans 12\">13/02/2014</span>");
gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_CENTER);
gtk_container_add (GTK_CONTAINER (clock->window), widget);
clock->window = weston_gtk_clock_new();
gdk_window = gtk_widget_get_window(clock->window);
clock->surface = gdk_wayland_window_get_wl_surface(gdk_window);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment