diff --git a/README.md b/README.md index c94f2a3..1609d3b 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ All attributes are optional, so the most basic plugins simply print lines consis Lines containing only dashes (`---`) are *separators*. -Lines above the first separator belong to the button itself. If there are multiple such lines, they are displayed in succession, each of them for 3 seconds before switching to the next. Additionally, all button lines get a dropdown menu item, except if their `dropdown` attribute is set to `false`. +Lines above the first separator belong to the button itself. If there are multiple such lines, they are displayed in succession, each of them for 3 seconds before switching to the next (timeout can be configured with `timeout` attribute). Additionally, all button lines get a dropdown menu item, except if their `dropdown` attribute is set to `false`. Lines below the first separator are rendered as dropdown menu items. Further separators create graphical separator menu items. diff --git a/argos@pew.worldwidemann.com/button.js b/argos@pew.worldwidemann.com/button.js index cd7bec2..e2adcdc 100644 --- a/argos@pew.worldwidemann.com/button.js +++ b/argos@pew.worldwidemann.com/button.js @@ -38,7 +38,7 @@ var ArgosButton = new Lang.Class({ this._isDestroyed = false; this._updateTimeout = null; - this._cycleTimeout = null; + this._cycleTimeouts = []; this.connect("destroy", Lang.bind(this, this._onDestroy)); @@ -59,9 +59,8 @@ var ArgosButton = new Lang.Class({ if (this._updateTimeout !== null) Mainloop.source_remove(this._updateTimeout); - if (this._cycleTimeout !== null) - Mainloop.source_remove(this._cycleTimeout); + this._cycleTimeouts.forEach(cycle => Mainloop.source_remove(cycle)); this.menu.removeAll(); }, @@ -131,25 +130,26 @@ var ArgosButton = new Lang.Class({ this.menu.removeAll(); - if (this._cycleTimeout !== null) { - Mainloop.source_remove(this._cycleTimeout); - this._cycleTimeout = null; - } + this._cycleTimeouts.forEach(cycle => Mainloop.source_remove(cycle)); + this._cycleTimeouts = []; if (buttonLines.length === 0) { this._lineView.setMarkup(GLib.markup_escape_text(this._file.get_basename(), -1)); } else if (buttonLines.length === 1) { this._lineView.setLine(buttonLines[0]); } else { - this._lineView.setLine(buttonLines[0]); - let i = 0; - this._cycleTimeout = Mainloop.timeout_add_seconds(3, Lang.bind(this, function() { - i++; - this._lineView.setLine(buttonLines[i % buttonLines.length]); - return true; - })); - + let fullsec = 0; for (let j = 0; j < buttonLines.length; j++) { + GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, fullsec, Lang.bind(this, function() { + this._cycleTimeouts.push(Mainloop.timeout_add_seconds(fullsec, Lang.bind(this, function() { + this._lineView.setLine(buttonLines[j]); + return true; + }))); + this._lineView.setLine(buttonLines[j]); + return false; + })); + fullsec += +buttonLines[j].timeout || 3; + if (buttonLines[j].dropdown !== "false") this.menu.addMenuItem(new ArgosMenuItem(this, buttonLines[j])); }