diff options
-rw-r--r-- | endless/eospagemanager.c | 80 | ||||
-rw-r--r-- | endless/eospagemanager.h | 13 | ||||
-rw-r--r-- | endless/eoswindow.c | 78 | ||||
-rw-r--r-- | test/smoke-tests/app-window.js | 2 | ||||
-rw-r--r-- | test/smoke-tests/images/cat_eye.jpg | bin | 0 -> 873906 bytes | |||
-rw-r--r-- | test/smoke-tests/images/dog_eye.jpg | bin | 0 -> 122508 bytes |
6 files changed, 168 insertions, 5 deletions
diff --git a/endless/eospagemanager.c b/endless/eospagemanager.c index 98f6108..9bf6de4 100644 --- a/endless/eospagemanager.c +++ b/endless/eospagemanager.c @@ -96,6 +96,7 @@ struct _EosPageManagerPageInfo gchar *name; gboolean fake_page_actions_visible; GtkWidget *custom_toolbox_widget; + gchar *background; }; struct _EosPageManagerPrivate @@ -121,6 +122,7 @@ enum CHILD_PROP_NAME, CHILD_PROP_PAGE_ACTIONS, CHILD_PROP_CUSTOM_TOOLBOX_WIDGET, + CHILD_PROP_BACKGROUND, NCHILDPROPS }; @@ -401,7 +403,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); } @@ -467,6 +469,9 @@ eos_page_manager_get_child_property (GtkContainer *container, case CHILD_PROP_NAME: g_value_set_string (value, eos_page_manager_get_page_name (self, child)); break; + case CHILD_PROP_BACKGROUND: + g_value_set_string (value, eos_page_manager_get_page_background (self, child)); + break; case CHILD_PROP_PAGE_ACTIONS: g_value_set_boolean (value, @@ -499,6 +504,9 @@ eos_page_manager_set_child_property (GtkContainer *container, case CHILD_PROP_NAME: eos_page_manager_set_page_name (self, child, g_value_get_string (value)); break; + case CHILD_PROP_BACKGROUND: + eos_page_manager_set_page_background (self, child, g_value_get_string (value)); + break; case CHILD_PROP_PAGE_ACTIONS: eos_page_manager_set_page_actions (self, child, @@ -621,6 +629,18 @@ eos_page_manager_class_init (EosPageManagerClass *klass) GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + /** + * EosPageManager:background: + * + * 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] = + g_param_spec_string ("background", "Background", + "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; @@ -973,6 +993,62 @@ eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *self, } /** + * eos_page_manager_get_page_background: + * @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 for more information. + * + * Returns: the background of @page, or the empty string if @page does not have a + * background. + */ +const gchar * +eos_page_manager_get_page_background (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); + + if (info->background == NULL) + return ""; + + return info->background; +} + +/** + * eos_page_manager_set_page_background: + * @self: the page manager + * @page: the page to be renamed + * @background: the URI string for the background image of this page. + * + * Changes the background of @page, which must previously have been added to the + * page manager. + * See #EosPageManager:background for more information. + */ +void +eos_page_manager_set_page_background (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); + + info->background = g_strdup (background); + gtk_widget_child_notify (GTK_WIDGET (self), "background"); + + if (page == eos_page_manager_get_visible_page(self)) + g_object_notify (G_OBJECT (self), "visible-page-background"); +} + +/** * eos_page_manager_remove_page_by_name: * @self: the page manager * @name: the name of the page to remove @@ -1004,4 +1080,4 @@ eos_page_manager_remove_page_by_name (EosPageManager *self, g_signal_emit_by_name (self, "remove", info->page); assert_internal_state (self); -}
\ No newline at end of file +} diff --git a/endless/eospagemanager.h b/endless/eospagemanager.h index 90b52e7..07f03b5 100644 --- a/endless/eospagemanager.h +++ b/endless/eospagemanager.h @@ -110,6 +110,19 @@ EOS_SDK_ALL_API_VERSIONS void eos_page_manager_remove_page_by_name (EosPageManager *self, const gchar *name); +EOS_SDK_ALL_API_VERSIONS +const gchar *eos_page_manager_get_page_background (EosPageManager *self, + GtkWidget *page); + +EOS_SDK_ALL_API_VERSIONS +void eos_page_manager_set_page_background (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); + G_END_DECLS #endif /* EOS_PAGE_MANAGER_H */ diff --git a/endless/eoswindow.c b/endless/eoswindow.c index a42d883..a739a60 100644 --- a/endless/eoswindow.c +++ b/endless/eoswindow.c @@ -4,6 +4,7 @@ #include "eoswindow.h" #include "eosapplication.h" +#include "eospagemanager.h" #include "eostopbar-private.h" #include "eosmainarea-private.h" @@ -32,6 +33,8 @@ * ]| */ +#define _BACKGROUND_IMAGE_CSS_TEMPLATE "EosWindow { background-image: url(\"%s\"); }" + G_DEFINE_TYPE (EosWindow, eos_window, GTK_TYPE_APPLICATION_WINDOW) #define WINDOW_PRIVATE(o) \ @@ -48,8 +51,9 @@ 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; + GtkCssProvider *background_provider; }; enum @@ -319,6 +323,71 @@ eos_window_forall (GtkContainer *container, } static void +set_background_to_page (EosWindow *self, + EosPageManager *page_manager) +{ + gint length; + GError *error = NULL; + GtkCssProvider *provider = self->priv->background_provider; + GdkScreen *screen = gdk_screen_get_default (); + GtkWidget *visible_page = eos_page_manager_get_visible_page (page_manager); + const gchar *background; + gchar background_css[128]; + + if (visible_page != NULL) + { + background = eos_page_manager_get_page_background (page_manager, visible_page); + length = sprintf (background_css, _BACKGROUND_IMAGE_CSS_TEMPLATE, background); + gtk_style_context_remove_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider)); + gtk_css_provider_load_from_data (provider, + background_css, + length, + &error); + gtk_style_context_add_provider_for_screen (screen, + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + if (error != NULL) + { + g_error ("%s", error->message); + } + } +} + +static void +on_background_changed_cb (GtkWidget *child, + GParamSpec *pspec, + gpointer user_data) +{ + if (user_data != NULL) + set_background_to_page (EOS_WINDOW (user_data), EOS_PAGE_MANAGER (child)); +} + +static void +eos_window_add (GtkContainer *container, + GtkWidget *widget) +{ + if (EOS_IS_PAGE_MANAGER (widget)) + { + set_background_to_page (EOS_WINDOW (container), EOS_PAGE_MANAGER (widget)); + g_signal_connect (widget, "notify::visible-page", + G_CALLBACK (on_background_changed_cb), container); + } + GTK_CONTAINER_CLASS (eos_window_parent_class)->add (container, widget); +} + +static void +eos_window_remove (GtkContainer *container, + GtkWidget *widget) +{ + /* This should be safe to call even if @widget is not a page manager or even + an actual child of @container. */ + g_signal_handlers_disconnect_by_func (widget, + on_background_changed_cb, + container); + GTK_CONTAINER_CLASS (eos_window_parent_class)->remove (container, widget); +} + +static void eos_window_class_init (EosWindowClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -339,6 +408,8 @@ eos_window_class_init (EosWindowClass *klass) widget_class->unmap = eos_window_unmap; widget_class->show = eos_window_show; container_class->forall = eos_window_forall; + container_class->add = eos_window_add; + container_class->remove = eos_window_remove; /** * EosWindow:application: @@ -392,6 +463,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 +542,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 +} diff --git a/test/smoke-tests/app-window.js b/test/smoke-tests/app-window.js index 4c1f9c6..702e376 100644 --- a/test/smoke-tests/app-window.js +++ b/test/smoke-tests/app-window.js @@ -100,10 +100,12 @@ const TestApplication = new Lang.Class ({ this._pm = new Endless.PageManager(); this._pm.add(this._page0, { name: "page0", + background: "images/cat_eye.jpg", custom_toolbox_widget: this._toolbox }); this._pm.add(this._page1, { name: "page1", + background: "images/dog_eye.jpg", custom_toolbox_widget: this._toolbox, page_actions: true }); diff --git a/test/smoke-tests/images/cat_eye.jpg b/test/smoke-tests/images/cat_eye.jpg Binary files differnew file mode 100644 index 0000000..b041a3a --- /dev/null +++ b/test/smoke-tests/images/cat_eye.jpg diff --git a/test/smoke-tests/images/dog_eye.jpg b/test/smoke-tests/images/dog_eye.jpg Binary files differnew file mode 100644 index 0000000..9d851c5 --- /dev/null +++ b/test/smoke-tests/images/dog_eye.jpg |