Adding backend and fill options

This commit is contained in:
Roman 2023-08-11 00:30:42 +09:00
parent 21e9f2436a
commit 8592feeddc
5 changed files with 51 additions and 16 deletions

View File

@ -6,16 +6,16 @@ GUI wallpaper setter for both Wayland and X11 window managers that works as a fr
## Features
- Support for GIF animations (with `swww` backend)
- Support for GIF animations (with `swww`)
- GUI wallpaper selection
- Works on both Wayland and X11
- Restores wallpaper on launch of your WM
- Works on both Wayland (with `swaybg` or `swww`) and X11 (with `feh`)
- Restores wallpaper at launch of your WM
## Installation
You need to install at least one of the backends and the waypaper, which works as a frontend.
You need to install at least one of the backends and Waypaper, which works as a frontend.
### 1. Install backend
### 1. Install a backend
Install a preferred backend from your package manager: [swaybg](https://github.com/swaywm/swaybg) or [swww](https://github.com/Horus645/swww) on Wayland or [feh](https://github.com/derf/feh) on x11. You can also install and test all of them.
@ -23,15 +23,15 @@ Install a preferred backend from your package manager: [swaybg](https://github.c
- [swww](https://github.com/Horus645/swww) - the wayland backend that also supports animated GIFs.
- [feh](https://github.com/derf/feh) - the x11 backend that supports static images.
### 2. Install waypaper (from PyPi)
### 2. Install Waypaper (from PyPi)
`pipx install waypaper`
If `pipx` is not found, you first need to install `pipx` from your package manager, it's sometimes called `python-pipx`.
### 2. Install waypaper (from AUR)
### 2. Install Waypaper (from AUR)
[waypaper-git](https://aur.archlinux.org/packages/waypaper-git) package is available in AUR, thanks to *metak*. If you are on arch-based system, you can install it as:
[waypaper-git](https://aur.archlinux.org/packages/waypaper-git) package is available in AUR, thanks to *metak*. So, on arch-based system, you can install it as:
`yay -S waypaper-git`
@ -42,7 +42,7 @@ If `pipx` is not found, you first need to install `pipx` from your package manag
## Usage
`waypaper` command will run GUI application.
`waypaper` command will run GUI application. Make sure to choose the backend that you installed.
To restore your wallpaper at launch, add `waypaper --restore` to your startup config. For example:
@ -53,12 +53,22 @@ To restore your wallpaper at launch, add `waypaper --restore` to your startup co
**In Sway or I3**
`exec waypaper --restore`
### Options
`--restore` - sets the last chosen wallpaper. Useful at launch of the window manager.
`--backend=XXX` - specifies which backend to use, which can be either `swaybg`, `swww`, or `feh`. Useful if you use waypaper on both wayland and x11 on the same machine. By default, last used backend is used.
`--fill=XXX` - specifies filling type, which can be eiher `fill`, `stretch`, `fit`, `center`, or `tile`.
## Troubleshooting
- If wallpaper does not change, make sure that `swaybg` or `swww` is installed.
- If application does not run, make sure to install gobject library (it might be called `python-gobject` or `python3-gi` in your package manager). Although it is supposed to be installed automatically with the package.
- Please understand that not all backends work on all system, choose the right one for you and stick to it.
- If you use different WMs on the same system, specify the backend when you restore the wallpaper at launch. For example: `
`waypaper --restore --backend=feh`
## Roadmap

View File

@ -5,7 +5,7 @@ from waypaper.changer import change_wallpaper
from waypaper.config import cf
__version__ = "1.3"
__version__ = "1.4"
def run():

View File

@ -10,6 +10,7 @@ from gi.repository import Gtk, GdkPixbuf, Gdk
from waypaper.changer import change_wallpaper
from waypaper.config import cf
from waypaper.options import FILL_OPTIONS, BACKEND_OPTIONS
def get_image_paths(root_folder, include_subfolders=False, depth=None):
@ -67,19 +68,18 @@ class App(Gtk.Window):
# Create a backend dropdown menu:
# self.backend_option_label = Gtk.Label(label="")
self.backend_option_combo = Gtk.ComboBoxText()
options = ["swaybg", "swww", "feh"]
for option in options:
for option in BACKEND_OPTIONS:
self.backend_option_combo.append_text(option)
active_num = options.index(cf.backend)
active_num = BACKEND_OPTIONS.index(cf.backend)
self.backend_option_combo.set_active(active_num)
self.backend_option_combo.connect("changed", self.on_backend_option_changed)
# Create a fill option dropdown menu:
# self.fill_option_label = Gtk.Label(label="")
self.fill_option_combo = Gtk.ComboBoxText()
options = ["Fill", "Stretch", "Fit", "Center", "Tile"]
for option in options:
self.fill_option_combo.append_text(option)
for option in FILL_OPTIONS:
capitalized_option = option[0].upper() + option[1:]
self.fill_option_combo.append_text(capitalized_option)
self.fill_option_combo.set_active(0)
self.fill_option_combo.connect("changed", self.on_fill_option_changed)

View File

@ -2,8 +2,11 @@
import configparser
import pathlib
import getopt
import sys
import os
from waypaper.options import FILL_OPTIONS, BACKEND_OPTIONS
class Config:
"""User configuration loaded from the config.ini file"""
@ -61,6 +64,25 @@ class Config:
config.write(configfile)
def read_parameters_from_user_arguments(self):
"""Read user arguments that were provided at the run. This values take priority over config.ini"""
try:
opts, _ = getopt.getopt(sys.argv[1:],"",["backend=", "restore", "fill="])
for opt, arg in opts:
# Reading backend:
if opt in '--backend' and arg in BACKEND_OPTIONS:
self.backend = arg
# Reading fill option:
if opt in '--fill' and arg in FILL_OPTIONS:
self.fill_option = arg
except getopt.GetoptError as e_message:
print("Invalid user arguments. %s", e_message)
pass
cf = Config()
# Create config folder:
@ -73,3 +95,4 @@ if not os.path.exists(cf.config_file):
# Read config file:
cf.read()
cf.read_parameters_from_user_arguments()

2
waypaper/options.py Normal file
View File

@ -0,0 +1,2 @@
BACKEND_OPTIONS = ["swaybg", "swww", "feh"]
FILL_OPTIONS = ["fill", "stretch", "fit", "center", "tile"]