mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-27 21:58:18 +01:00
Fix pointer focus on winit
This commit is contained in:
parent
94d7c4463e
commit
e86228f4f8
4 changed files with 37 additions and 29 deletions
|
@ -66,16 +66,21 @@ require("pinnacle").setup(function(pinnacle)
|
||||||
|
|
||||||
-- Just testing stuff
|
-- Just testing stuff
|
||||||
input.keybind({ mod_key }, keys.h, function()
|
input.keybind({ mod_key }, keys.h, function()
|
||||||
local wins = window.get_all()
|
local win = window.get_focused()
|
||||||
for _, win in pairs(wins) do
|
if win ~= nil then
|
||||||
print("loc: " .. (win:loc() and win:loc().x or "nil") .. ", " .. (win:loc() and win:loc().y or "nil"))
|
win:set_size({ w = 500, h = 500 })
|
||||||
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
|
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]]
|
-- local op = output.get_focused() --[[@as Output]]
|
||||||
-- print("res: " .. (op:res() and (op:res().w .. ", " .. op:res().h) or "nil"))
|
-- print("res: " .. (op:res() and (op:res().w .. ", " .. op:res().h) or "nil"))
|
||||||
|
|
|
@ -61,9 +61,11 @@ impl IsAlive for FocusTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<FocusTarget> for WlSurface {
|
impl TryFrom<FocusTarget> for WlSurface {
|
||||||
fn from(value: FocusTarget) -> Self {
|
type Error = ();
|
||||||
value.wl_surface().expect("no wl_surface")
|
|
||||||
|
fn try_from(value: FocusTarget) -> Result<Self, Self::Error> {
|
||||||
|
value.wl_surface().ok_or(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -393,6 +393,7 @@ impl<B: Backend> XdgShellHandler for State<B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
crate::grab::move_grab::move_request_client(
|
crate::grab::move_grab::move_request_client(
|
||||||
self,
|
self,
|
||||||
surface.wl_surface(),
|
surface.wl_surface(),
|
||||||
|
|
34
src/input.rs
34
src/input.rs
|
@ -12,14 +12,14 @@ use smithay::{
|
||||||
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
|
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
|
||||||
KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionEvent,
|
KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionEvent,
|
||||||
},
|
},
|
||||||
desktop::{space::SpaceElement, WindowSurfaceType},
|
desktop::space::SpaceElement,
|
||||||
input::{
|
input::{
|
||||||
keyboard::{keysyms, FilterResult},
|
keyboard::{keysyms, FilterResult},
|
||||||
pointer::{AxisFrame, ButtonEvent, MotionEvent},
|
pointer::{AxisFrame, ButtonEvent, MotionEvent},
|
||||||
},
|
},
|
||||||
reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::ResizeEdge,
|
reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::ResizeEdge,
|
||||||
utils::{Logical, Point, SERIAL_COUNTER},
|
utils::{Logical, Point, SERIAL_COUNTER},
|
||||||
wayland::compositor,
|
wayland::{compositor, seat::WaylandFocus},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -42,14 +42,14 @@ impl InputState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> State<B> {
|
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
|
where
|
||||||
P: Into<Point<f64, Logical>>,
|
P: Into<Point<f64, Logical>>,
|
||||||
{
|
{
|
||||||
// TODO: layer map, popups, fullscreen
|
// TODO: layer map, popups, fullscreen
|
||||||
self.space
|
self.space
|
||||||
.element_under(point)
|
.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) {
|
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
|
return; // TODO: kinda ugly return here
|
||||||
} else if event.button_code() == BUTTON_RIGHT {
|
} else if event.button_code() == BUTTON_RIGHT {
|
||||||
|
let FocusTarget::Window(window) = window else { return };
|
||||||
let window_geometry = window.geometry();
|
let window_geometry = window.geometry();
|
||||||
let window_x = window_loc.x as f64;
|
let window_x = window_loc.x as f64;
|
||||||
let window_y = window_loc.y as f64;
|
let window_y = window_loc.y as f64;
|
||||||
|
@ -139,6 +140,7 @@ impl<B: Backend> State<B> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Move window to top of stack.
|
// Move window to top of stack.
|
||||||
|
let FocusTarget::Window(window) = window else { return };
|
||||||
self.space.raise_element(&window, true);
|
self.space.raise_element(&window, true);
|
||||||
if let WindowElement::X11(surface) = &window {
|
if let WindowElement::X11(surface) = &window {
|
||||||
self.xwm
|
self.xwm
|
||||||
|
@ -380,15 +382,17 @@ impl State<WinitData> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let surface_under_pointer =
|
let surface_under_pointer = self
|
||||||
self.space
|
.space
|
||||||
.element_under(pointer_loc)
|
.element_under(pointer_loc)
|
||||||
.and_then(|(window, location)| {
|
.map(|(window, loc)| (FocusTarget::Window(window.clone()), loc));
|
||||||
window
|
// .and_then(|(window, location)| {
|
||||||
.surface_under(pointer_loc - location.to_f64(), WindowSurfaceType::ALL)
|
// window
|
||||||
.map(|(_s, p)| (FocusTarget::Window(window.clone()), p + location))
|
// .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(
|
pointer.motion(
|
||||||
self,
|
self,
|
||||||
surface_under_pointer,
|
surface_under_pointer,
|
||||||
|
@ -441,9 +445,7 @@ impl State<UdevData> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let surface_under = self
|
let surface_under = self.surface_under(self.pointer_location);
|
||||||
.surface_under(self.pointer_location)
|
|
||||||
.map(|(window, loc)| (FocusTarget::Window(window), loc));
|
|
||||||
|
|
||||||
// tracing::info!("{:?}", self.pointer_location);
|
// tracing::info!("{:?}", self.pointer_location);
|
||||||
if let Some(ptr) = self.seat.get_pointer() {
|
if let Some(ptr) = self.seat.get_pointer() {
|
||||||
|
@ -508,9 +510,7 @@ impl State<UdevData> {
|
||||||
|
|
||||||
self.pointer_location = self.clamp_coords(self.pointer_location);
|
self.pointer_location = self.clamp_coords(self.pointer_location);
|
||||||
|
|
||||||
let surface_under = self
|
let surface_under = self.surface_under(self.pointer_location);
|
||||||
.surface_under(self.pointer_location)
|
|
||||||
.map(|(window, loc)| (FocusTarget::Window(window), loc));
|
|
||||||
|
|
||||||
if let Some(ptr) = self.seat.get_pointer() {
|
if let Some(ptr) = self.seat.get_pointer() {
|
||||||
ptr.motion(
|
ptr.motion(
|
||||||
|
|
Loading…
Reference in a new issue