Skip to content

Commit 9ec1f0b

Browse files
authored
[desaturate-all@hkoosha] Add some new features (#7130)
1. Add "bedtime mode" where the user can configure an enable/disable time 2. Add an option to restore the previous effect state on Cinnamon startup 3. Add the ability to control the saturation amount (gray-scale 0% to 100%) * Closes #7103
1 parent a0f7042 commit 9ec1f0b

File tree

14 files changed

+494
-39
lines changed

14 files changed

+494
-39
lines changed

desaturate-all@hkoosha/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# Desaturate All
22

3-
_Make your workspace looklike all greyscale._
3+
Make your workspace grey-scale.
4+
5+
## Features:
6+
7+
1. Make the screen 100% grey-scale (or any amount of color desaturation you choose)
8+
2. Keyboard shortcut to toggle the effect (optional)
9+
3. Automatically restores the effect state on Cinnamon startup (optional)
10+
4. Automatically enables and disables the effect at specified times, aka "bedtime mode" (optional)
11+
412

desaturate-all@hkoosha/files/desaturate-all@hkoosha/applet.js

+85-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Settings = imports.ui.settings;
44
const UUID = "desaturate-all@hkoosha";
55
const Clutter = imports.gi.Clutter;
66
const Main = imports.ui.main;
7+
const Mainloop = imports.mainloop;
78

89
function MyApplet() {
910
this._init.apply(this, arguments);
@@ -12,7 +13,7 @@ function MyApplet() {
1213
MyApplet.prototype = {
1314
__proto__: Applet.IconApplet.prototype,
1415

15-
_init: function(aMetadata, aOrientation, aPanelHeight, aInstanceId) {
16+
_init(aMetadata, aOrientation, aPanelHeight, aInstanceId) {
1617
Applet.IconApplet.prototype._init.call(this, aOrientation, aPanelHeight, aInstanceId);
1718

1819
if (Applet.hasOwnProperty("AllowedLayout")) {
@@ -23,25 +24,104 @@ MyApplet.prototype = {
2324
this.set_applet_icon_symbolic_name("applications-graphics");
2425

2526
this.settings = new Settings.AppletSettings(this, UUID, this.instance_id);
27+
2628
this.settings.bind("keybinding", "keybinding", this.on_keybinding_changed);
29+
this.settings.bind("saturation", "saturation", this.on_saturation_changed);
30+
this.settings.bind("resume-on-startup", "resumeOnStartup");
31+
this.settings.bind("state", "state");
32+
33+
this.settings.connect( "changed::automatic", Lang.bind(this, this.on_automatic_changed));
34+
this.settings.connect( "changed::start-timechooser", Lang.bind(this, this.on_time_changed));
35+
this.settings.connect( "changed::end-timechooser", Lang.bind(this, this.on_time_changed));
2736

2837
this.on_keybinding_changed();
38+
this.on_saturation_changed();
39+
if (!this.settings.getValue("automatic")) {
40+
if (this.resumeOnStartup && this.state)
41+
this._toggleEffect();
42+
} else {
43+
this._toggleEffect_based_on_time("init");
44+
}
2945
},
3046

31-
_toggleEffect: function() {
32-
if (Main.uiGroup.has_effects() && Main.uiGroup.get_effects().indexOf(this.effect) > -1) {
47+
_toggleEffect(enable = null) {
48+
let effectEnabled = Main.uiGroup.has_effects() && Main.uiGroup.get_effects().indexOf(this.effect) > -1;
49+
if (enable != true && effectEnabled) {
3350
Main.uiGroup.remove_effect(this.effect);
34-
} else {
51+
this.settings.setValue("state", false);
52+
} else if (enable != false && !effectEnabled){
3553
Main.uiGroup.add_effect(this.effect);
54+
this.settings.setValue("state", true);
55+
}
56+
},
57+
58+
_toggleEffect_based_on_time() {
59+
if (this.toggleDelay) {
60+
Mainloop.source_remove(this.toggleDelay);
61+
this.toggleDelay = null;
62+
}
63+
64+
if (!this.settings.getValue("automatic"))
65+
return;
66+
67+
const date = new Date();
68+
const enableAt = new Date();
69+
const disableAt = new Date();
70+
71+
let enableTime = this.settings.getValue("start-timechooser");
72+
enableAt.setHours( enableTime.h );
73+
enableAt.setMinutes( enableTime.m );
74+
enableAt.setSeconds( 0 );
75+
76+
let disableTime = this.settings.getValue("end-timechooser");
77+
disableAt.setHours( disableTime.h );
78+
disableAt.setMinutes( disableTime.m );
79+
disableAt.setSeconds( 0 );
80+
81+
if (disableAt < enableAt)
82+
disableAt.setDate( disableAt.getDate() + 1 );
83+
84+
let enable = (date < disableAt && date >= enableAt);
85+
this._toggleEffect( enable );
86+
87+
let diffTime;
88+
if (enable) {
89+
diffTime = Math.abs(disableAt - date) / 1000;
90+
//log( `Disabling in ${diffTime} seconds` );
91+
} else {
92+
diffTime = Math.abs(enableAt - date) / 1000;
93+
//log( `Enabling in ${diffTime} seconds` );
94+
}
95+
this.toggleDelay = Mainloop.timeout_add_seconds(diffTime, () => {this.toggleDelay = null; this._toggleEffect_based_on_time();} );
96+
},
97+
98+
on_automatic_changed(signal, key, oldValue, value) {
99+
if (oldValue != value) {
100+
this._toggleEffect_based_on_time();
36101
}
37102
},
38103

39-
on_applet_clicked: function() {
104+
on_time_changed(signal, key, oldValue, value) {
105+
if (oldValue.h !== value.h || oldValue.m !== value.m) {
106+
this._toggleEffect_based_on_time();
107+
}
108+
},
109+
110+
on_applet_clicked() {
40111
this._toggleEffect();
41112
},
42113

43114
on_keybinding_changed() {
44115
Main.keybindingManager.addHotKey(UUID, this.keybinding, Lang.bind(this, this._toggleEffect));
116+
},
117+
118+
on_saturation_changed() {
119+
if (!this.satDelay) {
120+
this.effect.set_factor((100-this.saturation)/100);
121+
} else {
122+
Mainloop.source_remove(this.satDelay);
123+
}
124+
this.satDelay = Mainloop.timeout_add(200, () => this.satDelay = null );
45125
}
46126
};
47127

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "Desaturate All",
33
"uuid": "desaturate-all@hkoosha",
4-
"description": "Convert your screen to grayscale."
4+
"description": "Convert your screen to gray-scale.",
5+
"version": "1.1"
56
}

desaturate-all@hkoosha/files/desaturate-all@hkoosha/po/ca.po

+35-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ msgstr ""
99
"Project-Id-Version: \n"
1010
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-applets/"
1111
"issues\n"
12-
"POT-Creation-Date: 2025-01-22 12:52-0500\n"
12+
"POT-Creation-Date: 2025-04-27 15:03-0400\n"
1313
"PO-Revision-Date: 2025-02-13 20:57+0100\n"
1414
"Last-Translator: Odyssey <odysseyhyd@gmail.com>\n"
1515
"Language-Team: \n"
@@ -24,9 +24,41 @@ msgid "Desaturate All"
2424
msgstr "Dessaturar Tot"
2525

2626
#. metadata.json->description
27-
msgid "Convert your screen to grayscale."
27+
#, fuzzy
28+
msgid "Convert your screen to gray-scale."
2829
msgstr "Converteix la teva pantalla a escala de grisos."
2930

31+
#. settings-schema.json->saturation->description
32+
msgid "Color saturation"
33+
msgstr ""
34+
3035
#. settings-schema.json->keybinding->description
31-
msgid "Shortcut to toggle grayscale"
36+
#, fuzzy
37+
msgid "Shortcut to toggle desaturation effect"
3238
msgstr "Drecera del teclat per alternar l'escala de grisos"
39+
40+
#. settings-schema.json->automatic->description
41+
msgid "Automatic"
42+
msgstr ""
43+
44+
#. settings-schema.json->automatic->tooltip
45+
msgid ""
46+
"Automatically enable and disable the desaturation effect based on the time "
47+
"of day"
48+
msgstr ""
49+
50+
#. settings-schema.json->start-timechooser->description
51+
msgid "Time of day to automatically enable"
52+
msgstr ""
53+
54+
#. settings-schema.json->end-timechooser->description
55+
msgid "Time of day to automatically disable"
56+
msgstr ""
57+
58+
#. settings-schema.json->resume-on-startup->description
59+
msgid "Restore desaturation effect state on startup"
60+
msgstr ""
61+
62+
#. settings-schema.json->resume-on-startup->tooltip
63+
msgid "Restore the previously set desaturation state when cinnamon starts"
64+
msgstr ""

desaturate-all@hkoosha/files/desaturate-all@hkoosha/po/da.po

+34-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-applets/"
1010
"issues\n"
11-
"POT-Creation-Date: 2025-01-22 12:52-0500\n"
11+
"POT-Creation-Date: 2025-04-27 15:03-0400\n"
1212
"PO-Revision-Date: 2023-12-28 15:43+0100\n"
1313
"Last-Translator: Alan Mortensen <alanmortensen.am@gmail.com>\n"
1414
"Language-Team: \n"
@@ -24,9 +24,40 @@ msgid "Desaturate All"
2424
msgstr "Fjern farver overalt"
2525

2626
#. metadata.json->description
27-
msgid "Convert your screen to grayscale."
27+
#, fuzzy
28+
msgid "Convert your screen to gray-scale."
2829
msgstr "Konvertér alle farver til gråtoner og tilbage igen med et enkelt klik."
2930

31+
#. settings-schema.json->saturation->description
32+
msgid "Color saturation"
33+
msgstr ""
34+
3035
#. settings-schema.json->keybinding->description
31-
msgid "Shortcut to toggle grayscale"
36+
msgid "Shortcut to toggle desaturation effect"
37+
msgstr ""
38+
39+
#. settings-schema.json->automatic->description
40+
msgid "Automatic"
41+
msgstr ""
42+
43+
#. settings-schema.json->automatic->tooltip
44+
msgid ""
45+
"Automatically enable and disable the desaturation effect based on the time "
46+
"of day"
47+
msgstr ""
48+
49+
#. settings-schema.json->start-timechooser->description
50+
msgid "Time of day to automatically enable"
51+
msgstr ""
52+
53+
#. settings-schema.json->end-timechooser->description
54+
msgid "Time of day to automatically disable"
55+
msgstr ""
56+
57+
#. settings-schema.json->resume-on-startup->description
58+
msgid "Restore desaturation effect state on startup"
59+
msgstr ""
60+
61+
#. settings-schema.json->resume-on-startup->tooltip
62+
msgid "Restore the previously set desaturation state when cinnamon starts"
3263
msgstr ""

desaturate-all@hkoosha/files/desaturate-all@hkoosha/po/de.po

+34-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-applets/"
1010
"issues\n"
11-
"POT-Creation-Date: 2025-01-22 12:52-0500\n"
11+
"POT-Creation-Date: 2025-04-27 15:03-0400\n"
1212
"PO-Revision-Date: 2024-03-22 22:14+0100\n"
1313
"Last-Translator: Martin Posselt <nekomajin@gmx.de>\n"
1414
"Language-Team: \n"
@@ -24,9 +24,40 @@ msgid "Desaturate All"
2424
msgstr "Alles entsättigen"
2525

2626
#. metadata.json->description
27-
msgid "Convert your screen to grayscale."
27+
#, fuzzy
28+
msgid "Convert your screen to gray-scale."
2829
msgstr "Die Bildschirmausgabe in Graustufen umwandeln."
2930

31+
#. settings-schema.json->saturation->description
32+
msgid "Color saturation"
33+
msgstr ""
34+
3035
#. settings-schema.json->keybinding->description
31-
msgid "Shortcut to toggle grayscale"
36+
msgid "Shortcut to toggle desaturation effect"
37+
msgstr ""
38+
39+
#. settings-schema.json->automatic->description
40+
msgid "Automatic"
41+
msgstr ""
42+
43+
#. settings-schema.json->automatic->tooltip
44+
msgid ""
45+
"Automatically enable and disable the desaturation effect based on the time "
46+
"of day"
47+
msgstr ""
48+
49+
#. settings-schema.json->start-timechooser->description
50+
msgid "Time of day to automatically enable"
51+
msgstr ""
52+
53+
#. settings-schema.json->end-timechooser->description
54+
msgid "Time of day to automatically disable"
55+
msgstr ""
56+
57+
#. settings-schema.json->resume-on-startup->description
58+
msgid "Restore desaturation effect state on startup"
59+
msgstr ""
60+
61+
#. settings-schema.json->resume-on-startup->tooltip
62+
msgid "Restore the previously set desaturation state when cinnamon starts"
3263
msgstr ""

desaturate-all@hkoosha/files/desaturate-all@hkoosha/po/desaturate-all@hkoosha.pot

+34-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#, fuzzy
66
msgid ""
77
msgstr ""
8-
"Project-Id-Version: desaturate-all@hkoosha 1.0\n"
8+
"Project-Id-Version: desaturate-all@hkoosha 1.1\n"
99
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-applets/"
1010
"issues\n"
11-
"POT-Creation-Date: 2025-01-22 12:52-0500\n"
11+
"POT-Creation-Date: 2025-04-27 15:03-0400\n"
1212
"PO-Revision-Date: \n"
1313
"Last-Translator: \n"
1414
"Language-Team: \n"
@@ -22,9 +22,39 @@ msgid "Desaturate All"
2222
msgstr ""
2323

2424
#. metadata.json->description
25-
msgid "Convert your screen to grayscale."
25+
msgid "Convert your screen to gray-scale."
26+
msgstr ""
27+
28+
#. settings-schema.json->saturation->description
29+
msgid "Color saturation"
2630
msgstr ""
2731

2832
#. settings-schema.json->keybinding->description
29-
msgid "Shortcut to toggle grayscale"
33+
msgid "Shortcut to toggle desaturation effect"
34+
msgstr ""
35+
36+
#. settings-schema.json->automatic->description
37+
msgid "Automatic"
38+
msgstr ""
39+
40+
#. settings-schema.json->automatic->tooltip
41+
msgid ""
42+
"Automatically enable and disable the desaturation effect based on the time "
43+
"of day"
44+
msgstr ""
45+
46+
#. settings-schema.json->start-timechooser->description
47+
msgid "Time of day to automatically enable"
48+
msgstr ""
49+
50+
#. settings-schema.json->end-timechooser->description
51+
msgid "Time of day to automatically disable"
52+
msgstr ""
53+
54+
#. settings-schema.json->resume-on-startup->description
55+
msgid "Restore desaturation effect state on startup"
56+
msgstr ""
57+
58+
#. settings-schema.json->resume-on-startup->tooltip
59+
msgid "Restore the previously set desaturation state when cinnamon starts"
3060
msgstr ""

0 commit comments

Comments
 (0)