Fix minor bugs and do minor cleanup

This commit is contained in:
Ottatop 2024-03-21 16:40:08 -05:00
parent 2880792d9f
commit 5fd8c60f21
7 changed files with 111 additions and 123 deletions

View file

@ -38,7 +38,7 @@ use tokio::{
}; };
use tokio_stream::{Stream, StreamExt}; use tokio_stream::{Stream, StreamExt};
use tonic::{Request, Response, Status, Streaming}; use tonic::{Request, Response, Status, Streaming};
use tracing::{error, warn}; use tracing::{debug, error, warn};
use crate::{ use crate::{
config::ConnectorSavedState, config::ConnectorSavedState,
@ -230,19 +230,19 @@ impl input_service_server::InputService for InputService {
use pinnacle_api_defs::pinnacle::input::v0alpha1::set_keybind_request::Key; use pinnacle_api_defs::pinnacle::input::v0alpha1::set_keybind_request::Key;
let keysym = match key { let keysym = match key {
Key::RawCode(num) => { Key::RawCode(num) => {
tracing::info!("set keybind: {:?}, raw {}", modifiers, num); debug!("Set keybind: {:?}, raw {}", modifiers, num);
xkbcommon::xkb::Keysym::new(num) xkbcommon::xkb::Keysym::new(num)
} }
Key::XkbName(s) => { Key::XkbName(s) => {
if s.chars().count() == 1 { if s.chars().count() == 1 {
let Some(ch) = s.chars().next() else { unreachable!() }; let Some(ch) = s.chars().next() else { unreachable!() };
let keysym = xkbcommon::xkb::Keysym::from_char(ch); let keysym = xkbcommon::xkb::Keysym::from_char(ch);
tracing::info!("set keybind: {:?}, {:?}", modifiers, keysym); debug!("Set keybind: {:?}, {:?}", modifiers, keysym);
keysym keysym
} else { } else {
let keysym = let keysym =
xkbcommon::xkb::keysym_from_name(&s, xkbcommon::xkb::KEYSYM_NO_FLAGS); xkbcommon::xkb::keysym_from_name(&s, xkbcommon::xkb::KEYSYM_NO_FLAGS);
tracing::info!("set keybind: {:?}, {:?}", modifiers, keysym); debug!("Set keybind: {:?}, {:?}", modifiers, keysym);
keysym keysym
} }
} }
@ -262,7 +262,7 @@ impl input_service_server::InputService for InputService {
) -> Result<Response<Self::SetMousebindStream>, Status> { ) -> Result<Response<Self::SetMousebindStream>, Status> {
let request = request.into_inner(); let request = request.into_inner();
tracing::debug!(request = ?request); debug!(request = ?request);
let modifiers = request let modifiers = request
.modifiers() .modifiers()
@ -508,7 +508,7 @@ impl process_service_server::ProcessService for ProcessService {
&self, &self,
request: Request<SpawnRequest>, request: Request<SpawnRequest>,
) -> Result<Response<Self::SpawnStream>, Status> { ) -> Result<Response<Self::SpawnStream>, Status> {
tracing::debug!("ProcessService.spawn"); debug!("ProcessService.spawn");
let request = request.into_inner(); let request = request.into_inner();
let once = request.once(); let once = request.once();
@ -780,7 +780,7 @@ impl tag_service_server::TagService for TagService {
{ {
output.with_state_mut(|state| { output.with_state_mut(|state| {
state.tags.extend(new_tags.clone()); state.tags.extend(new_tags.clone());
tracing::debug!("tags added, are now {:?}", state.tags); debug!("tags added, are now {:?}", state.tags);
}); });
} }
@ -938,7 +938,7 @@ impl output_service_server::OutputService for OutputService {
} }
output.change_current_state(None, None, None, Some(loc)); output.change_current_state(None, None, None, Some(loc));
state.space.map_output(&output, loc); state.space.map_output(&output, loc);
tracing::debug!("Mapping output {} to {loc:?}", output.name()); debug!("Mapping output {} to {loc:?}", output.name());
state.request_layout(&output); state.request_layout(&output);
}) })
.await .await

View file

@ -92,10 +92,7 @@ impl window_service_server::WindowService for WindowService {
let Some(window) = window_id.window(state) else { return }; let Some(window) = window_id.window(state) else { return };
// TODO: with no x or y, defaults unmapped windows to 0, 0 // TODO: with no x or y, defaults unmapped windows to 0, 0
let mut window_loc = state let mut window_loc = state.space.element_location(&window).unwrap_or_default();
.space
.element_location(&window)
.unwrap_or((x.unwrap_or_default(), y.unwrap_or_default()).into());
window_loc.x = x.unwrap_or(window_loc.x); window_loc.x = x.unwrap_or(window_loc.x);
window_loc.y = y.unwrap_or(window_loc.y); window_loc.y = y.unwrap_or(window_loc.y);
@ -104,7 +101,7 @@ impl window_service_server::WindowService for WindowService {
window_size.h = height.unwrap_or(window_size.h); window_size.h = height.unwrap_or(window_size.h);
let rect = Rectangle::from_loc_and_size(window_loc, window_size); let rect = Rectangle::from_loc_and_size(window_loc, window_size);
// window.change_geometry(rect);
window.with_state_mut(|state| { window.with_state_mut(|state| {
use crate::window::window_state::FloatingOrTiled; use crate::window::window_state::FloatingOrTiled;
state.floating_or_tiled = match state.floating_or_tiled { state.floating_or_tiled = match state.floating_or_tiled {
@ -349,7 +346,6 @@ impl window_service_server::WindowService for WindowService {
} }
} }
state.request_layout(&output);
state.schedule_render(&output); state.schedule_render(&output);
}) })
.await .await

View file

@ -267,7 +267,7 @@ impl State {
let mut pointer_element = PointerElement::<GlesTexture>::new(); let mut pointer_element = PointerElement::<GlesTexture>::new();
pointer_element.set_status(self.cursor_status.clone()); pointer_element.set_status(self.cursor_status.clone());
// The z-index of these is determined by `state.fixup_focus()`, which is called at the end // The z-index of these is determined by `state.fixup_z_layering()`, which is called at the end
// of every event loop cycle // of every event loop cycle
let windows = self.space.elements().cloned().collect::<Vec<_>>(); let windows = self.space.elements().cloned().collect::<Vec<_>>();
@ -304,7 +304,7 @@ impl State {
.render_output(renderer, age, &output_render_elements, [0.6, 0.6, 0.6, 1.0]) .render_output(renderer, age, &output_render_elements, [0.6, 0.6, 0.6, 1.0])
.map_err(|err| match err { .map_err(|err| match err {
damage::Error::Rendering(err) => err.into(), damage::Error::Rendering(err) => err.into(),
damage::Error::OutputNoMode(_) => todo!(), damage::Error::OutputNoMode(_) => panic!("winit output has no mode set"),
}) })
}); });
@ -312,7 +312,6 @@ impl State {
Ok(render_output_result) => { Ok(render_output_result) => {
let has_rendered = render_output_result.damage.is_some(); let has_rendered = render_output_result.damage.is_some();
if let Some(damage) = render_output_result.damage { if let Some(damage) = render_output_result.damage {
// tracing::debug!("damage rects are {damage:?}");
if let Err(err) = winit.backend.submit(Some(&damage)) { if let Err(err) = winit.backend.submit(Some(&damage)) {
tracing::warn!("{}", err); tracing::warn!("{}", err);
} }

View file

@ -6,14 +6,17 @@ use smithay::{
// | input::keyboard // | input::keyboard
input::{ input::{
pointer::{ pointer::{
AxisFrame, ButtonEvent, Focus, GrabStartData, MotionEvent, PointerGrab, AxisFrame, ButtonEvent, Focus, GestureHoldBeginEvent, GestureHoldEndEvent,
PointerInnerHandle, RelativeMotionEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData,
MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent,
}, },
Seat, SeatHandler, Seat, SeatHandler,
}, },
reexports::wayland_server::protocol::wl_surface::WlSurface, reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::{IsAlive, Logical, Point, Rectangle, Serial}, utils::{IsAlive, Logical, Point, Rectangle, Serial},
}; };
use tracing::{debug, warn};
use crate::{ use crate::{
state::{State, WithState}, state::{State, WithState},
@ -26,8 +29,6 @@ pub struct MoveSurfaceGrab {
/// The window being moved /// The window being moved
pub window: WindowElement, pub window: WindowElement,
pub initial_window_loc: Point<i32, Logical>, pub initial_window_loc: Point<i32, Logical>,
/// Which button initiated the grab
pub button_used: u32,
} }
impl PointerGrab<State> for MoveSurfaceGrab { impl PointerGrab<State> for MoveSurfaceGrab {
@ -103,22 +104,13 @@ impl PointerGrab<State> for MoveSurfaceGrab {
return; return;
} }
let is_floating = if window_under.with_state(|state| {
window_under.with_state(|state| state.floating_or_tiled.is_floating()); state.floating_or_tiled.is_floating() || state.target_loc.is_some()
}) {
if is_floating {
return; return;
} }
// let has_pending_resize = window_under.with_state(|state| { debug!("Swapping window positions");
// !matches!(state.loc_request_state, LocationRequestState::Idle)
// });
//
// if has_pending_resize {
// return;
// }
tracing::debug!("Swapping window positions");
state.swap_window_positions(&self.window, &window_under); state.swap_window_positions(&self.window, &window_under);
} }
} else { } else {
@ -174,7 +166,7 @@ impl PointerGrab<State> for MoveSurfaceGrab {
) { ) {
handle.button(data, event); handle.button(data, event);
if !handle.current_pressed().contains(&self.button_used) { if !handle.current_pressed().contains(&self.start_data.button) {
handle.unset_grab(data, event.serial, event.time, true); handle.unset_grab(data, event.serial, event.time, true);
} }
} }
@ -194,74 +186,74 @@ impl PointerGrab<State> for MoveSurfaceGrab {
fn gesture_swipe_begin( fn gesture_swipe_begin(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureSwipeBeginEvent, event: &GestureSwipeBeginEvent,
) { ) {
todo!() handle.gesture_swipe_begin(data, event);
} }
fn gesture_swipe_update( fn gesture_swipe_update(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureSwipeUpdateEvent, event: &GestureSwipeUpdateEvent,
) { ) {
todo!() handle.gesture_swipe_update(data, event);
} }
fn gesture_swipe_end( fn gesture_swipe_end(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureSwipeEndEvent, event: &GestureSwipeEndEvent,
) { ) {
todo!() handle.gesture_swipe_end(data, event);
} }
fn gesture_pinch_begin( fn gesture_pinch_begin(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GesturePinchBeginEvent, event: &GesturePinchBeginEvent,
) { ) {
todo!() handle.gesture_pinch_begin(data, event);
} }
fn gesture_pinch_update( fn gesture_pinch_update(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GesturePinchUpdateEvent, event: &GesturePinchUpdateEvent,
) { ) {
todo!() handle.gesture_pinch_update(data, event);
} }
fn gesture_pinch_end( fn gesture_pinch_end(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GesturePinchEndEvent, event: &GesturePinchEndEvent,
) { ) {
todo!() handle.gesture_pinch_end(data, event);
} }
fn gesture_hold_begin( fn gesture_hold_begin(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureHoldBeginEvent, event: &GestureHoldBeginEvent,
) { ) {
todo!() handle.gesture_hold_begin(data, event);
} }
fn gesture_hold_end( fn gesture_hold_end(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureHoldEndEvent, event: &GestureHoldEndEvent,
) { ) {
todo!() handle.gesture_hold_end(data, event);
} }
} }
@ -271,12 +263,11 @@ pub fn move_request_client(
surface: &WlSurface, surface: &WlSurface,
seat: &Seat<State>, seat: &Seat<State>,
serial: Serial, serial: Serial,
button_used: u32,
) { ) {
let pointer = seat.get_pointer().expect("seat had no pointer"); let pointer = seat.get_pointer().expect("seat had no pointer");
if let Some(start_data) = crate::grab::pointer_grab_start_data(&pointer, surface, serial) { if let Some(start_data) = crate::grab::pointer_grab_start_data(&pointer, surface, serial) {
let Some(window) = state.window_for_surface(surface) else { let Some(window) = state.window_for_surface(surface) else {
tracing::error!("Surface had no window, cancelling move request"); warn!("Surface had no window, cancelling move request");
return; return;
}; };
@ -289,12 +280,11 @@ pub fn move_request_client(
start_data, start_data,
window, window,
initial_window_loc, initial_window_loc,
button_used,
}; };
pointer.set_grab(state, grab, serial, Focus::Clear); pointer.set_grab(state, grab, serial, Focus::Clear);
} else { } else {
tracing::warn!("no grab start data"); debug!("No grab start data for grab, cancelling");
} }
} }
@ -308,7 +298,7 @@ pub fn move_request_server(
) { ) {
let pointer = seat.get_pointer().expect("seat had no pointer"); let pointer = seat.get_pointer().expect("seat had no pointer");
let Some(window) = state.window_for_surface(surface) else { let Some(window) = state.window_for_surface(surface) else {
tracing::error!("Surface had no window, cancelling move request"); warn!("Surface had no window, cancelling move request");
return; return;
}; };
@ -329,7 +319,6 @@ pub fn move_request_server(
start_data, start_data,
window, window,
initial_window_loc, initial_window_loc,
button_used,
}; };
pointer.set_grab(state, grab, serial, Focus::Clear); pointer.set_grab(state, grab, serial, Focus::Clear);

View file

@ -3,7 +3,12 @@
use smithay::{ use smithay::{
desktop::{space::SpaceElement, WindowSurface}, desktop::{space::SpaceElement, WindowSurface},
input::{ input::{
pointer::{AxisFrame, ButtonEvent, Focus, GrabStartData, PointerGrab, PointerInnerHandle}, pointer::{
AxisFrame, ButtonEvent, Focus, GestureHoldBeginEvent, GestureHoldEndEvent,
GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData,
PointerGrab, PointerInnerHandle,
},
Seat, SeatHandler, Seat, SeatHandler,
}, },
reexports::{ reexports::{
@ -136,19 +141,11 @@ impl PointerGrab<State> for ResizeSurfaceGrab {
let data = states.cached_state.current::<SurfaceCachedState>(); let data = states.cached_state.current::<SurfaceCachedState>();
(data.min_size, data.max_size) (data.min_size, data.max_size)
}), }),
None => ((0, 0).into(), (0, 0).into()), None => (Size::default(), Size::default()),
}; };
// HACK: Here I set the min height to be self.window.geometry().loc.y.abs() because if it's
// | lower then the compositor crashes trying to create a size with height -1 if you make the
// | window height too small.
// | However I don't know if the loc.y from window.geometry will always be the negative
// | of the csd height.
let min_width = i32::max(1, min_size.w); let min_width = i32::max(1, min_size.w);
let min_height = i32::max( let min_height = i32::max(1, min_size.h);
i32::max(0, self.window.geometry().loc.y.abs()) + 1,
min_size.h,
);
let max_width = if max_size.w != 0 { max_size.w } else { i32::MAX }; let max_width = if max_size.w != 0 { max_size.w } else { i32::MAX };
let max_height = if max_size.h != 0 { max_size.h } else { i32::MAX }; let max_height = if max_size.h != 0 { max_size.h } else { i32::MAX };
@ -254,74 +251,74 @@ impl PointerGrab<State> for ResizeSurfaceGrab {
fn gesture_swipe_begin( fn gesture_swipe_begin(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureSwipeBeginEvent, event: &GestureSwipeBeginEvent,
) { ) {
todo!() handle.gesture_swipe_begin(data, event);
} }
fn gesture_swipe_update( fn gesture_swipe_update(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureSwipeUpdateEvent, event: &GestureSwipeUpdateEvent,
) { ) {
todo!() handle.gesture_swipe_update(data, event);
} }
fn gesture_swipe_end( fn gesture_swipe_end(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureSwipeEndEvent, event: &GestureSwipeEndEvent,
) { ) {
todo!() handle.gesture_swipe_end(data, event);
} }
fn gesture_pinch_begin( fn gesture_pinch_begin(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GesturePinchBeginEvent, event: &GesturePinchBeginEvent,
) { ) {
todo!() handle.gesture_pinch_begin(data, event);
} }
fn gesture_pinch_update( fn gesture_pinch_update(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GesturePinchUpdateEvent, event: &GesturePinchUpdateEvent,
) { ) {
todo!() handle.gesture_pinch_update(data, event);
} }
fn gesture_pinch_end( fn gesture_pinch_end(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GesturePinchEndEvent, event: &GesturePinchEndEvent,
) { ) {
todo!() handle.gesture_pinch_end(data, event);
} }
fn gesture_hold_begin( fn gesture_hold_begin(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureHoldBeginEvent, event: &GestureHoldBeginEvent,
) { ) {
todo!() handle.gesture_hold_begin(data, event);
} }
fn gesture_hold_end( fn gesture_hold_end(
&mut self, &mut self,
_data: &mut State, data: &mut State,
_handle: &mut PointerInnerHandle<'_, State>, handle: &mut PointerInnerHandle<'_, State>,
_event: &smithay::input::pointer::GestureHoldEndEvent, event: &GestureHoldEndEvent,
) { ) {
todo!() handle.gesture_hold_end(data, event);
} }
} }

View file

@ -589,13 +589,11 @@ impl XdgShellHandler for State {
fn move_request(&mut self, surface: ToplevelSurface, seat: WlSeat, serial: Serial) { fn move_request(&mut self, surface: ToplevelSurface, seat: WlSeat, serial: Serial) {
tracing::debug!("move_request_client"); tracing::debug!("move_request_client");
const BUTTON_LEFT: u32 = 0x110; // We assume the left mouse button is used
crate::grab::move_grab::move_request_client( crate::grab::move_grab::move_request_client(
self, self,
surface.wl_surface(), surface.wl_surface(),
&Seat::from_resource(&seat).expect("couldn't get seat from WlSeat"), &Seat::from_resource(&seat).expect("couldn't get seat from WlSeat"),
serial, serial,
BUTTON_LEFT,
); );
} }

View file

@ -11,7 +11,7 @@ use smithay::{
}; };
use tokio::sync::mpsc::UnboundedSender; use tokio::sync::mpsc::UnboundedSender;
use tonic::Status; use tonic::Status;
use tracing::error; use tracing::warn;
use crate::{ use crate::{
output::OutputName, output::OutputName,
@ -23,7 +23,7 @@ use crate::{
}; };
impl State { impl State {
pub fn update_windows_with_geometries( fn update_windows_with_geometries(
&mut self, &mut self,
output: &Output, output: &Output,
geometries: Vec<Rectangle<i32, Logical>>, geometries: Vec<Rectangle<i32, Logical>>,
@ -56,13 +56,22 @@ impl State {
map.non_exclusive_zone() map.non_exclusive_zone()
}; };
for (win, geo) in tiled_windows.zip(geometries.into_iter().map(|mut geo| { let mut zipped = tiled_windows.zip(geometries.into_iter().map(|mut geo| {
geo.loc += output_geo.loc + non_exclusive_geo.loc; geo.loc += output_geo.loc + non_exclusive_geo.loc;
geo geo
})) { }));
for (win, geo) in zipped.by_ref() {
win.change_geometry(geo); win.change_geometry(geo);
} }
let (remaining_wins, _remaining_geos) = zipped.unzip::<_, _, Vec<_>, Vec<_>>();
for win in remaining_wins {
assert!(win.with_state(|state| state.floating_or_tiled.is_floating()));
win.toggle_floating();
}
for window in windows_on_foc_tags.iter() { for window in windows_on_foc_tags.iter() {
match window.with_state(|state| state.fullscreen_or_maximized) { match window.with_state(|state| state.fullscreen_or_maximized) {
FullscreenOrMaximized::Fullscreen => { FullscreenOrMaximized::Fullscreen => {
@ -156,7 +165,7 @@ pub struct LayoutState {
impl State { impl State {
pub fn request_layout(&mut self, output: &Output) { pub fn request_layout(&mut self, output: &Output) {
let Some(sender) = self.layout_state.layout_request_sender.as_ref() else { let Some(sender) = self.layout_state.layout_request_sender.as_ref() else {
error!("Layout requested but no client has connected to the layout service"); warn!("Layout requested but no client has connected to the layout service");
return; return;
}; };