Fix cursor not updating in xwayland windows

This commit is contained in:
Ottatop 2023-08-01 10:53:37 -05:00
parent f0218e7b4e
commit e4f9aee687
6 changed files with 44 additions and 16 deletions

View file

@ -149,11 +149,11 @@ require("pinnacle").setup(function(pinnacle)
-- local tags_table = { "Terminal", "Browser", "Code", "Email", "Potato" }
-- op:add_tags(tags_table)
for _, t in pairs(tag.get_by_name("1")) do
if t:output() and t:output():focused() then
t:toggle()
end
end
-- for _, t in pairs(tag.get_by_name("1")) do
-- t:toggle()
-- end
tag.toggle("1", op)
end)
---@type Layout[]

View file

@ -241,6 +241,7 @@ pub fn run_udev() -> Result<(), Box<dyn Error>> {
*/
let udev_backend = UdevBackend::new(state.seat.name())?;
// Create DrmNodes from already connected GPUs
for (device_id, path) in udev_backend.device_list() {
if let Err(err) = DrmNode::from_dev_id(device_id)
.map_err(DeviceAddError::DrmNode)
@ -252,6 +253,7 @@ pub fn run_udev() -> Result<(), Box<dyn Error>> {
event_loop
.handle()
.insert_source(udev_backend, move |event, _, data| match event {
// GPU connected
UdevEvent::Added { device_id, path } => {
if let Err(err) = DrmNode::from_dev_id(device_id)
.map_err(DeviceAddError::DrmNode)
@ -265,6 +267,7 @@ pub fn run_udev() -> Result<(), Box<dyn Error>> {
data.state.device_changed(node)
}
}
// GPU disconnected
UdevEvent::Removed { device_id } => {
if let Ok(node) = DrmNode::from_dev_id(device_id) {
data.state.device_removed(node)
@ -462,7 +465,7 @@ pub fn run_udev() -> Result<(), Box<dyn Error>> {
}
event_loop.run(
Some(Duration::from_millis(6)),
Some(Duration::from_millis(1)),
&mut CalloopData { state, display },
|data| {
data.state.space.refresh();

View file

@ -20,7 +20,10 @@ use smithay::{
delegate_dmabuf,
desktop::{
space,
utils::{surface_primary_scanout_output, update_surface_primary_scanout_output},
utils::{
send_frames_surface_tree, surface_primary_scanout_output,
update_surface_primary_scanout_output,
},
},
input::pointer::{CursorImageAttributes, CursorImageStatus},
output::{Output, Subpixel},
@ -345,9 +348,22 @@ pub fn run_winit() -> Result<(), Box<dyn Error>> {
.set_cursor_visible(cursor_visible);
let throttle = Some(Duration::from_secs(1));
// let throttle = Some(Duration::ZERO);
let time = state.clock.now();
if let CursorImageStatus::Surface(surf) = &state.cursor_status {
if let Some(op) = state.focus_state.focused_output.as_ref() {
send_frames_surface_tree(
surf,
op,
time,
Some(Duration::ZERO),
|_, _| None,
);
}
}
state.space.elements().for_each(|window| {
window.with_surfaces(|surface, states_inner| {
let primary_scanout_output = update_surface_primary_scanout_output(

View file

@ -71,6 +71,7 @@ impl TryFrom<FocusTarget> for WlSurface {
impl<B: Backend> PointerTarget<State<B>> for FocusTarget {
fn enter(&self, seat: &Seat<State<B>>, data: &mut State<B>, event: &MotionEvent) {
// tracing::debug!("Pointer enter on {self:?}");
match self {
FocusTarget::Window(window) => PointerTarget::enter(window, seat, data, event),
FocusTarget::Popup(popup) => {
@ -137,6 +138,7 @@ impl<B: Backend> PointerTarget<State<B>> for FocusTarget {
serial: smithay::utils::Serial,
time: u32,
) {
// tracing::debug!("Pointer leave on {self:?}");
match self {
FocusTarget::Window(window) => PointerTarget::leave(window, seat, data, serial, time),
FocusTarget::Popup(popup) => {

View file

@ -36,9 +36,6 @@ impl<B: Backend> XwmHandler for CalloopData<B> {
tracing::debug!("window type is {win_type:?}");
// tracing::debug!("new x11 window from map_window_request");
// tracing::debug!("window popup is {}", window.is_popup());
//
// TODO: TOMORROW: figure out why keyboard input isn't going to games (prolly you never
// | change keyboard focus)
if window.is_override_redirect() {
let loc = window.geometry().loc;

View file

@ -15,7 +15,7 @@ use smithay::{
desktop::space::SpaceElement,
input::{
keyboard::{keysyms, FilterResult},
pointer::{AxisFrame, ButtonEvent, MotionEvent},
pointer::{AxisFrame, ButtonEvent, MotionEvent, PointerTarget},
},
reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::ResizeEdge,
utils::{Logical, Point, SERIAL_COUNTER},
@ -164,6 +164,10 @@ impl<B: Backend> State<B> {
// NOTE: *Do not* set keyboard focus to an override redirect window. This leads
// | to wonky things like right-click menus not correctly getting pointer
// | clicks or showing up at all.
// TODO: TOMORROW: Firefox needs 2 clicks to open up right-click menu, first
// | one immediately dissapears
if !matches!(&window, WindowElement::X11(surf) if surf.is_override_redirect()) {
keyboard.set_focus(self, Some(FocusTarget::Window(window.clone())), serial);
}
@ -400,14 +404,20 @@ impl State<WinitData> {
.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:?}");
// tracing::debug!("pointer focus: {:?}", pointer.current_focus());
if let Some((focus, _point)) = &surface_under_pointer {
focus.motion(
&self.seat.clone(),
self,
&MotionEvent {
location: pointer_loc,
serial,
time: event.time_msec(),
},
);
}
pointer.motion(
self,
surface_under_pointer,