Update
This commit is contained in:
parent
3eedfa1eb5
commit
fbfd7e722e
5 changed files with 156 additions and 19 deletions
60
README.md
60
README.md
|
@ -2,3 +2,63 @@
|
||||||
|
|
||||||
Set a different wallpaper for the background of each Sway workspace
|
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
|
||||||
|
|
73
src/cli.rs
73
src/cli.rs
|
@ -1,8 +1,79 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(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 {
|
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|...}
|
/// directory with: wallpaper_dir/output/workspace_name.{jpg|png|...}
|
||||||
pub wallpaper_dir: String,
|
pub wallpaper_dir: String,
|
||||||
}
|
}
|
||||||
|
|
27
src/image.rs
27
src/image.rs
|
@ -14,6 +14,8 @@ pub fn workspace_bgs_from_output_image_dir(
|
||||||
dir_path: impl AsRef<Path>,
|
dir_path: impl AsRef<Path>,
|
||||||
slot_pool: &mut SlotPool,
|
slot_pool: &mut SlotPool,
|
||||||
format: wl_shm::Format,
|
format: wl_shm::Format,
|
||||||
|
brightness: i32,
|
||||||
|
contrast: f32,
|
||||||
)
|
)
|
||||||
-> Result<Vec<WorkspaceBackground>, String>
|
-> Result<Vec<WorkspaceBackground>, String>
|
||||||
{
|
{
|
||||||
|
@ -35,17 +37,7 @@ pub fn workspace_bgs_from_output_image_dir(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Resolve symlinks
|
let path = entry.path();
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Skip dirs
|
// Skip dirs
|
||||||
if path.is_dir() { continue }
|
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
|
// It is possible to adjust the contrast and brightness here
|
||||||
// .adjust_contrast(-25.0)
|
let mut image = raw_image;
|
||||||
// .brighten(-60)
|
if contrast != 0.0 {
|
||||||
.into_rgb8();
|
image = image.adjust_contrast(contrast)
|
||||||
|
}
|
||||||
|
if brightness != 0 {
|
||||||
|
image = image.brighten(brightness)
|
||||||
|
}
|
||||||
|
|
||||||
|
let image = image.into_rgb8();
|
||||||
|
|
||||||
let buffer = match format {
|
let buffer = match format {
|
||||||
wl_shm::Format::Xrgb8888 =>
|
wl_shm::Format::Xrgb8888 =>
|
||||||
|
|
|
@ -89,6 +89,8 @@ fn main()
|
||||||
sway_connection_task: SwayConnectionTask::new(
|
sway_connection_task: SwayConnectionTask::new(
|
||||||
tx.clone(), Arc::clone(&waker)
|
tx.clone(), Arc::clone(&waker)
|
||||||
),
|
),
|
||||||
|
brightness: cli.brightness.unwrap_or(0),
|
||||||
|
contrast: cli.contrast.unwrap_or(0.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
event_queue.roundtrip(&mut state).unwrap();
|
event_queue.roundtrip(&mut state).unwrap();
|
||||||
|
|
|
@ -41,6 +41,8 @@ pub struct State {
|
||||||
pub pixel_format: Option<wl_shm::Format>,
|
pub pixel_format: Option<wl_shm::Format>,
|
||||||
pub background_layers: Vec<BackgroundLayer>,
|
pub background_layers: Vec<BackgroundLayer>,
|
||||||
pub sway_connection_task: SwayConnectionTask,
|
pub sway_connection_task: SwayConnectionTask,
|
||||||
|
pub brightness: i32,
|
||||||
|
pub contrast: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
@ -181,7 +183,9 @@ impl OutputHandler for State {
|
||||||
let workspace_backgrounds = match workspace_bgs_from_output_image_dir(
|
let workspace_backgrounds = match workspace_bgs_from_output_image_dir(
|
||||||
&output_wallpaper_dir,
|
&output_wallpaper_dir,
|
||||||
&mut self.shm_slot_pool,
|
&mut self.shm_slot_pool,
|
||||||
pixel_format
|
pixel_format,
|
||||||
|
self.brightness,
|
||||||
|
self.contrast
|
||||||
) {
|
) {
|
||||||
Ok(workspace_bgs) => {
|
Ok(workspace_bgs) => {
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -341,6 +345,9 @@ impl BackgroundLayer
|
||||||
|
|
||||||
let Some(workspace_bg) = self.workspace_backgrounds.iter()
|
let Some(workspace_bg) = self.workspace_backgrounds.iter()
|
||||||
.find(|workspace_bg| workspace_bg.workspace_name == workspace_name)
|
.find(|workspace_bg| workspace_bg.workspace_name == workspace_name)
|
||||||
|
.or_else(|| self.workspace_backgrounds.iter()
|
||||||
|
.find(|workspace_bg| workspace_bg.workspace_name == "_default")
|
||||||
|
)
|
||||||
else {
|
else {
|
||||||
error!(
|
error!(
|
||||||
"There is no wallpaper image on output '{}' for workspace '{}', only for: {}",
|
"There is no wallpaper image on output '{}' for workspace '{}', only for: {}",
|
||||||
|
|
Loading…
Add table
Reference in a new issue