diff options
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/Makefile.am | 2 | ||||
| -rw-r--r-- | shell/favorites.c | 134 | ||||
| -rw-r--r-- | shell/favorites.h | 38 | ||||
| -rw-r--r-- | shell/gtk-shell.c | 20 |
4 files changed, 189 insertions, 5 deletions
diff --git a/shell/Makefile.am b/shell/Makefile.am index 9fbaa93..44433f0 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -15,6 +15,8 @@ weston_gtk_shell_SOURCES = \ app-launcher.h \ clock.c \ clock.h \ + favorites.c \ + favorites.h \ launcher-grid.c \ launcher-grid.h \ shell-app-system.c \ diff --git a/shell/favorites.c b/shell/favorites.c new file mode 100644 index 0000000..9d3d021 --- /dev/null +++ b/shell/favorites.c @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2013 Collabora Ltd. + * + * Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> + */ + +#include "config.h" + +#include "favorites.h" + +#include <gio/gio.h> +#include <gio/gdesktopappinfo.h> +#include <gtk/gtk.h> + +enum { + PROP_0, +}; + +struct WestonGtkFavoritesPrivate { + GSettings *settings; +}; + +G_DEFINE_TYPE(WestonGtkFavorites, weston_gtk_favorites, GTK_TYPE_BOX) + +static void +favorite_clicked (GtkButton *button, + WestonGtkFavorites *self) +{ + GAppInfo *info = g_object_get_data (G_OBJECT(button), "info"); + GError *error = NULL; + + g_app_info_launch (info, NULL, NULL, &error); + if (error) + { + g_warning ("Could not launch app %s: %s", + g_app_info_get_name (info), + error->message); + g_clear_error (&error); + } +} + +static void +add_favorite (WestonGtkFavorites *self, + const gchar *favorite) +{ + GDesktopAppInfo *info; + GtkWidget *button, *image; + GIcon *icon; + + info = g_desktop_app_info_new (favorite); + + if (!info) + return; + + icon = g_app_info_get_icon (G_APP_INFO (info)); + image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU); + button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (button), image); + + g_object_set_data_full (G_OBJECT (button), "info", info, g_object_unref); + + g_signal_connect (button, "clicked", G_CALLBACK (favorite_clicked), self); + + gtk_box_pack_end (GTK_BOX (self), button, FALSE, FALSE, 0); +} + +static void +remove_favorite (GtkWidget *favorite, + gpointer user_data) +{ + gtk_widget_destroy (favorite); +} + +static void +favorites_changed (GSettings *settings, + const gchar *key, + WestonGtkFavorites *self) +{ + gchar **favorites = g_settings_get_strv (settings, key); + gint i; + + /* Remove all favorites first */ + gtk_container_foreach (GTK_CONTAINER (self), remove_favorite, NULL); + + for (i = 0; i < g_strv_length (favorites); i++) + { + gchar *fav = favorites[i]; + + add_favorite (self, fav); + } + + g_strfreev (favorites); +} + +static void +weston_gtk_favorites_dispose (GObject *object) +{ + WestonGtkFavorites *self = WESTON_GTK_FAVORITES (object); + + g_clear_object (&self->priv->settings); + + G_OBJECT_CLASS (weston_gtk_favorites_parent_class)->dispose (object); +} + +static void +weston_gtk_favorites_init (WestonGtkFavorites *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + WESTON_GTK_TYPE_FAVORITES, + WestonGtkFavoritesPrivate); + + self->priv->settings = g_settings_new ("org.raspberrypi.weston-gtk-shell"); + g_signal_connect (self->priv->settings, "changed::favorites", + G_CALLBACK (favorites_changed), self); + favorites_changed (self->priv->settings, "favorites", self); + + gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL); +} + +static void +weston_gtk_favorites_class_init (WestonGtkFavoritesClass *klass) +{ + GObjectClass *object_class = (GObjectClass *)klass; + + object_class->dispose = weston_gtk_favorites_dispose; + + g_type_class_add_private (object_class, sizeof (WestonGtkFavoritesPrivate)); +} + +GtkWidget * +weston_gtk_favorites_new (void) +{ + return g_object_new (WESTON_GTK_TYPE_FAVORITES, NULL); +} diff --git a/shell/favorites.h b/shell/favorites.h new file mode 100644 index 0000000..4c192e1 --- /dev/null +++ b/shell/favorites.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2013 Collabora Ltd. + * + * Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> + */ + +#ifndef __WESTON_GTK_FAVORITES_H__ +#define __WESTON_GTK_FAVORITES_H__ + +#include <gtk/gtk.h> + +#define WESTON_GTK_TYPE_FAVORITES (weston_gtk_favorites_get_type ()) +#define WESTON_GTK_FAVORITES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WESTON_GTK_TYPE_FAVORITES, WestonGtkFavorites)) +#define WESTON_GTK_FAVORITES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WESTON_GTK_TYPE_FAVORITES, WestonGtkFavoritesClass)) +#define WESTON_GTK_IS_FAVORITES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WESTON_GTK_TYPE_FAVORITES)) +#define WESTON_GTK_IS_FAVORITES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WESTON_GTK_TYPE_FAVORITES)) +#define WESTON_GTK_FAVORITES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WESTON_GTK_TYPE_FAVORITES, WestonGtkFavoritesClass)) + +typedef struct WestonGtkFavorites WestonGtkFavorites; +typedef struct WestonGtkFavoritesClass WestonGtkFavoritesClass; +typedef struct WestonGtkFavoritesPrivate WestonGtkFavoritesPrivate; + +struct WestonGtkFavorites +{ + GtkBox parent; + + WestonGtkFavoritesPrivate *priv; +}; + +struct WestonGtkFavoritesClass +{ + GtkBoxClass parent_class; +}; + +GType weston_gtk_favorites_get_type (void) G_GNUC_CONST; +GtkWidget *weston_gtk_favorites_new (void); + +#endif /* __WESTON_GTK_FAVORITES_H__ */ diff --git a/shell/gtk-shell.c b/shell/gtk-shell.c index dc94591..2d6dc13 100644 --- a/shell/gtk-shell.c +++ b/shell/gtk-shell.c @@ -5,8 +5,9 @@ #include <gdk/gdkwayland.h> #include "desktop-shell-client-protocol.h" -#include "launcher-grid.h" #include "clock.h" +#include "favorites.h" +#include "launcher-grid.h" extern char **environ; /* defined by libc */ @@ -112,7 +113,7 @@ panel_create(struct desktop *desktop) { GdkWindow *gdk_window; struct element *panel; - GtkWidget *box1, *button; + GtkWidget *box1, *box2, *button; panel = malloc(sizeof *panel); memset(panel, 0, sizeof *panel); @@ -126,13 +127,22 @@ panel_create(struct desktop *desktop) box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_container_add (GTK_CONTAINER (panel->window), box1); + /* We have a box on the left and a box on the right set to expand + * so that they both have the same size and thus the favorites end + * exactly in the middle of the panel. + */ + box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); button = gtk_button_new_with_label ("Menu"); g_signal_connect (button, "clicked", G_CALLBACK (launcher_grid_toggle), desktop); - gtk_box_pack_start (GTK_BOX(box1), button, FALSE, FALSE, 0); - gtk_widget_show (button); + gtk_box_pack_start (GTK_BOX (box2), button, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); + + gtk_box_pack_start (GTK_BOX (box1), weston_gtk_favorites_new (), FALSE, FALSE, 0); - gtk_box_pack_end (GTK_BOX(box1), weston_gtk_clock_new (), FALSE, FALSE, 6); + box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_end (GTK_BOX (box2), weston_gtk_clock_new (), FALSE, FALSE, 6); + gtk_box_pack_end (GTK_BOX (box1), box2, TRUE, TRUE, 0); gtk_widget_show_all (box1); |
