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
This commit is contained in:
Georges Basile Stavracas Neto 2018-07-12 14:36:46 +02:00
parent 2ee321e0d8
commit 038f8b6ea5
No known key found for this signature in database
GPG Key ID: 886C17EE170D1385

View File

@ -773,6 +773,44 @@ function getInputSourceManager() {
return _inputSourceManager; 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({ var InputSourceIndicator = new Lang.Class({
Name: 'InputSourceIndicator', Name: 'InputSourceIndicator',
Extends: PanelMenu.Button, Extends: PanelMenu.Button,
@ -783,10 +821,7 @@ var InputSourceIndicator = new Lang.Class({
this._menuItems = {}; this._menuItems = {};
this._indicatorLabels = {}; this._indicatorLabels = {};
this._container = new Shell.GenericContainer(); this._container = new InputSourceIndicatorContainer();
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._hbox = new St.BoxLayout({ style_class: 'panel-status-menu-box' }); this._hbox = new St.BoxLayout({ style_class: 'panel-status-menu-box' });
this._hbox.add_child(this._container); this._hbox.add_child(this._container);
@ -1021,48 +1056,4 @@ var InputSourceIndicator = new Lang.Class({
Util.spawn(['gkbd-keyboard-display', '-l', description]); 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);
}
}
}); });