Skip to content
Open
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
18 changes: 9 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", branch
cosmic-client-toolkit = { git = "https://github.com/pop-os//cosmic-protocols", branch = "main" }

[patch.crates-io]
smithay = { git = "https://github.com/smithay/smithay.git", rev = "211c19d" }
smithay = { git = "https://github.com/skygrango/smithay.git", rev = "0b7e1ae" }
193 changes: 120 additions & 73 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only

use crate::wayland::handlers::pointer_constraints::with_pointer_constraint;
use crate::{
backend::render::ElementFilter,
config::{
Expand Down Expand Up @@ -35,6 +36,7 @@ use calloop::{
use cosmic_comp_config::{NumlockState, workspace::WorkspaceLayout};
use cosmic_settings_config::shortcuts;
use cosmic_settings_config::shortcuts::action::{Direction, ResizeDirection};
use smithay::wayland::pointer_constraints::PointerConstraint;
use smithay::{
backend::input::{
AbsolutePositionEvent, Axis, AxisSource, Device, DeviceCapability, GestureBeginEvent,
Expand Down Expand Up @@ -63,7 +65,6 @@ use smithay::{
wayland::{
image_copy_capture::{BufferConstraints, CursorSessionRef},
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat,
pointer_constraints::{PointerConstraint, with_pointer_constraint},
seat::WaylandFocus,
tablet_manager::{TabletDescriptor, TabletSeatTrait},
},
Expand Down Expand Up @@ -347,27 +348,6 @@ impl State {
_ => {}
});
}
let original_position = position;
position += event.delta().as_global();

let output = shell
.outputs()
.find(|output| output.geometry().to_f64().contains(position))
.cloned()
.unwrap_or(current_output.clone());

let output_geometry = output.geometry();
position.x = position.x.clamp(
output_geometry.loc.x as f64,
(output_geometry.loc.x + output_geometry.size.w - 1) as f64,
);
position.y = position.y.clamp(
output_geometry.loc.y as f64,
(output_geometry.loc.y + output_geometry.size.h - 1) as f64,
);

let new_under = State::surface_under(position, &output, &shell)
.map(|(target, pos)| (target, pos.as_logical()));

std::mem::drop(shell);
ptr.relative_motion(
Expand All @@ -385,6 +365,25 @@ impl State {
return;
}

let original_position = position;
position += event.delta().as_global();
let shell = self.common.shell.read();
let output = shell
.outputs()
.find(|output| output.geometry().to_f64().contains(position))
.cloned()
.unwrap_or(current_output.clone());
drop(shell);
let output_geometry = output.geometry();
position.x = position.x.clamp(
output_geometry.loc.x as f64,
(output_geometry.loc.x + output_geometry.size.w - 1) as f64,
);
position.y = position.y.clamp(
output_geometry.loc.y as f64,
(output_geometry.loc.y + output_geometry.size.h - 1) as f64,
);

if ptr.is_grabbed() {
if seat
.user_data()
Expand Down Expand Up @@ -492,50 +491,90 @@ impl State {
}
}

// If confined, don't move pointer if it would go outside surface or region
if pointer_confined && let Some((surface, surface_loc)) = &under {
if new_under.as_ref().and_then(|(under, _)| under.wl_surface())
!= surface.wl_surface()
{
ptr.frame(self);
return;
}
match surface {
PointerFocusTarget::WlSurface { surface, .. } => {
if under_from_surface_tree(
surface,
position.as_logical() - surface_loc.to_f64(),
(0, 0),
WindowSurfaceType::ALL,
)
.is_none()
{
ptr.frame(self);
return;
}
}
PointerFocusTarget::X11Surface { surface, .. } => {
if surface
.surface_under(
// If confined, help user to update valid coordinates can improve user experience
let shell = self.common.shell.read();
let new_under = if pointer_confined && let Some((surface, surface_loc)) = &under
{
let is_legal = |pos: Point<f64, Global>, shell: &Shell| {
let new_under = State::surface_under(pos, &output, shell)
.map(|(target, pos)| (target, pos.as_logical()));

//We should only check size, not the surface, so that we can move the mouse over the OSD in confined mode
// if new_under.as_ref().and_then(|(under, _)| under.wl_surface())
// != surface.wl_surface()
// {
// return (false, None);
// }

match surface {
PointerFocusTarget::WlSurface { surface, .. } => {
if under_from_surface_tree(
surface,
position.as_logical() - surface_loc.to_f64(),
(0, 0),
WindowSurfaceType::ALL,
)
.is_none()
{
ptr.frame(self);
return;
{
return (false, None);
}
}
PointerFocusTarget::X11Surface { surface, .. } => {
if surface
.surface_under(
position.as_logical() - surface_loc.to_f64(),
(0, 0),
WindowSurfaceType::ALL,
)
.is_none()
{
return (false, None);
}
}
_ => {}
}

if let Some(region) = &confine_region
&& !region
.contains((pos.as_logical() - *surface_loc).to_i32_round())
{
return (false, None);
}
(true, new_under)
};

match is_legal(position, &shell) {
(true, under) => under,
_ => {
let y_only_pos = Point::new(original_position.x, position.y);
let x_only_pos = Point::new(position.x, original_position.y);
match is_legal(y_only_pos, &shell) {
(true, under) => {
position = y_only_pos;
under
}
_ => match is_legal(x_only_pos, &shell) {
(true, under) => {
position = x_only_pos;
under
}
_ => {
position = original_position;
None
}
},
}
}
_ => {}
}
if let Some(region) = confine_region
&& !region
.contains((position.as_logical() - *surface_loc).to_i32_round())
{
ptr.frame(self);
return;
}
} else {
State::surface_under(position, &output, &shell)
.map(|(target, pos)| (target, pos.as_logical()))
};

drop(shell);
if pointer_confined && new_under.is_none() {
ptr.frame(self);
return;
}

let serial = SERIAL_COUNTER.next_serial();
Expand All @@ -550,24 +589,32 @@ impl State {
);
ptr.frame(self);

// If pointer is now in a constraint region, activate it
// If pointer is now in a constraint region and window is in focused, activate it
if let Some((under, surface_location)) = new_under
.and_then(|(target, loc)| Some((target.wl_surface()?.into_owned(), loc)))
{
with_pointer_constraint(&under, &ptr, |constraint| match constraint {
Some(constraint) if !constraint.is_active() => {
let region = match &*constraint {
PointerConstraint::Locked(locked) => locked.region(),
PointerConstraint::Confined(confined) => confined.region(),
};
let point =
(ptr.current_location() - surface_location).to_i32_round();
if region.is_none_or(|region| region.contains(point)) {
constraint.activate();
let shell = self.common.shell.read();
let is_focused = seat
.get_keyboard()
.and_then(|k| k.current_focus())
.is_some_and(|f| f.has_surface(&shell, &under));

if is_focused {
with_pointer_constraint(&under, &ptr, |constraint| match constraint {
Some(constraint) if !constraint.is_active() => {
let region = match &*constraint {
PointerConstraint::Locked(locked) => locked.region(),
PointerConstraint::Confined(confined) => confined.region(),
};
let point =
(ptr.current_location() - surface_location).to_i32_round();
if region.is_none_or(|region| region.contains(point)) {
constraint.activate();
}
}
}
_ => {}
});
_ => {}
});
}
}

let mut shell = self.common.shell.write();
Expand Down Expand Up @@ -2304,7 +2351,7 @@ impl State {
}
}

fn cursor_sessions_for_output<'a>(
pub fn cursor_sessions_for_output<'a>(
shell: &'a Shell,
output: &'a Output,
) -> impl Iterator<Item = CursorSessionRef> + 'a {
Expand Down
8 changes: 8 additions & 0 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ impl CosmicMapped {
.any(|(w, _)| w.has_surface(surface, surface_type))
}

pub fn surface_offset(&self, surface: &WlSurface) -> Option<Point<i32, Logical>> {
self.windows().find_map(|(window, window_offset)| {
window
.surface_offset(surface)
.map(|offset| window_offset + offset)
})
}

/// Give the pointer target under a relative offset into this element.
///
/// Returns Target + Offset relative to the target
Expand Down
Loading