padOsd: Add PadChooser class

This is a popdown button that allows choosing between pads in
the same group.

https://bugzilla.gnome.org/show_bug.cgi?id=779986
This commit is contained in:
Carlos Garnacho 2017-02-13 15:12:28 +01:00
parent e0c0d9223e
commit e057333bf3

View File

@ -30,6 +30,72 @@ const CCW = 1;
const UP = 0; const UP = 0;
const DOWN = 1; const DOWN = 1;
const PadChooser = new Lang.Class({
Name: 'PadChooser',
_init: function (device, groupDevices) {
this.actor = new St.Button({ style_class: 'pad-chooser-button',
toggle_mode: true,
x_fill: false,
y_fill: false,
x_align: St.Align.MIDDLE,
y_align: St.Align.MIDDLE });
this.currentDevice = device;
this._padChooserMenu = null;
let arrow = new St.Icon({ style_class: 'popup-menu-arrow',
icon_name: 'pan-down-symbolic',
accessible_role: Atk.Role.ARROW });
this.actor.set_child(arrow);
this._ensureMenu(groupDevices);
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
this.actor.connect('clicked', Lang.bind(this, function (actor) {
if (actor.get_checked()) {
if (this._padChooserMenu != null)
this._padChooserMenu.open(true);
else
this.set_checked(false);
} else {
this._padChooserMenu.close(true);
}
}));
},
_ensureMenu: function (devices) {
this._padChooserMenu = new PopupMenu.PopupMenu(this.actor, 0.5, St.Side.TOP);
this._padChooserMenu.connect('menu-closed', Lang.bind(this, function() { this.actor.set_checked(false); }));
this._padChooserMenu.actor.hide();
Main.uiGroup.add_actor(this._padChooserMenu.actor);
for (let i = 0; i < devices.length; i++) {
let device = devices[i];
if (device == this.currentDevice)
continue;
this._padChooserMenu.addAction(device.get_device_name(), () => {
this.emit('pad-selected', device);
});
}
},
_onDestroy: function () {
this._padChooserMenu.destroy();
},
update: function (devices) {
if (this._padChooserMenu)
this._padChooserMenu.actor.destroy();
this.actor.set_checked(false);
this._ensureMenu(devices);
},
destroy: function () {
this.actor.destroy();
},
});
Signals.addSignalMethods(PadChooser.prototype);
const KeybindingEntry = new Lang.Class({ const KeybindingEntry = new Lang.Class({
Name: 'KeybindingEntry', Name: 'KeybindingEntry',