cargo fmt

This commit is contained in:
Victoria Brekenfeld 2022-05-03 13:37:51 +02:00
parent f7ff84d2a0
commit 8ccb93d8eb
15 changed files with 460 additions and 239 deletions

View file

@ -35,7 +35,7 @@ use smithay::{
nix::{fcntl::OFlag, sys::stat::dev_t},
wayland_server::protocol::wl_output,
},
utils::signaling::{Linkable, Signaler, SignalToken},
utils::signaling::{Linkable, SignalToken, Signaler},
wayland::output::{Mode as OutputMode, Output, PhysicalProperties},
};
@ -172,7 +172,7 @@ pub fn init_backend(event_loop: &mut EventLoop<'static, State>, state: &mut Stat
.handle()
.register_dispatcher(udev_dispatcher.clone())
.unwrap();
let handle = event_loop.handle();
let loop_signal = state.common.event_loop_signal.clone();
let dispatcher = udev_dispatcher.clone();
@ -184,29 +184,55 @@ pub fn init_backend(event_loop: &mut EventLoop<'static, State>, state: &mut Stat
let drm_node = match DrmNode::from_dev_id(dev) {
Ok(node) => node,
Err(err) => {
slog_scope::error!("Failed to read drm device {}: {}", path.display(), err);
continue
},
slog_scope::error!(
"Failed to read drm device {}: {}",
path.display(),
err
);
continue;
}
};
if state.backend.kms().devices.contains_key(&drm_node) {
if let Err(err) = state.device_changed(dev) {
slog_scope::error!("Failed to update drm device {}: {}", path.display(), err);
slog_scope::error!(
"Failed to update drm device {}: {}",
path.display(),
err
);
}
} else {
if let Err(err) = state.device_added(dev, path.into()) {
slog_scope::error!("Failed to add drm device {}: {}", path.display(), err);
slog_scope::error!(
"Failed to add drm device {}: {}",
path.display(),
err
);
}
}
}
state.common
state
.common
.output_conf
.update(&mut *state.common.display.borrow_mut());
state.common.config.read_outputs(state.common.output_conf.outputs(), &mut state.backend, &mut state.common.shell);
state.common.config.read_outputs(
state.common.output_conf.outputs(),
&mut state.backend,
&mut state.common.shell,
);
state.common.shell.refresh_outputs();
state.common.config.write_outputs(state.common.output_conf.outputs());
state
.common
.config
.write_outputs(state.common.output_conf.outputs());
for surface in state.backend.kms().devices.values_mut().flat_map(|d| d.surfaces.values_mut()) {
for surface in state
.backend
.kms()
.devices
.values_mut()
.flat_map(|d| d.surfaces.values_mut())
{
surface.pending = false;
}
for output in state.common.shell.outputs() {
@ -216,10 +242,14 @@ pub fn init_backend(event_loop: &mut EventLoop<'static, State>, state: &mut Stat
loop_signal.wakeup();
}
});
state.backend = BackendData::Kms(KmsState {
api,
_tokens: vec![libinput_event_source, session_event_source, udev_event_source],
_tokens: vec![
libinput_event_source,
session_event_source,
udev_event_source,
],
primary,
session,
signaler,
@ -240,7 +270,7 @@ impl State {
if !self.backend.kms().session.is_active() {
return Ok(());
}
let fd = SessionFd::new(
self.backend
.kms()
@ -352,33 +382,44 @@ impl State {
let mut wl_outputs = Vec::new();
let mut w = self.common.shell.global_space().size.w;
for (crtc, conn) in outputs {
match device.setup_surface(
crtc,
conn,
&mut self.common.event_loop_handle,
(0, w),
) {
match device.setup_surface(crtc, conn, &mut self.common.event_loop_handle, (0, w)) {
Ok(output) => {
w += output.user_data().get::<RefCell<OutputConfig>>().unwrap().borrow().mode_size().w;
w += output
.user_data()
.get::<RefCell<OutputConfig>>()
.unwrap()
.borrow()
.mode_size()
.w;
wl_outputs.push(output);
}
Err(err) => slog_scope::warn!("Failed to initialize output: {}", err),
};
}
self.backend.kms().devices.insert(drm_node, device);
self.common.output_conf.add_heads(wl_outputs.iter());
self.common
.output_conf
.update(&mut *self.common.display.borrow_mut());
for output in wl_outputs {
if let Err(err) = self.backend.kms().apply_config_for_output(&output, &mut self.common.shell, false) {
if let Err(err) =
self.backend
.kms()
.apply_config_for_output(&output, &mut self.common.shell, false)
{
slog_scope::warn!("Failed to initialize output: {}", err);
}
}
self.common.config.read_outputs(self.common.output_conf.outputs(), &mut self.backend, &mut self.common.shell);
self.common.config.read_outputs(
self.common.output_conf.outputs(),
&mut self.backend,
&mut self.common.shell,
);
self.common.shell.refresh_outputs();
self.common.config.write_outputs(self.common.output_conf.outputs());
self.common
.config
.write_outputs(self.common.output_conf.outputs());
Ok(())
}
@ -387,7 +428,7 @@ impl State {
if !self.backend.kms().session.is_active() {
return Ok(());
}
let drm_node = DrmNode::from_dev_id(dev)?;
let mut outputs_removed = Vec::new();
let mut outputs_added = Vec::new();
@ -404,14 +445,15 @@ impl State {
}
}
for (crtc, conn) in changes.added {
match device.setup_surface(
crtc,
conn,
&mut self.common.event_loop_handle,
(0, w),
) {
match device.setup_surface(crtc, conn, &mut self.common.event_loop_handle, (0, w)) {
Ok(output) => {
w += output.user_data().get::<RefCell<OutputConfig>>().unwrap().borrow().mode_size().w;
w += output
.user_data()
.get::<RefCell<OutputConfig>>()
.unwrap()
.borrow()
.mode_size()
.w;
outputs_added.push(output);
}
Err(err) => slog_scope::warn!("Failed to initialize output: {}", err),
@ -422,16 +464,26 @@ impl State {
self.common.output_conf.remove_heads(outputs_removed.iter());
self.common.output_conf.add_heads(outputs_added.iter());
for output in outputs_added {
if let Err(err) = self.backend.kms().apply_config_for_output(&output, &mut self.common.shell, false) {
if let Err(err) =
self.backend
.kms()
.apply_config_for_output(&output, &mut self.common.shell, false)
{
slog_scope::warn!("Failed to initialize output: {}", err);
}
}
self.common
.output_conf
.update(&mut self.common.display.borrow_mut());
self.common.config.read_outputs(self.common.output_conf.outputs(), &mut self.backend, &mut self.common.shell);
self.common.config.read_outputs(
self.common.output_conf.outputs(),
&mut self.backend,
&mut self.common.shell,
);
self.common.shell.refresh_outputs();
self.common.config.write_outputs(self.common.output_conf.outputs());
self.common
.config
.write_outputs(self.common.output_conf.outputs());
Ok(())
}
@ -459,9 +511,15 @@ impl State {
.update(&mut *self.common.display.borrow_mut());
if self.backend.kms().session.is_active() {
self.common.config.read_outputs(self.common.output_conf.outputs(), &mut self.backend, &mut self.common.shell);
self.common.config.read_outputs(
self.common.output_conf.outputs(),
&mut self.backend,
&mut self.common.shell,
);
self.common.shell.refresh_outputs();
self.common.config.write_outputs(self.common.output_conf.outputs());
self.common
.config
.write_outputs(self.common.output_conf.outputs());
}
Ok(())
@ -621,18 +679,11 @@ impl Surface {
self.surface.as_mut().unwrap().reset_buffers();
}
let workspace = state
.shell
.active_space(&self.output);
let workspace = state.shell.active_space(&self.output);
let nodes = workspace
.get_fullscreen(&self.output)
.map(|w| vec![w])
.unwrap_or_else(||
workspace
.space
.windows()
.collect::<Vec<_>>()
)
.unwrap_or_else(|| workspace.space.windows().collect::<Vec<_>>())
.into_iter()
.flat_map(|w| {
w.toplevel()
@ -696,10 +747,7 @@ impl Surface {
}
impl KmsState {
pub fn switch_vt(
&mut self,
num: i32,
) -> Result<(), anyhow::Error> {
pub fn switch_vt(&mut self, num: i32) -> Result<(), anyhow::Error> {
self.session.change_vt(num).map_err(Into::into)
}
@ -823,7 +871,7 @@ impl KmsState {
*/
let data = (*device, *crtc);
//if surface.vrr {
surface.render_timer.add_timeout(Duration::ZERO, data);
surface.render_timer.add_timeout(Duration::ZERO, data);
//} else {
// surface.render_timer.add_timeout(duration, data);
//}

View file

@ -12,7 +12,10 @@ pub mod x11;
// TODO
// pub mod wayland; // tbd in smithay
pub fn init_backend_auto(event_loop: &mut EventLoop<'static, State>, state: &mut State) -> Result<()> {
pub fn init_backend_auto(
event_loop: &mut EventLoop<'static, State>,
state: &mut State,
) -> Result<()> {
match std::env::var("COSMIC_BACKEND") {
Ok(x) if x == "x11" => x11::init_backend(event_loop, state),
Ok(x) if x == "winit" => winit::init_backend(event_loop, state),

View file

@ -14,18 +14,17 @@ use smithay::{
renderer::{
gles2::{Gles2Renderbuffer, Gles2Renderer, Gles2Texture},
multigpu::{egl::EglGlesBackend, Error as MultiError, MultiFrame, MultiRenderer},
ImportAll, Renderer, Frame, TextureFilter,
Frame, ImportAll, Renderer, TextureFilter,
},
},
desktop::{
draw_layer_surface, draw_window, layer_map_for_output,
space::{RenderElement, RenderError, SpaceOutputTuple, SurfaceTree},
draw_window, draw_layer_surface, Window, layer_map_for_output, utils::damage_from_surface_tree,
utils::damage_from_surface_tree,
Window,
},
utils::{Logical, Point, Rectangle, Transform},
wayland::{
shell::wlr_layer::Layer as WlrLayer,
output::Output,
},
wayland::{output::Output, shell::wlr_layer::Layer as WlrLayer},
};
mod cursor;
@ -115,7 +114,12 @@ pub fn needs_buffer_reset(output: &Output, state: &Common) -> bool {
let userdata = output.user_data();
userdata.insert_if_missing(|| DidCustomRendering(AtomicBool::new(false)));
userdata.get::<DidCustomRendering>().unwrap().0.swap(will_render_custom, Ordering::AcqRel) != will_render_custom
userdata
.get::<DidCustomRendering>()
.unwrap()
.0
.swap(will_render_custom, Ordering::AcqRel)
!= will_render_custom
}
pub fn render_output<R>(
@ -132,7 +136,9 @@ where
<R as Renderer>::TextureId: Clone + 'static,
CustomElem: RenderElement<R>,
{
renderer.downscale_filter(TextureFilter::Linear).map_err(RenderError::Rendering)?;
renderer
.downscale_filter(TextureFilter::Linear)
.map_err(RenderError::Rendering)?;
#[cfg(feature = "debug")]
{
@ -259,10 +265,16 @@ where
#[cfg(feature = "debug")]
{
let fps_overlay = fps_ui(_gpu, state, fps, Rectangle::from_loc_and_size((0, 0), output_geo.size), scale);
let fps_overlay = fps_ui(
_gpu,
state,
fps,
Rectangle::from_loc_and_size((0, 0), output_geo.size),
scale,
);
custom_elements.push(fps_overlay.into());
}
for seat in &state.seats {
let pointer = match seat.get_pointer() {
Some(ptr) => ptr,

View file

@ -183,9 +183,7 @@ pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Res
}
Err(winit::WinitError::WindowClosed) => {
let output = state.backend.winit().output.clone();
state.common.shell.remove_output(
&output,
);
state.common.shell.remove_output(&output);
if let Some(token) = token.take() {
event_loop_handle.remove(token);
}
@ -207,11 +205,12 @@ pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Res
.common
.output_conf
.update(&mut *state.common.display.borrow_mut());
state
.common
.shell
.add_output(&output);
state.common.config.read_outputs(std::iter::once(&output), &mut state.backend, &mut state.common.shell);
state.common.shell.add_output(&output);
state.common.config.read_outputs(
std::iter::once(&output),
&mut state.backend,
&mut state.common.shell,
);
state.common.shell.refresh_outputs();
state.common.config.write_outputs(std::iter::once(&output));

View file

@ -263,16 +263,15 @@ pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Res
.common
.output_conf
.update(&mut *state.common.display.borrow_mut());
state
.common
.shell
.add_output(&output);
state.common.config.read_outputs(std::iter::once(&output), &mut state.backend, &mut state.common.shell);
state.common.shell.add_output(&output);
state.common.config.read_outputs(
std::iter::once(&output),
&mut state.backend,
&mut state.common.shell,
);
state.common.shell.refresh_outputs();
state.common.config.write_outputs(std::iter::once(&output));
event_loop
.handle()
.insert_source(backend, |event, _, state| match event {
@ -295,9 +294,7 @@ pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Res
.surfaces
.retain(|s| s.window.id() != window_id);
for output in outputs_removed.into_iter() {
state.common.shell.remove_output(
&output,
);
state.common.shell.remove_output(&output);
}
}
X11Event::Resized {