summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/reference/endless/endless-sections.txt2
-rw-r--r--endless/eospagemanager.c75
-rw-r--r--endless/eospagemanager.h3
-rw-r--r--endless/eoswindow.c145
-rw-r--r--test/test-page-manager.c34
5 files changed, 97 insertions, 162 deletions
diff --git a/docs/reference/endless/endless-sections.txt b/docs/reference/endless/endless-sections.txt
index 329eaf9..1ae685d 100644
--- a/docs/reference/endless/endless-sections.txt
+++ b/docs/reference/endless/endless-sections.txt
@@ -55,6 +55,8 @@ eos_page_manager_get_page_actions
eos_page_manager_set_page_actions
eos_page_manager_get_page_custom_toolbox_widget
eos_page_manager_set_page_custom_toolbox_widget
+eos_page_manager_get_page_background
+eos_page_manager_set_page_background
eos_page_manager_remove_page_by_name
<SUBSECTION Standard>
EOS_IS_PAGE_MANAGER
diff --git a/endless/eospagemanager.c b/endless/eospagemanager.c
index 9d23bd5..b8d7c1e 100644
--- a/endless/eospagemanager.c
+++ b/endless/eospagemanager.c
@@ -96,7 +96,7 @@ struct _EosPageManagerPageInfo
gchar *name;
gboolean fake_page_actions_visible;
GtkWidget *custom_toolbox_widget;
- gchar *background;
+ gchar *background_uri;
};
struct _EosPageManagerPrivate
@@ -113,7 +113,6 @@ enum
PROP_0,
PROP_VISIBLE_PAGE,
PROP_VISIBLE_PAGE_NAME,
- PROP_VISIBLE_PAGE_BACKGROUND,
NPROPS
};
@@ -134,6 +133,7 @@ static void
page_info_free (EosPageManagerPageInfo *info)
{
g_free (info->name);
+ g_free (info->background_uri);
g_slice_free (EosPageManagerPageInfo, info);
}
@@ -226,7 +226,6 @@ set_visible_page_from_info (EosPageManager *self,
GObject *self_object = G_OBJECT (self);
g_object_notify(self_object, "visible-page");
g_object_notify(self_object, "visible-page-name");
- g_object_notify(self_object, "visible-page-background");
}
static void
@@ -247,10 +246,6 @@ eos_page_manager_get_property (GObject *object,
g_value_set_string (value, eos_page_manager_get_visible_page_name (self));
break;
- case PROP_VISIBLE_PAGE_BACKGROUND:
- g_value_set_string (value, eos_page_manager_get_visible_page_background (self));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -475,8 +470,10 @@ 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));
+ g_value_set_string (value,
+ eos_page_manager_get_page_background (self, child));
break;
case CHILD_PROP_PAGE_ACTIONS:
@@ -510,8 +507,10 @@ 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));
+ eos_page_manager_set_page_background (self, child,
+ g_value_get_string (value));
break;
case CHILD_PROP_PAGE_ACTIONS:
@@ -589,21 +588,6 @@ eos_page_manager_class_init (EosPageManagerClass *klass)
"",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- /**
- * EosPageManager:visible-page-background:
- *
- * The name of URI for the page that is currently being displayed by the
- * page manager. If the page manager has no pages, then this is %NULL.
- * However, if there is a page currently being displayed but it has no name,
- * then this is the empty string (<code>""</code>).
- */
- eos_page_manager_props[PROP_VISIBLE_PAGE_BACKGROUND] =
- g_param_spec_string ("visible-page-background", "Visible background URI",
- "URI for the background of page currently displaying"
- "in the page manager",
- "",
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
g_object_class_install_properties (object_class, NPROPS,
eos_page_manager_props);
@@ -802,29 +786,6 @@ eos_page_manager_set_visible_page_name (EosPageManager *self,
}
/**
- * eos_page_manager_get_visible_page_background:
- * @self: the page manager
- *
- * Gets the background of the page widget that @self is currently displaying.
- * See #EosPageManager:visible-page for more information.
- *
- * Returns: the background of the page, or %NULL if @self does not have any pages,
- * or the empty string if the page does not have a background.
- */
-const gchar *
-eos_page_manager_get_visible_page_background (EosPageManager *self)
-{
- // TODO: if page managers are nested, this shows the value for the leaf
- // (non-page manager) page background URI.
- g_return_val_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self), NULL);
-
- if (self->priv->visible_page_info == NULL)
- return NULL;
-
- return self->priv->visible_page_info->background;
-}
-
-/**
* eos_page_manager_get_page_name:
* @self: the page manager
* @page: the page to be queried
@@ -1045,7 +1006,7 @@ eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *self,
* 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
+ * Returns: the background of @page, or the %NULL if @page does not have a
* background.
*/
const gchar *
@@ -1058,20 +1019,18 @@ eos_page_manager_get_page_background (EosPageManager *self,
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;
+ return info->background_uri;
}
/**
* 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.
+ * @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 for more information.
*/
void
@@ -1085,11 +1044,11 @@ eos_page_manager_set_page_background (EosPageManager *self,
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 (g_strcmp0 (info->background_uri, background) == 0)
+ return;
- if (page == eos_page_manager_get_visible_page(self))
- g_object_notify (G_OBJECT (self), "visible-page-background");
+ info->background_uri = g_strdup (background);
+ gtk_container_child_notify (GTK_CONTAINER (self), page, "background");
}
/**
diff --git a/endless/eospagemanager.h b/endless/eospagemanager.h
index 40de4bc..73ac28f 100644
--- a/endless/eospagemanager.h
+++ b/endless/eospagemanager.h
@@ -80,9 +80,6 @@ void eos_page_manager_set_visible_page_name (EosPageManager *se
const gchar *page_name);
EOS_SDK_ALL_API_VERSIONS
-const gchar *eos_page_manager_get_visible_page_background (EosPageManager *self);
-
-EOS_SDK_ALL_API_VERSIONS
const gchar *eos_page_manager_get_page_name (EosPageManager *self,
GtkWidget *page);
diff --git a/endless/eoswindow.c b/endless/eoswindow.c
index 80fd118..9fd2486 100644
--- a/endless/eoswindow.c
+++ b/endless/eoswindow.c
@@ -35,10 +35,16 @@
*/
// 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 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)
@@ -58,6 +64,7 @@ struct _EosWindowPrivate
GtkWidget *current_page;
gulong child_page_actions_handler;
gulong child_custom_toolbox_handler;
+ gulong child_background_handler;
GtkCssProvider *background_provider;
};
@@ -122,6 +129,63 @@ 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:
+ */
+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 (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
@@ -140,12 +204,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)
{
@@ -159,6 +226,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",
+ G_CALLBACK (update_page_background),
+ self);
}
}
@@ -328,69 +400,6 @@ eos_window_forall (GtkContainer *container,
}
static void
-set_background_to_page (EosWindow *self,
- EosPageManager *page_manager)
-{
- GtkCssProvider *provider = self->priv->background_provider;
- GdkScreen *screen = gdk_screen_get_default ();
- const gchar *background = eos_page_manager_get_visible_page_background (page_manager);
- gint background_css_length = strlen (background) + strlen (_BACKGROUND_IMAGE_CSS_TEMPLATE) + 1;
- gchar background_css[background_css_length];
- GError *error = NULL;
-
- if (background != NULL && strlen (background) > 0)
- {
- 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,
- 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-background",
- 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);
@@ -411,8 +420,6 @@ 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:
diff --git a/test/test-page-manager.c b/test/test-page-manager.c
index ce5bf35..fa09736 100644
--- a/test/test-page-manager.c
+++ b/test/test-page-manager.c
@@ -128,20 +128,6 @@ test_pm_prop_visible_page_name (PageManagerFixture *fixture,
}
static void
-test_pm_prop_visible_page_background (PageManagerFixture *fixture,
- gconstpointer unused)
-{
- gchar *name;
- g_object_get (fixture->pm, "visible-page-background", &name, NULL);
- g_assert_cmpstr (name, !=, EXPECTED_PAGE_BACKGROUND);
- g_free (name);
- g_object_set (fixture->pm, "visible-page-name", EXPECTED_PAGE_NAME, NULL);
- g_object_get (fixture->pm, "visible-page-background", &name, NULL);
- g_assert_cmpstr (name, ==, EXPECTED_PAGE_BACKGROUND);
- g_free (name);
-}
-
-static void
test_pm_get_set_page_name (PageManagerFixture *fixture,
gconstpointer unused)
{
@@ -366,11 +352,11 @@ test_pm_page_no_background (PageManagerFixture *fixture,
GtkWidget *new_page = gtk_label_new("new");
gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
background_get = eos_page_manager_get_page_background (EOS_PAGE_MANAGER (fixture->pm), new_page);
- g_assert_cmpstr (background_get, ==, "");
+ g_assert_cmpstr (background_get, ==, NULL);
gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page,
"background", &background_prop,
NULL);
- g_assert_cmpstr (background_prop, ==, "");
+ g_assert_cmpstr (background_prop, ==, NULL);
g_free (background_prop);
}
@@ -470,18 +456,6 @@ test_empty_pm_visible_page_name (PageManagerFixture *fixture,
}
static void
-test_empty_pm_visible_page_background (PageManagerFixture *fixture,
- gconstpointer unused)
-{
- const gchar *background_get;
- gchar *background_prop;
- background_get = eos_page_manager_get_visible_page_background (EOS_PAGE_MANAGER (fixture->pm));
- g_assert (background_get == NULL);
- g_object_get (fixture->pm, "visible-page-background", &background_prop, NULL);
- g_assert (background_prop == NULL);
-}
-
-static void
test_empty_pm_add_page_behavior (PageManagerFixture *fixture,
gconstpointer unused)
{
@@ -509,8 +483,6 @@ add_page_manager_tests (void)
test_pm_prop_visible_page_name);
ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-name",
test_pm_get_set_page_name);
- ADD_PAGE_MANAGER_TEST ("/page-manager/prop-visible-page-background",
- test_pm_prop_visible_page_background);
ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-name",
test_pm_child_prop_name);
ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-actions",
@@ -536,8 +508,6 @@ add_page_manager_tests (void)
test_empty_pm_visible_page);
ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/empty-visible-page-name",
test_empty_pm_visible_page_name);
- ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/empty-visible-page-background",
- test_empty_pm_visible_page_background);
ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/add-page-behavior",
test_empty_pm_add_page_behavior);