Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Support for touch input #199

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cosmic-panel-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ smithay = { git = "https://github.com/smithay/smithay", default-features = false
sctk.workspace = true
# sctk = { package = "smithay-client-toolkit", path = "../../fork/client-toolkit", default-features = false, features = ["calloop", "xkbcommon"] }
wayland-protocols = { version = "0.31.0", features = ["staging"] }
xdg-shell-wrapper-config = { git = "https://github.com/pop-os/xdg-shell-wrapper" }
xdg-shell-wrapper = { git = "https://github.com/pop-os/xdg-shell-wrapper" }
xdg-shell-wrapper-config = { git = "https://github.com/pop-os/xdg-shell-wrapper", branch = "touch" }
xdg-shell-wrapper = { git = "https://github.com/pop-os/xdg-shell-wrapper", branch = "touch" }
# xdg-shell-wrapper = { path = "../../xdg-shell-wrapper" }
# xdg-shell-wrapper-config = { path = "../../xdg-shell-wrapper/xdg-shell-wrapper-config" }
cctk = { package = "cosmic-client-toolkit", git = "https://github.com/pop-os/cosmic-protocols", rev = "e65fa5e" }
Expand Down
75 changes: 75 additions & 0 deletions cosmic-panel-bin/src/space/wrapper_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,81 @@ impl WrapperSpace for PanelSpace {
}
}

fn touch_under(
&mut self,
(x, y): (i32, i32),
seat_name: &str,
c_wl_surface: c_wl_surface::WlSurface,
) -> Option<ServerPointerFocus> {
let mut prev_hover = self
.s_hovered_surface
.iter_mut()
.enumerate()
.find(|(_, f)| f.seat_name == seat_name);
let prev_foc = self.s_focused_surface.iter_mut().find(|f| f.1 == seat_name);
// first check if the motion is on a popup's client surface
if let Some(p) = self
.popups
.iter()
.find(|p| p.c_popup.wl_surface() == &c_wl_surface)
{
let geo = smithay::desktop::PopupKind::Xdg(p.s_surface.clone()).geometry();
Some(ServerPointerFocus {
surface: p.s_surface.wl_surface().clone(),
seat_name: seat_name.to_string(),
c_pos: p.rectangle.loc,
s_pos: p.rectangle.loc - geo.loc,
})
} else {
// if not on this panel's client surface return None
if self
.layer
.as_ref()
.map(|s| *s.wl_surface() != c_wl_surface)
.unwrap_or(true)
{
return None;
}
// FIXME
// There has to be a way to avoid messing with the scaling like this...
if let Some((w, relative_loc)) = self.space.elements().rev().find_map(|e| {
let Some(render_location) = self.space.element_location(e) else {
self.generated_ptr_event_count =
self.generated_ptr_event_count.saturating_sub(1);
return None;
};
let mut bbox = e.bbox().to_f64();
bbox.size.w /= self.scale;
bbox.size.h /= self.scale;
bbox.loc.x = render_location.x as f64;
bbox.loc.y = render_location.y as f64;
if bbox.contains((x as f64, y as f64)) {
Some((e.clone(), render_location))
} else {
None
}
}) {
// XXX HACK
let geo = w
.bbox()
.to_f64()
.to_physical(1.0)
.to_logical(self.scale)
.to_i32_round();
Some(ServerPointerFocus {
surface: w.wl_surface().unwrap(),
seat_name: seat_name.to_string(),
c_pos: geo.loc,
s_pos: relative_loc,
})
} else {
None
}
}
}



/// update active window based on pointer location
fn update_pointer(
&mut self,
Expand Down
32 changes: 32 additions & 0 deletions cosmic-panel-bin/src/space_container/wrapper_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,38 @@ impl WrapperSpace for SpaceContainer {
self.renderer.as_mut()
}

fn touch_under(
&mut self,
dim: (i32, i32),
seat_name: &str,
c_wl_surface: c_wl_surface::WlSurface,
) -> Option<ServerPointerFocus> {
if let Some((popup_space_i, popup_space)) = self
.space_list
.iter_mut()
.enumerate()
.find(|s| !s.1.popups.is_empty())
{
if let Some(p_ret) = popup_space.touch_under(dim, seat_name, c_wl_surface.clone()) {
Some(p_ret)
} else {
self.space_list.iter_mut().enumerate().find_map(|(i, s)| {
if i != popup_space_i {
s.touch_under(dim, seat_name, c_wl_surface.clone())
} else {
None
}
})
}
} else {
self.space_list.iter_mut().find_map(|s| {
s.touch_under(dim, seat_name, c_wl_surface.clone())
})
}
}



// all pointer / keyboard handling should be called on any space with an active popup first, then on the rest
// Eg: likely opening a popup on one panel, then without clicking anywhere else, opening a popup on another panel will crash
fn update_pointer(
Expand Down
2 changes: 1 addition & 1 deletion cosmic-panel-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ tracing = "0.1.37"
wayland-protocols-wlr = { version = "0.2.0", features = ["server", "client"], optional = true}
cosmic-config = { git = "https://github.com/pop-os/libcosmic" }
# xdg-shell-wrapper-config = { path = "../../xdg-shell-wrapper/xdg-shell-wrapper-config", optional = true }
xdg-shell-wrapper-config = { git = "https://github.com/pop-os/xdg-shell-wrapper", optional = true }
xdg-shell-wrapper-config = { git = "https://github.com/pop-os/xdg-shell-wrapper", branch = "touch", optional = true }
sctk.workspace = true
sctk.optional = true