Commit 6373ed59 authored by Jonny Lamb's avatar Jonny Lamb
Browse files

panel: move panel and vertical clock widgets into their own files

parent 2fde0675
......@@ -25,6 +25,10 @@ weston_gtk_shell_SOURCES = \
shell-app-system.h \
sound-applet.c \
sound-applet.h \
panel.c \
panel.h \
vertical-clock.c \
vertical-clock.h \
weston-gtk-shell-resources.c \
weston-gtk-shell-resources.h \
desktop-shell-client-protocol.h \
......
......@@ -13,7 +13,8 @@
#include "clock.h"
#include "favorites.h"
#include "launcher-grid.h"
#include "sound-applet.h"
#include "panel.h"
#include "vertical-clock.h"
extern char **environ; /* defined by libc */
......@@ -41,18 +42,6 @@ struct desktop {
guint initial_panel_timeout_id;
guint hide_panel_idle_id;
/* revealers that show and hide the small clock that's only
* visible when the panel is half-hidden. these should be
* moved from here and should live in the panel's private
* data. */
GtkWidget *revealer_clock;
GtkWidget *revealer_buttons;
/* queue of widgets on which to connect to the
* enter-notify-event signal so we know we're still on the
* panel. */
GQueue *panel_widgets;
};
/* TODO: guessed from the mockups, it'd be nice to have this in stone
......@@ -82,11 +71,6 @@ connect_enter_leave_signals (gpointer data)
g_signal_connect (desktop->clock->window, "leave-notify-event",
G_CALLBACK (panel_window_leave_cb), desktop);
for (l = desktop->panel_widgets->head; l != NULL; l = l->next) {
g_signal_connect (l->data, "enter-notify-event",
G_CALLBACK (panel_window_enter_cb), desktop);
}
return FALSE;
}
......@@ -180,38 +164,6 @@ launcher_grid_toggle (GtkWidget *widget, struct desktop *desktop)
gtk_widget_set_visible (desktop->launcher_grid->window, !grid_visible);
}
static GtkWidget *
small_clock_create (struct desktop *desktop)
{
GtkWidget *box;
GtkWidget *label;
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
label = gtk_label_new ("");
gtk_style_context_add_class (gtk_widget_get_style_context (label),
"wgs-clock");
gtk_widget_set_size_request (label, 31, -1);
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
label = gtk_label_new ("");
gtk_label_set_markup (GTK_LABEL (label), "<span font=\"Droid Sans 12\">11\n"
":\n"
"47</span>");
gtk_style_context_add_class (gtk_widget_get_style_context (label),
"wgs-clock");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
gtk_widget_set_size_request (label, 25, -1);
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
desktop->revealer_clock = gtk_revealer_new ();
gtk_revealer_set_transition_type (GTK_REVEALER (desktop->revealer_clock),
GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
gtk_container_add (GTK_CONTAINER (desktop->revealer_clock), box);
return desktop->revealer_clock;
}
static GtkWidget *
clock_create (struct desktop *desktop)
{
......@@ -252,8 +204,8 @@ panel_window_enter_cb (GtkWidget *widget,
shell_helper_slide_surface_back(desktop->helper,
desktop->clock->surface);
gtk_revealer_set_reveal_child (GTK_REVEALER (desktop->revealer_clock), FALSE);
gtk_revealer_set_reveal_child (GTK_REVEALER (desktop->revealer_buttons), TRUE);
weston_gtk_panel_set_expand(WESTON_GTK_PANEL(desktop->panel->window),
TRUE);
return FALSE;
}
......@@ -276,8 +228,8 @@ leave_panel_idle_cb (gpointer data)
desktop->clock->surface,
25 - 56 - width, 0);
gtk_revealer_set_reveal_child (GTK_REVEALER (desktop->revealer_clock), TRUE);
gtk_revealer_set_reveal_child (GTK_REVEALER (desktop->revealer_buttons), FALSE);
weston_gtk_panel_set_expand(WESTON_GTK_PANEL(desktop->panel->window),
FALSE);
return FALSE;
}
......@@ -311,82 +263,19 @@ panel_hide_timeout_cb (gpointer data)
static void
panel_create(struct desktop *desktop)
{
GdkWindow *gdk_window;
struct element *panel;
GtkWidget *box1, *box2, *box3, *ebox, *button;
GtkWidget *image; /* TODO */
GdkWindow *gdk_window;
panel = malloc(sizeof *panel);
memset(panel, 0, sizeof *panel);
panel->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(panel->window), "gtk shell");
gtk_window_set_decorated(GTK_WINDOW(panel->window), FALSE);
gtk_widget_realize(panel->window);
panel->window = weston_gtk_panel_new();
desktop->initial_panel_timeout_id = g_timeout_add_seconds(2,
panel_hide_timeout_cb,
desktop);
g_signal_connect(panel->window, "app-menu-toggled",
G_CALLBACK(launcher_grid_toggle), desktop);
gtk_style_context_add_class (gtk_widget_get_style_context (panel->window),
"wgs-panel");
box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (panel->window), box1);
/* TODO: clock */
clock_create(desktop);
ebox = gtk_event_box_new ();
gtk_box_pack_start (GTK_BOX (box1), ebox, FALSE, FALSE, 0);
g_queue_push_tail (desktop->panel_widgets, ebox);
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (ebox), box2);
desktop->revealer_buttons = gtk_revealer_new ();
gtk_revealer_set_transition_type (GTK_REVEALER (desktop->revealer_buttons),
GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
gtk_revealer_set_reveal_child (GTK_REVEALER (desktop->revealer_buttons), TRUE);
gtk_box_pack_start (GTK_BOX (box2), desktop->revealer_buttons, FALSE, FALSE, 0);
box3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (desktop->revealer_buttons), box3);
/* TODO: wifi */
image = gtk_image_new_from_icon_name ("network-wireless-signal-excellent-symbolic",
GTK_ICON_SIZE_LARGE_TOOLBAR);
gtk_style_context_add_class (gtk_widget_get_style_context (image),
"wgs-wifi");
gtk_box_pack_start (GTK_BOX (box3), image, FALSE, FALSE, 0);
/* TODO: sound */
image = gtk_image_new_from_icon_name ("audio-volume-high-symbolic",
GTK_ICON_SIZE_LARGE_TOOLBAR);
gtk_style_context_add_class (gtk_widget_get_style_context (image),
"wgs-audio");
gtk_box_pack_start (GTK_BOX (box3), image, FALSE, FALSE, 0);
/* TODO: small clock */
image = small_clock_create (desktop);
gtk_box_pack_start (GTK_BOX (box2), image, FALSE, FALSE, 0);
/* favourites */
ebox = gtk_event_box_new ();
gtk_box_pack_start (GTK_BOX (box1), ebox, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (ebox), weston_gtk_favorites_new ());
g_queue_push_tail (desktop->panel_widgets, ebox);
/* menu */
ebox = gtk_event_box_new ();
gtk_box_pack_end (GTK_BOX (box1), ebox, FALSE, FALSE, 0);
button = weston_gtk_app_icon_new ("view-grid-symbolic");
g_signal_connect (button, "clicked",
G_CALLBACK (launcher_grid_toggle), desktop);
gtk_container_add (GTK_CONTAINER (ebox), button);
g_queue_push_tail (desktop->panel_widgets, ebox);
desktop->initial_panel_timeout_id =
g_timeout_add_seconds(2, panel_hide_timeout_cb, desktop);
/* set it up as the panel */
gdk_window = gtk_widget_get_window(panel->window);
......@@ -535,7 +424,6 @@ main(int argc, char *argv[])
desktop->output = NULL;
desktop->shell = NULL;
desktop->helper = NULL;
desktop->panel_widgets = g_queue_new ();
desktop->gdk_display = gdk_display_get_default();
desktop->display =
......@@ -556,6 +444,7 @@ main(int argc, char *argv[])
css_setup(desktop);
panel_create(desktop);
clock_create(desktop);
launcher_grid_create (desktop);
background_create(desktop);
......
/*
* Copyright (C) 2014 Collabora Ltd.
*
* Author: Jonny Lamb <jonny.lamb@collabora.co.uk>
*/
#include "config.h"
#include "panel.h"
#include "app-icon.h"
#include "favorites.h"
#include "vertical-clock.h"
enum {
APP_MENU_TOGGLED,
N_SIGNALS
};
static guint signals[N_SIGNALS] = { 0 };
struct WestonGtkPanelPrivate {
gboolean hidden;
GtkWidget *revealer_buttons; /* for the wifi and sound buttons */
GtkWidget *revealer_clock; /* for the vertical clock */
};
G_DEFINE_TYPE(WestonGtkPanel, weston_gtk_panel, GTK_TYPE_WINDOW)
static void
weston_gtk_panel_init (WestonGtkPanel *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
WESTON_GTK_PANEL_TYPE,
WestonGtkPanelPrivate);
}
static gboolean
widget_enter_notify_event_cb (GtkWidget *widget,
GdkEventCrossing *event,
WestonGtkPanel *self)
{
g_signal_emit_by_name (self, "enter-notify-event", event);
}
static void
widget_connect_enter_signal (WestonGtkPanel *self,
GtkWidget *widget)
{
g_signal_connect (widget, "enter-notify-event",
G_CALLBACK (widget_enter_notify_event_cb), self);
}
static void
app_menu_button_clicked_cb (GtkButton *button,
WestonGtkPanel *self)
{
g_signal_emit (self, signals[APP_MENU_TOGGLED], 0);
}
static void
weston_gtk_panel_constructed (GObject *object)
{
WestonGtkPanel *self = WESTON_GTK_PANEL (object);
GtkWidget *main_box, *menu_box, *buttons_box;
GtkWidget *ebox;
GtkWidget *image;
GtkWidget *button;
G_OBJECT_CLASS (weston_gtk_panel_parent_class)->constructed (object);
/* window properties */
gtk_window_set_title (GTK_WINDOW (self), "gtk shell");
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
gtk_widget_realize(GTK_WIDGET (self));
/* make it black and slightly alpha */
gtk_style_context_add_class (
gtk_widget_get_style_context (GTK_WIDGET (self)),
"wgs-panel");
/* main vbox */
main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (self), main_box);
/* for the wifi/sound buttons and vertical clock we have a few more
* boxes. the hbox has two cells. in each cell there is a
* GtkRevealer for hiding and showing the content. only one revealer
* is ever visibile at one point and transitions happen at the same
* time so the width stays constant (the animation duration is the
* same). the first revealer contains another box which has the two
* wifi and sound buttons. the second revealer has the vertical
* clock widget.
*/
/* GtkBoxes seem to eat up enter/leave events, so let's use an event
* box for the entire thing. */
ebox = gtk_event_box_new ();
gtk_box_pack_start (GTK_BOX (main_box), ebox, FALSE, FALSE, 0);
widget_connect_enter_signal (self, ebox);
menu_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (ebox), menu_box);
/* revealer for the wifi & sound buttons */
self->priv->revealer_buttons = gtk_revealer_new ();
gtk_revealer_set_transition_type (GTK_REVEALER (self->priv->revealer_buttons),
GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->revealer_buttons),
TRUE);
gtk_box_pack_start (GTK_BOX (menu_box),
self->priv->revealer_buttons, FALSE, FALSE, 0);
/* the box for the wifi & sound buttons */
buttons_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (self->priv->revealer_buttons), buttons_box);
/* wifi button */
image = gtk_image_new_from_icon_name ("network-wireless-signal-excellent-symbolic",
GTK_ICON_SIZE_LARGE_TOOLBAR);
gtk_style_context_add_class (gtk_widget_get_style_context (image),
"wgs-wifi");
gtk_box_pack_start (GTK_BOX (buttons_box), image, FALSE, FALSE, 0);
/* sound button */
image = gtk_image_new_from_icon_name ("audio-volume-high-symbolic",
GTK_ICON_SIZE_LARGE_TOOLBAR);
gtk_style_context_add_class (gtk_widget_get_style_context (image),
"wgs-audio");
gtk_box_pack_start (GTK_BOX (buttons_box), image, FALSE, FALSE, 0);
/* revealer for the vertical clock */
self->priv->revealer_clock = gtk_revealer_new ();
gtk_revealer_set_transition_type (GTK_REVEALER (self->priv->revealer_clock),
GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->revealer_clock),
FALSE);
gtk_box_pack_start (GTK_BOX (menu_box),
self->priv->revealer_clock, FALSE, FALSE, 0);
/* vertical clock */
gtk_container_add (GTK_CONTAINER (self->priv->revealer_clock),
weston_gtk_vertical_clock_new ());
/* end of the menu buttons and vertical clock */
/* favorites */
ebox = gtk_event_box_new ();
gtk_box_pack_start (GTK_BOX (main_box), ebox, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (ebox), weston_gtk_favorites_new ());
widget_connect_enter_signal (self, ebox);
/* bottom app menu button */
ebox = gtk_event_box_new ();
gtk_box_pack_end (GTK_BOX (main_box), ebox, FALSE, FALSE, 0);
button = weston_gtk_app_icon_new ("view-grid-symbolic");
g_signal_connect (button, "clicked",
G_CALLBACK (app_menu_button_clicked_cb), self);
gtk_container_add (GTK_CONTAINER (ebox), button);
widget_connect_enter_signal (self, ebox);
/* done */
self->priv->hidden = FALSE;
}
static void
weston_gtk_panel_class_init (WestonGtkPanelClass *klass)
{
GObjectClass *object_class = (GObjectClass *)klass;
GParamSpec *param_spec;
object_class->constructed = weston_gtk_panel_constructed;
signals[APP_MENU_TOGGLED] = g_signal_new ("app-menu-toggled",
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
NULL, G_TYPE_NONE, 0);
g_type_class_add_private (object_class, sizeof (WestonGtkPanelPrivate));
}
GtkWidget *
weston_gtk_panel_new (void)
{
return g_object_new (WESTON_GTK_PANEL_TYPE,
NULL);
}
void
weston_gtk_panel_set_expand (WestonGtkPanel *self,
gboolean expand)
{
gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->revealer_buttons), expand);
gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->revealer_clock), !expand);
}
/*
* Copyright (C) 2014 Collabora Ltd.
*
* Author: Jonny Lamb <jonny.lamb@collabora.co.uk>
*/
#ifndef __WESTON_GTK_PANEL_H__
#define __WESTON_GTK_PANEL_H__
#include <gtk/gtk.h>
#define WESTON_GTK_PANEL_TYPE (weston_gtk_panel_get_type ())
#define WESTON_GTK_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WESTON_GTK_PANEL_TYPE, WestonGtkPanel))
#define WESTON_GTK_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WESTON_GTK_PANEL_TYPE, WestonGtkPanelClass))
#define WESTON_GTK_IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WESTON_GTK_PANEL_TYPE))
#define WESTON_GTK_IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WESTON_GTK_PANEL_TYPE))
#define WESTON_GTK_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WESTON_GTK_PANEL_TYPE, WestonGtkPanelClass))
typedef struct WestonGtkPanel WestonGtkPanel;
typedef struct WestonGtkPanelClass WestonGtkPanelClass;
typedef struct WestonGtkPanelPrivate WestonGtkPanelPrivate;
struct WestonGtkPanel
{
GtkWindow parent;
WestonGtkPanelPrivate *priv;
};
struct WestonGtkPanelClass
{
GtkWindowClass parent_class;
};
#define WESTON_GTK_PANEL_WIDTH 56
GType weston_gtk_panel_get_type (void) G_GNUC_CONST;
GtkWidget * weston_gtk_panel_new (void);
void weston_gtk_panel_set_expand (WestonGtkPanel *self, gboolean expand);
#endif /* __WESTON_GTK_PANEL_H__ */
/*
* Copyright (C) 2014 Collabora Ltd.
*
* Author: Jonny Lamb <jonny.lamb@collabora.co.uk>
*/
#include "config.h"
#include "vertical-clock.h"
#include "panel.h"
struct WestonGtkVerticalClockPrivate {
GtkWidget *label;
};
G_DEFINE_TYPE(WestonGtkVerticalClock, weston_gtk_vertical_clock, GTK_TYPE_BOX)
/* this widget takes up the entire width of the panel and displays
* padding for the first (panel width - vertical clock width) pixels,
* then shows the vertical clock itself. the idea is to put this into
* a GtkRevealer and only show it when appropriate. */
static void
weston_gtk_vertical_clock_init (WestonGtkVerticalClock *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
WESTON_GTK_VERTICAL_CLOCK_TYPE,
WestonGtkVerticalClockPrivate);
}
static void
weston_gtk_vertical_clock_constructed (GObject *object)
{
WestonGtkVerticalClock *self = WESTON_GTK_VERTICAL_CLOCK (object);
GtkWidget *padding;
gint width;
G_OBJECT_CLASS (weston_gtk_vertical_clock_parent_class)->constructed (object);
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
/* a label just to pad things out to the correct width */
width = WESTON_GTK_PANEL_WIDTH - WESTON_GTK_VERTICAL_CLOCK_WIDTH;
padding = gtk_label_new ("");
gtk_style_context_add_class (gtk_widget_get_style_context (padding),
"wgs-clock");
gtk_widget_set_size_request (padding, width, -1);
gtk_box_pack_start (GTK_BOX (self), padding, FALSE, FALSE, 0);
/* the actual clock label */
self->priv->label = gtk_label_new ("");
gtk_label_set_markup (GTK_LABEL (self->priv->label),
"<span font=\"Droid Sans 12\">11\n"
":\n"
"47</span>");
gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->label),
"wgs-clock");
gtk_label_set_justify (GTK_LABEL (self->priv->label), GTK_JUSTIFY_CENTER);
gtk_widget_set_size_request (self->priv->label,
WESTON_GTK_VERTICAL_CLOCK_WIDTH, -1);
gtk_box_pack_start (GTK_BOX (self), self->priv->label, FALSE, FALSE, 0);
}
static void
weston_gtk_vertical_clock_dispose (GObject *object)
{
WestonGtkVerticalClock *self = WESTON_GTK_VERTICAL_CLOCK (object);
G_OBJECT_CLASS (weston_gtk_vertical_clock_parent_class)->dispose (object);
}
static void
weston_gtk_vertical_clock_class_init (WestonGtkVerticalClockClass *klass)
{
GObjectClass *object_class = (GObjectClass *)klass;
object_class->constructed = weston_gtk_vertical_clock_constructed;
object_class->dispose = weston_gtk_vertical_clock_dispose;
g_type_class_add_private (object_class, sizeof (WestonGtkVerticalClockPrivate));
}
GtkWidget *
weston_gtk_vertical_clock_new (void)
{
return g_object_new (WESTON_GTK_VERTICAL_CLOCK_TYPE,
NULL);
}
/*
* Copyright (C) 2014 Collabora Ltd.
*
* Author: Jonny Lamb <jonny.lamb@collabora.co.uk>
*/
#ifndef __WESTON_GTK_VERTICAL_CLOCK_H__
#define __WESTON_GTK_VERTICAL_CLOCK_H__
#include <gtk/gtk.h>
#define WESTON_GTK_VERTICAL_CLOCK_TYPE (weston_gtk_vertical_clock_get_type ())
#define WESTON_GTK_VERTICAL_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WESTON_GTK_VERTICAL_CLOCK_TYPE, WestonGtkVerticalClock))
#define WESTON_GTK_VERTICAL_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WESTON_GTK_VERTICAL_CLOCK_TYPE, WestonGtkVerticalClockClass))
#define WESTON_GTK_IS_VERTICAL_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WESTON_GTK_VERTICAL_CLOCK_TYPE))
#define WESTON_GTK_IS_VERTICAL_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WESTON_GTK_VERTICAL_CLOCK_TYPE))
#define WESTON_GTK_VERTICAL_CLOCK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WESTON_GTK_VERTICAL_CLOCK_TYPE, WestonGtkVerticalClockClass))
typedef struct WestonGtkVerticalClock WestonGtkVerticalClock;
typedef struct WestonGtkVerticalClockClass WestonGtkVerticalClockClass;
typedef struct WestonGtkVerticalClockPrivate WestonGtkVerticalClockPrivate;
struct WestonGtkVerticalClock
{
GtkBox parent;
WestonGtkVerticalClockPrivate *priv;
};
struct WestonGtkVerticalClockClass
{
GtkBoxClass parent_class;
};
#define WESTON_GTK_VERTICAL_CLOCK_WIDTH 25
GType weston_gtk_vertical_clock_get_type (void) G_GNUC_CONST;
GtkWidget * weston_gtk_vertical_clock_new (void);
#endif /* __WESTON_GTK_VERTICAL_CLOCK_H__ */
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