Skip to content

Commit 6563415

Browse files
Discojapiluisbocanegra
Discojapi
authored andcommitted
feat: add manual color fetch mode
Disables automatic color extraction to be done manually instead Adds `--manual-fetch` in backend and `manual_fetch` in config and widget Adds `fetch_colors` in config to trigger color extraction from widget 'Fetch colors' button
1 parent f8840ea commit 6563415

File tree

4 files changed

+105
-19
lines changed

4 files changed

+105
-19
lines changed

src/kde_material_you_colors/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def defaults(self):
177177
"chroma_multiplier": [args.chroma_multiplier, 1, 2],
178178
"tone_multiplier": [args.tone_multiplier, 1, 2],
179179
"qdbus_executable": [args.qdbus_executable, None, 3],
180+
"manual_fetch": [args.manual_fetch, False, 0],
181+
"fetch_colors": [None, False, 0],
180182
}
181183

182184
def parse_conf(self):

src/kde_material_you_colors/data/sample_config.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ ncolor = 0
152152
# of detections for those cases to save power.
153153
# NOTE:
154154
# Should be bigger than main_loop_delay (will take main_loop_delay otherwise)
155+
# Ignored if manual color fetch is enabled
155156
# Default is 900 seconds (15 minutes)
156157
# Commented by default
157158
#screenshot_delay = 900
@@ -201,3 +202,9 @@ tone_multiplier = 1
201202
# Default is qdbus6
202203
# Deprecated, no longer needed as of version 1.10.0. Switched to gdbus command from glib2
203204
# qdbus_executable = qdbus6
205+
206+
# Manual fetch
207+
# Disables the automatic color fetching and
208+
# scheduled screenshot take in screenshot mode
209+
# Default is False
210+
manual_fetch = False

src/kde_material_you_colors/main.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ def main():
348348
default=None,
349349
metavar="<string>",
350350
)
351+
parser.add_argument(
352+
"--manual-fetch",
353+
action="store_true",
354+
help="Dissables automatic color fetching",
355+
default=None,
356+
)
351357

352358
# Get commandline arguments
353359
args = parser.parse_args()
@@ -395,12 +401,17 @@ def main():
395401
plugin_watcher = utils.Watcher(wallpaper.plugin)
396402
source_watcher = utils.Watcher(wallpaper.source)
397403
pause_watcher = utils.Watcher(config.read("pause_mode"))
404+
manual_fetch_watcher = utils.Watcher(config.read("manual_fetch"))
405+
fetch_watcher = utils.Watcher(config.read("fetch_colors"))
398406
if pause_watcher.value:
399407
msg = "Pause mode enabled" if pause_watcher.value else "Pause mode disabled"
400408
logging.warning(msg)
401409
if wallpaper.type == "screenshot":
402410
head = "Screenshot mode enabled"
403-
cont = f"Waiting {config.read('screenshot_delay')}s between updates"
411+
if config.read("manual_fetch"):
412+
cont = "Manual color fetch enabled, press 'Fetch colors' in the widget to take a new screenshot"
413+
else:
414+
cont = f"Waiting {config.read('screenshot_delay')}s between updates"
404415
notify.send_notification(head, cont)
405416
logging.warning("%s, %s", head, cont)
406417
if wallpaper.error:
@@ -436,10 +447,21 @@ def main():
436447
#
437448
#
438449
#
439-
#
440-
# update wallpaper
441-
wallpaper.update(config, skip_screenshot=counter != 0)
442-
wallpaper_watcher.set_value(wallpaper.current)
450+
# update wallpaper, only if manual_fetch is false
451+
manual_fetch_watcher.set_value(config.read("manual_fetch"))
452+
453+
if manual_fetch_watcher.has_changed():
454+
msg = "Manual color fetch enabled." if manual_fetch_watcher.value else "Manual color fetch disabled."
455+
logging.info(msg)
456+
457+
fetch_watcher.set_value(config.read("fetch_colors"))
458+
if fetch_watcher.has_changed() and fetch_watcher.value:
459+
logging.info("Fetching colors in current wallpaper...")
460+
counter = 0
461+
462+
if not config.read("manual_fetch") or (fetch_watcher.has_changed() and fetch_watcher.value):
463+
wallpaper.update(config, skip_screenshot=counter != 0)
464+
wallpaper_watcher.set_value(wallpaper.current)
443465

444466
target_cycles = config.read("screenshot_delay") / (
445467
config.read("main_loop_delay") or 1
@@ -477,6 +499,7 @@ def main():
477499
logging.info(f"{wallpaper}")
478500
apply_themes.apply(config, wallpaper, light_mode_watcher.value)
479501
apply = False
502+
counter += 1
480503

481504
if group1:
482505
if wallpaper.error:
@@ -486,7 +509,10 @@ def main():
486509
logging.error(f"Could not get wallpaper {str(wallpaper.error)}")
487510
if plugin_watcher.changed and wallpaper.type == "screenshot":
488511
head = "Screenshot mode enabled"
489-
cont = f"Waiting {config.read('screenshot_delay')}s between updates"
512+
if config.read("manual_fetch"):
513+
cont = "Manual color fetch enabled, press 'Fetch colors' in the widget to take a new screenshot"
514+
else:
515+
cont = f"Waiting {config.read('screenshot_delay')}s between updates"
490516
notify.send_notification(head, cont)
491517
logging.warning("%s, %s", head, cont)
492518
if wallpaper.source:
@@ -499,7 +525,7 @@ def main():
499525
apply_themes.apply(config, wallpaper, light_mode_watcher.value)
500526
counter = 0
501527

502-
if wallpaper.is_screenshot():
528+
if wallpaper.is_screenshot() and not config.read("manual_fetch"):
503529
if target_cycles > counter:
504530
counter += 1
505531
else:

src/plasmoid/package/contents/ui/FullRepresentation.qml

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ ColumnLayout {
5959

6060
property bool pauseMode: false
6161

62+
property bool manual_fetch: false
63+
64+
6265
signal savePauseMode()
6366

67+
6468
property Item parentMain
6569

6670
KCoreAddons.KUser {
@@ -83,7 +87,6 @@ ColumnLayout {
8387
}
8488
}
8589

86-
8790
// Get a list of installed icon themes as id,name
8891
// - discard hidden themes
8992
// - discard cursor themes
@@ -331,7 +334,6 @@ ColumnLayout {
331334
level: 1
332335
text: Plasmoid.metaData.name
333336
}
334-
335337
PlasmaComponents3.ToolButton {
336338
display: PlasmaComponents3.AbstractButton.IconOnly
337339
visible: !onDesktop
@@ -346,7 +348,6 @@ ColumnLayout {
346348
text: parent.text
347349
}
348350
}
349-
350351
PlasmaComponents3.ToolButton {
351352
display: PlasmaComponents3.AbstractButton.IconOnly
352353
checkable: false
@@ -452,14 +453,12 @@ ColumnLayout {
452453
}
453454
}
454455
}
455-
456456
Connections {
457457
target: fullRepresentation
458458
function onSavePauseMode() {
459459
settings.pause_mode = fullRepresentation.pauseMode
460460
}
461461
}
462-
463462
onMaterialYouDataChanged: {
464463
if (materialYouData!=null && materialYouDataString!=null) {
465464
if (JSON.stringify(materialYouData) !== materialYouDataString) {
@@ -545,6 +544,8 @@ ColumnLayout {
545544
property int screenshot_delay: 900; \
546545
property bool once_after_change: false; \
547546
property bool pause_mode: false; \
547+
property bool manual_fetch: false; \
548+
property bool fetch_colors: false; \
548549
property bool screenshot_only_mode: false; \
549550
property int scheme_variant: 5; \
550551
property real chroma_multiplier: 1.0; \
@@ -813,17 +814,37 @@ ColumnLayout {
813814
// Color selection
814815
RowLayout {
815816
Layout.preferredWidth: mainLayout.width
816-
817-
PlasmaComponents3.Label {
818-
text: "Select color"
819-
id:selectColorLabel
820-
Layout.fillWidth: settings.color!==""
817+
RowLayout {
818+
id: selectColorLayout
819+
PlasmaComponents3.Label {
820+
text: "Select color"
821+
id:selectColorLabel
822+
}
823+
// Button to manually fetch the colors on screen //
824+
Timer {
825+
id: fetchTimer
826+
interval: settings.main_loop_delay * 1000; running: false; repeat: false;
827+
onTriggered: settings.fetch_colors = false
828+
}
829+
RowLayout {
830+
PlasmaComponents3.Button {
831+
text: "Fetch colors"
832+
icon.name: 'refreshstructure'
833+
onClicked: {
834+
settings.fetch_colors = true
835+
fetchTimer.start()
836+
}
837+
PlasmaComponents3.ToolTip {
838+
text: "Manually fetch the colors on the current wallpaper"
839+
}
840+
}
841+
}
821842
}
822843

823844
// Single color picker when color is not empty
824845
Components.CustomColorButton { // Components.Custom
825846
id: colorButton
826-
Layout.alignment: Qt.AlignHCenter
847+
Layout.alignment : Qt.AlignRight
827848
visible: settings.color!==""
828849
showAlphaChannel: false
829850
dialogTitle: "Choose source color"
@@ -841,7 +862,7 @@ ColumnLayout {
841862
GridLayout { //PlasmaComponents3.ScrollView
842863
property var gridSpacing: Kirigami.Units.mediumSpacing
843864
visible: settings.color===""
844-
columns: Math.floor((mainLayout.width - selectColorLabel.width) / (
865+
columns: Math.floor((mainLayout.width - selectColorLayout.width) / (
845866
controlHeight * .75 + gridSpacing))
846867
rowSpacing: gridSpacing
847868
columnSpacing: gridSpacing
@@ -1935,6 +1956,36 @@ ColumnLayout {
19351956
}
19361957
}
19371958
}
1959+
RowLayout {
1960+
PlasmaComponents3.Label {
1961+
text: "Manual color fetch only"
1962+
Layout.alignment: Qt.AlignLeft
1963+
}
1964+
1965+
PlasmaComponents3.CheckBox {
1966+
checked: settings.manual_fetch
1967+
1968+
onCheckedChanged: {
1969+
settings.manual_fetch = checked
1970+
fullRepresentation.manual_fetch = checked
1971+
}
1972+
}
1973+
1974+
PlasmaComponents3.ToolButton {
1975+
icon.name: "help-contents"
1976+
1977+
hoverEnabled: true
1978+
onClicked: manualFetchPopup.open()
1979+
1980+
PlasmaComponents3.ToolTip {
1981+
id: manualFetchPopup
1982+
x: parent.width / 2
1983+
y: parent.height
1984+
text: "The backend won't fetch the colors in the delay times, instead, it will fetch only when the 'Fetch colors' button is pressed by the user. Useful when using dynamic wallpapers."
1985+
}
1986+
}
1987+
}
1988+
19381989

19391990
RowLayout {
19401991
PlasmaComponents3.Label {

0 commit comments

Comments
 (0)