diff options
author | Matt Watson <mattdangerw@gmail.com> | 2013-06-11 17:57:37 -0700 |
---|---|---|
committer | Matt Watson <mattdangerw@gmail.com> | 2013-06-18 17:15:59 -0700 |
commit | 5636c3f01d8304ada10a196d78f5de5ea3acf567 (patch) | |
tree | 68c6aa0f6a31ab711e85919ed8fa2232c80f09e4 | |
parent | 49744ae28d3d4ec44069d899e0500ed571f8eba6 (diff) |
Window background drawing uses new page background props
[endlessm/eos-sdk#102]
-rw-r--r-- | endless/eoswindow.c | 72 | ||||
-rw-r--r-- | test/smoke-tests/app-window.js | 46 |
2 files changed, 80 insertions, 38 deletions
diff --git a/endless/eoswindow.c b/endless/eoswindow.c index 571aebb..29c0afc 100644 --- a/endless/eoswindow.c +++ b/endless/eoswindow.c @@ -38,9 +38,15 @@ #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_TEMPLATE "#%s { background-image: none;\n" \ + " background-color: transparent\n;" \ + " border-width: 0px; }\n" + +#define BACKGROUND_FRAME_CSS_TEMPLATE "#%s { background-image: url(\"%s\");\n" \ + " background-size: %s;\n" \ + " background-position: %s;\n" \ + " background-repeat: %s;\n" \ + " border-width: 0px; }\n" G_DEFINE_TYPE (EosWindow, eos_window, GTK_TYPE_APPLICATION_WINDOW) @@ -68,7 +74,7 @@ struct _EosWindowPrivate gulong child_center_topbar_handler; gulong child_background_handler; GtkCssProvider *background_provider; - const gchar *current_background_uri; + gchar *current_background_css; }; enum @@ -195,21 +201,31 @@ 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 *background_frame, + 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 *frame_name = gtk_widget_get_name (background_frame); + 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 (TRANSPARENT_FRAME_CSS_TEMPLATE, + frame_name); return g_strdup_printf (BACKGROUND_FRAME_CSS_TEMPLATE, - gtk_widget_get_name (widget), - background_uri); + frame_name, + background_uri, + background_size, + background_position, + background_repeats_string); } /* @@ -224,23 +240,20 @@ 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 *next_background_css = format_background_css (pm, + self->priv->next_background, + page); + // If page background are exactly the same, do not transition + if (g_strcmp0 (self->priv->current_background_css, next_background_css) == 0) + return; gchar *background_css = g_strconcat(next_background_css, - current_background_css, + self->priv->current_background_css, NULL); - + // Override the css GtkStyleProvider *provider = GTK_STYLE_PROVIDER (self->priv->background_provider); GdkScreen *screen = gdk_screen_get_default (); @@ -256,7 +269,7 @@ 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 = next_background_css; } /* @@ -284,7 +297,6 @@ update_page (EosWindow *self) g_signal_handler_disconnect (self->priv->current_page, self->priv->child_center_topbar_handler); } - self->priv->current_page = eos_page_manager_get_visible_page (pm); update_page_actions (self); @@ -318,6 +330,8 @@ update_page (EosWindow *self) "child-notify::center-topbar-widget", G_CALLBACK (update_page_center_topbar), self); + // If any background property changes we still call + // update_page_background, but leave the stack transition type as NONE. self->priv->child_background_handler = g_signal_connect_swapped (self->priv->current_page, "child-notify::background-uri", 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(); } |