Skip to content

Commit

Permalink
Use new primary scanout output if old output is disabled
Browse files Browse the repository at this point in the history
`Output` in Smithay doesn't track if the output still exists, other than
based on whether or not it has strong references. Which doesn't seem to
be working correctly.

There may be leaked strong references to `Output`s somewhere, and maybe
Smithay should track if an output is still valid, generally when it is
exposed as a Wayland global
(Smithay/smithay#1584). But a check like this
works for now.

Addresses #985.
  • Loading branch information
ids1024 authored and Drakulix committed Nov 13, 2024
1 parent 9f354ab commit 4db2e3e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use smithay::{
renderer::{
element::{
default_primary_scanout_output_compare, utils::select_dmabuf_feedback,
RenderElementStates,
RenderElementState, RenderElementStates,
},
ImportDma,
},
Expand Down Expand Up @@ -649,6 +649,19 @@ impl State {
}
}

fn primary_scanout_output_compare<'a>(
current_output: &'a Output,
current_state: &RenderElementState,
next_output: &'a Output,
next_state: &RenderElementState,
) -> &'a Output {
if !crate::wayland::protocols::output_configuration::head_is_enabled(current_output) {
return next_output;
}

default_primary_scanout_output_compare(current_output, current_state, next_output, next_state)
}

impl Common {
pub fn update_primary_output(
&self,
Expand All @@ -662,7 +675,7 @@ impl Common {
output,
states,
render_element_states,
default_primary_scanout_output_compare,
primary_scanout_output_compare,
);
if let Some(output) = primary_scanout_output {
with_fractional_scale(states, |fraction_scale| {
Expand Down
7 changes: 7 additions & 0 deletions src/wayland/protocols/output_configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ use std::{convert::TryFrom, sync::Mutex};

mod handlers;

pub fn head_is_enabled(output: &Output) -> bool {
output
.user_data()
.get::<OutputState>()
.map_or(false, |inner| inner.lock().unwrap().enabled)
}

#[derive(Debug)]
pub struct OutputConfigurationState<D> {
outputs: Vec<Output>,
Expand Down

0 comments on commit 4db2e3e

Please sign in to comment.