[gnome-shell/gbsneto/remove-generic-container: 35/38] 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: 35/38] keyboard: Stop using Shell.GenericContainer
- Date: Tue, 9 Oct 2018 01:45:50 +0000 (UTC)
commit 038f8b6ea5cfc8d4f71ea5ddb20d326995909829
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 | 87 ++++++++++++++++++++++--------------------------
1 file changed, 39 insertions(+), 48 deletions(-)
---
diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js
index b0cc9bb00..6d031d88c 100644
--- a/js/ui/status/keyboard.js
+++ b/js/ui/status/keyboard.js
@@ -773,6 +773,44 @@ function getInputSourceManager() {
return _inputSourceManager;
}
+var InputSourceIndicatorContainer = new Lang.Class({
+ Name: 'InputSourceIndicatorContainer',
+ Extends: St.Widget,
+
+ 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 +821,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 +1056,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]