Skip to content

Commit 2c7d56d

Browse files
fix: preserve backdrop-filter during brightness transitions
Fixes #373 Switched from CSS filter to overlay-based brightness/temperature control to fix backdrop-filter effects being removed during transitions. This also simplifies the implementation significantly. Brightness range is now 0-100% (can only darken, not brighten). Values >100% generally looked poor anyway.
1 parent 8029896 commit 2c7d56d

5 files changed

Lines changed: 23 additions & 33 deletions

File tree

MMM-Remote-Control.css

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#remote-control-overlay-temp {
1+
/* Overlays for temperature and brightness visualization - allow interaction through them */
2+
#remote-control-overlay-temp,
3+
#remote-control-overlay-brightness {
24
position: fixed;
35
top: 0;
46
left: 0;
@@ -9,11 +11,6 @@
911
pointer-events: none;
1012
}
1113

12-
/* Class for elements that receive brightness filter animation */
13-
.brightness-filtered {
14-
transition: filter 1.5s ease-in-out;
15-
}
16-
1714
/* QR Code Styling */
1815
.qrcode-container {
1916
display: flex;

MMM-Remote-Control.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,18 @@ Module.register("MMM-Remote-Control", {
135135
},
136136

137137
setBrightness (newBrightnessValue) {
138-
if (newBrightnessValue < 10) {
139-
newBrightnessValue = 0; // Setting Brightness to 0 turns off some displays backlight, it's neat for power saving
140-
} else if (newBrightnessValue > 200) {
141-
newBrightnessValue = 200;
142-
}
143-
const filterValue = `brightness(${newBrightnessValue}%)`;
138+
newBrightnessValue = Math.max(0, Math.min(100, newBrightnessValue));
144139
Log.debug("BRIGHTNESS", newBrightnessValue);
145-
const childNodesList = document.body.childNodes;
146-
for (const node of childNodesList) {
147-
// Only process Element nodes, skip scripts and text nodes
148-
if (node.nodeType === Node.ELEMENT_NODE && node.nodeName !== "SCRIPT") {
149-
node.style.filter = filterValue;
150-
// Only add animation class to elements without backdrop-filter
151-
const computed = globalThis.getComputedStyle(node);
152-
if (computed.backdropFilter === "none" && this.brightness !== newBrightnessValue) {
153-
node.classList.add("brightness-filtered");
154-
}
155-
}
140+
141+
let overlay = document.getElementById("remote-control-overlay-brightness");
142+
if (!overlay) {
143+
overlay = document.createElement("div");
144+
overlay.id = "remote-control-overlay-brightness";
145+
document.body.insertBefore(overlay, document.body.firstChild);
156146
}
147+
148+
const opacity = (100 - newBrightnessValue) / 100;
149+
overlay.style.backgroundColor = `rgba(0, 0, 0, ${opacity})`;
157150
this.brightness = newBrightnessValue;
158151
},
159152

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ See the [Examples Guide](docs/guide/examples.md) for more integration examples w
192192
193193
#### MagicMirror² Control
194194
195-
| Action | Description |
196-
| :--------: | -------------------------------------------------------------------------------------------------------------------------------------- |
197-
| RESTART | Restart your MagicMirror² |
198-
| REFRESH | Refresh mirror page |
199-
| UPDATE | Update MagicMirror² and any of it's modules |
200-
| SAVE | Save the current configuration (show and hide status of modules, and brightness), will be applied after the mirror starts |
201-
| BRIGHTNESS | Change mirror brightness, with the new value specified by `value`. `100` equals the default, possible range is between `10` and `200`. |
195+
| Action | Description |
196+
| :--------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
197+
| RESTART | Restart your MagicMirror² |
198+
| REFRESH | Refresh mirror page |
199+
| UPDATE | Update MagicMirror² and any of it's modules |
200+
| SAVE | Save the current configuration (show and hide status of modules, and brightness), will be applied after the mirror starts |
201+
| BRIGHTNESS | Change mirror brightness, with the new value specified by `value`. `100` equals the default (full brightness), possible range is between `0` (black) and `100`. |
202202
203203
#### MagicMirror² Electron Browser Window Control
204204

docs/guide/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Action: [
7777
},
7878
{
7979
notification: "REMOTE_ACTION",
80-
payload: { action: "BRIGHTNESS", value: 200 }
80+
payload: { action: "BRIGHTNESS", value: 100 }
8181
},
8282
{ notification: "REMOTE_ACTION", payload: { action: "REFRESH" } },
8383
{ notification: "REMOTE_ACTION", payload: { action: "RESTART" } }

remote.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@
323323
id="brightness-slider"
324324
type="range"
325325
min="0"
326-
max="200"
327-
step="10"
326+
max="100"
327+
step="5"
328328
value="100"
329329
class="slider"
330330
aria-label="%%TRANSLATE:BRIGHTNESS%%"

0 commit comments

Comments
 (0)