Text selection in terminals: drags stay with their window, middle-click paste works
CI / test (push) Canceled after 4m14s
CI / test (push) Canceled after 4m14s
V: "kwi is having problems selecting text". Two compositor gaps: - No implicit pointer grab. A drag that started in a window lost it as soon as the pointer crossed its edge (onto the frame, the panel, a divider or another window): the client got wl_pointer.leave mid-drag (Qt then forgets the held button), and the release went to the other window or nowhere, so the terminal's selection never ended and kept following the pointer. Selecting past the top/bottom edge to scroll, which Kwi and Konsole autoscroll on, could not work. Now a press forwarded to a client grabs the pointer: motion (in that surface's coordinates, also outside it), the wheel and every button go to it until the last button is up; then the pointer goes to whatever is under it. Anything that takes the pointer (a window move or resize, the overview, a screenshot) ends the grab as before. - No primary selection. zwp_primary_selection_device_manager_v1 was not offered, so Qt's QClipboard::supportsSelection() was false: selected text was never put on the primary selection and a middle click pasted nothing. Now offered (v1), with the offer sent to the focused client like the clipboard. Checked headless with Konsole (Qt 5 Wayland): a selection dragged out of the window keeps extending, is set as the primary selection on release, and a middle click in another Konsole window pastes it. Tests in selection_test.mbt (both grab tests fail without the fix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5himKXPLcfCZN6BXByd
This commit is contained in:
3 files changed
+466
No files matched your search
@@ -53,6 +53,19 @@ fn HostWindow::surface_at(self : HostWindow, x : Double, y : Double) -> (UInt, D
|
||||
(0U, x - ox.to_double(), y - oy.to_double())
|
||||
}
|
||||
|
||||
///| Screen point (x, y) in the coordinates of window `self`'s surface `sub` (a subsurface's
|
||||
/// wl_surface id, 0 for the window itself), wherever the point is: the pointer can be held
|
||||
/// outside the surface during a drag.
|
||||
fn HostWindow::surface_local(self : HostWindow, sub : UInt, x : Double, y : Double) -> (Double, Double) {
|
||||
let (ox, oy) = self.surface_origin()
|
||||
for s in self.subs {
|
||||
if s.sid == sub {
|
||||
return (x - (ox + s.x).to_double(), y - (oy + s.y).to_double())
|
||||
}
|
||||
}
|
||||
(x - ox.to_double(), y - oy.to_double())
|
||||
}
|
||||
|
||||
///| The window style in use (Settings > Session > Flat window frames). Global because the frame's
|
||||
/// size is part of every window's on-screen box (`client_rect`); the compositor sets it from the
|
||||
/// shell's setting (`ChandraCompositor::apply_window_style`).
|
||||
@@ -156,6 +169,13 @@ pub(all) struct ChandraCompositor {
|
||||
mut title_press : TitlePress?
|
||||
/// True while a button press was forwarded to a client (so its release is too).
|
||||
mut press_fwd : Bool
|
||||
/// Implicit pointer grab: a button was pressed on `ptr_win` (surface `ptr_sub`) and is still
|
||||
/// held, so motion, the wheel and the release all go to that surface, even outside it (text
|
||||
/// selection dragged past the window's edge, over the frame or the panel). `grab_buttons`
|
||||
/// counts the buttons held. Ends with the last release or when the compositor takes the
|
||||
/// pointer (`leave_pointer`: a window move, the overview, a screenshot).
|
||||
mut ptr_grab : Bool
|
||||
mut grab_buttons : Int
|
||||
mut kbd_win : UInt64?
|
||||
mut mods : UInt
|
||||
/// A Super key is down and nothing else was pressed since: releasing it is a Super tap (the
|
||||
@@ -328,6 +348,8 @@ pub fn ChandraCompositor::new(
|
||||
split_drag: None,
|
||||
title_press: None,
|
||||
press_fwd: false,
|
||||
ptr_grab: false,
|
||||
grab_buttons: 0,
|
||||
kbd_win: None,
|
||||
mods: 0U,
|
||||
super_solo: false,
|
||||
@@ -1751,6 +1773,8 @@ fn ChandraCompositor::handle_at(
|
||||
|
||||
///|
|
||||
fn ChandraCompositor::leave_pointer(self : ChandraCompositor) -> Unit {
|
||||
self.ptr_grab = false
|
||||
self.grab_buttons = 0
|
||||
match self.ptr_win {
|
||||
Some(w) => {
|
||||
self.server.pointer_leave(w, sub=self.ptr_sub)
|
||||
@@ -1761,6 +1785,34 @@ fn ChandraCompositor::leave_pointer(self : ChandraCompositor) -> Unit {
|
||||
}
|
||||
}
|
||||
|
||||
///| The window holding the implicit pointer grab, if one is held and the window still exists.
|
||||
fn ChandraCompositor::grab_window(self : ChandraCompositor) -> UInt64? {
|
||||
if !self.ptr_grab {
|
||||
return None
|
||||
}
|
||||
match self.ptr_win {
|
||||
Some(w) if self.windows.contains(w) => Some(w)
|
||||
_ => {
|
||||
self.ptr_grab = false
|
||||
self.grab_buttons = 0
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Pointer motion during an implicit grab: it goes to the grabbing surface, in its
|
||||
/// coordinates, wherever the pointer is. False when no grab is held.
|
||||
fn ChandraCompositor::grab_motion(self : ChandraCompositor, x : Double, y : Double, time_ms : UInt) -> Bool {
|
||||
match self.grab_window() {
|
||||
Some(wid) => {
|
||||
let (lx, ly) = self.windows.get(wid).unwrap().surface_local(self.ptr_sub, x, y)
|
||||
self.server.pointer_motion(wid, time_ms, lx, ly)
|
||||
true
|
||||
}
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
///| evdev keycode -> the key name lib/launcher understands (US layout).
|
||||
fn key_name(code : UInt, shift : Bool) -> String {
|
||||
let rows = [
|
||||
@@ -1850,6 +1902,9 @@ pub fn ChandraCompositor::handle_input(
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if self.grab_motion(x, y, time_ms) {
|
||||
return
|
||||
}
|
||||
if self.shell.inspecting() {
|
||||
self.leave_pointer()
|
||||
let id = match self.shell.component_at(xi, yi) {
|
||||
@@ -1944,6 +1999,13 @@ pub fn ChandraCompositor::handle_input(
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
match self.grab_window() {
|
||||
Some(w) => {
|
||||
self.server.pointer_axis(w, time_ms, axis, v, discrete)
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if self.overview is Some(_) {
|
||||
return // nothing scrolls under the overview
|
||||
}
|
||||
@@ -2000,6 +2062,26 @@ pub fn ChandraCompositor::handle_input(
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
match self.grab_window() {
|
||||
Some(w) => {
|
||||
self.server.pointer_button(w, time_ms, button, pressed)
|
||||
if pressed {
|
||||
self.grab_buttons = self.grab_buttons + 1
|
||||
} else {
|
||||
self.grab_buttons = self.grab_buttons - 1
|
||||
if self.grab_buttons <= 0 {
|
||||
// The last button is up: the grab ends, and the pointer goes to whatever is
|
||||
// under it now (the client sees it leave if that is elsewhere).
|
||||
self.ptr_grab = false
|
||||
self.grab_buttons = 0
|
||||
self.press_fwd = false
|
||||
self.handle_input(PointerMove(self.ptr_x, self.ptr_y), time_ms)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if pressed && self.popups.length() > 0 {
|
||||
// A click outside the open popups dismisses them (the click is swallowed).
|
||||
let mut i = self.popups.length() - 1
|
||||
@@ -2118,6 +2200,8 @@ pub fn ChandraCompositor::handle_input(
|
||||
Some(w) =>
|
||||
if pressed {
|
||||
self.press_fwd = true
|
||||
self.ptr_grab = true
|
||||
self.grab_buttons = 1
|
||||
self.server.pointer_button(w, time_ms, button, pressed)
|
||||
} else if self.press_fwd {
|
||||
self.press_fwd = false
|
||||
|
||||
Reference in new issue
Block a user