From 56b481f1754fdfe78eb542312eae2d6d4ba3b010 Mon Sep 17 00:00:00 2001 From: claudiux <33965039+claudiux@users.noreply.github.com> Date: Thu, 12 Dec 2024 21:49:31 +0100 Subject: [PATCH] horizontal-osd@berk-karaal: Improves compatibility with Cinnamon 6.4 (#791) --- .../horizontal-osd@berk-karaal/CustomOsd.js | 79 +++++++++++++++---- .../horizontal-osd@berk-karaal/metadata.json | 6 +- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/horizontal-osd@berk-karaal/files/horizontal-osd@berk-karaal/CustomOsd.js b/horizontal-osd@berk-karaal/files/horizontal-osd@berk-karaal/CustomOsd.js index da65f610..f1f38ea7 100644 --- a/horizontal-osd@berk-karaal/files/horizontal-osd@berk-karaal/CustomOsd.js +++ b/horizontal-osd@berk-karaal/files/horizontal-osd@berk-karaal/CustomOsd.js @@ -7,11 +7,48 @@ const Tweener = imports.ui.tweener; const Gio = imports.gi.Gio; const Gdk = imports.gi.Gdk; const Meta = imports.gi.Meta; +const GLib = imports.gi.GLib; + +const CINNAMON_VERSION = GLib.getenv('CINNAMON_VERSION'); const LEVEL_ANIMATION_TIME = 0.1; const FADE_TIME = 0.1; let HIDE_TIMEOUT = 1500; +function version_exceeds(version, min_version) { + let our_version = version.split("."); + let cmp_version = min_version.split("."); + let i; + + for (i = 0; i < our_version.length && i < cmp_version.length; i++) { + let our_part = parseInt(our_version[i]); + let cmp_part = parseInt(cmp_version[i]); + + if (isNaN(our_part) || isNaN(cmp_part)) { + return false; + } + + if (our_part < cmp_part) { + return false; + } else + if (our_part > cmp_part) { + return true; + } + } + + if (our_version.length < cmp_version.length) { + return false; + } else { + return true; + } +} + +// Removal of the percentage in the Cinnamon media OSD, from Cinnamon 6.4. +// See https://github.com/linuxmint/mint22.1-beta/issues/4#issuecomment-2535973291 +let PERCENT_SYMBOL = " %"; +if (version_exceeds(CINNAMON_VERSION, "6.4")) + PERCENT_SYMBOL = ""; + const OSD_SIZE = 110; let extension_settings = null; @@ -139,7 +176,7 @@ OsdWindow.prototype = { setLevel: function (level) { if (level != undefined) { - this._label.set_text(String(level) + " %"); + this._label.set_text(""+ level + PERCENT_SYMBOL); this._label.visible = this._level.actor.visible = true; if (this.actor.visible) @@ -316,23 +353,31 @@ OsdWindow.prototype = { }, _onOsdSettingsChanged: function () { - let currentSize = this._osdSettings.get_string("show-media-keys-osd"); - - switch (currentSize) { - case "disabled": - this._osdBaseSize = null; - break; - case "small": - this._sizeMultiplier = 0.7; - this._osdBaseSize = Math.floor(OSD_SIZE * this._sizeMultiplier); - break; - case "large": - this._sizeMultiplier = 1.0; - this._osdBaseSize = OSD_SIZE; - break; - default: + let currentSize = this._osdSettings.get_value("show-media-keys-osd"); + if (typeof(currentSize) == "boolean") { // Cinnamon 6+ + if (currentSize) { this._sizeMultiplier = 0.85; this._osdBaseSize = Math.floor(OSD_SIZE * this._sizeMultiplier); + } else { + this._osdBaseSize = null; + } + } else { + switch (currentSize) { + case "disabled": + this._osdBaseSize = null; + break; + case "small": + this._sizeMultiplier = 0.7; + this._osdBaseSize = Math.floor(OSD_SIZE * this._sizeMultiplier); + break; + case "large": + this._sizeMultiplier = 1.0; + this._osdBaseSize = OSD_SIZE; + break; + default: + this._sizeMultiplier = 0.85; + this._osdBaseSize = Math.floor(OSD_SIZE * this._sizeMultiplier); + } } this._monitorsChanged(); @@ -402,4 +447,4 @@ OsdWindowManager.prototype = { for (let i = 0; i < this._osdWindows.length; i++) this._osdWindows[i].cancel(); } -}; \ No newline at end of file +}; diff --git a/horizontal-osd@berk-karaal/files/horizontal-osd@berk-karaal/metadata.json b/horizontal-osd@berk-karaal/files/horizontal-osd@berk-karaal/metadata.json index f31533e9..ba5cfc5c 100644 --- a/horizontal-osd@berk-karaal/files/horizontal-osd@berk-karaal/metadata.json +++ b/horizontal-osd@berk-karaal/files/horizontal-osd@berk-karaal/metadata.json @@ -1,8 +1,8 @@ { "uuid": "horizontal-osd@berk-karaal", "name": "Horizontal OSD", - "author": "Berk Karaal", - "version": "0.0.2", + "author": "berk-karaal", + "version": "0.0.3", "description": "Horizontal and customizable OSDs", "url": "https://github.com/berk-karaal/cinnamon-horizontal-osd", "website": "https://github.com/berk-karaal/cinnamon-horizontal-osd", @@ -10,4 +10,4 @@ "5.2", "5.4" ] -} \ No newline at end of file +}