cargo fmt

This commit is contained in:
Vukašin Vojinović 2025-10-16 16:10:35 +02:00 committed by Victoria Brekenfeld
parent 5e9ea93819
commit b6c5d00bec
17 changed files with 264 additions and 277 deletions

View file

@ -2,10 +2,7 @@
use std::process::Command;
fn main() {
if let Ok(output) = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
{
if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}

View file

@ -141,9 +141,7 @@ impl Timings {
if let Some(frame) = self.pending_frame.as_mut() {
frame.render_duration_draw = Some(
Time::elapsed(&frame.render_start, clock.now())
- frame
.render_duration_elements
.unwrap_or(Duration::ZERO),
- frame.render_duration_elements.unwrap_or(Duration::ZERO),
);
}
}

View file

@ -773,223 +773,208 @@ where
)
};
render_input_order::<()>(
&shell,
output,
previous,
current,
element_filter,
|stage| {
match stage {
Stage::ZoomUI => {
elements.extend(ZoomState::render(renderer, output));
}
Stage::SessionLock(lock_surface) => {
elements.extend(
session_lock_elements(renderer, output, lock_surface)
.into_iter()
.map(Into::into)
.flat_map(crop_to_output)
.map(Into::into),
);
}
Stage::LayerPopup {
popup, location, ..
} => {
elements.extend(
render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>(
renderer,
popup.wl_surface(),
location
.to_local(output)
.as_logical()
.to_physical_precise_round(scale),
Scale::from(scale),
1.0,
FRAME_TIME_FILTER,
)
render_input_order::<()>(&shell, output, previous, current, element_filter, |stage| {
match stage {
Stage::ZoomUI => {
elements.extend(ZoomState::render(renderer, output));
}
Stage::SessionLock(lock_surface) => {
elements.extend(
session_lock_elements(renderer, output, lock_surface)
.into_iter()
.flat_map(crop_to_output)
.map(Into::into),
);
}
Stage::LayerSurface { layer, location } => {
elements.extend(
render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>(
renderer,
layer.wl_surface(),
location
.to_local(output)
.as_logical()
.to_physical_precise_round(scale),
Scale::from(scale),
1.0,
FRAME_TIME_FILTER,
)
.into_iter()
.flat_map(crop_to_output)
.map(Into::into),
);
}
Stage::OverrideRedirect { surface, location } => {
elements.extend(surface.wl_surface().into_iter().flat_map(|surface| {
render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>(
renderer,
&surface,
location
.to_local(output)
.as_logical()
.to_physical_precise_round(scale),
Scale::from(scale),
1.0,
FRAME_TIME_FILTER,
)
.into_iter()
.flat_map(crop_to_output)
.map(Into::into)
}));
}
Stage::StickyPopups(layout) => {
let alpha = match &overview.0 {
OverviewMode::Started(_, started) => {
(1.0 - (Instant::now().duration_since(*started).as_millis()
/ ANIMATION_DURATION.as_millis())
as f32)
.max(0.0)
* 0.4
+ 0.6
}
OverviewMode::Ended(_, ended) => {
((Instant::now().duration_since(*ended).as_millis()
/ ANIMATION_DURATION.as_millis())
as f32)
* 0.4
+ 0.6
}
OverviewMode::Active(_) => 0.6,
OverviewMode::None => 1.0,
};
elements.extend(
layout
.render_popups(renderer, alpha)
.into_iter()
.map(Into::into)
.flat_map(crop_to_output)
.map(Into::into),
);
}
Stage::Sticky(layout) => {
let alpha = match &overview.0 {
OverviewMode::Started(_, started) => {
(1.0 - (Instant::now().duration_since(*started).as_millis()
/ ANIMATION_DURATION.as_millis())
as f32)
.max(0.0)
* 0.4
+ 0.6
}
OverviewMode::Ended(_, ended) => {
((Instant::now().duration_since(*ended).as_millis()
/ ANIMATION_DURATION.as_millis())
as f32)
* 0.4
+ 0.6
}
OverviewMode::Active(_) => 0.6,
OverviewMode::None => 1.0,
};
let current_focus = (!move_active && is_active_space)
.then_some(last_active_seat)
.map(|seat| workspace.focus_stack.get(seat));
elements.extend(
layout
.render(
renderer,
current_focus.as_ref().and_then(|stack| {
stack.last().and_then(|t| match t {
FocusTarget::Window(w) => Some(w),
_ => None,
})
}),
resize_indicator.clone(),
active_hint,
alpha,
theme.cosmic(),
)
.into_iter()
.map(Into::into)
.flat_map(crop_to_output)
.map(Into::into),
.flat_map(crop_to_output)
.map(Into::into),
);
}
Stage::LayerPopup {
popup, location, ..
} => {
elements.extend(
render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>(
renderer,
popup.wl_surface(),
location
.to_local(output)
.as_logical()
.to_physical_precise_round(scale),
Scale::from(scale),
1.0,
FRAME_TIME_FILTER,
)
}
Stage::WorkspacePopups { workspace, offset } => {
elements.extend(
match workspace.render_popups(
.into_iter()
.flat_map(crop_to_output)
.map(Into::into),
);
}
Stage::LayerSurface { layer, location } => {
elements.extend(
render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>(
renderer,
layer.wl_surface(),
location
.to_local(output)
.as_logical()
.to_physical_precise_round(scale),
Scale::from(scale),
1.0,
FRAME_TIME_FILTER,
)
.into_iter()
.flat_map(crop_to_output)
.map(Into::into),
);
}
Stage::OverrideRedirect { surface, location } => {
elements.extend(surface.wl_surface().into_iter().flat_map(|surface| {
render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>(
renderer,
&surface,
location
.to_local(output)
.as_logical()
.to_physical_precise_round(scale),
Scale::from(scale),
1.0,
FRAME_TIME_FILTER,
)
.into_iter()
.flat_map(crop_to_output)
.map(Into::into)
}));
}
Stage::StickyPopups(layout) => {
let alpha = match &overview.0 {
OverviewMode::Started(_, started) => {
(1.0 - (Instant::now().duration_since(*started).as_millis()
/ ANIMATION_DURATION.as_millis()) as f32)
.max(0.0)
* 0.4
+ 0.6
}
OverviewMode::Ended(_, ended) => {
((Instant::now().duration_since(*ended).as_millis()
/ ANIMATION_DURATION.as_millis()) as f32)
* 0.4
+ 0.6
}
OverviewMode::Active(_) => 0.6,
OverviewMode::None => 1.0,
};
elements.extend(
layout
.render_popups(renderer, alpha)
.into_iter()
.map(Into::into)
.flat_map(crop_to_output)
.map(Into::into),
);
}
Stage::Sticky(layout) => {
let alpha = match &overview.0 {
OverviewMode::Started(_, started) => {
(1.0 - (Instant::now().duration_since(*started).as_millis()
/ ANIMATION_DURATION.as_millis()) as f32)
.max(0.0)
* 0.4
+ 0.6
}
OverviewMode::Ended(_, ended) => {
((Instant::now().duration_since(*ended).as_millis()
/ ANIMATION_DURATION.as_millis()) as f32)
* 0.4
+ 0.6
}
OverviewMode::Active(_) => 0.6,
OverviewMode::None => 1.0,
};
let current_focus = (!move_active && is_active_space)
.then_some(last_active_seat)
.map(|seat| workspace.focus_stack.get(seat));
elements.extend(
layout
.render(
renderer,
last_active_seat,
!move_active && is_active_space,
overview.clone(),
theme.cosmic(),
) {
Ok(elements) => {
elements
.into_iter()
.flat_map(crop_to_output)
.map(|element| {
CosmicElement::Workspace(
RelocateRenderElement::from_element(
element,
offset.to_physical_precise_round(scale),
Relocate::Relative,
),
)
})
}
Err(_) => {
return ControlFlow::Break(Err(OutputNoMode));
}
},
);
}
Stage::Workspace { workspace, offset } => {
elements.extend(
match workspace.render(
renderer,
last_active_seat,
!move_active && is_active_space,
overview.clone(),
current_focus.as_ref().and_then(|stack| {
stack.last().and_then(|t| match t {
FocusTarget::Window(w) => Some(w),
_ => None,
})
}),
resize_indicator.clone(),
active_hint,
alpha,
theme.cosmic(),
) {
Ok(elements) => {
elements
.into_iter()
.flat_map(crop_to_output)
.map(|element| {
CosmicElement::Workspace(
RelocateRenderElement::from_element(
element,
offset.to_physical_precise_round(scale),
Relocate::Relative,
),
)
})
}
Err(_) => {
return ControlFlow::Break(Err(OutputNoMode));
}
},
);
}
};
)
.into_iter()
.map(Into::into)
.flat_map(crop_to_output)
.map(Into::into),
)
}
Stage::WorkspacePopups { workspace, offset } => {
elements.extend(
match workspace.render_popups(
renderer,
last_active_seat,
!move_active && is_active_space,
overview.clone(),
theme.cosmic(),
) {
Ok(elements) => {
elements
.into_iter()
.flat_map(crop_to_output)
.map(|element| {
CosmicElement::Workspace(RelocateRenderElement::from_element(
element,
offset.to_physical_precise_round(scale),
Relocate::Relative,
))
})
}
Err(_) => {
return ControlFlow::Break(Err(OutputNoMode));
}
},
);
}
Stage::Workspace { workspace, offset } => {
elements.extend(
match workspace.render(
renderer,
last_active_seat,
!move_active && is_active_space,
overview.clone(),
resize_indicator.clone(),
active_hint,
theme.cosmic(),
) {
Ok(elements) => {
elements
.into_iter()
.flat_map(crop_to_output)
.map(|element| {
CosmicElement::Workspace(RelocateRenderElement::from_element(
element,
offset.to_physical_precise_round(scale),
Relocate::Relative,
))
})
}
Err(_) => {
return ControlFlow::Break(Err(OutputNoMode));
}
},
);
}
};
ControlFlow::Continue(())
},
)?;
ControlFlow::Continue(())
})?;
Ok(elements)
}

View file

@ -92,7 +92,9 @@ pub fn get_config<'a, T: 'a, F: Fn(&'a InputConfig) -> Option<T>>(
) -> Option<(T, bool)> {
if let Some(setting) = device_config.and_then(&f) {
Some((setting, false))
} else { f(default_config).map(|setting| (setting, true)) }
} else {
f(default_config).map(|setting| (setting, true))
}
}
fn config_set_error<T: std::fmt::Debug>(

View file

@ -49,8 +49,6 @@ pub fn init(evlh: &LoopHandle<'static, State>) -> Result<Vec<RegistrationToken>>
}
}
}
}
calloop::channel::Event::Closed => (),
})

View file

@ -80,10 +80,12 @@ impl State {
command.envs(
session::get_env(&self.common).expect("WAYLAND_DISPLAY should be valid UTF-8"),
);
unsafe { command.pre_exec(|| {
utils::rlimit::restore_nofile_limit();
Ok(())
}) };
unsafe {
command.pre_exec(|| {
utils::rlimit::restore_nofile_limit();
Ok(())
})
};
info!("Running {:?}", exec);
command

View file

@ -804,11 +804,15 @@ impl PointerTarget<State> for CosmicWindow {
}
fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {
if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) { PointerTarget::axis(&self.0, seat, data, frame) }
if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) {
PointerTarget::axis(&self.0, seat, data, frame)
}
}
fn frame(&self, seat: &Seat<State>, data: &mut State) {
if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) { PointerTarget::frame(&self.0, seat, data) }
if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) {
PointerTarget::frame(&self.0, seat, data)
}
}
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {

View file

@ -51,7 +51,8 @@ fn next_workspace(
shell
.workspaces
.spaces_for_output(&output)
.skip_while(|space| space.handle != current_handle).nth(1)
.skip_while(|space| space.handle != current_handle)
.nth(1)
.map(|space| (current_handle, space.handle))
}

View file

@ -962,45 +962,35 @@ impl MenuAlignment {
AxisAlignment::Centered,
)
.into_iter()
.chain(
for_alignment(
position,
size,
AxisAlignment::Centered,
AxisAlignment::Corner(0),
),
)
.chain(
for_alignment(
position,
size,
AxisAlignment::Corner(0),
AxisAlignment::Centered,
),
)
.chain(
for_alignment(
position,
size,
AxisAlignment::Corner(0),
AxisAlignment::Corner(0),
),
)
.chain(for_alignment(
position,
size,
AxisAlignment::Centered,
AxisAlignment::Corner(0),
))
.chain(for_alignment(
position,
size,
AxisAlignment::Corner(0),
AxisAlignment::Centered,
))
.chain(for_alignment(
position,
size,
AxisAlignment::Corner(0),
AxisAlignment::Corner(0),
))
.collect(),
(AxisAlignment::PreferCentered, y) => {
for_alignment(position, size, AxisAlignment::Centered, y)
.into_iter()
.chain(
for_alignment(position, size, AxisAlignment::Corner(0), y),
)
.chain(for_alignment(position, size, AxisAlignment::Corner(0), y))
.collect()
}
(x, AxisAlignment::PreferCentered) => {
for_alignment(position, size, x, AxisAlignment::Centered)
.into_iter()
.chain(
for_alignment(position, size, x, AxisAlignment::Corner(0)),
)
.chain(for_alignment(position, size, x, AxisAlignment::Corner(0)))
.collect()
}
}

View file

@ -95,7 +95,8 @@ impl MoveGrabState {
if output
.geometry()
.as_logical()
.intersection(window_geo).is_none()
.intersection(window_geo)
.is_none()
{
return Vec::new();
}
@ -113,8 +114,8 @@ impl MoveGrabState {
.corner_radius(window_geo.size, self.indicator_thickness);
let focus_element = if self.indicator_thickness > 0 {
Some(
CosmicMappedRenderElement::from(IndicatorShader::focus_element(
Some(CosmicMappedRenderElement::from(
IndicatorShader::focus_element(
renderer,
Key::Window(Usage::MoveGrabIndicator, self.window.key()),
Rectangle::new(
@ -135,8 +136,8 @@ impl MoveGrabState {
active_window_hint.green,
active_window_hint.blue,
],
)),
)
),
))
} else {
None
};
@ -435,8 +436,7 @@ impl MoveGrab {
}
}
let indicator_location =
shell.stacking_indicator(&current_output, self.previous);
let indicator_location = shell.stacking_indicator(&current_output, self.previous);
if indicator_location.is_some() != grab_state.stacking_indicator.is_some() {
grab_state.stacking_indicator = indicator_location.map(|geo| {
let element = stack_hover(

View file

@ -535,7 +535,9 @@ impl TouchGrab<State> for ResizeForkGrab {
event: &TouchMotionEvent,
seq: Serial,
) {
if event.slot == <Self as TouchGrab<State>>::start_data(self).slot && self.update_location(data, event.location, false) {
if event.slot == <Self as TouchGrab<State>>::start_data(self).slot
&& self.update_location(data, event.location, false)
{
handle.unset_grab(self, data);
}

View file

@ -336,9 +336,7 @@ impl BackendData {
) -> Result<Option<DrmNode>, anyhow::Error> {
match self {
BackendData::Kms(state) => {
return state
.dmabuf_imported(client, global, dmabuf)
.map(Some);
return state.dmabuf_imported(client, global, dmabuf).map(Some);
}
BackendData::Winit(state) => {
state.backend.renderer().import_dmabuf(&dmabuf, None)?;
@ -574,12 +572,14 @@ impl From<DrmNode> for KmsNodes {
pub fn client_has_no_security_context(client: &Client) -> bool {
client
.get_data::<ClientState>().is_none_or(|client_state| client_state.security_context.is_none())
.get_data::<ClientState>()
.is_none_or(|client_state| client_state.security_context.is_none())
}
pub fn client_is_privileged(client: &Client) -> bool {
client
.get_data::<ClientState>().is_some_and(|client_state| client_state.privileged)
.get_data::<ClientState>()
.is_some_and(|client_state| client_state.privileged)
}
fn enable_wayland_security() -> bool {

View file

@ -11,9 +11,11 @@ impl BufferHandler for State {
fn buffer_destroyed(&mut self, buffer: &WlBuffer) {
if let BackendData::Kms(kms_state) = &mut self.backend {
for device in kms_state.drm_devices.values_mut() {
if device.inner.active_buffers.remove(&buffer.downgrade()) && !device
if device.inner.active_buffers.remove(&buffer.downgrade())
&& !device
.inner
.in_use(kms_state.primary_node.read().unwrap().as_ref()) {
.in_use(kms_state.primary_node.read().unwrap().as_ref())
{
if let Err(err) = kms_state.refresh_used_devices() {
warn!(?err, "Failed to init devices.");
};

View file

@ -16,7 +16,8 @@ impl PointerConstraintsHandler for State {
fn new_constraint(&mut self, surface: &WlSurface, pointer: &PointerHandle<Self>) {
// XXX region
if pointer
.current_focus().is_some_and(|x| x.wl_surface().as_deref() == Some(surface))
.current_focus()
.is_some_and(|x| x.wl_surface().as_deref() == Some(surface))
{
with_pointer_constraint(surface, pointer, |constraint| {
constraint.unwrap().activate();

View file

@ -304,9 +304,11 @@ impl XdgShellHandler for State {
if should_focus {
Shell::set_focus(self, Some(&target), &seat, None, true);
}
} else if let Some(pending) = shell.pending_windows.iter_mut().find(|pending| {
pending.surface.wl_surface().as_deref() == Some(surface.wl_surface())
}) {
} else if let Some(pending) = shell
.pending_windows
.iter_mut()
.find(|pending| pending.surface.wl_surface().as_deref() == Some(surface.wl_surface()))
{
pending.fullscreen.take();
}
}

View file

@ -37,7 +37,8 @@ mod handlers;
pub fn head_is_enabled(output: &Output) -> bool {
output
.user_data()
.get::<OutputState>().is_some_and(|inner| inner.lock().unwrap().enabled)
.get::<OutputState>()
.is_some_and(|inner| inner.lock().unwrap().enabled)
}
#[derive(Debug)]

View file

@ -800,7 +800,9 @@ where
_dhandle: &DisplayHandle,
data_init: &mut DataInit<'_, D>,
) {
if let ext_image_copy_capture_cursor_session_v1::Request::GetCaptureSession { session } = request {
if let ext_image_copy_capture_cursor_session_v1::Request::GetCaptureSession { session } =
request
{
let new_data = CursorSessionData {
inner: data.inner.clone(),
};