[sushi/wip/cosimoc/no-clutter: 8/50] Don't use Clutter to position the toolbar
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi/wip/cosimoc/no-clutter: 8/50] Don't use Clutter to position the toolbar
- Date: Mon, 17 Jun 2019 18:33:17 +0000 (UTC)
commit 21c398d43834989babfe7f3119957fda6b29e31d
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Jul 19 11:17:02 2015 -0700
Don't use Clutter to position the toolbar
This is the first step towards removing the Clutter dependency.
src/js/ui/mainWindow.js | 99 +++++++++++++++++++-----------------------------
src/js/viewers/audio.js | 28 ++++----------
src/js/viewers/evince.js | 45 +++++++++-------------
src/js/viewers/gst.js | 9 ++---
src/js/viewers/html.js | 21 +++-------
src/js/viewers/image.js | 15 ++------
src/js/viewers/text.js | 16 ++------
7 files changed, 80 insertions(+), 153 deletions(-)
---
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 3985d95..4450840 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -42,7 +42,6 @@ const Constants = imports.util.constants;
const MimeHandler = imports.ui.mimeHandler;
const SpinnerBox = imports.ui.spinnerBox;
const Tweener = imports.ui.tweener;
-const Utils = imports.ui.utils;
var MainWindow = new Lang.Class({
Name: 'MainWindow',
@@ -55,9 +54,9 @@ var MainWindow = new Lang.Class({
this._pendingRenderer = null;
this._renderer = null;
this._texture = null;
- this._toolbarActor = null;
- this._fullScreenId = 0;
+ this._toolbar = null;
this._toolbarId = 0;
+ this._fullScreenId = 0;
this._unFullScreenId = 0;
this._mimeHandler = new MimeHandler.MimeHandler();
@@ -93,11 +92,14 @@ var MainWindow = new Lang.Class({
Gdk.WMFunction.RESIZE |
Gdk.WMFunction.CLOSE);
}));
+
+ this._embed = new Gtk.Overlay();
+ this._gtkWindow.add(this._embed);
},
_createClutterEmbed : function() {
this._clutterEmbed = new GtkClutter.Embed();
- this._gtkWindow.add(this._clutterEmbed);
+ this._embed.add(this._clutterEmbed);
this._clutterEmbed.set_receives_default(true);
this._clutterEmbed.set_can_default(true);
@@ -182,15 +184,9 @@ var MainWindow = new Lang.Class({
let stageWin = ClutterGdk.get_stage_window(this._stage);
let win_coords = event.get_coords();
- if ((event.get_source() == this._toolbarActor) ||
- (event.get_source() == this._texture &&
- !this._renderer.moveOnClick)) {
-
- if (event.get_source() == this._toolbarActor)
- this._resetToolbar();
-
+ if (event.get_source() == this._texture &&
+ !this._renderer.moveOnClick)
return false;
- }
let root_coords = stageWin.get_root_coords(win_coords[0],
win_coords[1]);
@@ -204,7 +200,7 @@ var MainWindow = new Lang.Class({
},
_onMotionNotifyEvent : function() {
- if (this._toolbarActor)
+ if (this._toolbar)
this._resetToolbar();
return false;
@@ -364,11 +360,7 @@ var MainWindow = new Lang.Class({
_exitFullScreen : function() {
this._isFullScreen = false;
-
- if (this._toolbarActor) {
- this._toolbarActor.set_opacity(0);
- this._removeToolbarTimeout();
- }
+ this._removeToolbarTimeout();
/* wait for the next stage allocation to fade in the texture
* and background again.
@@ -434,12 +426,7 @@ var MainWindow = new Lang.Class({
_enterFullScreen : function() {
this._isFullScreen = true;
-
- if (this._toolbarActor) {
- /* prepare the toolbar */
- this._toolbarActor.set_opacity(0);
- this._removeToolbarTimeout();
- }
+ this._removeToolbarTimeout();
/* wait for the next stage allocation to fade in the texture
* and background again.
@@ -466,29 +453,37 @@ var MainWindow = new Lang.Class({
************************* toolbar helpers ********************************
**************************************************************************/
_createToolbar : function() {
- if (this._toolbarActor) {
- this._removeToolbarTimeout();
- this._toolbarActor.destroy();
- this._toolbarActor = null;
+ this._removeToolbarTimeout();
+
+ if (this._toolbar) {
+ this._toolbar.destroy();
+ this._toolbar = null;
}
- if (this._renderer.createToolbar)
- this._toolbarActor = this._renderer.createToolbar();
+ if (this._renderer.populateToolbar) {
+ let rendererToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU,
+ halign: Gtk.Align.CENTER,
+ show_arrow: false,
+ visible: true });
+ rendererToolbar.get_style_context().add_class('osd');
+
+ this._toolbar = new Gtk.Revealer({ valign: Gtk.Align.END,
+ hexpand: true,
+ margin_bottom: Constants.TOOLBAR_SPACING,
+ margin_start: Constants.TOOLBAR_SPACING,
+ margin_end: Constants.TOOLBAR_SPACING,
+ transition_duration: 250,
+ transition_type: Gtk.RevealerTransitionType.CROSSFADE,
+ visible: true });
+ this._toolbar.add(rendererToolbar);
+
+ this._renderer.populateToolbar(rendererToolbar);
+ }
- if (!this._toolbarActor)
+ if (!this._toolbar)
return;
- Utils.alphaGtkWidget(this._toolbarActor.get_widget());
-
- this._toolbarActor.set_reactive(true);
- this._toolbarActor.set_opacity(0);
-
- this._toolbarActor.margin_bottom = Constants.TOOLBAR_SPACING;
- this._toolbarActor.margin_start = Constants.TOOLBAR_SPACING;
- this._toolbarActor.margin_end = Constants.TOOLBAR_SPACING;
-
- this._mainLayout.add(this._toolbarActor,
- Clutter.BinAlignment.CENTER, Clutter.BinAlignment.END);
+ this._embed.add_overlay(this._toolbar);
},
_removeToolbarTimeout: function() {
@@ -499,18 +494,8 @@ var MainWindow = new Lang.Class({
},
_resetToolbar : function() {
- if (this._toolbarId == 0) {
- Tweener.removeTweens(this._toolbarActor);
-
- this._toolbarActor.raise_top();
- this._toolbarActor.set_opacity(0);
-
- Tweener.addTween(this._toolbarActor,
- { opacity: 200,
- time: 0.1,
- transition: 'easeOutQuad'
- });
- }
+ if (this._toolbarId == 0)
+ this._toolbar.reveal_child = true;
this._removeToolbarTimeout();
this._toolbarId = Mainloop.timeout_add(1500,
@@ -520,11 +505,7 @@ var MainWindow = new Lang.Class({
_onToolbarTimeout : function() {
this._toolbarId = 0;
- Tweener.addTween(this._toolbarActor,
- { opacity: 0,
- time: 0.25,
- transition: 'easeOutQuad'
- });
+ this._toolbar.reveal_child = false;
return false;
},
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index 05daeba..604b9f1 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -194,7 +194,7 @@ const AudioRenderer = new Lang.Class({
},
_updateProgressBar : function() {
- if (!this._mainToolbar)
+ if (!this._progressBar)
return;
this._isSettingValue = true;
@@ -203,7 +203,7 @@ const AudioRenderer = new Lang.Class({
},
_updateCurrentLabel : function() {
- if (!this._mainToolbar)
+ if (!this._currentLabel)
return;
let currentTime =
@@ -213,7 +213,7 @@ const AudioRenderer = new Lang.Class({
},
_updateDurationLabel : function() {
- if (!this._mainToolbar)
+ if (!this._durationLabel)
return;
let totalTime = this._player.duration;
@@ -254,27 +254,17 @@ const AudioRenderer = new Lang.Class({
return [ width[1], height[1] ];
},
- createToolbar : function () {
- this._mainToolbar = new Gtk.Toolbar({ margin_start: Constants.TOOLBAR_SPACING,
- margin_end: Constants.TOOLBAR_SPACING });
- this._mainToolbar.get_style_context().add_class('osd');
- this._mainToolbar.set_icon_size(Gtk.IconSize.MENU);
- this._mainToolbar.show();
-
- this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar,
- opacity: 0,
- x_expand: true });
-
+ populateToolbar : function (toolbar) {
this._toolbarPlay = new Gtk.ToolButton({ icon_name: 'media-playback-pause-symbolic' });
this._toolbarPlay.show();
- this._mainToolbar.insert(this._toolbarPlay, 0);
+ toolbar.insert(this._toolbarPlay, 0);
this._currentLabel = new Gtk.Label({ margin_start: 6,
margin_end: 3 });
let item = new Gtk.ToolItem();
item.add(this._currentLabel);
item.show_all();
- this._mainToolbar.insert(item, 1);
+ toolbar.insert(item, 1);
this._toolbarPlay.connect('clicked',
Lang.bind(this, function () {
@@ -297,15 +287,13 @@ const AudioRenderer = new Lang.Class({
item.set_expand(true);
item.add(this._progressBar);
item.show_all();
- this._mainToolbar.insert(item, 2);
+ toolbar.insert(item, 2);
this._durationLabel = new Gtk.Label({ margin_start: 3 });
item = new Gtk.ToolItem();
item.add(this._durationLabel);
item.show_all();
- this._mainToolbar.insert(item, 3);
-
- return this._toolbarActor;
+ toolbar.insert(item, 3);
},
});
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index 181a40a..e1188d5 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -114,47 +114,36 @@ const EvinceRenderer = new Lang.Class({
return item;
},
- createToolbar : function() {
- this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU });
- this._mainToolbar.get_style_context().add_class('osd');
- this._mainToolbar.set_show_arrow(false);
- this._mainToolbar.show();
-
- this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar });
-
+ populateToolbar : function(toolbar) {
this._toolbarBack = new Gtk.ToolButton({ expand: false,
- icon_name: 'go-previous-symbolic' });
- this._toolbarBack.show();
- this._mainToolbar.insert(this._toolbarBack, -1);
+ icon_name: 'go-previous-symbolic',
+ visible: true });
+ toolbar.insert(this._toolbarBack, -1);
- this._toolbarBack.connect('clicked',
- Lang.bind(this, function () {
- this._view.previous_page();
- }));
+ this._toolbarBack.connect('clicked', Lang.bind(this, function () {
+ this._view.previous_page();
+ }));
let labelItem = this._createLabelItem();
- this._mainToolbar.insert(labelItem, -1);
+ toolbar.insert(labelItem, -1);
this._toolbarForward = new Gtk.ToolButton({ expand: false,
- icon_name: 'go-next-symbolic' });
- this._toolbarForward.show();
- this._mainToolbar.insert(this._toolbarForward, -1);
+ icon_name: 'go-next-symbolic',
+ visible: true });
+ toolbar.insert(this._toolbarForward, -1);
- this._toolbarForward.connect('clicked',
- Lang.bind(this, function () {
- this._view.next_page();
- }));
+ this._toolbarForward.connect('clicked', Lang.bind(this, function () {
+ this._view.next_page();
+ }));
let separator = new Gtk.SeparatorToolItem();
separator.show();
- this._mainToolbar.insert(separator, -1);
+ toolbar.insert(separator, -1);
- this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
- this._mainToolbar.insert(this._toolbarZoom, -1);
+ let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
+ toolbar.insert(toolbarZoom, -1);
this._updatePageLabel();
-
- return this._toolbarActor;
},
clear : function() {
diff --git a/src/js/viewers/gst.js b/src/js/viewers/gst.js
index 6a010f6..6e8545f 100644
--- a/src/js/viewers/gst.js
+++ b/src/js/viewers/gst.js
@@ -148,15 +148,12 @@ const GstRenderer = new Lang.Class({
},
createToolbar : function () {
- this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU });
+ this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU,
+ hexpand: true });
this._mainToolbar.get_style_context().add_class('osd');
this._mainToolbar.set_show_arrow(false);
this._mainToolbar.show();
- this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar,
- opacity: 0,
- x_expand: true });
-
this._toolbarPlay = new Gtk.ToolButton({ icon_name: 'media-playback-pause-symbolic' });
this._toolbarPlay.show();
this._mainToolbar.insert(this._toolbarPlay, 0);
@@ -201,7 +198,7 @@ const GstRenderer = new Lang.Class({
this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
this._mainToolbar.insert(this._toolbarZoom, 4);
- return this._toolbarActor;
+ return this._mainToolbar;
},
_onVideoSizeChange : function(player, width, height) {
diff --git a/src/js/viewers/html.js b/src/js/viewers/html.js
index 5135e2b..cd70d4f 100644
--- a/src/js/viewers/html.js
+++ b/src/js/viewers/html.js
@@ -69,25 +69,16 @@ const HTMLRenderer = new Lang.Class({
return allocation;
},
- createToolbar : function() {
- this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU });
- this._mainToolbar.get_style_context().add_class('osd');
- this._mainToolbar.set_show_arrow(false);
- this._mainToolbar.show();
-
- this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar });
-
- this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
- this._mainToolbar.insert(this._toolbarZoom, 0);
+ populateToolbar : function(toolbar) {
+ let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
+ toolbar.insert(toolbarZoom, 0);
let separator = new Gtk.SeparatorToolItem();
separator.show();
- this._mainToolbar.insert(separator, 1);
-
- this._toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
- this._mainToolbar.insert(this._toolbarRun, 2);
+ toolbar.insert(separator, 1);
- return this._toolbarActor;
+ let toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
+ toolbar.insert(toolbarRun, 2);
}
});
diff --git a/src/js/viewers/image.js b/src/js/viewers/image.js
index dff536e..08dc97f 100644
--- a/src/js/viewers/image.js
+++ b/src/js/viewers/image.js
@@ -111,18 +111,9 @@ const ImageRenderer = new Lang.Class({
this._advanceImage));
},
- createToolbar : function() {
- this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU });
- this._mainToolbar.get_style_context().add_class('osd');
- this._mainToolbar.set_show_arrow(false);
- this._mainToolbar.show();
-
- this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar });
-
- this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
- this._mainToolbar.insert(this._toolbarZoom, 0);
-
- return this._toolbarActor;
+ populateToolbar : function(toolbar) {
+ let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
+ toolbar.insert(toolbarZoom, 0);
},
destroy : function () {
diff --git a/src/js/viewers/text.js b/src/js/viewers/text.js
index 5aaa566..3a3cea6 100644
--- a/src/js/viewers/text.js
+++ b/src/js/viewers/text.js
@@ -112,19 +112,9 @@ const TextRenderer = new Lang.Class({
return allocation;
},
- createToolbar : function() {
- this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU });
- this._mainToolbar.get_style_context().add_class('osd');
- this._mainToolbar.set_show_arrow(false);
-
- this._toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
- this._mainToolbar.insert(this._toolbarRun, 0);
-
- this._mainToolbar.show();
-
- this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar });
-
- return this._toolbarActor;
+ populateToolbar : function(toolbar) {
+ let toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
+ toolbar.insert(toolbarRun, 0);
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]