Formatting only - apply added editorconfig to all files
This commit is contained in:
parent
736bbf2be1
commit
1f253ac3f9
7 changed files with 92 additions and 93 deletions
|
@ -174,4 +174,3 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
|
|
24
LICENSE-MIT
24
LICENSE-MIT
|
@ -1,19 +1,19 @@
|
|||
Copyright 2023 Gergő Sályi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the “Software”), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the “Software”), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
14
src/cli.rs
14
src/cli.rs
|
@ -16,24 +16,24 @@ Eg.
|
|||
|
||||
In more detail:
|
||||
|
||||
- wallpaper_dir: A directory, this will be the argument
|
||||
- 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
|
||||
- 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
|
||||
- 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,
|
||||
- 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
|
||||
- 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
|
||||
|
@ -46,7 +46,7 @@ which automatically avoids resizing operations and decreases startup time.
|
|||
|
||||
Example:
|
||||
|
||||
For one having a laptop with a built-in display eDP-1
|
||||
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
|
||||
|
|
28
src/image.rs
28
src/image.rs
|
@ -15,7 +15,7 @@ use smithay_client_toolkit::reexports::client::protocol::wl_shm;
|
|||
use crate::wayland::WorkspaceBackground;
|
||||
|
||||
pub fn workspace_bgs_from_output_image_dir(
|
||||
dir_path: impl AsRef<Path>,
|
||||
dir_path: impl AsRef<Path>,
|
||||
slot_pool: &mut SlotPool,
|
||||
format: wl_shm::Format,
|
||||
brightness: i32,
|
||||
|
@ -81,7 +81,7 @@ pub fn workspace_bgs_from_output_image_dir(
|
|||
let mut image = image.into_rgb8();
|
||||
let image_width = image.width();
|
||||
let image_height = image.height();
|
||||
|
||||
|
||||
if image_width == 0 {
|
||||
error!(
|
||||
"Image '{}' has zero width, skipping", workspace_name
|
||||
|
@ -98,7 +98,7 @@ pub fn workspace_bgs_from_output_image_dir(
|
|||
if image_width != surface_width || image_height != surface_height
|
||||
{
|
||||
debug!("Resizing image '{}' from {}x{} to {}x{}",
|
||||
workspace_name,
|
||||
workspace_name,
|
||||
image_width, image_height,
|
||||
surface_width, surface_height
|
||||
);
|
||||
|
@ -126,16 +126,16 @@ pub fn workspace_bgs_from_output_image_dir(
|
|||
).unwrap();
|
||||
|
||||
image = ImageBuffer::from_raw(
|
||||
surface_width,
|
||||
surface_height,
|
||||
surface_width,
|
||||
surface_height,
|
||||
dst_image.into_vec()
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
let buffer = match format {
|
||||
wl_shm::Format::Xrgb8888 =>
|
||||
wl_shm::Format::Xrgb8888 =>
|
||||
buffer_xrgb8888_from_image(image, slot_pool),
|
||||
wl_shm::Format::Bgr888 =>
|
||||
wl_shm::Format::Bgr888 =>
|
||||
buffer_bgr888_from_image(image, slot_pool),
|
||||
_ => unreachable!()
|
||||
};
|
||||
|
@ -154,14 +154,14 @@ pub fn workspace_bgs_from_output_image_dir(
|
|||
fn buffer_xrgb8888_from_image(
|
||||
image: ImageBuffer<Rgb<u8>, Vec<u8>>,
|
||||
slot_pool: &mut SlotPool,
|
||||
)
|
||||
-> Buffer
|
||||
)
|
||||
-> Buffer
|
||||
{
|
||||
let (buffer, canvas) = slot_pool
|
||||
.create_buffer(
|
||||
image.width() as i32,
|
||||
image.height() as i32,
|
||||
image.width() as i32 * 4,
|
||||
image.width() as i32,
|
||||
image.height() as i32,
|
||||
image.width() as i32 * 4,
|
||||
wl_shm::Format::Xrgb8888
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -183,8 +183,8 @@ fn buffer_xrgb8888_from_image(
|
|||
fn buffer_bgr888_from_image(
|
||||
image: ImageBuffer<Rgb<u8>, Vec<u8>>,
|
||||
slot_pool: &mut SlotPool,
|
||||
)
|
||||
-> Buffer
|
||||
)
|
||||
-> Buffer
|
||||
{
|
||||
// Align buffer stride to both 4 and pixel format block size
|
||||
// Not being aligned to 4 caused
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -6,17 +6,17 @@ mod wayland;
|
|||
use std::{
|
||||
io,
|
||||
os::fd::AsRawFd,
|
||||
path::Path,
|
||||
path::Path,
|
||||
sync::{
|
||||
Arc,
|
||||
mpsc::{channel, Receiver},
|
||||
Arc,
|
||||
mpsc::{channel, Receiver},
|
||||
}
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
use log::error;
|
||||
use mio::{
|
||||
Events, Interest, Poll, Token, Waker,
|
||||
Events, Interest, Poll, Token, Waker,
|
||||
unix::SourceFd,
|
||||
};
|
||||
use smithay_client_toolkit::{
|
||||
|
@ -48,7 +48,7 @@ fn main()
|
|||
"warn,multibg_sway=trace"
|
||||
)
|
||||
).init();
|
||||
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
env_logger::Builder::from_env(
|
||||
env_logger::Env::default().default_filter_or("warn")
|
||||
|
@ -99,7 +99,7 @@ fn main()
|
|||
};
|
||||
|
||||
event_queue.roundtrip(&mut state).unwrap();
|
||||
|
||||
|
||||
// ********************************
|
||||
// Main event loop
|
||||
// ********************************
|
||||
|
@ -136,8 +136,8 @@ fn main()
|
|||
for event in events.iter() {
|
||||
match event.token() {
|
||||
WAYLAND => handle_wayland_event(
|
||||
&mut state,
|
||||
&mut read_guard_option,
|
||||
&mut state,
|
||||
&mut read_guard_option,
|
||||
&mut event_queue
|
||||
),
|
||||
SWAY => handle_sway_event(&mut state, &rx),
|
||||
|
|
12
src/sway.rs
12
src/sway.rs
|
@ -17,12 +17,12 @@ pub struct SwayConnectionTask {
|
|||
tx: Sender<WorkspaceVisible>,
|
||||
waker: Arc<Waker>,
|
||||
}
|
||||
impl SwayConnectionTask
|
||||
impl SwayConnectionTask
|
||||
{
|
||||
pub fn new(tx: Sender<WorkspaceVisible>, waker: Arc<Waker>) -> Self {
|
||||
SwayConnectionTask {
|
||||
SwayConnectionTask {
|
||||
sway_conn: Connection::new()
|
||||
.expect("Failed to connect to sway socket"),
|
||||
.expect("Failed to connect to sway socket"),
|
||||
tx,
|
||||
waker
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ impl SwayConnectionTask
|
|||
output: workspace.output,
|
||||
workspace_name: workspace.name,
|
||||
}).unwrap();
|
||||
|
||||
|
||||
self.waker.wake().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn request_visible_workspaces(&mut self) {
|
||||
for workspace in self.sway_conn.get_workspaces().unwrap()
|
||||
.into_iter().filter(|w| w.visible)
|
||||
|
@ -50,7 +50,7 @@ impl SwayConnectionTask
|
|||
self.tx.send(WorkspaceVisible {
|
||||
output: workspace.output,
|
||||
workspace_name: workspace.name,
|
||||
}).unwrap();
|
||||
}).unwrap();
|
||||
}
|
||||
self.waker.wake().unwrap();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::path::PathBuf;
|
|||
|
||||
use log::{debug, error, warn};
|
||||
use smithay_client_toolkit::{
|
||||
delegate_compositor, delegate_layer, delegate_output, delegate_registry,
|
||||
delegate_compositor, delegate_layer, delegate_output, delegate_registry,
|
||||
delegate_shm,
|
||||
compositor::{CompositorHandler, CompositorState},
|
||||
output::{OutputHandler, OutputState},
|
||||
|
@ -11,25 +11,25 @@ use smithay_client_toolkit::{
|
|||
shell::{
|
||||
WaylandSurface,
|
||||
wlr_layer::{
|
||||
KeyboardInteractivity, Layer, LayerShell,
|
||||
KeyboardInteractivity, Layer, LayerShell,
|
||||
LayerShellHandler, LayerSurface, LayerSurfaceConfigure,
|
||||
},
|
||||
},
|
||||
shm::{
|
||||
Shm, ShmHandler,
|
||||
slot::{Buffer, SlotPool},
|
||||
slot::{Buffer, SlotPool},
|
||||
},
|
||||
};
|
||||
use smithay_client_toolkit::reexports::client::{
|
||||
Connection, Dispatch, Proxy, QueueHandle,
|
||||
protocol::{
|
||||
wl_output::{self, WlOutput},
|
||||
wl_shm,
|
||||
wl_output::{self, WlOutput},
|
||||
wl_shm,
|
||||
wl_surface::WlSurface
|
||||
},
|
||||
};
|
||||
use smithay_client_toolkit::reexports::protocols::wp::viewporter::client::{
|
||||
wp_viewport::WpViewport,
|
||||
wp_viewport::WpViewport,
|
||||
wp_viewporter::WpViewporter
|
||||
};
|
||||
|
||||
|
@ -128,9 +128,9 @@ impl CompositorHandler for State
|
|||
impl LayerShellHandler for State
|
||||
{
|
||||
fn closed(
|
||||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
_layer: &LayerSurface
|
||||
) {
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ impl LayerShellHandler for State
|
|||
configure: LayerSurfaceConfigure,
|
||||
_serial: u32,
|
||||
) {
|
||||
// The new layer is ready: request all the visible workspace from sway,
|
||||
// The new layer is ready: request all the visible workspace from sway,
|
||||
// it will get picked up by the main event loop and be drawn from there
|
||||
let bg_layer = self.background_layers.iter_mut()
|
||||
.find(|bg_layer| &bg_layer.layer == layer).unwrap();
|
||||
|
@ -155,7 +155,7 @@ impl LayerShellHandler for State
|
|||
|
||||
debug!(
|
||||
"Configured layer on output: {}, new surface size {}x{}",
|
||||
bg_layer.output_name,
|
||||
bg_layer.output_name,
|
||||
configure.new_size.0, configure.new_size.1
|
||||
);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ impl LayerShellHandler for State
|
|||
debug!(
|
||||
"Ignoring configure for already configured layer on output: {}, \
|
||||
new surface size {}x{}",
|
||||
bg_layer.output_name,
|
||||
bg_layer.output_name,
|
||||
configure.new_size.0, configure.new_size.1
|
||||
);
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ impl OutputHandler for State {
|
|||
.map(|mode| mode.dimensions)
|
||||
else {
|
||||
error!(
|
||||
"New output '{}' has no current mode set, skipping",
|
||||
"New output '{}' has no current mode set, skipping",
|
||||
output_name
|
||||
);
|
||||
return;
|
||||
|
@ -217,7 +217,7 @@ impl OutputHandler for State {
|
|||
let Some((logical_width, logical_height)) = info.logical_size
|
||||
else {
|
||||
error!(
|
||||
"New output '{}' has no logical_size, skipping",
|
||||
"New output '{}' has no logical_size, skipping",
|
||||
output_name
|
||||
);
|
||||
return;
|
||||
|
@ -234,15 +234,15 @@ impl OutputHandler for State {
|
|||
debug!(
|
||||
"New output, name: {}, resolution: {}x{}, integer scale factor: {}, \
|
||||
logical size: {}x{}",
|
||||
output_name, width, height, integer_scale_factor,
|
||||
output_name, width, height, integer_scale_factor,
|
||||
logical_width, logical_height
|
||||
);
|
||||
|
||||
let layer = self.layer_shell.create_layer_surface(
|
||||
qh,
|
||||
self.compositor_state.create_surface(qh),
|
||||
Layer::Background,
|
||||
layer_surface_name(&output_name),
|
||||
qh,
|
||||
self.compositor_state.create_surface(qh),
|
||||
Layer::Background,
|
||||
layer_surface_name(&output_name),
|
||||
Some(&output)
|
||||
);
|
||||
|
||||
|
@ -250,9 +250,9 @@ logical size: {}x{}",
|
|||
layer.set_keyboard_interactivity(KeyboardInteractivity::None);
|
||||
|
||||
let surface = layer.wl_surface();
|
||||
|
||||
|
||||
let mut viewport = None;
|
||||
|
||||
|
||||
if width == logical_width || height == logical_height {
|
||||
debug!("Output '{}' needs no scaling", output_name);
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ logical size: {}x{}",
|
|||
new_viewport.set_destination(logical_width, logical_height);
|
||||
viewport = Some(new_viewport);
|
||||
}
|
||||
|
||||
|
||||
layer.commit();
|
||||
|
||||
let pixel_format = self.pixel_format();
|
||||
|
@ -306,24 +306,24 @@ logical size: {}x{}",
|
|||
return;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
debug!(
|
||||
"Shm slot pool size for output '{}' after loading wallpapers: {} KiB",
|
||||
output_name,
|
||||
shm_slot_pool.len() / 1024
|
||||
);
|
||||
|
||||
self.background_layers.push(BackgroundLayer {
|
||||
output_name,
|
||||
width,
|
||||
height,
|
||||
layer,
|
||||
self.background_layers.push(BackgroundLayer {
|
||||
output_name,
|
||||
width,
|
||||
height,
|
||||
layer,
|
||||
configured: false,
|
||||
workspace_backgrounds,
|
||||
shm_slot_pool,
|
||||
viewport,
|
||||
});
|
||||
|
||||
|
||||
debug!(
|
||||
"New sum of shm slot pool sizes for all outputs: {} KiB",
|
||||
self.background_layers.iter()
|
||||
|
@ -343,7 +343,7 @@ logical size: {}x{}",
|
|||
error!("Updated output has no output info, skipping");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
let Some(output_name) = info.name
|
||||
else {
|
||||
error!("Updated output has no name, skipping");
|
||||
|
@ -355,7 +355,7 @@ logical size: {}x{}",
|
|||
.map(|mode| mode.dimensions)
|
||||
else {
|
||||
error!(
|
||||
"Updated output '{}' has no current mode set, skipping",
|
||||
"Updated output '{}' has no current mode set, skipping",
|
||||
output_name
|
||||
);
|
||||
return;
|
||||
|
@ -368,13 +368,13 @@ logical size: {}x{}",
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let integer_scale_factor = info.scale_factor;
|
||||
|
||||
|
||||
let Some((logical_width, logical_height)) = info.logical_size
|
||||
else {
|
||||
error!(
|
||||
"Updated output '{}' has no logical_size, skipping",
|
||||
"Updated output '{}' has no logical_size, skipping",
|
||||
output_name
|
||||
);
|
||||
return;
|
||||
|
@ -399,7 +399,7 @@ logical size: {}x{}",
|
|||
.find(|bg_layers| bg_layers.output_name == output_name)
|
||||
else {
|
||||
error!(
|
||||
"Updated output '{}' has no background layer, skipping",
|
||||
"Updated output '{}' has no background layer, skipping",
|
||||
output_name
|
||||
);
|
||||
return;
|
||||
|
@ -411,9 +411,9 @@ logical size: {}x{}",
|
|||
Restart multibg-sway or expect low wallpaper quality due to scaling"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
let surface = bg_layer.layer.wl_surface();
|
||||
|
||||
|
||||
if width == logical_width || height == logical_height {
|
||||
debug!("Output '{}' needs no scaling", output_name);
|
||||
surface.set_buffer_scale(1);
|
||||
|
@ -434,7 +434,7 @@ Restart multibg-sway or expect low wallpaper quality due to scaling"
|
|||
debug!("Output '{}' needs fractional scaling", output_name);
|
||||
surface.set_buffer_scale(1);
|
||||
bg_layer.viewport
|
||||
.get_or_insert_with(||
|
||||
.get_or_insert_with(||
|
||||
self.viewporter.get_viewport(surface, qh, ())
|
||||
)
|
||||
.set_destination(logical_width, logical_height);
|
||||
|
@ -460,7 +460,7 @@ Restart multibg-sway or expect low wallpaper quality due to scaling"
|
|||
error!("Destroyed output has no name, skipping");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
debug!(
|
||||
"Output destroyed: {}",
|
||||
output_name,
|
||||
|
@ -487,7 +487,7 @@ Restart multibg-sway or expect low wallpaper quality due to scaling"
|
|||
for workspace_bg in removed_bg_layer.workspace_backgrounds.iter() {
|
||||
if workspace_bg.buffer.slot().has_active_buffers() {
|
||||
warn!(
|
||||
"On destroyed output '{}' workspace background '{}' will be dropped while its shm slot still has active buffers",
|
||||
"On destroyed output '{}' workspace background '{}' will be dropped while its shm slot still has active buffers",
|
||||
output_name,
|
||||
workspace_bg.workspace_name,
|
||||
);
|
||||
|
@ -505,7 +505,7 @@ Restart multibg-sway or expect low wallpaper quality due to scaling"
|
|||
.collect::<Vec<_>>().join(", ")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
debug!(
|
||||
"New sum of shm slot pool sizes for all outputs: {} KiB",
|
||||
self.background_layers.iter()
|
||||
|
@ -570,7 +570,7 @@ pub struct BackgroundLayer {
|
|||
pub shm_slot_pool: SlotPool,
|
||||
pub viewport: Option<WpViewport>,
|
||||
}
|
||||
impl BackgroundLayer
|
||||
impl BackgroundLayer
|
||||
{
|
||||
pub fn draw_workspace_bg(&mut self, workspace_name: &str)
|
||||
{
|
||||
|
@ -607,7 +607,7 @@ impl BackgroundLayer
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Attach and commit to new workspace background
|
||||
if let Err(e) = workspace_bg.buffer.attach_to(self.layer.wl_surface()) {
|
||||
error!(
|
||||
|
@ -618,10 +618,10 @@ impl BackgroundLayer
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Damage the entire surface
|
||||
self.layer.wl_surface().damage_buffer(0, 0, self.width, self.height);
|
||||
|
||||
|
||||
self.layer.commit();
|
||||
|
||||
debug!(
|
||||
|
|
Loading…
Add table
Reference in a new issue