[gnome-shell/gbsneto/remove-generic-container: 57/61] keyboard: Stop using Shell.GenericContainer
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/gbsneto/remove-generic-container: 57/61] keyboard: Stop using Shell.GenericContainer
- Date: Wed, 12 Sep 2018 11:55:48 +0000 (UTC)
commit a346cf95a942d0a6d5faccf3cd31547f3a85f95d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Jul 12 14:36:46 2018 +0200
keyboard: Stop using Shell.GenericContainer
This is the last remaining usage of Shell.GenericContainer
in the codebase, and posed small challenges compared to the
other removals.
A new St.Widget subclass called InputSourceIndicatorContainer
was added as a replacement to the Shell.GenericContainer. It
was needed because GNOME Shell needs to override the regular
size allocation functions, but InputSourceIndicator already
is a St.Widget with its own size allocation overrides.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/153
js/ui/status/keyboard.js | 91 +++++++++++++++++++++++-------------------------
1 file changed, 43 insertions(+), 48 deletions(-)
---
diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js
index b0cc9bb00..20e4fa51d 100644
--- a/js/ui/status/keyboard.js
+++ b/js/ui/status/keyboard.js
@@ -773,6 +773,48 @@ function getInputSourceManager() {
return _inputSourceManager;
}
+var InputSourceIndicatorContainer = new Lang.Class({
+ Name: 'InputSourceIndicatorContainer',
+ Extends: St.Widget,
+
+ _init() {
+ this.parent();
+ },
+
+ vfunc_get_preferred_width(forHeight) {
+ // Here, and in vfunc_get_preferred_height, we need to query
+ // for the height of all children, but we ignore the results
+ // for those we don't actually display.
+ return this.get_children().reduce((maxWidth, child) => {
+ let width = child.get_preferred_width(forHeight);
+ return [Math.max(maxWidth[0], width[0]),
+ Math.max(maxWidth[1], width[1])];
+ }, [0, 0]);
+ },
+
+ vfunc_get_preferred_height(forWidth) {
+ return this.get_children().reduce((maxHeight, child) => {
+ let height = child.get_preferred_height(forWidth);
+ return [Math.max(maxHeight[0], height[0]),
+ Math.max(maxHeight[1], height[1])];
+ }, [0, 0]);
+ },
+
+ vfunc_allocate(box, flags) {
+ this.set_allocation(box, flags);
+
+ // translate box to (0, 0)
+ box.x2 -= box.x1;
+ box.x1 = 0;
+ box.y2 -= box.y1;
+ box.y1 = 0;
+
+ this.get_children().forEach(c => {
+ c.allocate_align_fill(box, 0.5, 0.5, false, false, flags);
+ });
+ }
+});
+
var InputSourceIndicator = new Lang.Class({
Name: 'InputSourceIndicator',
Extends: PanelMenu.Button,
@@ -783,10 +825,7 @@ var InputSourceIndicator = new Lang.Class({
this._menuItems = {};
this._indicatorLabels = {};
- this._container = new Shell.GenericContainer();
- this._container.connect('get-preferred-width', this._containerGetPreferredWidth.bind(this));
- this._container.connect('get-preferred-height', this._containerGetPreferredHeight.bind(this));
- this._container.connect('allocate', this._containerAllocate.bind(this));
+ this._container = new InputSourceIndicatorContainer();
this._hbox = new St.BoxLayout({ style_class: 'panel-status-menu-box' });
this._hbox.add_child(this._container);
@@ -1021,48 +1060,4 @@ var InputSourceIndicator = new Lang.Class({
Util.spawn(['gkbd-keyboard-display', '-l', description]);
},
-
- _containerGetPreferredWidth(container, for_height, alloc) {
- // Here, and in _containerGetPreferredHeight, we need to query
- // for the height of all children, but we ignore the results
- // for those we don't actually display.
- let max_min_width = 0, max_natural_width = 0;
-
- for (let i in this._inputSourceManager.inputSources) {
- let label = this._indicatorLabels[i];
- let [min_width, natural_width] = label.get_preferred_width(for_height);
- max_min_width = Math.max(max_min_width, min_width);
- max_natural_width = Math.max(max_natural_width, natural_width);
- }
-
- alloc.min_size = max_min_width;
- alloc.natural_size = max_natural_width;
- },
-
- _containerGetPreferredHeight(container, for_width, alloc) {
- let max_min_height = 0, max_natural_height = 0;
-
- for (let i in this._inputSourceManager.inputSources) {
- let label = this._indicatorLabels[i];
- let [min_height, natural_height] = label.get_preferred_height(for_width);
- max_min_height = Math.max(max_min_height, min_height);
- max_natural_height = Math.max(max_natural_height, natural_height);
- }
-
- alloc.min_size = max_min_height;
- alloc.natural_size = max_natural_height;
- },
-
- _containerAllocate(container, box, flags) {
- // translate box to (0, 0)
- box.x2 -= box.x1;
- box.x1 = 0;
- box.y2 -= box.y1;
- box.y1 = 0;
-
- for (let i in this._inputSourceManager.inputSources) {
- let label = this._indicatorLabels[i];
- label.allocate_align_fill(box, 0.5, 0.5, false, false, flags);
- }
- }
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]