diff --git a/src/catacomb.rs b/src/catacomb.rs index 86477e4..ed2facc 100644 --- a/src/catacomb.rs +++ b/src/catacomb.rs @@ -7,6 +7,7 @@ use std::time::{Duration, Instant}; use _decoration::zv1::server::zxdg_toplevel_decoration_v1::Mode as DecorationMode; use _server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as ManagerMode; +use catacomb_ipc::Orientation; use smithay::backend::allocator::dmabuf::Dmabuf; use smithay::backend::renderer::ImportDma; use smithay::input::keyboard::XkbConfig; @@ -262,17 +263,22 @@ impl Catacomb { let touch = seat.add_touch(); let touch_state = TouchState::new(event_loop.clone(), touch); - // Subscribe to device orientation changes. - let accel_token = Accelerometer::new().subscribe(&event_loop, |orientation, catacomb| { - catacomb.handle_orientation(orientation); - }); - // Start IPC socket listener. ipc_server::spawn_ipc_socket(&event_loop, &socket_name).expect("spawn IPC socket"); // Create window manager. let windows = Windows::new(&display_handle, event_loop.clone()); + // Subscribe to device orientation changes. + let accel_token = Accelerometer::new().subscribe(&event_loop, |orientation, catacomb| { + catacomb.handle_orientation(orientation); + }); + + // Disable accelerometer polling if orientation starts locked. + if windows.orientation_locked() { + trace_error(event_loop.disable(&accel_token)); + } + // Run user startup script. if let Some(mut script_path) = dirs::config_dir() { script_path.push("catacomb"); @@ -448,6 +454,20 @@ impl Catacomb { self.backend.set_sleep(sleep); } + + /// Lock the output's orientation. + pub fn lock_orientation(&mut self, orientation: Option) { + trace_error(self.event_loop.disable(&self.accelerometer_token)); + self.windows.lock_orientation(orientation); + self.unstall(); + } + + /// Unlock the output's orientation. + pub fn unlock_orientation(&mut self) { + trace_error(self.event_loop.enable(&self.accelerometer_token)); + self.windows.unlock_orientation(); + self.unstall(); + } } impl CompositorHandler for Catacomb { diff --git a/src/ipc_server.rs b/src/ipc_server.rs index 8aca7a0..3fe0b6e 100644 --- a/src/ipc_server.rs +++ b/src/ipc_server.rs @@ -57,14 +57,8 @@ fn handle_message(buffer: &mut String, mut stream: UnixStream, catacomb: &mut Ca // Handle IPC events. match message { - IpcMessage::Orientation { unlock: true, .. } => { - catacomb.windows.unlock_orientation(); - catacomb.unstall(); - }, - IpcMessage::Orientation { lock: orientation, .. } => { - catacomb.windows.lock_orientation(orientation); - catacomb.unstall(); - }, + IpcMessage::Orientation { unlock: true, .. } => catacomb.unlock_orientation(), + IpcMessage::Orientation { lock: orientation, .. } => catacomb.lock_orientation(orientation), IpcMessage::Scale { scale, app_id: Some(app_id) } => { let app_id = match AppIdMatcher::try_from(app_id) { Ok(app_id) => app_id, diff --git a/src/orientation.rs b/src/orientation.rs index f5fd577..98aba8e 100644 --- a/src/orientation.rs +++ b/src/orientation.rs @@ -162,6 +162,7 @@ impl AccelerometerSource for SensorAccelerometer { { loop_handle .insert_source(Timer::immediate(), move |_, _, catacomb| { + println!("POLLING ACCELEROMETER"); let fallback = self.last.unwrap_or(Orientation::Portrait); let orientation = self.orientation().unwrap_or(fallback); if Some(orientation) != self.last { diff --git a/src/windows/mod.rs b/src/windows/mod.rs index b43bf38..b719975 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -782,6 +782,11 @@ impl Windows { self.update_orientation(self.unlocked_orientation); } + /// Get orientation lock state. + pub fn orientation_locked(&self) -> bool { + self.orientation_locked + } + /// Check if any window was damaged since the last redraw. pub fn damaged(&mut self) -> bool { if self.dirty {