summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorP. F. Chimento <philip.chimento@gmail.com>2013-06-19 06:06:41 -0700
committerP. F. Chimento <philip.chimento@gmail.com>2013-06-19 06:06:41 -0700
commitdde468286c1a240da7bd509a67a3d0619432142e (patch)
tree2a88028fd552806bffa654169906035bdb97c7ba
parent751d9fe9b77c6d849c6aa18327cc3b4bd7e5cb38 (diff)
parent85a8d7d56792cc07e13ff50cfcc67ffe6be7d645 (diff)
Merge pull request #118 from endlessm/issues/102
Issues/102 [Depends on 88!]
-rw-r--r--docs/reference/endless/endless-sections.txt6
-rw-r--r--endless/eospagemanager.c244
-rw-r--r--endless/eospagemanager.h27
-rw-r--r--endless/eoswindow.c153
-rw-r--r--test/smoke-tests/app-window.js46
-rw-r--r--test/test-page-manager.c251
6 files changed, 598 insertions, 129 deletions
diff --git a/docs/reference/endless/endless-sections.txt b/docs/reference/endless/endless-sections.txt
index 5400315..88db2b2 100644
--- a/docs/reference/endless/endless-sections.txt
+++ b/docs/reference/endless/endless-sections.txt
@@ -61,6 +61,12 @@ eos_page_manager_get_page_center_topbar_widget
eos_page_manager_set_page_center_topbar_widget
eos_page_manager_get_page_background_uri
eos_page_manager_set_page_background_uri
+eos_page_manager_get_page_background_size
+eos_page_manager_set_page_background_size
+eos_page_manager_get_page_background_position
+eos_page_manager_set_page_background_position
+eos_page_manager_get_page_background_repeats
+eos_page_manager_set_page_background_repeats
eos_page_manager_get_transition_duration
eos_page_manager_set_transition_duration
eos_page_manager_get_transition_type
diff --git a/endless/eospagemanager.c b/endless/eospagemanager.c
index 5f92634..25443d6 100644
--- a/endless/eospagemanager.c
+++ b/endless/eospagemanager.c
@@ -88,6 +88,9 @@
* the page manager, so you should make a point of giving all your pages names.
*/
+#define DEFAULT_BACKGROUND_SIZE "100% 100%"
+#define DEFAULT_BACKGROUND_POSITION "0% 0%"
+
G_DEFINE_TYPE (EosPageManager, eos_page_manager, GTK_TYPE_CONTAINER)
#define PAGE_MANAGER_PRIVATE(o) \
@@ -100,9 +103,12 @@ struct _EosPageManagerPageInfo
gchar *name;
gboolean fake_page_actions_visible;
GtkWidget *custom_toolbox_widget;
- gchar *background_uri;
GtkWidget *left_topbar_widget;
GtkWidget *center_topbar_widget;
+ gchar *background_uri;
+ gchar *background_size;
+ gchar *background_position;
+ gboolean background_repeats;
};
struct _EosPageManagerPrivate
@@ -150,9 +156,12 @@ enum
CHILD_PROP_NAME,
CHILD_PROP_PAGE_ACTIONS,
CHILD_PROP_CUSTOM_TOOLBOX_WIDGET,
- CHILD_PROP_BACKGROUND_URI,
CHILD_PROP_LEFT_TOPBAR_WIDGET,
CHILD_PROP_CENTER_TOPBAR_WIDGET,
+ CHILD_PROP_BACKGROUND_URI,
+ CHILD_PROP_BACKGROUND_SIZE,
+ CHILD_PROP_BACKGROUND_POSITION,
+ CHILD_PROP_BACKGROUND_REPEATS,
NCHILDPROPS
};
@@ -164,6 +173,8 @@ page_info_free (EosPageManagerPageInfo *info)
{
g_free (info->name);
g_free (info->background_uri);
+ g_free (info->background_size);
+ g_free (info->background_position);
g_slice_free (EosPageManagerPageInfo, info);
}
@@ -463,6 +474,9 @@ eos_page_manager_add (GtkContainer *container,
gtk_container_add (GTK_CONTAINER (self->priv->stack), new_page);
EosPageManagerPageInfo *info = g_slice_new0 (EosPageManagerPageInfo);
+ info->background_size = g_strdup (DEFAULT_BACKGROUND_SIZE);
+ info->background_position = g_strdup (DEFAULT_BACKGROUND_POSITION);
+ info->background_repeats = TRUE;
info->page = new_page;
self->priv->page_info = g_list_prepend (self->priv->page_info, info);
g_hash_table_insert (self->priv->pages_by_widget, new_page, info);
@@ -556,6 +570,24 @@ eos_page_manager_get_child_property (GtkContainer *container,
child));
break;
+ case CHILD_PROP_BACKGROUND_SIZE:
+ g_value_set_string (value,
+ eos_page_manager_get_page_background_size (self,
+ child));
+ break;
+
+ case CHILD_PROP_BACKGROUND_POSITION:
+ g_value_set_string (value,
+ eos_page_manager_get_page_background_position (self,
+ child));
+ break;
+
+ case CHILD_PROP_BACKGROUND_REPEATS:
+ g_value_set_boolean (value,
+ eos_page_manager_get_page_background_repeats (self,
+ child));
+ break;
+
case CHILD_PROP_PAGE_ACTIONS:
g_value_set_boolean (value,
eos_page_manager_get_page_actions (self, child));
@@ -605,6 +637,21 @@ eos_page_manager_set_child_property (GtkContainer *container,
g_value_get_string (value));
break;
+ case CHILD_PROP_BACKGROUND_SIZE:
+ eos_page_manager_set_page_background_size (self, child,
+ g_value_get_string (value));
+ break;
+
+ case CHILD_PROP_BACKGROUND_POSITION:
+ eos_page_manager_set_page_background_position (self, child,
+ g_value_get_string (value));
+ break;
+
+ case CHILD_PROP_BACKGROUND_REPEATS:
+ eos_page_manager_set_page_background_repeats (self, child,
+ g_value_get_boolean (value));
+ break;
+
case CHILD_PROP_PAGE_ACTIONS:
eos_page_manager_set_page_actions (self, child,
g_value_get_boolean (value));
@@ -803,6 +850,44 @@ eos_page_manager_class_init (EosPageManagerClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ /**
+ * EosPageManager:background-size:
+ *
+ * The size of the page background, given as a css snippet string. This
+ * string can be set to any valid css value for the background-size
+ * property. See https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
+ */
+ eos_page_manager_child_props[CHILD_PROP_BACKGROUND_SIZE] =
+ g_param_spec_string ("background-size", "Background Size",
+ "Size of background of the page",
+ DEFAULT_BACKGROUND_SIZE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * EosPageManager:background-position:
+ *
+ * The position of the page background, given as a css snippet string. This
+ * string can be set to any valid css position value. See
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/position_value
+ */
+ eos_page_manager_child_props[CHILD_PROP_BACKGROUND_POSITION] =
+ g_param_spec_string ("background-position", "Background Position",
+ "Position of background of the page",
+ DEFAULT_BACKGROUND_POSITION,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * EosPageManager:background-repeats:
+ *
+ * This child property controls whether or not the background of the page
+ * will tile when drawn. Defaults to TRUE.
+ */
+ eos_page_manager_child_props[CHILD_PROP_BACKGROUND_REPEATS] =
+ g_param_spec_boolean ("background-repeats", "Background Repeats",
+ "If page background repeats",
+ TRUE,
+ 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;
@@ -1321,6 +1406,161 @@ eos_page_manager_set_page_background_uri (EosPageManager *self,
}
/**
+ * eos_page_manager_get_page_background_size:
+ * @self: the page manager
+ * @page: the page to be queried
+ *
+ * Gets the size of the background image of @page, which must previously have
+ * been added to the page manager.
+ * See #EosPageManager:background-size for more information.
+ *
+ * Returns: the size of @page, as an EosSizePercentage.
+ */
+const gchar *
+eos_page_manager_get_page_background_size (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_size;
+}
+
+/**
+ * eos_page_manager_set_page_background_size:
+ * @self: the page manager
+ * @page: the page to be modified
+ * @size: the desired size of the background image of this page.
+ *
+ * Changes the size of the background of @page, which must previously have
+ * been added to the page manager. See #EosPageManager:background-size for
+ * more information.
+ */
+void
+eos_page_manager_set_page_background_size (EosPageManager *self,
+ GtkWidget *page,
+ const gchar *size)
+{
+ 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_size, size) == 0)
+ return;
+
+ info->background_size = g_strdup (size);
+ gtk_container_child_notify (GTK_CONTAINER (self), page, "background-size");
+}
+
+
+/**
+ * eos_page_manager_get_page_background_position:
+ * @self: the page manager
+ * @page: the page to be queried
+ *
+ * Gets the position of the background image of @page, which must previously have
+ * been added to the page manager.
+ * See #EosPageManager:background-position for more information.
+ *
+ * Returns: the position of @page, as an EosSizePercentage.
+ */
+const gchar *
+eos_page_manager_get_page_background_position (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_position;
+}
+
+/**
+ * eos_page_manager_set_page_background_position:
+ * @self: the page manager
+ * @page: the page to be modified
+ * @position: the desired position of the background image of this page.
+ *
+ * Changes the position of the background of @page, which must previously have
+ * been added to the page manager. See #EosPageManager:background-position for
+ * more information.
+ */
+void
+eos_page_manager_set_page_background_position (EosPageManager *self,
+ GtkWidget *page,
+ const gchar *position)
+{
+ 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_position, position) == 0)
+ return;
+
+ info->background_position = g_strdup (position);
+ gtk_container_child_notify (GTK_CONTAINER (self), page, "background-position");
+}
+
+
+/**
+ * eos_page_manager_get_page_background_repeats:
+ * @self: the page manager
+ * @page: the page to be queried
+ *
+ * Gets whether or not the background image of @page will tile when drawn.
+ * @page must previously have been added to the page manager. See
+ * #EosPageManager:background-repeats for more information.
+ *
+ * Returns: True if the background of @page will repeat.
+ */
+gboolean
+eos_page_manager_get_page_background_repeats (EosPageManager *self,
+ GtkWidget *page)
+{
+ g_return_val_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self), FALSE);
+ g_return_val_if_fail (page != NULL && GTK_IS_WIDGET (page), FALSE);
+
+ EosPageManagerPageInfo *info = find_page_info_by_widget (self, page);
+ g_return_val_if_fail (info != NULL, FALSE);
+
+ return info->background_repeats;
+}
+
+/**
+ * eos_page_manager_set_page_background_repeats:
+ * @self: the page manager
+ * @page: the page to be modified
+ * @repeats: True if the background of @page will repeat.
+ *
+ * Sets whether or not the background image of @page will tile when drawn.
+ * @page must previously have been added to the page manager. See
+ * #EosPageManager:background-repeats for more information.
+ */
+void
+eos_page_manager_set_page_background_repeats (EosPageManager *self,
+ GtkWidget *page,
+ gboolean repeats)
+{
+ 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_repeats = repeats;
+ gtk_container_child_notify (GTK_CONTAINER (self), page, "background-repeats");
+}
+
+/**
* 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 db6a693..3c86eac 100644
--- a/endless/eospagemanager.h
+++ b/endless/eospagemanager.h
@@ -174,6 +174,33 @@ void eos_page_manager_set_page_background_uri (EosPageManage
const gchar *background);
EOS_SDK_ALL_API_VERSIONS
+const gchar *eos_page_manager_get_page_background_size (EosPageManager *self,
+ GtkWidget *page);
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_page_manager_set_page_background_size (EosPageManager *self,
+ GtkWidget *page,
+ const gchar *size);
+
+EOS_SDK_ALL_API_VERSIONS
+const gchar *eos_page_manager_get_page_background_position (EosPageManager *self,
+ GtkWidget *page);
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_page_manager_set_page_background_position (EosPageManager *self,
+ GtkWidget *page,
+ const gchar *position);
+
+EOS_SDK_ALL_API_VERSIONS
+gboolean eos_page_manager_get_page_background_repeats (EosPageManager *self,
+ GtkWidget *page);
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_page_manager_set_page_background_repeats (EosPageManager *self,
+ GtkWidget *page,
+ gboolean repeats);
+
+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 571aebb..8e30f94 100644
--- a/endless/eoswindow.c
+++ b/endless/eoswindow.c
@@ -38,9 +38,17 @@
#define BACKGROUND_FRAME_NAME_TEMPLATE "_eos-window-background-%d"
-#define BACKGROUND_FRAME_CSS_TEMPLATE "#%s { background-image: url(\"%s\");" \
- " background-size: 100%% 100%%;" \
- " border-width: 0px; }"
+#define TRANSPARENT_FRAME_CSS_PROPERTIES "{ background-image: none;\n" \
+ " background-color: transparent\n;" \
+ " border-width: 0px; }\n"
+
+#define BACKGROUND_FRAME_CSS_PROPERTIES_TEMPLATE "{ background-image: url(\"%s\");\n" \
+ " background-size: %s;\n" \
+ " background-position: %s;\n" \
+ " background-repeat: %s;\n" \
+ " border-width: 0px; }\n"
+
+#define CSS_TEMPLATE "#%s %s #%s %s"
G_DEFINE_TYPE (EosWindow, eos_window, GTK_TYPE_APPLICATION_WINDOW)
@@ -62,13 +70,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_left_topbar_handler;
- gulong child_center_topbar_handler;
- gulong child_background_handler;
+ gulong visible_page_property_handler;
GtkCssProvider *background_provider;
- const gchar *current_background_uri;
+ gchar *current_background_css_props;
};
enum
@@ -195,21 +199,27 @@ sync_stack_animation (EosWindow *self)
eos_page_manager_get_transition_duration (pm));
}
-// Helper to generate css override
+// Helper to generate frame css override
static gchar *
-format_background_css (GtkWidget *widget, const gchar *background_uri)
+format_background_css (EosPageManager *pm,
+ GtkWidget *page)
{
- // If background uri is NULL (unset) our css override is empty. The frame
- // will be transparent by default so any css styling of EosWindow will "show
- // through" the pages.
-
- // TODO: Enforce transparent frame background with CSS in case the user has
- // overriden default frame styling.
+ const gchar *background_uri = eos_page_manager_get_page_background_uri (pm, page);
+ const gchar *background_size = eos_page_manager_get_page_background_size (pm, page);
+ const gchar *background_position = eos_page_manager_get_page_background_position (pm, page);
+ gboolean background_repeats = eos_page_manager_get_page_background_repeats (pm, page);
+ const gchar *background_repeats_string = background_repeats ? "repeat" : "no-repeat";
+
+ // If background uri is NULL (unset) our css override forces the frame to be
+ // transparent. So any css styling of EosWindow will "show through" the
+ // pages.
if (background_uri == NULL)
- return "";
- return g_strdup_printf (BACKGROUND_FRAME_CSS_TEMPLATE,
- gtk_widget_get_name (widget),
- background_uri);
+ return TRANSPARENT_FRAME_CSS_PROPERTIES;
+ return g_strdup_printf (BACKGROUND_FRAME_CSS_PROPERTIES_TEMPLATE,
+ background_uri,
+ background_size,
+ background_position,
+ background_repeats_string);
}
/*
@@ -224,23 +234,21 @@ update_page_background (EosWindow *self)
{
EosPageManager *pm = EOS_PAGE_MANAGER (self->priv->page_manager);
GtkWidget *page = self->priv->current_page;
- // If no page set, no override
+ // If no page set, do not transition
if (page == NULL)
return;
-
- const gchar *next_background_uri = eos_page_manager_get_page_background_uri (pm, page);
- // If backgrounds are the same, do not transition.
- if (g_strcmp0 (next_background_uri, self->priv->current_background_uri) == 0)
- return;
// Set up css override for transition background...
- gchar *next_background_css = format_background_css (self->priv->next_background,
- next_background_uri);
- gchar *current_background_css = format_background_css (self->priv->current_background,
- self->priv->current_background_uri);
- gchar *background_css = g_strconcat(next_background_css,
- current_background_css,
- NULL);
-
+ gchar *next_background_css_props = format_background_css (pm,
+ page);
+ // If page background are exactly the same, do not transition
+ if (g_strcmp0 (self->priv->current_background_css_props, next_background_css_props) == 0)
+ return;
+ gchar *background_css = g_strdup_printf(CSS_TEMPLATE,
+ gtk_widget_get_name (self->priv->current_background),
+ self->priv->current_background_css_props,
+ gtk_widget_get_name (self->priv->next_background),
+ next_background_css_props);
+ // Override the css
GtkStyleProvider *provider =
GTK_STYLE_PROVIDER (self->priv->background_provider);
GdkScreen *screen = gdk_screen_get_default ();
@@ -256,7 +264,38 @@ update_page_background (EosWindow *self)
GtkWidget *temp = self->priv->next_background;
self->priv->next_background = self->priv->current_background;
self->priv->current_background = temp;
- self->priv->current_background_uri = next_background_uri;
+ self->priv->current_background_css_props = next_background_css_props;
+}
+
+/*
+ * update_visible_page_properties:
+ * @widget: the page
+ * @child_property: the property that changed
+ * @user_data: pointer to the window
+ *
+ * Updates the currently displaying page when one of its child properties
+ * changes.
+ */
+static void
+update_visible_page_properties (GtkWidget *widget,
+ GParamSpec *child_property,
+ gpointer data)
+{
+ EosWindow *self = (EosWindow *)data;
+ const gchar *property_name = child_property->name;
+ if (g_strcmp0 (property_name, "page-actions") == 0)
+ update_page_actions (self);
+ else if (g_strcmp0 (property_name, "custom-toolbox-widget") == 0)
+ update_page_toolbox (self);
+ else if (g_strcmp0 (property_name, "left-topbar-widget") == 0)
+ update_page_left_topbar (self);
+ else if (g_strcmp0 (property_name, "center-topbar-widget") == 0)
+ update_page_center_topbar (self);
+ else if (g_strcmp0 (property_name, "background-uri") == 0
+ || g_strcmp0 (property_name, "background-size") == 0
+ || g_strcmp0 (property_name, "background-position") == 0
+ || g_strcmp0 (property_name, "background-repeats") == 0)
+ update_page_background (self);
}
/*
@@ -274,17 +313,8 @@ update_page (EosWindow *self)
if (self->priv->current_page)
{
g_signal_handler_disconnect (self->priv->current_page,
- 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);
- g_signal_handler_disconnect (self->priv->current_page,
- self->priv->child_left_topbar_handler);
- g_signal_handler_disconnect (self->priv->current_page,
- self->priv->child_center_topbar_handler);
+ self->priv->visible_page_property_handler);
}
-
self->priv->current_page = eos_page_manager_get_visible_page (pm);
update_page_actions (self);
@@ -298,31 +328,11 @@ update_page (EosWindow *self)
if (self->priv->current_page)
{
- self->priv->child_page_actions_handler =
- g_signal_connect_swapped (self->priv->current_page,
- "child-notify::page-actions",
- G_CALLBACK (update_page_actions),
- self);
- self->priv->child_custom_toolbox_handler =
- g_signal_connect_swapped (self->priv->current_page,
- "child-notify::custom-toolbox-widget",
- G_CALLBACK (update_page_toolbox),
- self);
- self->priv->child_left_topbar_handler =
- g_signal_connect_swapped (self->priv->current_page,
- "child-notify::left-topbar-widget",
- G_CALLBACK (update_page_left_topbar),
- self);
- self->priv->child_center_topbar_handler =
- g_signal_connect_swapped (self->priv->current_page,
- "child-notify::center-topbar-widget",
- G_CALLBACK (update_page_center_topbar),
- self);
- self->priv->child_background_handler =
- g_signal_connect_swapped (self->priv->current_page,
- "child-notify::background-uri",
- G_CALLBACK (update_page_background),
- self);
+ self->priv->visible_page_property_handler =
+ g_signal_connect (self->priv->current_page,
+ "child-notify",
+ G_CALLBACK (update_visible_page_properties),
+ self);
}
}
@@ -557,6 +567,7 @@ eos_window_init (EosWindow *self)
self->priv = WINDOW_PRIVATE (self);
self->priv->background_provider = gtk_css_provider_new ();
+ self->priv->current_background_css_props = TRANSPARENT_FRAME_CSS_PROPERTIES;
self->priv->top_bar = eos_top_bar_new ();
gtk_widget_set_parent (self->priv->top_bar, GTK_WIDGET (self));
diff --git a/test/smoke-tests/app-window.js b/test/smoke-tests/app-window.js
index 42381a8..6821358 100644
--- a/test/smoke-tests/app-window.js
+++ b/test/smoke-tests/app-window.js
@@ -7,8 +7,8 @@ const GObject = imports.gi.GObject;
const TEST_APPLICATION_ID = 'com.endlessm.example.test';
-const CAT_BACKGROUND_PATH = './test/smoke-tests/images/cat_eye.jpg';
const DOG_BACKGROUND_PATH = './test/smoke-tests/images/dog_eye.jpg';
+const CAT_BACKGROUND_PATH = './test/smoke-tests/images/cat_eye.jpg';
const Page0 = new Lang.Class ({
Name: 'Page0',
@@ -80,8 +80,12 @@ const Page1 = new Lang.Class ({
this.add(this.button1);
this.button2 = new Gtk.Button({ label: 'Go to page named "page0"' });
this.add(this.button2);
- this.button3 = new Gtk.Button({ label: 'Swap this page background' });
+ this.button3 = new Gtk.Button({ label: 'Sync page backgrounds' });
this.add(this.button3);
+ this.button4 = new Gtk.Button({ label: 'Crazy background' });
+ this.add(this.button4);
+ this.button5 = new Gtk.Button({ label: 'Reset background' });
+ this.add(this.button5);
}
});
@@ -165,12 +169,13 @@ const TestApplication = new Lang.Class ({
this._pm.visible_page_name = "page0";
}));
this._page1.button3.connect('clicked', Lang.bind(this, function () {
- let background_uri = this._pm.get_page_background_uri(this._page1);
- if (background_uri === CAT_BACKGROUND_PATH)
- background_uri = DOG_BACKGROUND_PATH;
- else
- background_uri = CAT_BACKGROUND_PATH;
- this._pm.set_page_background_uri(this._page1, background_uri);
+ this._setupDogBackground(this._page1);
+ }));
+ this._page1.button4.connect('clicked', Lang.bind(this, function () {
+ this._setupCrazyDogBackground(this._page1);
+ }));
+ this._page1.button5.connect('clicked', Lang.bind(this, function () {
+ this._setupCatBackground(this._page1);
}));
@@ -198,13 +203,15 @@ const TestApplication = new Lang.Class ({
this._pm.add(this._page1, {
name: "page1",
- background_uri: DOG_BACKGROUND_PATH,
custom_toolbox_widget: this._toolbox,
left_topbar_widget: this._left_topbar,
center_topbar_widget: this._center_topbar,
page_actions: true
});
+ this._setupDogBackground(this._page0);
+ this._setupCatBackground(this._page1);
+
this._window = new Endless.Window({
application: this,
page_manager: this._pm
@@ -212,6 +219,27 @@ const TestApplication = new Lang.Class ({
this._window.show_all();
},
+ _setupDogBackground: function (page) {
+ this._pm.set_page_background_uri(page, DOG_BACKGROUND_PATH);
+ this._pm.set_page_background_size(page, "auto");
+ this._pm.set_page_background_position(page, "center");
+ this._pm.set_page_background_repeats(page, false);
+ },
+
+ _setupCrazyDogBackground: function (page) {
+ this._pm.set_page_background_uri(page, DOG_BACKGROUND_PATH);
+ this._pm.set_page_background_size(page, "100px 100px");
+ this._pm.set_page_background_position(page, "0% 0%");
+ this._pm.set_page_background_repeats(page, true);
+ },
+
+ _setupCatBackground: function (page) {
+ this._pm.set_page_background_uri(page, CAT_BACKGROUND_PATH);
+ this._pm.set_page_background_size(page, "auto");
+ this._pm.set_page_background_position(page, "center");
+ this._pm.set_page_background_repeats(page, false);
+ },
+
_onButtonClicked: function () {
this._window.destroy();
}
diff --git a/test/test-page-manager.c b/test/test-page-manager.c
index ecff997..a39fb3f 100644
--- a/test/test-page-manager.c
+++ b/test/test-page-manager.c
@@ -6,26 +6,31 @@
#define PAGE1_NAME "page1"
#define PAGE2_NAME "page2"
#define PAGE3_NAME "page3"
-#define PAGE1_BACKGROUND "back1"
-#define PAGE2_BACKGROUND "back2"
-#define PAGE3_BACKGROUND "back3"
+#define PAGE1_PROP_STRING "prop1"
+#define PAGE2_PROP_STRING "prop2"
+#define PAGE3_PROP_STRING "prop3"
#define EXPECTED_PAGE_NAME PAGE2_NAME
#define EXPECTED_CHANGED_PAGE_NAME "changed-name"
#define DUPLICATE_PAGE_NAME "duplicate-name"
#define EXPECTED_DUPLICATE_PAGE_NAME_ERRMSG "*Not setting page name to \"" \
DUPLICATE_PAGE_NAME "\", because page manager already contains a page by " \
"that name*"
-#define EXPECTED_PAGE_BACKGROUND PAGE2_BACKGROUND
+#define EXPECTED_PAGE_PROP_STRING PAGE2_PROP_STRING
#define EXPECTED_CHANGED_NAME "changed-name"
#define ADD_PAGE_MANAGER_TEST(path, test_func) \
g_test_add ((path), PageManagerFixture, NULL, \
pm_fixture_setup, (test_func), pm_fixture_teardown)
+#define ADD_PAGE_MANAGER_TEST_WITH_ARGS(path, test_func, args) \
+ g_test_add ((path), PageManagerFixture, args, \
+ pm_fixture_setup, (test_func), pm_fixture_teardown)
#define ADD_EMPTY_PAGE_MANAGER_TEST(path, test_func) \
g_test_add ((path), PageManagerFixture, NULL, \
empty_pm_fixture_setup, (test_func), pm_fixture_teardown);
#define DURATION_DEFAULT 200
#define DURATION_1 1
#define DURATION_2 9999
+#define BACKGROUND_SIZE_DEFAULT "100% 100%"
+#define BACKGROUND_POSITION_DEFAULT "0% 0%"
typedef struct
{
@@ -48,19 +53,26 @@ pm_fixture_setup (PageManagerFixture *fixture,
gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
fixture->page1,
"name", PAGE1_NAME,
- "background-uri", PAGE1_BACKGROUND,
+ "background-uri", PAGE1_PROP_STRING,
+ "background-size", PAGE1_PROP_STRING,
+ "background-position", PAGE1_PROP_STRING,
NULL);
gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
fixture->page2,
"name", PAGE2_NAME,
"custom-toolbox-widget", fixture->toolbox2,
- "background-uri", PAGE2_BACKGROUND,
+ "background-uri", PAGE2_PROP_STRING,
+ "background-size", PAGE2_PROP_STRING,
+ "background-position", PAGE2_PROP_STRING,
NULL);
gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
fixture->page3,
"name", PAGE3_NAME,
"page-actions", TRUE,
- "background-uri", PAGE3_BACKGROUND,
+ "background-uri", PAGE3_PROP_STRING,
+ "background-size", PAGE3_PROP_STRING,
+ "background-position", PAGE3_PROP_STRING,
+ "background-repeats", FALSE,
NULL);
}
@@ -224,6 +236,47 @@ test_pm_child_prop_page_actions (PageManagerFixture *fixture,
}
static void
+test_pm_get_set_background_repeats (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ gboolean repeats;
+ repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm),
+ fixture->page1);
+ g_assert (repeats == TRUE);
+ repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm),
+ fixture->page3);
+ g_assert (repeats == FALSE);
+ eos_page_manager_set_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm),
+ fixture->page3,
+ TRUE);
+ repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm),
+ fixture->page3);
+ g_assert (repeats == TRUE);
+}
+
+static void
+test_pm_child_prop_background_repeats (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ gboolean repeats;
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1,
+ "background-repeats", &repeats,
+ NULL);
+ g_assert (repeats == TRUE);
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3,
+ "background-repeats", &repeats,
+ NULL);
+ g_assert (repeats == FALSE);
+ gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page3,
+ "background-repeats", TRUE,
+ NULL);
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3,
+ "background-repeats", &repeats,
+ NULL);
+ g_assert (repeats == TRUE);
+}
+
+static void
test_pm_get_set_page_custom_toolbox (PageManagerFixture *fixture,
gconstpointer unused)
{
@@ -286,33 +339,34 @@ test_pm_child_prop_custom_toolbox (PageManagerFixture *fixture,
}
static void
-test_pm_child_prop_background (PageManagerFixture *fixture,
- gconstpointer unused)
+test_pm_child_prop_string (PageManagerFixture *fixture,
+ gconstpointer data)
{
- gchar *background;
+ gchar *prop_name = (gchar *)data;
+ gchar *prop_string;
gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1,
- "background-uri", &background,
+ prop_name, &prop_string,
NULL);
- g_assert_cmpstr (background, ==, PAGE1_BACKGROUND);
- g_free (background);
+ g_assert_cmpstr (prop_string, ==, PAGE1_PROP_STRING);
+ g_free (prop_string);
gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2,
- "background-uri", &background,
+ prop_name, &prop_string,
NULL);
- g_assert_cmpstr (background, ==, PAGE2_BACKGROUND);
- g_free (background);
+ g_assert_cmpstr (prop_string, ==, PAGE2_PROP_STRING);
+ g_free (prop_string);
gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3,
- "background-uri", &background,
+ prop_name, &prop_string,
NULL);
- g_assert_cmpstr (background, ==, PAGE3_BACKGROUND);
- g_free (background);
+ g_assert_cmpstr (prop_string, ==, PAGE3_PROP_STRING);
+ g_free (prop_string);
gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page2,
- "background-uri", EXPECTED_CHANGED_NAME,
+ prop_name, EXPECTED_CHANGED_NAME,
NULL);
gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2,
- "background-uri", &background,
+ prop_name, &prop_string,
NULL);
- g_assert_cmpstr (background, ==, EXPECTED_CHANGED_NAME);
- g_free (background);
+ g_assert_cmpstr (prop_string, ==, EXPECTED_CHANGED_NAME);
+ g_free (prop_string);
}
static void
@@ -347,45 +401,129 @@ test_pm_set_page_no_name (PageManagerFixture *fixture,
}
static void
-test_pm_page_no_background (PageManagerFixture *fixture,
+test_pm_no_background_uri (PageManagerFixture *fixture,
gconstpointer unused)
{
- const gchar *background_get;
- gchar *background_prop;
+ const gchar *background_uri_get;
+ gchar *background_uri_prop;
GtkWidget *new_page = gtk_label_new("new");
gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
- background_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
+ background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
new_page);
- g_assert_cmpstr (background_get, ==, NULL);
+ g_assert_cmpstr (background_uri_get, ==, NULL);
gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page,
- "background-uri", &background_prop,
+ "background-uri", &background_uri_prop,
NULL);
- g_assert_cmpstr (background_prop, ==, NULL);
- g_free (background_prop);
+ g_assert_cmpstr (background_uri_prop, ==, NULL);
+ g_free (background_uri_prop);
}
static void
-test_pm_page_change_background (PageManagerFixture *fixture,
+test_pm_get_set_background_uri (PageManagerFixture *fixture,
gconstpointer unused)
{
- const gchar *background_get;
- const gchar *background_name_1 = "first background name";
- const gchar *background_name_2 = "second background name";
+ const gchar *background_uri_get;
+ const gchar *background_uri_name_1 = "first background uri name";
+ const gchar *background_uri_name_2 = "second background uri name";
GtkWidget *new_page = gtk_label_new("new");
gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
eos_page_manager_set_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
new_page,
- background_name_1);
- background_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
+ background_uri_name_1);
+ background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
new_page);
- g_assert_cmpstr (background_get, ==, background_name_1);
+ g_assert_cmpstr (background_uri_get, ==, background_uri_name_1);
eos_page_manager_set_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
new_page,
- background_name_2);
- background_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
+ background_uri_name_2);
+ background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
+ new_page);
+ g_assert_cmpstr (background_uri_get, ==, background_uri_name_2);
+}
+
+static void
+test_pm_default_background_size (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ const gchar *background_size_get;
+ gchar *background_size_prop;
+ GtkWidget *new_page = gtk_label_new("new");
+ gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
+ background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
+ new_page);
+ g_assert_cmpstr (background_size_get, ==, BACKGROUND_SIZE_DEFAULT);
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page,
+ "background-size", &background_size_prop,
+ NULL);
+ g_assert_cmpstr (background_size_prop, ==, BACKGROUND_SIZE_DEFAULT);
+ g_free (background_size_prop);
+}
+
+static void
+test_pm_get_set_background_size (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ const gchar *background_size_get;
+ const gchar *background_size_name_1 = "first background size name";
+ const gchar *background_size_name_2 = "second background size name";
+ GtkWidget *new_page = gtk_label_new("new");
+ gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
+ eos_page_manager_set_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
+ new_page,
+ background_size_name_1);
+ background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
+ new_page);
+ g_assert_cmpstr (background_size_get, ==, background_size_name_1);
+
+ eos_page_manager_set_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
+ new_page,
+ background_size_name_2);
+ background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
+ new_page);
+ g_assert_cmpstr (background_size_get, ==, background_size_name_2);
+}
+
+static void
+test_pm_default_background_position (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ const gchar *background_position_get;
+ gchar *background_position_prop;
+ GtkWidget *new_page = gtk_label_new("new");
+ gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
+ background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
+ new_page);
+ g_assert_cmpstr (background_position_get, ==, BACKGROUND_POSITION_DEFAULT);
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page,
+ "background-position", &background_position_prop,
+ NULL);
+ g_assert_cmpstr (background_position_prop, ==, BACKGROUND_POSITION_DEFAULT);
+ g_free (background_position_prop);
+}
+
+static void
+test_pm_get_set_background_position (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ const gchar *background_position_get;
+ const gchar *background_position_name_1 = "first background position name";
+ const gchar *background_position_name_2 = "second background position name";
+ GtkWidget *new_page = gtk_label_new("new");
+ gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
+ eos_page_manager_set_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
+ new_page,
+ background_position_name_1);
+ background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
+ new_page);
+ g_assert_cmpstr (background_position_get, ==, background_position_name_1);
+
+ eos_page_manager_set_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
+ new_page,
+ background_position_name_2);
+ background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
new_page);
- g_assert_cmpstr (background_get, ==, background_name_2);
+ g_assert_cmpstr (background_position_get, ==, background_position_name_2);
}
static void
@@ -572,15 +710,34 @@ add_page_manager_tests (void)
test_pm_get_set_page_custom_toolbox);
ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-custom-toolbox",
test_pm_child_prop_custom_toolbox);
- ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-background",
- test_pm_child_prop_background);
ADD_PAGE_MANAGER_TEST ("/page-manager/page-no-name", test_pm_page_no_name);
ADD_PAGE_MANAGER_TEST ("/page-manager/set-page-no-name",
test_pm_set_page_no_name);
- ADD_PAGE_MANAGER_TEST ("/page-manager/page-no-background",
- test_pm_page_no_background);
- ADD_PAGE_MANAGER_TEST ("/page-manager/page-set-background",
- test_pm_page_change_background);
+ ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-uri",
+ test_pm_child_prop_string,
+ "background-uri");
+ ADD_PAGE_MANAGER_TEST ("/page-manager/no-background-uri",
+ test_pm_no_background_uri);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-uri",
+ test_pm_get_set_background_uri);
+ ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-size",
+ test_pm_child_prop_string,
+ "background-size");
+ ADD_PAGE_MANAGER_TEST ("/page-manager/default-background-size",
+ test_pm_default_background_size);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-size",
+ test_pm_get_set_background_size);
+ ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-position",
+ test_pm_child_prop_string,
+ "background-position");
+ ADD_PAGE_MANAGER_TEST ("/page-manager/default-background-position",
+ test_pm_default_background_position);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/set-background-position",
+ test_pm_get_set_background_position);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-repeats",
+ test_pm_get_set_background_repeats);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-background-repeats",
+ test_pm_child_prop_background_repeats);
ADD_PAGE_MANAGER_TEST ("/page-manager/remove-page-by-name",
test_pm_remove_page_by_name);
ADD_PAGE_MANAGER_TEST ("/page-manager/duplicate-page-name",