Refactor, move application state struct to main.rs
This commit is contained in:
parent
a56c1a81c7
commit
b06204360d
2 changed files with 46 additions and 47 deletions
45
src/main.rs
45
src/main.rs
|
|
@ -7,7 +7,7 @@ mod wayland;
|
||||||
use std::{
|
use std::{
|
||||||
io,
|
io,
|
||||||
os::fd::AsRawFd,
|
os::fd::AsRawFd,
|
||||||
path::Path,
|
path::{Path, PathBuf},
|
||||||
sync::{
|
sync::{
|
||||||
Arc,
|
Arc,
|
||||||
mpsc::{channel, Receiver},
|
mpsc::{channel, Receiver},
|
||||||
|
|
@ -31,6 +31,7 @@ use smithay_client_toolkit::reexports::client::{
|
||||||
Connection, EventQueue,
|
Connection, EventQueue,
|
||||||
backend::{ReadEventsGuard, WaylandError},
|
backend::{ReadEventsGuard, WaylandError},
|
||||||
globals::registry_queue_init,
|
globals::registry_queue_init,
|
||||||
|
protocol::wl_shm,
|
||||||
};
|
};
|
||||||
use smithay_client_toolkit::reexports::protocols
|
use smithay_client_toolkit::reexports::protocols
|
||||||
::wp::viewporter::client::wp_viewporter::WpViewporter;
|
::wp::viewporter::client::wp_viewporter::WpViewporter;
|
||||||
|
|
@ -39,9 +40,49 @@ use crate::{
|
||||||
cli::{Cli, PixelFormat},
|
cli::{Cli, PixelFormat},
|
||||||
compositors::{Compositor, ConnectionTask, WorkspaceVisible},
|
compositors::{Compositor, ConnectionTask, WorkspaceVisible},
|
||||||
signal::SignalPipe,
|
signal::SignalPipe,
|
||||||
wayland::State,
|
wayland::BackgroundLayer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub struct State {
|
||||||
|
pub compositor_state: CompositorState,
|
||||||
|
pub registry_state: RegistryState,
|
||||||
|
pub output_state: OutputState,
|
||||||
|
pub shm: Shm,
|
||||||
|
pub layer_shell: LayerShell,
|
||||||
|
pub viewporter: WpViewporter,
|
||||||
|
pub wallpaper_dir: PathBuf,
|
||||||
|
pub force_xrgb8888: bool,
|
||||||
|
pub pixel_format: Option<wl_shm::Format>,
|
||||||
|
pub background_layers: Vec<BackgroundLayer>,
|
||||||
|
pub compositor_connection_task: ConnectionTask,
|
||||||
|
pub brightness: i32,
|
||||||
|
pub contrast: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
fn pixel_format(&mut self) -> wl_shm::Format
|
||||||
|
{
|
||||||
|
*self.pixel_format.get_or_insert_with(|| {
|
||||||
|
|
||||||
|
if !self.force_xrgb8888 {
|
||||||
|
// Consume less gpu memory by using Bgr888 if available,
|
||||||
|
// fall back to the always supported Xrgb8888 otherwise
|
||||||
|
for format in self.shm.formats() {
|
||||||
|
if let wl_shm::Format::Bgr888 = format {
|
||||||
|
debug!("Using pixel format: {:?}", format);
|
||||||
|
return *format
|
||||||
|
}
|
||||||
|
// XXX: One may add Rgb888 and HDR support here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!("Using default pixel format: Xrgb8888");
|
||||||
|
wl_shm::Format::Xrgb8888
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn main() -> Result<(), ()> {
|
fn main() -> Result<(), ()> {
|
||||||
run().map_err(|e| { error!("{e:#}"); })
|
run().map_err(|e| { error!("{e:#}"); })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use smithay_client_toolkit::{
|
use smithay_client_toolkit::{
|
||||||
delegate_compositor, delegate_layer, delegate_output, delegate_registry,
|
delegate_compositor, delegate_layer, delegate_output, delegate_registry,
|
||||||
delegate_shm,
|
delegate_shm,
|
||||||
compositor::{CompositorHandler, CompositorState, Region},
|
compositor::{CompositorHandler, Region},
|
||||||
output::{OutputHandler, OutputState},
|
output::{OutputHandler, OutputState},
|
||||||
registry::{ProvidesRegistryState, RegistryState},
|
registry::{ProvidesRegistryState, RegistryState},
|
||||||
registry_handlers,
|
registry_handlers,
|
||||||
shell::{
|
shell::{
|
||||||
WaylandSurface,
|
WaylandSurface,
|
||||||
wlr_layer::{
|
wlr_layer::{
|
||||||
Anchor, KeyboardInteractivity, Layer, LayerShell,
|
Anchor, KeyboardInteractivity, Layer,
|
||||||
LayerShellHandler, LayerSurface, LayerSurfaceConfigure,
|
LayerShellHandler, LayerSurface, LayerSurfaceConfigure,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -24,7 +22,6 @@ use smithay_client_toolkit::reexports::client::{
|
||||||
Connection, Dispatch, Proxy, QueueHandle,
|
Connection, Dispatch, Proxy, QueueHandle,
|
||||||
protocol::{
|
protocol::{
|
||||||
wl_output::{self, Transform, WlOutput},
|
wl_output::{self, Transform, WlOutput},
|
||||||
wl_shm,
|
|
||||||
wl_surface::WlSurface
|
wl_surface::WlSurface
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -34,49 +31,10 @@ use smithay_client_toolkit::reexports::protocols::wp::viewporter::client::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
State,
|
||||||
image::workspace_bgs_from_output_image_dir,
|
image::workspace_bgs_from_output_image_dir,
|
||||||
compositors::ConnectionTask,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct State {
|
|
||||||
pub compositor_state: CompositorState,
|
|
||||||
pub registry_state: RegistryState,
|
|
||||||
pub output_state: OutputState,
|
|
||||||
pub shm: Shm,
|
|
||||||
pub layer_shell: LayerShell,
|
|
||||||
pub viewporter: WpViewporter,
|
|
||||||
pub wallpaper_dir: PathBuf,
|
|
||||||
pub force_xrgb8888: bool,
|
|
||||||
pub pixel_format: Option<wl_shm::Format>,
|
|
||||||
pub background_layers: Vec<BackgroundLayer>,
|
|
||||||
pub compositor_connection_task: ConnectionTask,
|
|
||||||
pub brightness: i32,
|
|
||||||
pub contrast: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
|
||||||
fn pixel_format(&mut self) -> wl_shm::Format
|
|
||||||
{
|
|
||||||
*self.pixel_format.get_or_insert_with(|| {
|
|
||||||
|
|
||||||
if !self.force_xrgb8888 {
|
|
||||||
// Consume less gpu memory by using Bgr888 if available,
|
|
||||||
// fall back to the always supported Xrgb8888 otherwise
|
|
||||||
for format in self.shm.formats() {
|
|
||||||
if let wl_shm::Format::Bgr888 = format {
|
|
||||||
debug!("Using pixel format: {:?}", format);
|
|
||||||
return *format
|
|
||||||
}
|
|
||||||
// XXX: One may add Rgb888 and HDR support here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("Using default pixel format: Xrgb8888");
|
|
||||||
wl_shm::Format::Xrgb8888
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CompositorHandler for State
|
impl CompositorHandler for State
|
||||||
{
|
{
|
||||||
fn scale_factor_changed(
|
fn scale_factor_changed(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue