From d654e8992a3537cf6a06e17d791245e559c46f4f Mon Sep 17 00:00:00 2001 From: Henning Bopp Date: Sun, 23 Dec 2018 23:01:06 +0100 Subject: [PATCH 1/2] Add custom button refresh time As supposed in #18 --- README.md | 3 ++- argos@pew.worldwidemann.com/button.js | 33 +++++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c94f2a3..989abd6 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. @@ -232,6 +232,7 @@ Control how the line is rendered. | `ansi` | `true` or `false` | If `false`, disable interpretation of ANSI escape sequences in the line text. | | `useMarkup` | `true` or `false` | If `false`, disable interpretation of Pango markup in the line text. **Argos only.** | | `unescape` | `true` or `false` | If `false`, disable interpretation of backslash escapes such as `\n` in the line text. **Argos only.** | +| `timeout` | Timeout in seconds | If the line is a button line, it sets how long an entry is visible (defaults to 3) **Argos only.** | #### Actions diff --git a/argos@pew.worldwidemann.com/button.js b/argos@pew.worldwidemann.com/button.js index cd7bec2..5e4ed0d 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,8 +59,10 @@ var ArgosButton = new Lang.Class({ if (this._updateTimeout !== null) Mainloop.source_remove(this._updateTimeout); - if (this._cycleTimeout !== null) - Mainloop.source_remove(this._cycleTimeout); + if (this._cycleTimeouts.length > 0){ + this._cycleTimeouts.forEach(cycle => Mainloop.source_remove(cycle)); + this._cycleTimeouts = []; + } this.menu.removeAll(); }, @@ -131,9 +133,9 @@ var ArgosButton = new Lang.Class({ this.menu.removeAll(); - if (this._cycleTimeout !== null) { - Mainloop.source_remove(this._cycleTimeout); - this._cycleTimeout = null; + if (this._cycleTimeouts.length > 0) { + this._cycleTimeouts.forEach(cycle => Mainloop.source_remove(cycle)); + this._cycleTimeouts = []; } if (buttonLines.length === 0) { @@ -141,15 +143,18 @@ var ArgosButton = new Lang.Class({ } 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])); } From 440947c5c53672e138b178024fb627a634900c55 Mon Sep 17 00:00:00 2001 From: Henning Bopp Date: Mon, 31 Dec 2018 15:04:56 +0100 Subject: [PATCH 2/2] Fixed code style and removed README additions --- README.md | 1 - argos@pew.worldwidemann.com/button.js | 11 +++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 989abd6..1609d3b 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,6 @@ Control how the line is rendered. | `ansi` | `true` or `false` | If `false`, disable interpretation of ANSI escape sequences in the line text. | | `useMarkup` | `true` or `false` | If `false`, disable interpretation of Pango markup in the line text. **Argos only.** | | `unescape` | `true` or `false` | If `false`, disable interpretation of backslash escapes such as `\n` in the line text. **Argos only.** | -| `timeout` | Timeout in seconds | If the line is a button line, it sets how long an entry is visible (defaults to 3) **Argos only.** | #### Actions diff --git a/argos@pew.worldwidemann.com/button.js b/argos@pew.worldwidemann.com/button.js index 5e4ed0d..e2adcdc 100644 --- a/argos@pew.worldwidemann.com/button.js +++ b/argos@pew.worldwidemann.com/button.js @@ -59,11 +59,8 @@ var ArgosButton = new Lang.Class({ if (this._updateTimeout !== null) Mainloop.source_remove(this._updateTimeout); - if (this._cycleTimeouts.length > 0){ - this._cycleTimeouts.forEach(cycle => Mainloop.source_remove(cycle)); - this._cycleTimeouts = []; - } + this._cycleTimeouts.forEach(cycle => Mainloop.source_remove(cycle)); this.menu.removeAll(); }, @@ -133,10 +130,8 @@ var ArgosButton = new Lang.Class({ this.menu.removeAll(); - if (this._cycleTimeouts.length > 0) { - this._cycleTimeouts.forEach(cycle => Mainloop.source_remove(cycle)); - this._cycleTimeouts = []; - } + 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));