diff --git a/js/ui/padOsd.js b/js/ui/padOsd.js index f6965333571ba04b4285a541457a3d9113bbc20c..115b72be2ed74ed824b4438ee3ae1df0e6628836 100644 --- a/js/ui/padOsd.js +++ b/js/ui/padOsd.js @@ -2,7 +2,7 @@ /* exported PadOsd, PadOsdService */ const { Atk, Clutter, GDesktopEnums, Gio, - GLib, GObject, Gtk, Meta, Rsvg, St } = imports.gi; + GLib, GObject, Gtk, Meta, Pango, Rsvg, St } = imports.gi; const Signals = imports.signals; const Main = imports.ui.main; @@ -329,6 +329,7 @@ var PadDiagram = GObject.registerClass({ this._imagePath = imagePath; this._handle = this._composeStyledDiagram(); + this._initLabels(); } // eslint-disable-next-line camelcase @@ -343,6 +344,26 @@ var PadDiagram = GObject.registerClass({ this.add_actor(actor); } + _initLabels() { + let i = 0; + for (i = 0; ; i++) { + if (!this._addLabel(Meta.PadActionType.BUTTON, i)) + break; + } + + for (i = 0; ; i++) { + if (!this._addLabel(Meta.PadActionType.RING, i, CW) || + !this._addLabel(Meta.PadActionType.RING, i, CCW)) + break; + } + + for (i = 0; ; i++) { + if (!this._addLabel(Meta.PadActionType.STRIP, i, UP) || + !this._addLabel(Meta.PadActionType.STRIP, i, DOWN)) + break; + } + } + _wrappingSvgHeader() { return '' + ' 0 ? (number + 1).toString() : ''; let dirStr = dir == CW ? 'CW' : 'CCW'; let labelName = 'LabelRing%s%s'.format(numStr, dirStr); let leaderName = 'LeaderRing%s%s'.format(numStr, dirStr); - - return this._getItemLabelCoords(labelName, leaderName); + return [labelName, leaderName]; } - getStripLabelCoords(number, dir) { + _getStripLabels(number, dir) { let numStr = number > 0 ? (number + 1).toString() : ''; let dirStr = dir == UP ? 'Up' : 'Down'; let labelName = 'LabelStrip%s%s'.format(numStr, dirStr); let leaderName = 'LeaderStrip%s%s'.format(numStr, dirStr); - - return this._getItemLabelCoords(labelName, leaderName); + return [labelName, leaderName]; } - getLabelCoords(action, idx, dir) { + _getLabelCoords(action, idx, dir) { if (action == Meta.PadActionType.BUTTON) - return this.getButtonLabelCoords(idx); + return this._getItemLabelCoords(...this._getButtonLabels(idx)); else if (action == Meta.PadActionType.RING) - return this.getRingLabelCoords(idx, dir); + return this._getItemLabelCoords(...this._getRingLabels(idx, dir)); else if (action == Meta.PadActionType.STRIP) - return this.getStripLabelCoords(idx, dir); + return this._getItemLabelCoords(...this._getStripLabels(idx, dir)); return [false]; } @@ -557,26 +563,30 @@ var PadDiagram = GObject.registerClass({ this._invalidateSvg(); } - addLabel(label, type, idx, dir) { - this._labels.push([label, type, idx, dir]); + _addLabel(action, idx, dir) { + let [found, x, y, arrangement] = this._getLabelCoords(action, idx, dir); + if (!found) + return false; + + let label = new St.Label(); + this._labels.push({ label, action, idx, dir, x, y, arrangement }); this.add_actor(label); + return true; } updateLabels(getText) { for (let i = 0; i < this._labels.length; i++) { - let [label, action, idx, dir] = this._labels[i]; + const { label, action, idx, dir } = this._labels[i]; let str = getText(action, idx, dir); label.set_text(str); } + + this.queue_relayout(); } _applyLabel(label, action, idx, dir, str) { - if (str != null) { + if (str !== null) label.set_text(str); - - let [found_, x, y, arrangement] = this.getLabelCoords(action, idx, dir); - this._allocateChild(label, x, y, arrangement); - } label.show(); } @@ -584,18 +594,20 @@ var PadDiagram = GObject.registerClass({ this._editorActor.hide(); if (this._prevEdited) { - let [label, action, idx, dir] = this._prevEdited; + const { label, action, idx, dir } = this._prevEdited; this._applyLabel(label, action, idx, dir, str); this._prevEdited = null; } if (this._curEdited) { - let [label, action, idx, dir] = this._curEdited; + const { label, action, idx, dir } = this._curEdited; this._applyLabel(label, action, idx, dir, str); if (continues) this._prevEdited = this._curEdited; this._curEdited = null; } + + this.queue_relayout(); } startEdition(action, idx, dir) { @@ -605,21 +617,19 @@ var PadDiagram = GObject.registerClass({ return; for (let i = 0; i < this._labels.length; i++) { - let [label, itemAction, itemIdx, itemDir] = this._labels[i]; - if (action == itemAction && idx == itemIdx && dir == itemDir) { + if (action == this._labels[i].action && + idx == this._labels[i].idx && dir == this._labels[i].dir) { this._curEdited = this._labels[i]; - editedLabel = label; + editedLabel = this._curEdited.label; break; } } if (this._curEdited == null) return; - let [found] = this.getLabelCoords(action, idx, dir); - if (!found) - return; this._editorActor.show(); editedLabel.hide(); + this.queue_relayout(); } }); @@ -693,6 +703,7 @@ var PadOsd = GObject.registerClass({ this._titleLabel = new St.Label({ style: 'font-side: larger; font-weight: bold;', x_align: Clutter.ActorAlign.CENTER }); + this._titleLabel.clutter_text.set_ellipsize(Pango.EllipsizeMode.NONE); this._titleLabel.clutter_text.set_text(padDevice.get_device_name()); labelBox.add_actor(this._titleLabel); @@ -710,31 +721,7 @@ var PadOsd = GObject.registerClass({ x_expand: true, y_expand: true }); this.add_actor(this._padDiagram); - - // FIXME: Fix num buttons. - let i = 0; - for (i = 0; i < 50; i++) { - let [found] = this._padDiagram.getButtonLabelCoords(i); - if (!found) - break; - this._createLabel(Meta.PadActionType.BUTTON, i); - } - - for (i = 0; i < padDevice.get_n_rings(); i++) { - let [found] = this._padDiagram.getRingLabelCoords(i, CW); - if (!found) - break; - this._createLabel(Meta.PadActionType.RING, i, CW); - this._createLabel(Meta.PadActionType.RING, i, CCW); - } - - for (i = 0; i < padDevice.get_n_strips(); i++) { - let [found] = this._padDiagram.getStripLabelCoords(i, UP); - if (!found) - break; - this._createLabel(Meta.PadActionType.STRIP, i, UP); - this._createLabel(Meta.PadActionType.STRIP, i, DOWN); - } + this._updateActionLabels(); let buttonBox = new St.Widget({ layout_manager: new Clutter.BinLayout(), x_expand: true, @@ -787,11 +774,6 @@ var PadOsd = GObject.registerClass({ return str ? str : _("None"); } - _createLabel(type, number, dir) { - let label = new St.Label({ text: this._getActionText(type, number) }); - this._padDiagram.addLabel(label, type, number, dir); - } - _updateActionLabels() { this._padDiagram.updateLabels(this._getActionText.bind(this)); } @@ -867,8 +849,7 @@ var PadOsd = GObject.registerClass({ this._tipLabel.set_text(_("Press any key to exit")); } - this._titleLabel.clutter_text.set_markup( - '%s'.format(title)); + this._titleLabel.set_text(title); } _isEditedAction(type, number, dir) {