Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual color fetch feature and fixes on dynamic wallpaper compatibility #242

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/kde_material_you_colors/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def defaults(self):
"chroma_multiplier": [args.chroma_multiplier, 1, 2],
"tone_multiplier": [args.tone_multiplier, 1, 2],
"qdbus_executable": [args.qdbus_executable, None, 3],
"manual_fetch": [args.manual_fetch, False, 0],
"fetch_colors": [None, False, 0],
}

def parse_conf(self):
Expand Down
7 changes: 7 additions & 0 deletions src/kde_material_you_colors/data/sample_config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ ncolor = 0
# of detections for those cases to save power.
# NOTE:
# Should be bigger than main_loop_delay (will take main_loop_delay otherwise)
# Ignored if manual color fetch is enabled
# Default is 900 seconds (15 minutes)
# Commented by default
#screenshot_delay = 900
Expand Down Expand Up @@ -196,3 +197,9 @@ tone_multiplier = 1
# Default is qdbus6
# Deprecated, no longer needed as of version 1.10.0. Switched to gdbus command from glib2
# qdbus_executable = qdbus6

# Manual fetch
# Disables the automatic color fetching and
# scheduled screenshot take in screenshot mode
# Default is False
manual_fetch = False
40 changes: 33 additions & 7 deletions src/kde_material_you_colors/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ def main():
default=None,
metavar="<string>",
)
parser.add_argument(
"--manual-fetch",
action="store_true",
help="Dissables automatic color fetching",
default=None,
)

# Get commandline arguments
args = parser.parse_args()
Expand Down Expand Up @@ -388,12 +394,17 @@ def main():
plugin_watcher = utils.Watcher(wallpaper.plugin)
source_watcher = utils.Watcher(wallpaper.source)
pause_watcher = utils.Watcher(config.read("pause_mode"))
manual_fetch_watcher = utils.Watcher(config.read("manual_fetch"))
fetch_watcher = utils.Watcher(config.read("fetch_colors"))
if pause_watcher.value:
msg = "Pause mode enabled" if pause_watcher.value else "Pause mode disabled"
logging.warning(msg)
if wallpaper.type == "screenshot":
head = "Screenshot mode enabled"
cont = f"Waiting {config.read('screenshot_delay')}s between updates"
if config.read("manual_fetch"):
cont = "Manual color fetch enabled, press 'Fetch colors' in the widget to take a new screenshot"
else:
cont = f"Waiting {config.read('screenshot_delay')}s between updates"
notify.send_notification(head, cont)
logging.warning("%s, %s", head, cont)
if wallpaper.error:
Expand Down Expand Up @@ -429,10 +440,21 @@ def main():
#
#
#
#
# update wallpaper
wallpaper.update(config, skip_screenshot=counter != 0)
wallpaper_watcher.set_value(wallpaper.current)
# update wallpaper, only if manual_fetch is false
manual_fetch_watcher.set_value(config.read("manual_fetch"))

if manual_fetch_watcher.has_changed():
msg = "Manual color fetch enabled." if manual_fetch_watcher.value else "Manual color fetch disabled."
logging.info(msg)

fetch_watcher.set_value(config.read("fetch_colors"))
if fetch_watcher.has_changed() and fetch_watcher.value:
logging.info("Fetching colors in current wallpaper...")
counter = 0

if not config.read("manual_fetch") or (fetch_watcher.has_changed() and fetch_watcher.value):
wallpaper.update(config, skip_screenshot=counter != 0)
wallpaper_watcher.set_value(wallpaper.current)

target_cycles = config.read("screenshot_delay") / (
config.read("main_loop_delay") or 1
Expand Down Expand Up @@ -470,6 +492,7 @@ def main():
logging.info(f"{wallpaper}")
apply_themes.apply(config, wallpaper, light_mode_watcher.value)
apply = False
counter += 1

if group1:
if wallpaper.error:
Expand All @@ -479,7 +502,10 @@ def main():
logging.error(f"Could not get wallpaper {str(wallpaper.error)}")
if plugin_watcher.changed and wallpaper.type == "screenshot":
head = "Screenshot mode enabled"
cont = f"Waiting {config.read('screenshot_delay')}s between updates"
if config.read("manual_fetch"):
cont = "Manual color fetch enabled, press 'Fetch colors' in the widget to take a new screenshot"
else:
cont = f"Waiting {config.read('screenshot_delay')}s between updates"
notify.send_notification(head, cont)
logging.warning("%s, %s", head, cont)
if wallpaper.source:
Expand All @@ -492,7 +518,7 @@ def main():
apply_themes.apply(config, wallpaper, light_mode_watcher.value)
counter = 0

if wallpaper.is_screenshot():
if wallpaper.is_screenshot() and not config.read("manual_fetch"):
if target_cycles > counter:
counter += 1
else:
Expand Down
75 changes: 63 additions & 12 deletions src/plasmoid/package/contents/ui/FullRepresentation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ ColumnLayout {

property bool pauseMode: false

property bool manual_fetch: false


signal savePauseMode()


property Item parentMain

KCoreAddons.KUser {
Expand All @@ -83,7 +87,6 @@ ColumnLayout {
}
}


// Get a list of installed icon themes as id,name
// - discard hidden themes
// - discard cursor themes
Expand Down Expand Up @@ -331,7 +334,6 @@ ColumnLayout {
level: 1
text: Plasmoid.metaData.name
}

PlasmaComponents3.ToolButton {
display: PlasmaComponents3.AbstractButton.IconOnly
visible: !onDesktop
Expand All @@ -346,7 +348,6 @@ ColumnLayout {
text: parent.text
}
}

PlasmaComponents3.ToolButton {
display: PlasmaComponents3.AbstractButton.IconOnly
checkable: false
Expand Down Expand Up @@ -452,14 +453,12 @@ ColumnLayout {
}
}
}

Connections {
target: fullRepresentation
function onSavePauseMode() {
settings.pause_mode = fullRepresentation.pauseMode
}
}

onMaterialYouDataChanged: {
if (materialYouData!=null && materialYouDataString!=null) {
if (JSON.stringify(materialYouData) !== materialYouDataString) {
Expand Down Expand Up @@ -544,6 +543,8 @@ ColumnLayout {
property int screenshot_delay: 900; \
property bool once_after_change: false; \
property bool pause_mode: false; \
property bool manual_fetch: false; \
property bool fetch_colors: false; \
property bool screenshot_only_mode: false; \
property int scheme_variant: 5; \
property real chroma_multiplier: 1.0; \
Expand Down Expand Up @@ -812,17 +813,37 @@ ColumnLayout {
// Color selection
RowLayout {
Layout.preferredWidth: mainLayout.width

PlasmaComponents3.Label {
text: "Select color"
id:selectColorLabel
Layout.fillWidth: settings.color!==""
RowLayout {
id: selectColorLayout
PlasmaComponents3.Label {
text: "Select color"
id:selectColorLabel
}
// Button to manually fetch the colors on screen //
Timer {
id: fetchTimer
interval: settings.main_loop_delay * 1000; running: false; repeat: false;
onTriggered: settings.fetch_colors = false
}
RowLayout {
PlasmaComponents3.Button {
text: "Fetch colors"
icon.name: 'refreshstructure'
onClicked: {
settings.fetch_colors = true
fetchTimer.start()
}
PlasmaComponents3.ToolTip {
text: "Manually fetch the colors on the current wallpaper"
}
}
}
}

// Single color picker when color is not empty
Components.CustomColorButton { // Components.Custom
id: colorButton
Layout.alignment: Qt.AlignHCenter
Layout.alignment : Qt.AlignRight
visible: settings.color!==""
showAlphaChannel: false
dialogTitle: "Choose source color"
Expand All @@ -840,7 +861,7 @@ ColumnLayout {
GridLayout { //PlasmaComponents3.ScrollView
property var gridSpacing: Kirigami.Units.mediumSpacing
visible: settings.color===""
columns: Math.floor((mainLayout.width - selectColorLabel.width) / (
columns: Math.floor((mainLayout.width - selectColorLayout.width) / (
controlHeight * .75 + gridSpacing))
rowSpacing: gridSpacing
columnSpacing: gridSpacing
Expand Down Expand Up @@ -1919,6 +1940,36 @@ ColumnLayout {
}
}
}
RowLayout {
PlasmaComponents3.Label {
text: "Manual color fetch only"
Layout.alignment: Qt.AlignLeft
}

PlasmaComponents3.CheckBox {
checked: settings.manual_fetch

onCheckedChanged: {
settings.manual_fetch = checked
fullRepresentation.manual_fetch = checked
}
}

PlasmaComponents3.ToolButton {
icon.name: "help-contents"

hoverEnabled: true
onClicked: manualFetchPopup.open()

PlasmaComponents3.ToolTip {
id: manualFetchPopup
x: parent.width / 2
y: parent.height
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."
}
}
}


RowLayout {
PlasmaComponents3.Label {
Expand Down