Skip to content

Commit

Permalink
Merge pull request #238 from LGFae/deprecate-swww-init
Browse files Browse the repository at this point in the history
Deprecate swww init
  • Loading branch information
LGFae authored Mar 23, 2024
2 parents 62b31fc + 8cafdab commit e016f48
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 73 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

MSRV is now 1.74.0.

#### Deprecated

`swww init` is now considered deprecated. Use `swww-daemon` instead. To run it
in the background, simply do `swww-daemon &`.

#### Fixes

* fix the `let_underscore_lock` error. Note that all 0.8.* will probably no
Expand Down Expand Up @@ -35,7 +40,8 @@ MSRV is now 1.74.0.
improvements. Unfortunately, it seems to not work for some people on some
notebooks (see [Known Issues](#known-issues)).
* Implemented a way to force the use of a specific wayland_shm format, as a
workaround for [Known Issues](#known-issues).
workaround for [Known Issues](#known-issues). Also went ahead and implemented
some cli options for the daemon.
* Support for animated pngs
* Support for animations when piping images from standard input
* Fps is now a `u16`, so we can support newest monitors framerates
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ makes switching from one image to the next to happen very abruptly.

Start by initializing the daemon:
```
swww init
swww-daemon
```
Then, simply pass the image you want to display:
Then, in a different terminal, simply pass the image you want to display:
```
swww img <path/to/img>
Expand Down
51 changes: 18 additions & 33 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
mod animations;
pub mod bump_pool;
mod cli;
mod wallpaper;
use log::{debug, error, info, warn, LevelFilter};
use nix::{
Expand Down Expand Up @@ -103,45 +104,25 @@ extern "C" fn signal_handler(_s: i32) {
}

fn main() -> Result<(), String> {
let mut args = std::env::args();
let _ = args.next();
if let Some(arg) = args.next() {
if arg != "--format" {
return Err(format!("Unrecognized command line argument: {arg}"));
}

match args.next().as_deref() {
Some("xrgb") => {
PIXEL_FORMAT.set(PixelFormat::Xrgb).unwrap();
WL_SHM_FORMAT.set(wl_shm::Format::Xrgb8888).unwrap();
}
Some("xbgr") => {
PIXEL_FORMAT.set(PixelFormat::Xbgr).unwrap();
WL_SHM_FORMAT.set(wl_shm::Format::Xbgr8888).unwrap();
}
Some("rgb") => {
PIXEL_FORMAT.set(PixelFormat::Rgb).unwrap();
WL_SHM_FORMAT.set(wl_shm::Format::Rgb888).unwrap();
}
Some("bgr") => {
PIXEL_FORMAT.set(PixelFormat::Bgr).unwrap();
WL_SHM_FORMAT.set(wl_shm::Format::Bgr888).unwrap();
}
_ => {
return Err(
"`--format` command line option must be one of: 'xrgb', 'xbgr', 'rgb' or 'bgr'"
.to_string(),
)
}
let cli = cli::Cli::new();

if let Some(format) = cli.format {
PIXEL_FORMAT.set(format).unwrap();
match format {
PixelFormat::Xrgb => WL_SHM_FORMAT.set(wl_shm::Format::Xrgb8888),
PixelFormat::Xbgr => WL_SHM_FORMAT.set(wl_shm::Format::Xbgr8888),
PixelFormat::Rgb => WL_SHM_FORMAT.set(wl_shm::Format::Rgb888),
PixelFormat::Bgr => WL_SHM_FORMAT.set(wl_shm::Format::Bgr888),
}
.unwrap()
}

rayon::ThreadPoolBuilder::default()
.thread_name(|i| format!("rayon thread {i}"))
.stack_size(1 << 18) // 256KiB; we do not need a large stack
.build_global()
.expect("failed to configure rayon global thread pool");
make_logger();
make_logger(cli.quiet);
let listener = SocketWrapper::new()?;
let wake = setup_signals_and_pipe();

Expand Down Expand Up @@ -691,14 +672,18 @@ impl ProvidesRegistryState for Daemon {
registry_handlers![OutputState];
}

fn make_logger() {
fn make_logger(quiet: bool) {
let config = simplelog::ConfigBuilder::new()
.set_thread_level(LevelFilter::Error) // let me see where the processing is happening
.set_thread_mode(ThreadLogMode::Both)
.build();

TermLogger::init(
LevelFilter::Debug,
if quiet {
LevelFilter::Error
} else {
LevelFilter::Debug
},
config,
TerminalMode::Stderr,
ColorChoice::AlwaysAnsi,
Expand Down
2 changes: 1 addition & 1 deletion doc/swww-clear-cache.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ those locations corresponding to the current image/animation being displayed.

Furthermore, the cache will keep preprocessed versions of `gif`s. So, if you
load a large `gif`, you would have to pay the price for its processing the first
time.
time.

Note that `swww` will automatically delete any preprocessed animation created
with a previous version of `swww` from the cache.
Expand Down
42 changes: 21 additions & 21 deletions doc/swww-daemon.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ swww-daemon(1)
# NAME
swww-daemon

# DESCRIPTION
# SYNOPSIS
swww-daemon [-q|--quiet] [-f|--format <xrgb|xbgr|rgb|bgr>]

The *swww-daemon* will run continuously, waiting for commands in
_$XDG_RUNTIME_DIR/swww.socket_(or _/tmp/swww/swww.socket_, if $XDG_RUNTIME_DIR
is not set). The daemon will take care of both creating and deleting that file
when it is initialized or killed.
# OPTIONS

*-f*,*--format* <xrgb|xbgr|rgb|bgr>
Force the daemon to use a specific wl_shm format.

*There is no reason for you to run the swww-daemon manually*. The daemon should
be started through *swww init* and killed through *swww kill*. Running the
daemon manually would only help for debugging, or developing *swww*. *swww init*
has the benefits that it checks to see if another instance is already running,
and it waits for the daemon to be ready, so something like
IMPORTANT: make sure this is a value your compositor actually supports!
'swww-daemon' will automatically select the best format for itself during
initialization; this is only here for fallback, debug, and workaround
purposes.

```
swww init && swww img bg.png
```
*-q*,*--quiet*
Makes the daemon only log errors.

works, but
*-h*, *--help*
Print help (see a summary with '-h')

```
swww-daemon &
swww img bg.png
```
*-V*, *--version*
Print version

*can potentially fail*, because the daemon might still not be ready by the time
the client sends the image.
# DESCRIPTION

Bottom line is: just use *swww init* to initialize the daemon.
The *swww-daemon* will run continuously, waiting for commands in
_$XDG_RUNTIME_DIR/swww.socket_ (or _/tmp/swww/swww.socket_, if $XDG_RUNTIME_DIR
is not set). The daemon will take care of both creating and deleting that file
when it is initialized or killed.

# SEE ALSO
*swww-init*(1)
6 changes: 3 additions & 3 deletions doc/swww-img.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ swww-img

*--resize* <RESIZE>
Whether to resize the image and the method by which to resize it.

Possible values:
- _no_: Do not resize the image
- _crop_: Resize the image to fill the whole screen, cropping out parts that don't fit
Expand Down Expand Up @@ -83,7 +83,7 @@ swww-img
_none_ is an alias to _simple_, that also sets the _transition-step_ to
255. This has the effect of the transition completing instantly.

_fade_ is like _simple_ but uses bezier curves while fading the image, its a
_fade_ is like _simple_ but uses bezier curves while fading the image, its a
more polished looking version of _simple_ with less artifacts

The _left_, _right_, _top_ and _bottom_ options make the transition happen
Expand Down Expand Up @@ -222,7 +222,7 @@ Importantly, **cache will only be loaded during initialization if you use swww
init**. That is, calling `swww-daemon` directly will **NOT** load the cache, but
calling `swww-init` will.

The `swww-daemon` will actually wait until the first image has been set before
The `swww-daemon` will actually wait until the first image has been set before
trying to load the cache.

Finally, the cache will keep preprocessed versions of `gif`s. So, if you load a
Expand Down
17 changes: 8 additions & 9 deletions doc/swww-init.1.scd
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
swww-init(1)

# NAME
swww-init
swww-init (DEPRECATED)

# SYNOPSIS
*swww init* [--no-daemon]
*swww init* [--no-daemon] [--no-cache] [--format <xrgb|xbgr|rgb|bgr>]

# OPTIONS

Expand All @@ -19,14 +19,14 @@ swww-init
Don't load the cache *during initialization* (it still loads on monitor
(re)connection).

If want to always pass an image for `swww` to load, this option can help make the
results some reliable: `swww init --no-cache && swww img <some img>`
If want to always pass an image for 'swww' to load, this option can help make the
results some reliable: 'swww init --no-cache && swww img <some img>'

*--format* <xrgb|xbgr|rgb|bgr>
Force the daemon to use a specific wl_shm format.

IMPORTANT: make sure this is a value your compositor actually supports!
`swww-daemon` will automatically select the best format for itself during
'swww-daemon' will automatically select the best format for itself during
initialization; this is only here for fallback, debug, and workaround
purposes.

Expand All @@ -35,9 +35,8 @@ swww-init

# DESCRIPTION

Initializes the daemon. This is the recommended way of doing it, since we make
sure to check if another instance is already running, and wait until the daemon
is 100% ready to receive requests.
Initializes the daemon. This is used to be the recommended way of doing it, but
that is no longer the case. You should call 'swww-daemon' directly instead.

# SEE ALSO
*swww-daemon*(1)
2 changes: 1 addition & 1 deletion doc/swww-kill.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ swww-kill
*-h*, *--help*
Print help (see a summary with '-h')

# DESCRIPTION
# DESCRIPTION

Kills the daemon. This is the recommended way of doing it, since we wait to make
sure the socket file was deleted, thus confirming the daemon exited.
Expand Down
2 changes: 1 addition & 1 deletion doc/swww-query.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ swww-query
*-h*, *--help*
Print help (see a summary with '-h')

# DESCRIPTION
# DESCRIPTION

Asks the daemon to print output information (names and dimensions).

Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ fn main() -> Result<(), String> {
no_daemon, format, ..
} = &swww
{
eprintln!(
"DEPRECATION WARNING: `swww init` IS DEPRECATED. Call `swww-daemon` directly instead"
);
match is_daemon_running() {
Ok(false) => {
let socket_path = get_socket_path();
Expand Down
2 changes: 1 addition & 1 deletion version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mv -v TMP Cargo.toml
sed "s/^version = .*/version = \"$1\"/" utils/Cargo.toml > TMP
mv -v TMP utils/Cargo.toml

sed "s/^version = .*/version = \"$1\"/" daemon/Cargo.toml > TM
sed "s/^version = .*/version = \"$1\"/" daemon/Cargo.toml > TMP
mv -v TMP daemon/Cargo.toml

# CHANGELOG:
Expand Down

0 comments on commit e016f48

Please sign in to comment.