Skip to content

Commit

Permalink
Handle ungrabbing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Koranir committed Jan 8, 2025
1 parent 3c5ec70 commit 095bbf9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
target::{KeyboardFocusTarget, PointerFocusTarget},
Stage,
},
grabs::{ReleaseMode, ResizeEdge},
grabs::{ReleaseMode, ResizeEdge, UngrabOnPointerUp},
layout::{
floating::ResizeGrabMarker,
tiling::{NodeDesc, TilingLayout},
Expand Down Expand Up @@ -75,7 +75,7 @@ use xkbcommon::xkb::{Keycode, Keysym};
use std::{
any::Any,
borrow::Cow,
cell::RefCell,
cell::{Cell, RefCell},

Check warning on line 78 in src/input/mod.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `Cell`
collections::HashSet,
ops::ControlFlow,
time::{Duration, Instant},
Expand Down Expand Up @@ -757,7 +757,13 @@ impl State {
&state.common.xdg_activation_state,
false,
);

drop(shell);

seat_clone
.user_data()
.get_or_insert(UngrabOnPointerUp::new)
.set(true);
dispatch_grab(
res, seat_clone, serial, state,
);
Expand Down Expand Up @@ -835,6 +841,13 @@ impl State {
false,
);
drop(shell);

seat_clone
.user_data()
.get_or_insert(
UngrabOnPointerUp::new,
)
.set(true);
dispatch_grab(
res, seat_clone, serial, state,
);
Expand Down Expand Up @@ -875,6 +888,13 @@ impl State {
},
);
ptr.frame(self);
} else if event.state() == ButtonState::Released {
if let Some(ungrab) = seat.user_data().get::<UngrabOnPointerUp>() {
if ungrab.get() {
ungrab.set(false);
ptr.unset_grab(self, serial, event.time_msec())
}
}
}
}
InputEvent::PointerAxis { event, .. } => {
Expand Down
18 changes: 18 additions & 0 deletions src/shell/grabs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cell::Cell;

use cosmic_settings_config::shortcuts;
use smithay::{
input::{
Expand Down Expand Up @@ -67,6 +69,22 @@ pub enum ReleaseMode {
NoMouseButtons,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UngrabOnPointerUp(Cell<bool>);
impl UngrabOnPointerUp {
pub fn new() -> Self {
Self(Cell::new(false))
}

pub fn get(&self) -> bool {
self.0.get()
}

pub fn set(&self, ungrab: bool) {
self.0.set(ungrab);
}
}

mod menu;
pub use self::menu::*;
mod moving;
Expand Down

0 comments on commit 095bbf9

Please sign in to comment.