diff --git a/blurwal/backends/gsettings.py b/blurwal/backends/gsettings.py new file mode 100644 index 0000000000000000000000000000000000000000..bb169e3ea98c6784929dbf0419af0f5a737035c7 --- /dev/null +++ b/blurwal/backends/gsettings.py @@ -0,0 +1,50 @@ +""" +Author: Joshua Robinson +License: MIT +""" + +import logging +import pathlib +import subprocess +import sys +from typing import List, Optional + +from blurwal.backends import base + + +class GsettingsBackend(base.Backend): + """ + Wallpaper operations utilizing gnome/budgie's gsettings backend. + """ + + def get_wallpaper_set_cmds(self, path: pathlib.Path) -> List[List[str]]: + """ + Return a list of commands to be executed to set the wallpaper. + + :param path: The image to set as the wallpaper + :return: A list of commands to be executed + """ + return [['gsettings', + 'set', 'org.gnome.desktop.background', + 'picture-uri', 'file://' + str(path)]] + + def get_current(self) -> Optional[pathlib.Path]: + """ + Return the current wallpaper's path from gsettings + + :return: The current wallpaper's path (formatted for gsettings) or + None if not retrievable + """ + try: + process = subprocess.check_output(['gsettings', + 'get', + 'org.gnome.desktop.background', + 'picture-uri']) + + filepath = process.strip().decode().replace("'file://", "", 1)[:-1] + + return pathlib.Path(filepath) + except subprocess.CalledProcessError: + logging.exception('Could not retrieve current wallpaper, call to' + 'gsettings returned a non-zero exit status.') + sys.exit(1) diff --git a/blurwal/environment.py b/blurwal/environment.py index cec4cb9f940609e39b4fc744d008250ef655f27b..8997f1fcfdba2437fd41cb47472e3a350a530cbc 100644 --- a/blurwal/environment.py +++ b/blurwal/environment.py @@ -12,16 +12,21 @@ import shutil from typing import Dict, Optional, Tuple, Type from blurwal import paths, utils -from blurwal.backends import base, feh, xfconf +from blurwal.backends import base, feh, xfconf, gsettings #: Supported backend names with their implementation and binary BACKENDS: Dict[str, Tuple[Type[base.Backend], str]] = { 'feh': (feh.FehBackend, 'feh'), - 'xfce': (xfconf.XfconfBackend, 'xfconf-query') + 'xfce': (xfconf.XfconfBackend, 'xfconf-query'), + 'gnome': (gsettings.GsettingsBackend, 'gsettings') } #: A map of XDG_CURRENT_DESKTOP values to their respective backends -XDG_TO_BACKEND: Dict[str, str] = {'XFCE': 'xfce'} +XDG_TO_BACKEND: Dict[str, str] = { + 'XFCE': 'xfce', + 'Budgie:GNOME': 'gnome', + 'GNOME': 'gnome' +} def get_backend(name: Optional[str]) -> Optional[base.Backend]: