Fix pointer focus on winit

This commit is contained in:
Ottatop 2023-07-28 15:16:25 -05:00
parent 94d7c4463e
commit e86228f4f8
4 changed files with 37 additions and 29 deletions

View file

@ -66,16 +66,21 @@ require("pinnacle").setup(function(pinnacle)
-- Just testing stuff
input.keybind({ mod_key }, keys.h, function()
local wins = window.get_all()
for _, win in pairs(wins) do
print("loc: " .. (win:loc() and win:loc().x or "nil") .. ", " .. (win:loc() and win:loc().y or "nil"))
print("size: " .. (win:size() and win:size().w or "nil") .. ", " .. (win:size() and win:size().h or "nil"))
print("class: " .. (win:class() or "nil"))
print("title: " .. (win:title() or "nil"))
print("float: " .. tostring(win:floating()))
local win = window.get_focused()
if win ~= nil then
win:set_size({ w = 500, h = 500 })
end
print("----------------------")
-- local wins = window.get_all()
-- for _, win in pairs(wins) do
-- print("loc: " .. (win:loc() and win:loc().x or "nil") .. ", " .. (win:loc() and win:loc().y or "nil"))
-- print("size: " .. (win:size() and win:size().w or "nil") .. ", " .. (win:size() and win:size().h or "nil"))
-- print("class: " .. (win:class() or "nil"))
-- print("title: " .. (win:title() or "nil"))
-- print("float: " .. tostring(win:floating()))
-- end
--
-- print("----------------------")
--
-- local op = output.get_focused() --[[@as Output]]
-- print("res: " .. (op:res() and (op:res().w .. ", " .. op:res().h) or "nil"))

View file

@ -61,9 +61,11 @@ impl IsAlive for FocusTarget {
}
}
impl From<FocusTarget> for WlSurface {
fn from(value: FocusTarget) -> Self {
value.wl_surface().expect("no wl_surface")
impl TryFrom<FocusTarget> for WlSurface {
type Error = ();
fn try_from(value: FocusTarget) -> Result<Self, Self::Error> {
value.wl_surface().ok_or(())
}
}

View file

@ -393,6 +393,7 @@ impl<B: Backend> XdgShellHandler for State<B> {
}
fn move_request(&mut self, surface: ToplevelSurface, seat: WlSeat, serial: Serial) {
tracing::debug!("move_request_client");
crate::grab::move_grab::move_request_client(
self,
surface.wl_surface(),

View file

@ -12,14 +12,14 @@ use smithay::{
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionEvent,
},
desktop::{space::SpaceElement, WindowSurfaceType},
desktop::space::SpaceElement,
input::{
keyboard::{keysyms, FilterResult},
pointer::{AxisFrame, ButtonEvent, MotionEvent},
},
reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::ResizeEdge,
utils::{Logical, Point, SERIAL_COUNTER},
wayland::compositor,
wayland::{compositor, seat::WaylandFocus},
};
use crate::{
@ -42,14 +42,14 @@ impl InputState {
}
impl<B: Backend> State<B> {
pub fn surface_under<P>(&self, point: P) -> Option<(WindowElement, Point<i32, Logical>)>
pub fn surface_under<P>(&self, point: P) -> Option<(FocusTarget, Point<i32, Logical>)>
where
P: Into<Point<f64, Logical>>,
{
// TODO: layer map, popups, fullscreen
self.space
.element_under(point)
.map(|(window, loc)| (window.clone(), loc))
.map(|(window, loc)| (window.clone().into(), loc))
}
fn pointer_button<I: InputBackend>(&mut self, event: I::PointerButtonEvent) {
@ -88,6 +88,7 @@ impl<B: Backend> State<B> {
}
return; // TODO: kinda ugly return here
} else if event.button_code() == BUTTON_RIGHT {
let FocusTarget::Window(window) = window else { return };
let window_geometry = window.geometry();
let window_x = window_loc.x as f64;
let window_y = window_loc.y as f64;
@ -139,6 +140,7 @@ impl<B: Backend> State<B> {
}
} else {
// Move window to top of stack.
let FocusTarget::Window(window) = window else { return };
self.space.raise_element(&window, true);
if let WindowElement::X11(surface) = &window {
self.xwm
@ -380,15 +382,17 @@ impl State<WinitData> {
}
}
let surface_under_pointer =
self.space
.element_under(pointer_loc)
.and_then(|(window, location)| {
window
.surface_under(pointer_loc - location.to_f64(), WindowSurfaceType::ALL)
.map(|(_s, p)| (FocusTarget::Window(window.clone()), p + location))
});
let surface_under_pointer = self
.space
.element_under(pointer_loc)
.map(|(window, loc)| (FocusTarget::Window(window.clone()), loc));
// .and_then(|(window, location)| {
// window
// .surface_under(pointer_loc - location.to_f64(), WindowSurfaceType::ALL)
// .map(|(_s, p)| (FocusTarget::Window(window.clone()), p + location))
// });
tracing::debug!("surface_under_pointer: {surface_under_pointer:?}");
pointer.motion(
self,
surface_under_pointer,
@ -441,9 +445,7 @@ impl State<UdevData> {
}
}
let surface_under = self
.surface_under(self.pointer_location)
.map(|(window, loc)| (FocusTarget::Window(window), loc));
let surface_under = self.surface_under(self.pointer_location);
// tracing::info!("{:?}", self.pointer_location);
if let Some(ptr) = self.seat.get_pointer() {
@ -508,9 +510,7 @@ impl State<UdevData> {
self.pointer_location = self.clamp_coords(self.pointer_location);
let surface_under = self
.surface_under(self.pointer_location)
.map(|(window, loc)| (FocusTarget::Window(window), loc));
let surface_under = self.surface_under(self.pointer_location);
if let Some(ptr) = self.seat.get_pointer() {
ptr.motion(