Double-click a window's title bar to maximize or restore it
CI / test (push) Failing after 16s

Two left presses on the same title bar within 400ms and 4px of each other
toggle maximize, like the title-bar button. A press that turned into a drag
never starts a double-click. A tiled window now floats only once the pointer
actually moves, so clicking or double-clicking its title bar leaves it in
(and restores it to) its tile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjF2tD2UuaXLzFzrvV
This commit is contained in:
Claude committed 2026-11-25 19:00:40 +00:00
1 parent 4fc4a963b4
commit 3454619162
3 files changed
+271 -5

No files matched your search

+129
View File
@@ -0,0 +1,129 @@
///| 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 => ()
}
}