This commit is contained in:
Gergő Sályi 2023-04-07 21:49:13 +02:00
parent 3eedfa1eb5
commit fbfd7e722e
5 changed files with 156 additions and 19 deletions

View file

@ -2,3 +2,63 @@
Set a different wallpaper for the background of each Sway workspace
## Usage
$ multibg-sway <WALLPAPER_DIR>
Wallpapers should be arranged in the following directory structure:
wallpaper_dir/output/workspace_name.{jpg|png|...}
Eg.
~/my_wallpapers/HDMI-A-1/1.jpg
In more detail:
- **wallpaper_dir**: A directory, this will be the argument for the multibg-sway command
- **output**: A directory with the same name as a sway output eg. eDP-1, HDMI-A-1
- If one has multiple outputs with the same resolution this can be a symlink to the directory of the other output.
- To get the name of current outputs from sway one may run:
$ swaymsg -t get_outputs
- **workspace_name**: The name of the sway workspace, by sway defaults: 1, 2, 3, ..., 10
- Can be a manually defined workspace name (eg. in sway config), but renaming workspaces while multibg_sway is running is not supported currently
- Can define a fallback wallpaper with the special name: _default
- Can be a symlink to use a wallpaper image for multiple workspaces
Wallpaper images are not resized by multibg-sway currently, so they should have the same resolution as the output
### Example:
For one having a laptop with a built-in display eDP-1 and an external monitor HDMI-A-1, wallpapers can be arranged such as:
~/my_wallpapers
├─ eDP-1
│ ├─ _default.jpg
│ ├─ 1.jpg
│ ├─ 2.png
│ └─ browser.jpg
└─ HDMI-A-1
├─ 1.jpg
└─ 3.png
Then start multibg_sway:
$ multibg-sway ~/my_wallpapers
It is recommended to edit the wallpaper images in a dedicated image editor. Nevertheless the contrast and brightness might be adjusted here:
$ multibg-sway --contrast=-25 --brightness=-60 ~/my_wallpapers
## Installation
- With Rust toolchain:
- For Arch Linux from AUR:
## Alternatives
- swaybg
- swww
- mpvpaper
- oguri

View file

@ -1,8 +1,79 @@
use clap::Parser;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(author, version, long_about = None, about = "\
Set a different wallpaper for the background of each Sway workspace
$ multibg-sway <WALLPAPER_DIR>
Wallpapers should be arranged in the following directory structure:
wallpaper_dir/output/workspace_name.{jpg|png|...}
Eg.
~/my_wallpapers/HDMI-A-1/1.jpg
In more detail:
- wallpaper_dir: A directory, this will be the argument
for the multibg-sway command
- output: A directory with the same name as a sway output
eg. eDP-1, HDMI-A-1
- If one has multiple outputs with the same resolution this
can be a symlink to the directory of the other output
- To get the name of current outputs from sway one may run:
$ swaymsg -t get_outputs
- workspace_name: The name of the sway workspace,
by sway defaults: 1, 2, 3, ..., 10
- Can be a manually defined workspace name (eg. in sway config),
but renaming workspaces while multibg_sway is running
is not supported currently
- Can define a fallback wallpaper with the special name: _default
- Can be a symlink to use a wallpaper image for multiple workspaces
Wallpaper images are not resized by multibg-sway currently,
so they should have the same resolution as the output
Example:
For one having a laptop with a built-in display eDP-1
and an external monitor HDMI-A-1, wallpapers can be arranged such as:
~/my_wallpapers
eDP-1
_default.jpg
1.jpg
2.png
browser.jpg
HDMI-A-1
1.jpg
3.png
Then start multibg_sway:
$ multibg-sway ~/my_wallpapers
It is recommended to edit the wallpaper images in a dedicated image editor.
Nevertheless the contrast and brightness might be adjusted here:
$ multibg-sway --contrast=-25 --brightness=-60 ~/my_wallpapers
")]
pub struct Cli {
/// adjust contrast, eg. -c=-25 (default: 0)
#[arg(short, long)]
pub contrast: Option<f32>,
/// adjust brightness, eg. -b=-60 (default: 0)
#[arg(short, long)]
pub brightness: Option<i32>,
/// directory with: wallpaper_dir/output/workspace_name.{jpg|png|...}
pub wallpaper_dir: String,
}

View file

@ -14,6 +14,8 @@ pub fn workspace_bgs_from_output_image_dir(
dir_path: impl AsRef<Path>,
slot_pool: &mut SlotPool,
format: wl_shm::Format,
brightness: i32,
contrast: f32,
)
-> Result<Vec<WorkspaceBackground>, String>
{
@ -34,18 +36,8 @@ pub fn workspace_bgs_from_output_image_dir(
continue;
}
};
// Resolve symlinks
let path = match entry.path().canonicalize() {
Ok(file_type) => file_type,
Err(e) => {
error!(
"Skipping '{:?}' in '{:?}' due to an error: {}",
entry.path(), dir_path.as_ref(), e
);
continue;
}
};
let path = entry.path();
// Skip dirs
if path.is_dir() { continue }
@ -71,11 +63,16 @@ pub fn workspace_bgs_from_output_image_dir(
}
};
let image = raw_image
// It is possible to adjust the contrast and brightness here
// .adjust_contrast(-25.0)
// .brighten(-60)
.into_rgb8();
// It is possible to adjust the contrast and brightness here
let mut image = raw_image;
if contrast != 0.0 {
image = image.adjust_contrast(contrast)
}
if brightness != 0 {
image = image.brighten(brightness)
}
let image = image.into_rgb8();
let buffer = match format {
wl_shm::Format::Xrgb8888 =>

View file

@ -89,6 +89,8 @@ fn main()
sway_connection_task: SwayConnectionTask::new(
tx.clone(), Arc::clone(&waker)
),
brightness: cli.brightness.unwrap_or(0),
contrast: cli.contrast.unwrap_or(0.0)
};
event_queue.roundtrip(&mut state).unwrap();

View file

@ -41,6 +41,8 @@ pub struct State {
pub pixel_format: Option<wl_shm::Format>,
pub background_layers: Vec<BackgroundLayer>,
pub sway_connection_task: SwayConnectionTask,
pub brightness: i32,
pub contrast: f32,
}
impl State {
@ -181,7 +183,9 @@ impl OutputHandler for State {
let workspace_backgrounds = match workspace_bgs_from_output_image_dir(
&output_wallpaper_dir,
&mut self.shm_slot_pool,
pixel_format
pixel_format,
self.brightness,
self.contrast
) {
Ok(workspace_bgs) => {
debug!(
@ -341,6 +345,9 @@ impl BackgroundLayer
let Some(workspace_bg) = self.workspace_backgrounds.iter()
.find(|workspace_bg| workspace_bg.workspace_name == workspace_name)
.or_else(|| self.workspace_backgrounds.iter()
.find(|workspace_bg| workspace_bg.workspace_name == "_default")
)
else {
error!(
"There is no wallpaper image on output '{}' for workspace '{}', only for: {}",