summaryrefslogtreecommitdiff
path: root/endless
diff options
context:
space:
mode:
Diffstat (limited to 'endless')
-rw-r--r--endless/eospagemanager.c90
-rw-r--r--endless/eospagemanager.h9
-rw-r--r--endless/eoswindow.c92
3 files changed, 183 insertions, 8 deletions
diff --git a/endless/eospagemanager.c b/endless/eospagemanager.c
index 28eaa13..3919b5b 100644
--- a/endless/eospagemanager.c
+++ b/endless/eospagemanager.c
@@ -58,14 +58,14 @@
* |[
* gtk_container_add_with_properties (GTK_CONTAINER (page_manager), page,
* "name", "front-page",
- * "background", "image.jpg",
+ * "background_uri", "image.jpg",
* NULL);
* ]|
* In Javascript, this has been simplified to use JSON:
* |[
* page_manager.add(page, {
* name: 'front-page',
- * background: 'image.jpg'
+ * background_uri: 'image.jpg'
* });
* ]|
* To remove a page, use gtk_container_remove() or
@@ -97,6 +97,7 @@ struct _EosPageManagerPageInfo
gchar *name;
gboolean fake_page_actions_visible;
GtkWidget *custom_toolbox_widget;
+ gchar *background_uri;
};
struct _EosPageManagerPrivate
@@ -122,6 +123,7 @@ enum
CHILD_PROP_NAME,
CHILD_PROP_PAGE_ACTIONS,
CHILD_PROP_CUSTOM_TOOLBOX_WIDGET,
+ CHILD_PROP_BACKGROUND_URI,
NCHILDPROPS
};
@@ -132,6 +134,7 @@ static void
page_info_free (EosPageManagerPageInfo *info)
{
g_free (info->name);
+ g_free (info->background_uri);
g_slice_free (EosPageManagerPageInfo, info);
}
@@ -399,7 +402,7 @@ eos_page_manager_add (GtkContainer *container,
/* If there were no pages yet, then this one must become the visible one */
if (self->priv->visible_page_info == NULL)
- self->priv->visible_page_info = info;
+ eos_page_manager_set_visible_page (self, new_page);
assert_internal_state (self);
}
@@ -466,6 +469,12 @@ eos_page_manager_get_child_property (GtkContainer *container,
g_value_set_string (value, eos_page_manager_get_page_name (self, child));
break;
+ case CHILD_PROP_BACKGROUND_URI:
+ g_value_set_string (value,
+ eos_page_manager_get_page_background_uri (self,
+ child));
+ break;
+
case CHILD_PROP_PAGE_ACTIONS:
g_value_set_boolean (value,
eos_page_manager_get_page_actions (self, child));
@@ -498,6 +507,11 @@ eos_page_manager_set_child_property (GtkContainer *container,
eos_page_manager_set_page_name (self, child, g_value_get_string (value));
break;
+ case CHILD_PROP_BACKGROUND_URI:
+ eos_page_manager_set_page_background_uri (self, child,
+ g_value_get_string (value));
+ break;
+
case CHILD_PROP_PAGE_ACTIONS:
eos_page_manager_set_page_actions (self, child,
g_value_get_boolean (value));
@@ -619,6 +633,18 @@ eos_page_manager_class_init (EosPageManagerClass *klass)
GTK_TYPE_WIDGET,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ /**
+ * EosPageManager:background-uri:
+ *
+ * The URI for the image file for the background of this page. Setting this to
+ * %NULL indicates that the window's default background should be used.
+ */
+ eos_page_manager_child_props[CHILD_PROP_BACKGROUND_URI] =
+ g_param_spec_string ("background-uri", "Background URI",
+ "URI for background of the page",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
/* Install child properties all at once, because there is no
gtk_container_class_install_child_properties() function */
int count;
@@ -678,7 +704,7 @@ eos_page_manager_get_visible_page (EosPageManager *self)
{
g_return_val_if_fail (EOS_IS_PAGE_MANAGER (self), NULL);
- if(self->priv->visible_page_info == NULL)
+ if (self->priv->visible_page_info == NULL)
return NULL;
return self->priv->visible_page_info->page;
@@ -724,7 +750,7 @@ eos_page_manager_get_visible_page_name (EosPageManager *self)
{
g_return_val_if_fail (EOS_IS_PAGE_MANAGER (self), NULL);
- if(self->priv->visible_page_info == NULL)
+ if (self->priv->visible_page_info == NULL)
return NULL;
return self->priv->visible_page_info->name;
@@ -969,6 +995,60 @@ eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *self,
}
/**
+ * eos_page_manager_get_page_background_uri:
+ * @self: the page manager
+ * @page: the page to be queried
+ *
+ * Gets the URI for the background image of @page, which must previously have
+ * been added to the page manager.
+ * See #EosPageManager:background-uri for more information.
+ *
+ * Returns: the background of @page, or the %NULL if @page does not have a
+ * background.
+ */
+const gchar *
+eos_page_manager_get_page_background_uri (EosPageManager *self,
+ GtkWidget *page)
+{
+ g_return_val_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self), NULL);
+ g_return_val_if_fail (page != NULL && GTK_IS_WIDGET (page), NULL);
+
+ EosPageManagerPageInfo *info = find_page_info_by_widget (self, page);
+ g_return_val_if_fail (info != NULL, NULL);
+
+ return info->background_uri;
+}
+
+/**
+ * eos_page_manager_set_page_background_uri:
+ * @self: the page manager
+ * @page: the page to be modified
+ * @background: (allow-none): the URI for the background image of this page.
+ *
+ * Changes the background of @page, which must previously have been added to the
+ * page manager.
+ * Setting %NULL removes the background, using the window's default background.
+ * See #EosPageManager:background-uri for more information.
+ */
+void
+eos_page_manager_set_page_background_uri (EosPageManager *self,
+ GtkWidget *page,
+ const gchar *background)
+{
+ g_return_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self));
+ g_return_if_fail (page != NULL && GTK_IS_WIDGET (page));
+
+ EosPageManagerPageInfo *info = find_page_info_by_widget (self, page);
+ g_return_if_fail (info != NULL);
+
+ if (g_strcmp0 (info->background_uri, background) == 0)
+ return;
+
+ info->background_uri = g_strdup (background);
+ gtk_container_child_notify (GTK_CONTAINER (self), page, "background-uri");
+}
+
+/**
* eos_page_manager_remove_page_by_name:
* @self: the page manager
* @name: the name of the page to remove
diff --git a/endless/eospagemanager.h b/endless/eospagemanager.h
index 90b52e7..a05800a 100644
--- a/endless/eospagemanager.h
+++ b/endless/eospagemanager.h
@@ -107,6 +107,15 @@ void eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *se
GtkWidget *custom_toolbox_widget);
EOS_SDK_ALL_API_VERSIONS
+const gchar *eos_page_manager_get_page_background_uri (EosPageManager *self,
+ GtkWidget *page);
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_page_manager_set_page_background_uri (EosPageManager *self,
+ GtkWidget *page,
+ const gchar *background);
+
+EOS_SDK_ALL_API_VERSIONS
void eos_page_manager_remove_page_by_name (EosPageManager *self,
const gchar *name);
diff --git a/endless/eoswindow.c b/endless/eoswindow.c
index a42d883..7804663 100644
--- a/endless/eoswindow.c
+++ b/endless/eoswindow.c
@@ -1,9 +1,11 @@
/* Copyright 2013 Endless Mobile, Inc. */
#include "config.h"
+#include "string.h"
#include "eoswindow.h"
#include "eosapplication.h"
+#include "eospagemanager.h"
#include "eostopbar-private.h"
#include "eosmainarea-private.h"
@@ -32,6 +34,18 @@
* ]|
*/
+// Put in a transition for fun, should be part of API though someday...
+#define BACKGROUND_IMAGE_CSS_TEMPLATE \
+ "EosWindow { background-image: url(\"%s\");" \
+ "transition-property: background-image;" \
+ "transition-duration: 0.5s;" \
+ "background-size:100%% 100%%; }"
+#define EMPTY_BACKGROUND_CSS \
+ "EosWindow { background-image: none;" \
+ "transition-property: background-image;" \
+ "transition-duration: 0.5s;" \
+ "background-size:100% 100%; }"
+
G_DEFINE_TYPE (EosWindow, eos_window, GTK_TYPE_APPLICATION_WINDOW)
#define WINDOW_PRIVATE(o) \
@@ -48,8 +62,10 @@ struct _EosWindowPrivate
/* For keeping track of what to display alongside the current page */
GtkWidget *current_page;
- gulong child_page_actions_handler;
- gulong child_custom_toolbox_handler;
+ gulong child_page_actions_handler;
+ gulong child_custom_toolbox_handler;
+ gulong child_background_handler;
+ GtkCssProvider *background_provider;
};
enum
@@ -113,6 +129,67 @@ update_page_toolbox (EosWindow *self)
}
}
+static void
+remove_page_background (EosWindow *self)
+{
+ GtkStyleProvider *provider =
+ GTK_STYLE_PROVIDER (self->priv->background_provider);
+ GdkScreen *screen = gdk_screen_get_default ();
+ GError *error = NULL;
+
+ gtk_style_context_remove_provider_for_screen (screen, provider);
+ gtk_css_provider_load_from_data (self->priv->background_provider,
+ EMPTY_BACKGROUND_CSS, -1,
+ &error);
+ gtk_style_context_add_provider_for_screen (screen, provider,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ if (error != NULL)
+ g_warning ("Error loading background CSS: %s", error->message);
+}
+
+/*
+ * update_page_background:
+ * @self: the window
+ *
+ * Ensures that the window's background image is in line with the currently
+ * showing page and its child properties.
+ */
+static void
+update_page_background (EosWindow *self)
+{
+ EosPageManager *pm = EOS_PAGE_MANAGER (self->priv->page_manager);
+ GtkWidget *page = self->priv->current_page;
+
+ if (page == NULL)
+ {
+ remove_page_background (self);
+ return;
+ }
+
+ const gchar *background = eos_page_manager_get_page_background_uri (pm, page);
+ if (background == NULL)
+ {
+ remove_page_background (self);
+ return;
+ }
+
+ gchar *background_css = g_strdup_printf (BACKGROUND_IMAGE_CSS_TEMPLATE,
+ background);
+
+ GtkStyleProvider *provider =
+ GTK_STYLE_PROVIDER (self->priv->background_provider);
+ GdkScreen *screen = gdk_screen_get_default ();
+ GError *error = NULL;
+
+ gtk_style_context_remove_provider_for_screen (screen, provider);
+ gtk_css_provider_load_from_data (self->priv->background_provider,
+ background_css, -1, &error);
+ gtk_style_context_add_provider_for_screen (screen, provider,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ if (error != NULL)
+ g_warning ("Error loading background CSS: %s", error->message);
+}
+
/*
* update_page:
* @self: the window
@@ -131,12 +208,15 @@ update_page (EosWindow *self)
self->priv->child_page_actions_handler);
g_signal_handler_disconnect (self->priv->current_page,
self->priv->child_custom_toolbox_handler);
+ g_signal_handler_disconnect (self->priv->current_page,
+ self->priv->child_background_handler);
}
self->priv->current_page = eos_page_manager_get_visible_page (pm);
update_page_actions (self);
update_page_toolbox (self);
+ update_page_background (self);
if (self->priv->current_page)
{
@@ -150,6 +230,11 @@ update_page (EosWindow *self)
"child-notify::custom-toolbox-widget",
G_CALLBACK (update_page_toolbox),
self);
+ self->priv->child_background_handler =
+ g_signal_connect_swapped (self->priv->current_page,
+ "child-notify::background-uri",
+ G_CALLBACK (update_page_background),
+ self);
}
}
@@ -392,6 +477,7 @@ eos_window_init (EosWindow *self)
{
self->priv = WINDOW_PRIVATE (self);
+ self->priv->background_provider = gtk_css_provider_new ();
self->priv->top_bar = eos_top_bar_new ();
gtk_widget_set_parent (self->priv->top_bar, GTK_WIDGET (self));
@@ -470,4 +556,4 @@ eos_window_set_page_manager (EosWindow *self,
g_signal_connect_swapped (self->priv->page_manager, "notify::visible-page",
G_CALLBACK (update_page), self);
-} \ No newline at end of file
+}