Files
chandra/compositor/host/titleclick.mbt
T
Claude 90fdda2455
CI / test (push) Successful in 2m57s
Client-drawn window frames: GTK apps (GNOME Files) get no second title bar
GTK never asks for server-side decoration (it has no xdg-decoration support), so it draws its
own header bar plus a transparent shadow margin around it, and says where the real window is
with xdg_surface.set_window_geometry. Chandra drew its Breeze frame around every window anyway
and blitted the whole buffer from the frame's corner: a second title bar on top, and the
content shifted down/right by the shadow (a see-through gap), with the right/bottom cut off.

- The server reports per window who draws the frame (ToplevelFrame: client-side when the
  client never made a zxdg_toplevel_decoration_v1, plus the window-geometry offset).
- A client-decorated window gets no Chandra frame and fills the frame's whole box
  (HostWindow::client_rect): it is configured for that size, drawn with its buffer shifted by
  the geometry offset (its own shadow drawn around it), and pointer coordinates and popup
  placement use the same origin. Tiling, title-bar hit areas and resize zones are unchanged.
- xdg_toplevel.move / resize (dragging a header bar, a CSD border) start Chandra's move and
  resize drags; they were ignored before.
- Tiled windows get the tiled_left/right/top/bottom states, so GTK drops its shadow and
  rounded corners there.

Checked with real Nautilus 46 and gtk4-demo on the headless native compositor. Tests:
compositor/host/csd_test.mbt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hkfW5ttNd831XmdsC5
2026-11-26 01:35:31 +00:00

181 lines
5.5 KiB
MoonBit

///| Title-bar presses: drag to move, double-click to maximize or restore.
///
/// A left press on a title bar (away from its buttons) focuses the window and starts a move.
/// A tiled window is only turned floating once the pointer actually moves, so a plain click
/// (or double-click) leaves it in the tiling layout. Two presses on the same window's title
/// bar count as a double-click when the second comes within `double_click_ms` of the first,
/// lands within `double_click_px` of it, and the first press did not turn into a drag. The
/// double-click toggles maximize like the title-bar button: restoring brings back the size
/// and position the window had before (its tile, or where it floated).
///|
/// Longest gap between the two presses of a double-click, in milliseconds.
pub let double_click_ms : UInt32 = 400
///|
/// How far (in pixels, along either axis) the pointer may wander between the two presses,
/// and how far it may move while held before a press becomes a drag.
pub let double_click_px : Int32 = 4
///|
/// The last left press on a title bar.
struct TitlePress {
wid : UInt64
x : Int32
y : Int32
time : UInt32
/// The button is still down.
mut held : Bool
/// The pointer moved past `double_click_px` while held (a drag, not a click).
mut moved : Bool
/// A tiled window waiting for the pointer to move before it floats and starts moving.
mut float_pending : Bool
}
///|
fn abs_int(v : Int32) -> Int32 {
if v < 0 {
-v
} else {
v
}
}
///|
/// Left press at (x, y) on the title bar of `wid` (not on one of its buttons).
fn ChandraCompositor::title_bar_press(
self : ChandraCompositor,
wid : UInt64,
x : Int32,
y : Int32,
time_ms : UInt32,
) -> Unit {
self.leave_pointer()
match self.title_press {
Some(p) =>
if p.wid == wid &&
!p.moved &&
time_ms >= p.time &&
time_ms - p.time <= double_click_ms &&
abs_int(x - p.x) <= double_click_px &&
abs_int(y - p.y) <= double_click_px {
self.title_press = None
self.activate_window(wid)
self.press_title_button(wid, 2)
return
}
None => ()
}
self.activate_window(wid)
let tiled = match self.wm.windows.get(wid) {
Some(r) => !r.is_floating && !r.maximized && !r.fullscreen
None => false
}
self.title_press = Some({
wid,
x,
y,
time: time_ms,
held: true,
moved: false,
float_pending: tiled,
})
if !tiled {
ignore(self.wm.start_drag(wid, @wm.DragMode::Move, x, y))
}
}
///|
/// Pointer motion to (x, y) while a title-bar press may be held. Returns true when the motion
/// is consumed (a tiled window held but not yet dragged far enough to float).
fn ChandraCompositor::title_bar_motion(
self : ChandraCompositor,
x : Int32,
y : Int32,
) -> Bool {
match self.title_press {
Some(p) =>
if p.held {
if abs_int(x - p.x) > double_click_px ||
abs_int(y - p.y) > double_click_px {
p.moved = true
if p.float_pending {
// Drag the window by its title bar; a tiled window becomes floating first.
p.float_pending = false
self.apply_actions(self.wm.float_window(p.wid, self.work_area))
ignore(self.wm.start_drag(p.wid, @wm.DragMode::Move, p.x, p.y))
}
false
} else {
p.float_pending
}
} else {
false
}
None => false
}
}
///|
/// The left button was released.
fn ChandraCompositor::title_bar_release(self : ChandraCompositor) -> Unit {
match self.title_press {
Some(p) => {
p.held = false
p.float_pending = false
}
None => ()
}
}
///|
/// xdg_toplevel.move from a client-decorated window (a press on its own title bar): the same
/// drag as a press on Chandra's title bar, without the double-click (the client handles that
/// and asks to maximize). Only while the press that asked for it is still held.
fn ChandraCompositor::client_move(self : ChandraCompositor, wid : UInt64) -> Unit {
if !self.press_fwd || self.ptr_win != Some(wid) || self.wm.drag is Some(_) {
return
}
// The compositor takes the pointer for the drag: the client sees it leave (and no release).
self.press_fwd = false
self.leave_pointer()
let x = self.ptr_x.to_int()
let y = self.ptr_y.to_int()
let tiled = match self.wm.windows.get(wid) {
Some(r) => !r.is_floating && !r.maximized && !r.fullscreen
None => return
}
self.title_press = Some({ wid, x, y, time: 0, held: true, moved: true, float_pending: tiled })
if !tiled {
ignore(self.wm.start_drag(wid, @wm.DragMode::Move, x, y))
}
}
///|
/// xdg_toplevel.resize from a client-decorated window (a press on its own border or shadow):
/// a floating window resizes from that edge, like Chandra's own resize zones. Tiled windows
/// resize through the dividers instead.
fn ChandraCompositor::client_resize(self : ChandraCompositor, wid : UInt64, edges : UInt) -> Unit {
if !self.press_fwd || self.ptr_win != Some(wid) || self.wm.drag is Some(_) {
return
}
match self.wm.windows.get(wid) {
Some(r) => if !r.is_floating || r.maximized || r.fullscreen { return }
None => return
}
let mode = match edges {
1U => @wm.DragMode::ResizeN
2U => @wm.DragMode::ResizeS
4U => @wm.DragMode::ResizeW
8U => @wm.DragMode::ResizeE
5U => @wm.DragMode::ResizeNW
9U => @wm.DragMode::ResizeNE
6U => @wm.DragMode::ResizeSW
10U => @wm.DragMode::ResizeSE
_ => return
}
self.press_fwd = false
self.leave_pointer()
ignore(self.wm.start_drag(wid, mode, self.ptr_x.to_int(), self.ptr_y.to_int()))
}