Skip to content

Commit

Permalink
A huge refactoring && cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Weselton committed Dec 15, 2024
1 parent 6707c92 commit 769c610
Show file tree
Hide file tree
Showing 70 changed files with 1,151 additions and 1,328 deletions.
6 changes: 1 addition & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
use std::process::Command;

fn main() {
if let Some(output) = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
.ok()
{
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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/backend/kms/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl Device {

let added = config
.iter()
.filter(|(conn, maybe)| match (surfaces.get(&conn), maybe) {
.filter(|(conn, maybe)| match (surfaces.get(conn), maybe) {
(Some(current_crtc), Some(new_crtc)) => current_crtc != new_crtc,
(None, _) => true,
_ => false,
Expand All @@ -462,7 +462,7 @@ impl Device {
.outputs
.iter()
.filter(|(conn, _)| match config.get(conn) {
Some(Some(c)) => surfaces.get(&conn).is_some_and(|crtc| c != crtc),
Some(Some(c)) => surfaces.get(conn).is_some_and(|crtc| c != crtc),
_ => true,
})
.map(|(conn, _)| *conn)
Expand All @@ -485,7 +485,7 @@ impl Device {
.outputs
.get(&conn)
.cloned()
.map(|output| Ok(output))
.map(Ok)
.unwrap_or_else(|| create_output_for_conn(&mut self.drm, conn))
.context("Failed to create `Output`")?;

Expand Down Expand Up @@ -621,7 +621,7 @@ fn populate_modes(
.iter()
.find(|mode| mode.mode_type().contains(ModeTypeFlags::PREFERRED))
.copied()
.or(conn_info.modes().get(0).copied())
.or(conn_info.modes().first().copied())
else {
anyhow::bail!("No mode found");
};
Expand Down
2 changes: 1 addition & 1 deletion src/backend/kms/drm_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn display_configuration(
.flat_map(|conn| device.get_connector(*conn, false).ok())
.filter(|conn| {
if let Some(enc) = conn.current_encoder() {
if let Some(enc) = device.get_encoder(enc).ok() {
if let Ok(enc) = device.get_encoder(enc) {
if let Some(crtc) = enc.crtc() {
return cleanup.contains(&crtc);
}
Expand Down
16 changes: 6 additions & 10 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn init_libinput(
.context("Failed to initialize libinput event source")?;

// Create relative pointer global
RelativePointerManagerState::new::<State>(&dh);
RelativePointerManagerState::new::<State>(dh);

Ok(libinput_context)
}
Expand Down Expand Up @@ -454,11 +454,9 @@ impl KmsState {
device.egl = Some(egl);
}
used_devices.insert(device.render_node);
} else {
if device.egl.is_some() {
let _ = device.egl.take();
self.api.as_mut().remove_node(&device.render_node);
}
} else if device.egl.is_some() {
let _ = device.egl.take();
self.api.as_mut().remove_node(&device.render_node);
}
}

Expand Down Expand Up @@ -749,10 +747,8 @@ impl KmsState {
None
};

if !test_only {
if mirrored_output != surface.output.mirroring() {
surface.set_mirroring(mirrored_output.clone());
}
if !test_only && mirrored_output != surface.output.mirroring() {
surface.set_mirroring(mirrored_output.clone());
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/backend/kms/render/pixman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl fmt::Debug for GbmPixmanDevice {
}
}

impl<A: AsFd + 'static> Default for GbmPixmanBackend<A> {
fn default() -> Self {
Self::new()
}
}

impl<A: AsFd + 'static> GbmPixmanBackend<A> {
pub fn new() -> Self {
GbmPixmanBackend {
Expand Down
32 changes: 11 additions & 21 deletions src/backend/kms/surface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,14 @@ pub type GbmDrmCompositor = DrmCompositor<
DrmDeviceFd,
>;

#[derive(Debug)]
#[derive(Debug, Default)]
pub enum QueueState {
#[default]
Idle,
/// A redraw is queued.
Queued(RegistrationToken),
/// We submitted a frame to the KMS and waiting for it to be presented.
WaitingForVBlank {
redraw_needed: bool,
},
WaitingForVBlank { redraw_needed: bool },
/// We did not submit anything to KMS and made a timer to fire at the estimated VBlank.
WaitingForEstimatedVBlank(RegistrationToken),
/// A redraw is queued on top of the above.
Expand All @@ -214,12 +213,6 @@ pub enum QueueState {
},
}

impl Default for QueueState {
fn default() -> Self {
QueueState::Idle
}
}

#[derive(Debug)]
pub enum ThreadCommand {
Suspend(SyncSender<()>),
Expand Down Expand Up @@ -781,7 +774,7 @@ impl SurfaceThreadState {

let now = self.clock.now();
let presentation_time = match metadata.as_ref().map(|data| &data.time) {
Some(DrmEventTime::Monotonic(tp)) => Some(tp.clone()),
Some(DrmEventTime::Monotonic(tp)) => Some(*tp),
_ => None,
};
let sequence = metadata.as_ref().map(|data| data.sequence).unwrap_or(0);
Expand Down Expand Up @@ -912,7 +905,7 @@ impl SurfaceThreadState {
warn!(?name, "Failed to submit rendering: {:?}", err);
state.queue_redraw(true);
}
return TimeoutAction::Drop;
TimeoutAction::Drop
})
.expect("Failed to schedule render");

Expand All @@ -922,7 +915,7 @@ impl SurfaceThreadState {
}
QueueState::WaitingForEstimatedVBlank(estimated_vblank) => {
self.state = QueueState::WaitingForEstimatedVBlankAndQueued {
estimated_vblank: estimated_vblank.clone(),
estimated_vblank: *estimated_vblank,
queued_render: token,
};
}
Expand All @@ -936,7 +929,7 @@ impl SurfaceThreadState {
} if force => {
self.loop_handle.remove(*queued_render);
self.state = QueueState::WaitingForEstimatedVBlankAndQueued {
estimated_vblank: estimated_vblank.clone(),
estimated_vblank: *estimated_vblank,
queued_render: token,
};
}
Expand All @@ -953,7 +946,7 @@ impl SurfaceThreadState {
self.mirroring.as_ref().unwrap_or(&self.output),
&self.primary_node,
&self.target_node,
&*self.shell.read().unwrap(),
&self.shell.read().unwrap(),
);

let mut renderer = if render_node != self.target_node {
Expand All @@ -966,17 +959,14 @@ impl SurfaceThreadState {

self.timings.start_render(&self.clock);

let mut vrr = match self.vrr_mode {
AdaptiveSync::Force => true,
_ => false,
};
let mut vrr = matches!(self.vrr_mode, AdaptiveSync::Force);

let mut elements = {
let shell = self.shell.read().unwrap();
let output = self.mirroring.as_ref().unwrap_or(&self.output);

let (previous_workspace, workspace) = shell.workspaces.active(output);
let (previous_idx, idx) = shell.workspaces.active_num(&output);
let (previous_idx, idx) = shell.workspaces.active_num(output);
let previous_workspace = previous_workspace
.zip(previous_idx)
.map(|((w, start), idx)| (w.handle, idx, start));
Expand Down Expand Up @@ -1497,7 +1487,7 @@ fn render_node_for_output(
.flat_map(|w| w.wl_surface().and_then(|s| source_node_for_surface(&s)))
.collect::<Vec<_>>();

if nodes.contains(&target_node) || nodes.is_empty() {
if nodes.contains(target_node) || nodes.is_empty() {
*target_node
} else {
*primary_node
Expand Down
7 changes: 2 additions & 5 deletions src/backend/kms/surface/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,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
.clone()
.unwrap_or(Duration::ZERO),
- frame.render_duration_elements.unwrap_or(Duration::ZERO),
);
}
}
Expand Down Expand Up @@ -201,7 +198,7 @@ impl Timings {
}
let secs = match (self.previous_frames.front(), self.previous_frames.back()) {
(Some(Frame { render_start, .. }), Some(end_frame)) => {
Time::elapsed(render_start, end_frame.render_start.clone()) + end_frame.frame_time()
Time::elapsed(render_start, end_frame.render_start) + end_frame.frame_time()
}
_ => Duration::ZERO,
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn init_backend_auto(
.startup_done
.store(true, std::sync::atomic::Ordering::SeqCst);
for output in state.common.shell.read().unwrap().outputs() {
state.backend.schedule_render(&output);
state.backend.schedule_render(output);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/backend/render/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where
{
let position = location.into();
let scale = scale.into();
let h = with_states(&surface, |states| {
let h = with_states(surface, |states| {
states
.data_map
.get::<Mutex<CursorImageAttributes>>()
Expand Down Expand Up @@ -174,7 +174,7 @@ where
R: Renderer + ImportAll,
<R as Renderer>::TextureId: Clone + 'static,
{
if get_role(&surface) != Some("dnd_icon") {
if get_role(surface) != Some("dnd_icon") {
warn!(
?surface,
"Trying to display as a dnd icon a surface that does not have the DndIcon role."
Expand Down Expand Up @@ -322,7 +322,7 @@ where
MemoryRenderBufferRenderElement::from_buffer(
renderer,
location.to_physical(scale),
&pointer_image,
pointer_image,
None,
None,
None,
Expand Down
Loading

0 comments on commit 769c610

Please sign in to comment.