Skip to content

Commit

Permalink
Update led state properly and don't render when inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottatop committed Aug 15, 2024
1 parent 65f2dce commit 6999ff8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
26 changes: 24 additions & 2 deletions src/backend/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,19 +1274,41 @@ impl Udev {
/// Render to the [`RenderSurface`] associated with the given `output`.
#[tracing::instrument(level = "debug", skip(self, pinnacle), fields(output = output.name()))]
fn render_surface(&mut self, pinnacle: &mut Pinnacle, output: &Output) {
let UdevOutputData { device_id, .. } = output.user_data().get().unwrap();
let is_active = self
.backends
.get(device_id)
.map(|device| device.drm.is_active())
.unwrap_or_default();

let Some(surface) = render_surface_for_output(output, &mut self.backends) else {
return;
};

let make_idle = |render_state: &mut RenderState,
loop_handle: &LoopHandle<'static, State>| {
if let RenderState::WaitingForEstimatedVblankAndScheduled(token)
| RenderState::WaitingForEstimatedVblank(token) = mem::take(render_state)
{
loop_handle.remove(token);
}
};

if !is_active {
warn!("Device is inactive");
make_idle(&mut surface.render_state, &pinnacle.loop_handle);
return;
}

if !pinnacle.outputs.contains_key(output) {
surface.render_state = RenderState::Idle;
make_idle(&mut surface.render_state, &pinnacle.loop_handle);
return;
}

// TODO: possibly lift this out and make it so that scheduling a render
// does nothing on powered off outputs
if output.with_state(|state| !state.powered) {
surface.render_state = RenderState::Idle;
make_idle(&mut surface.render_state, &pinnacle.loop_handle);
return;
}

Expand Down
7 changes: 7 additions & 0 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use smithay::{
PopupManager, WindowSurfaceType,
},
input::{
keyboard::LedState,
pointer::{CursorImageStatus, PointerHandle},
Seat, SeatHandler, SeatState,
},
Expand Down Expand Up @@ -670,6 +671,12 @@ impl SeatHandler for State {
set_data_device_focus(&self.pinnacle.display_handle, seat, focus_client.clone());
set_primary_focus(&self.pinnacle.display_handle, seat, focus_client);
}

fn led_state_changed(&mut self, _seat: &Seat<Self>, led_state: LedState) {
for device in self.pinnacle.input_state.libinput_devices.iter_mut() {
device.led_update(led_state.into());
}
}
}
delegate_seat!(State);

Expand Down
17 changes: 1 addition & 16 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use smithay::{
RelativeMotionEvent,
},
},
reexports::input::{self, Led},
reexports::input,
utils::{Logical, Point, Rectangle, SERIAL_COUNTER},
wayland::{
compositor::{self, RegionAttributes, SurfaceAttributes},
Expand Down Expand Up @@ -439,21 +439,6 @@ impl State {
.get_keyboard()
.expect("Seat has no keyboard");

let modifiers = keyboard.modifier_state();

let mut leds = Led::empty();
if modifiers.num_lock {
leds |= Led::NUMLOCK;
}
if modifiers.caps_lock {
leds |= Led::CAPSLOCK;
}

// FIXME: Leds only update once another key is pressed.
for device in self.pinnacle.input_state.libinput_devices.iter_mut() {
device.led_update(leds);
}

if self.pinnacle.lock_state.is_unlocked() {
// Focus the topmost exclusive layer, if any
for layer in self.pinnacle.layer_shell_state.layer_surfaces().rev() {
Expand Down

0 comments on commit 6999ff8

Please sign in to comment.