From 46abf97598e41f253971bb543911027e6b38c375 Mon Sep 17 00:00:00 2001 From: Andrew de los Reyes Date: Sun, 10 Nov 2024 13:34:54 -0800 Subject: [PATCH 1/3] DRAFT: writeCollection: Wait until previous invocation finished This commit changes how writeCollection works. Previously, it seemed to be a forced delay of some number of milliseconds that would need to happen before a call to ddcutil to change brightness could occur. Update to use a simpler logic: No more delays. If a ddcutil set brightness command is running, queue the next command that's generated and run it immediately after the first command completes. If a command is queued and another one comes in, the newest one replaces the queued one, becoming the only queued one. This patch is a draft. If this concept is acceptable, a futher update would be needed to remove the concept of writeCollectorWaitMs. Alternatively, we could keep the concept and mandate a minimum interval between two invocationsn of ddcutil, either measured from start time to start time, or end time to start time. --- .../convenienceExt.js | 3 + .../extension.js | 82 +++++++------------ 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/display-brightness-ddcutil@themightydeity.github.com/convenienceExt.js b/display-brightness-ddcutil@themightydeity.github.com/convenienceExt.js index 432e400..53a8c30 100644 --- a/display-brightness-ddcutil@themightydeity.github.com/convenienceExt.js +++ b/display-brightness-ddcutil@themightydeity.github.com/convenienceExt.js @@ -27,6 +27,9 @@ export function spawnWithCallback(settings, argv, callback) { callback(stderr); else if (stdout) callback(stdout); + else { + callback(""); + } } } catch (e) { brightnessLog(settings, e.message); diff --git a/display-brightness-ddcutil@themightydeity.github.com/extension.js b/display-brightness-ddcutil@themightydeity.github.com/extension.js index 97769fa..acb878d 100644 --- a/display-brightness-ddcutil@themightydeity.github.com/extension.js +++ b/display-brightness-ddcutil@themightydeity.github.com/extension.js @@ -136,11 +136,6 @@ export default class DDCUtilBrightnessControlExtension extends Extension { if (_reloadExtensionTimer) clearTimeout(_reloadExtensionTimer); - Object.keys(writeCollection).forEach(bus => { - if (writeCollection[bus].interval !== null) { - clearInterval(writeCollection[bus].interval); - } - }); if (monitorChangeTimeout !== null) { clearTimeout(monitorChangeTimeout) monitorChangeTimeout = null; @@ -154,45 +149,38 @@ export default class DDCUtilBrightnessControlExtension extends Extension { } } - ddcWriteInQueue(displayBus) { - if (writeCollection[displayBus].interval == null) { - writeCollection[displayBus].interval = setInterval(() => { - if (writeCollection[displayBus].countdown === 0) { - brightnessLog(this.settings, `Write in queue countdown over for ${displayBus}`); - writeCollection[displayBus].writer(); - clearInterval(writeCollection[displayBus].interval); - writeCollection[displayBus].interval = null; - const writeCollectorWaitMs = parseInt(this.settings.get_double('ddcutil-queue-ms')); - writeCollection[displayBus].countdown = writeCollectorWaitMs; - } else { - writeCollection[displayBus].countdown = writeCollection[displayBus].countdown - 1; - } - }, 1); + ddcWriteCollector(displayBus, writer) { + const kickoffNext = (reason) => { + brightnessLog(this.settings, `kickoffNext called ${reason}`); + writeCollection[displayBus].current = writeCollection[displayBus].next; + writeCollection[displayBus].next = null; + if (writeCollection[displayBus].current) { + writeCollection[displayBus].current(() => { + if (writeCollection === null) { + // Must be disabling. Do nothing. + return; + } + kickoffNext("on chain"); + }); + } else { + brightnessLog(this.settings, "writer done, nothing next"); + } } - } - ddcWriteCollector(displayBus, writer) { if (displayBus in writeCollection) { - /* by setting writer to latest one, - when waiting is over latest writer will run */ - writeCollection[displayBus].writer = writer; - brightnessLog(this.settings, `Write collector update, current countdown is ${writeCollection[displayBus].countdown} for ${displayBus}`); - /* countdown is over, meaning update process for this display can be added to the queue */ - const writeCollectorWaitMs = parseInt(this.settings.get_double('ddcutil-queue-ms')); - if (writeCollection[displayBus].countdown === writeCollectorWaitMs) { - brightnessLog(this.settings, 'Write collector update, trigger queue again'); - this.ddcWriteInQueue(displayBus); + writeCollection[displayBus].next = writer; + if (writeCollection[displayBus].current) { + brightnessLog(this.settings, "Saving writer for when ready"); + } else { + kickoffNext("on start"); } - } else { - brightnessLog(this.settings, `Write collector defining new display ${displayBus} and adding it to queue`); - /* display query is not defined yet */ - writeCollection[displayBus] = { - countdown: 0, - interval: null, - writer, - }; - this.ddcWriteInQueue(displayBus); + return; } + writeCollection[displayBus] = { + next: writer, + current: null + }; + kickoffNext("on start"); } setBrightness(display, newValue) { @@ -208,9 +196,10 @@ export default class DDCUtilBrightnessControlExtension extends Extension { const ddcutilPath = this.settings.get_string('ddcutil-binary-path'); const ddcutilAdditionalArgs = this.settings.get_string('ddcutil-additional-args'); const sleepMultiplier = this.settings.get_double('ddcutil-sleep-multiplier') / 40; - const writer = () => { - brightnessLog(this.settings, `async ${ddcutilPath} setvcp ${display.vcp} ${newBrightness} --bus ${display.bus} --sleep-multiplier ${sleepMultiplier} ${ddcutilAdditionalArgs}`); - GLib.spawn_command_line_async(`${ddcutilPath} setvcp ${display.vcp} ${newBrightness} --bus ${display.bus} --sleep-multiplier ${sleepMultiplier} ${ddcutilAdditionalArgs}`); + const writer = (ondone) => { + const cmd = `${ddcutilPath} setvcp ${display.vcp} ${newBrightness} --bus ${display.bus} --sleep-multiplier ${sleepMultiplier} ${ddcutilAdditionalArgs}`.split(" ").filter(x => x !== ""); + brightnessLog(this.settings, `async ${cmd.join(" ")}`); + spawnWithCallback(this.settings, cmd, (result) => {if (ondone) {ondone();}}); }; brightnessLog(this.settings, `display ${display.name}, current: ${display.current} => ${newValue / 100}, new brightness: ${newBrightness}, new value: ${newValue}`); display.current = newValue / 100; @@ -699,15 +688,6 @@ export default class DDCUtilBrightnessControlExtension extends Extension { this.reloadMenuWidgets(); if (this.settings.get_boolean('verbose-debugging')) brightnessLog(this.settings, JSON.stringify(this.settingsToJSObject())); - - const writeCollectorWaitMs = parseInt(this.settings.get_double('ddcutil-queue-ms')); - Object.keys(writeCollection).forEach(displayBus => { - writeCollection[displayBus].countdown = writeCollectorWaitMs; - if (writeCollection[displayBus].interval !== null) - clearInterval(writeCollection[displayBus].interval); - - writeCollection[displayBus].interval = null; - }); } onMonitorChange() { From 7a2f45177601cce9d8cc31c12a6c0c96e6682622 Mon Sep 17 00:00:00 2001 From: Andrew de los Reyes Date: Sun, 10 Nov 2024 13:42:28 -0800 Subject: [PATCH 2/3] convenienceExt.js: Add more debug logging --- .../convenienceExt.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/display-brightness-ddcutil@themightydeity.github.com/convenienceExt.js b/display-brightness-ddcutil@themightydeity.github.com/convenienceExt.js index 53a8c30..bf452da 100644 --- a/display-brightness-ddcutil@themightydeity.github.com/convenienceExt.js +++ b/display-brightness-ddcutil@themightydeity.github.com/convenienceExt.js @@ -11,11 +11,13 @@ export function brightnessLog(settings, str) { } export function spawnWithCallback(settings, argv, callback) { + brightnessLog(settings, `Calling: ${argv.join(' ')}`); const proc = Gio.Subprocess.new(argv, Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_SILENCE); proc.communicate_utf8_async(null, null, (proc, res) => { try { const [, stdout, stderr] = proc.communicate_utf8_finish(res); + brightnessLog(settings, "subprocess ended"); if (proc.get_successful()) { callback(stdout); } else { From 56a5b21a2d6b1c852c6efea96faaabf2f052b04f Mon Sep 17 00:00:00 2001 From: Andrew de los Reyes Date: Sun, 10 Nov 2024 13:42:59 -0800 Subject: [PATCH 3/3] changes in autogenerated files --- .../po/de.po | 12 ++++++------ .../po/display-brightness-ddcutil.pot | 12 ++++++------ .../po/es.po | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/display-brightness-ddcutil@themightydeity.github.com/po/de.po b/display-brightness-ddcutil@themightydeity.github.com/po/de.po index b4be99f..08f8426 100644 --- a/display-brightness-ddcutil@themightydeity.github.com/po/de.po +++ b/display-brightness-ddcutil@themightydeity.github.com/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-21 23:16+0300\n" +"POT-Creation-Date: 2024-11-10 13:27-0800\n" "PO-Revision-Date: 2022-02-13 09:53+0100\n" "Last-Translator: \n" "Language-Team: \n" @@ -168,20 +168,20 @@ msgstr "" msgid "Initializing" msgstr "Initialisiere" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:301 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:290 msgid "Settings" msgstr "Einstellungen" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:310 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:299 msgid "Reload" msgstr "Neu laden" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:327 -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:331 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:316 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:320 msgid "All" msgstr "Alle" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:600 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:589 msgid "Internal" msgstr "" diff --git a/display-brightness-ddcutil@themightydeity.github.com/po/display-brightness-ddcutil.pot b/display-brightness-ddcutil@themightydeity.github.com/po/display-brightness-ddcutil.pot index 2f6070f..0509c13 100644 --- a/display-brightness-ddcutil@themightydeity.github.com/po/display-brightness-ddcutil.pot +++ b/display-brightness-ddcutil@themightydeity.github.com/po/display-brightness-ddcutil.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-22 00:14+0300\n" +"POT-Creation-Date: 2024-11-10 13:31-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -160,20 +160,20 @@ msgstr "" msgid "Initializing" msgstr "" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:301 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:290 msgid "Settings" msgstr "" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:310 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:299 msgid "Reload" msgstr "" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:327 -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:331 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:316 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:320 msgid "All" msgstr "" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:600 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:589 msgid "Internal" msgstr "" diff --git a/display-brightness-ddcutil@themightydeity.github.com/po/es.po b/display-brightness-ddcutil@themightydeity.github.com/po/es.po index 62404af..3c350d4 100644 --- a/display-brightness-ddcutil@themightydeity.github.com/po/es.po +++ b/display-brightness-ddcutil@themightydeity.github.com/po/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: gnome-display-brightness-ddcutil\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-21 23:16+0300\n" +"POT-Creation-Date: 2024-11-10 13:27-0800\n" "PO-Revision-Date: 2023-11-26 12:05+0100\n" "Last-Translator: Óscar Fernández Díaz \n" "Language-Team: Spanish\n" @@ -163,20 +163,20 @@ msgstr "Pulse Esc para cancelar el atajo del teclado." msgid "Initializing" msgstr "Inicializando" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:301 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:290 msgid "Settings" msgstr "Configuración" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:310 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:299 msgid "Reload" msgstr "Recargar" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:327 -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:331 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:316 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:320 msgid "All" msgstr "Todos" -#: display-brightness-ddcutil@themightydeity.github.com/extension.js:600 +#: display-brightness-ddcutil@themightydeity.github.com/extension.js:589 msgid "Internal" msgstr ""