Desktop card: click and drag it around the wallpaper
Press on the card (when no window covers it) to grab it; it follows the pointer, clamped to the screen, with a hand cursor on hover and grabbing while dragged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
783618b89f
commit
bca69d8c90
4 files changed
+100
-6
No files matched your search
@@ -10,7 +10,8 @@ let desktop_widget_h : Int = 120
|
||||
|
||||
///|
|
||||
fn render_desktop_widget(
|
||||
screen_w : Int,
|
||||
x0 : Int,
|
||||
y0 : Int,
|
||||
tokens : @theme.Tokens,
|
||||
at : @types.Datetime,
|
||||
out : Array[@scene.DrawOp],
|
||||
@@ -38,7 +39,41 @@ fn render_desktop_widget(
|
||||
tokens.palette.foreground,
|
||||
),
|
||||
]
|
||||
let x0 = screen_w - desktop_widget_w - 24
|
||||
translate(ops, x0, 24, out)
|
||||
translate(@moon.render_disc(@ui.size(56, 56), tokens, p), x0 + desktop_widget_w - 56 - 18, 24 + 18, out)
|
||||
translate(ops, x0, y0, out)
|
||||
translate(@moon.render_disc(@ui.size(56, 56), tokens, p), x0 + desktop_widget_w - 56 - 18, y0 + 18, out)
|
||||
}
|
||||
|
||||
///| Default top-right position of the card, and the clamp that keeps it on screen.
|
||||
fn DesktopShell::desk_pos(self : DesktopShell) -> (Int, Int) {
|
||||
let (x, y) = if self.desk_set {
|
||||
(self.desk_x, self.desk_y)
|
||||
} else {
|
||||
(self.screen_w - desktop_widget_w - 24, 24)
|
||||
}
|
||||
let mx = if self.screen_w > desktop_widget_w { self.screen_w - desktop_widget_w } else { 0 }
|
||||
let my = if self.screen_h > desktop_widget_h { self.screen_h - desktop_widget_h } else { 0 }
|
||||
(if x < 0 { 0 } else if x > mx { mx } else { x }, if y < 0 { 0 } else if y > my { my } else { y })
|
||||
}
|
||||
|
||||
///| True if (x, y) is over the desktop card.
|
||||
pub fn DesktopShell::desk_hit(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
let (cx, cy) = self.desk_pos()
|
||||
x >= cx && x < cx + desktop_widget_w && y >= cy && y < cy + desktop_widget_h
|
||||
}
|
||||
|
||||
///| Start dragging the card if the press is on it. Call only when no window covers (x, y).
|
||||
pub fn DesktopShell::desk_press(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
if !self.desk_hit(x, y) {
|
||||
return false
|
||||
}
|
||||
let (cx, cy) = self.desk_pos()
|
||||
self.desk_drag = true
|
||||
self.desk_off_x = x - cx
|
||||
self.desk_off_y = y - cy
|
||||
true
|
||||
}
|
||||
|
||||
///| True while the card is being dragged.
|
||||
pub fn DesktopShell::desk_dragging(self : DesktopShell) -> Bool {
|
||||
self.desk_drag
|
||||
}
|
||||
@@ -191,6 +191,13 @@ pub(all) struct DesktopShell {
|
||||
mut persist : Bool
|
||||
mut tokens : @theme.Tokens
|
||||
mut screen_w : Int
|
||||
/// Desktop card position (once moved) and drag state.
|
||||
mut desk_set : Bool
|
||||
mut desk_x : Int
|
||||
mut desk_y : Int
|
||||
mut desk_drag : Bool
|
||||
mut desk_off_x : Int
|
||||
mut desk_off_y : Int
|
||||
mut screen_h : Int
|
||||
mut panel_h : Int
|
||||
/// Window list + layout mode, set by the compositor before each frame.
|
||||
@@ -259,6 +266,12 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
persist: false,
|
||||
tokens: conv_theme(@scene.ThemeTokens::moon_night()),
|
||||
screen_w: 0,
|
||||
desk_set: false,
|
||||
desk_x: 0,
|
||||
desk_y: 0,
|
||||
desk_drag: false,
|
||||
desk_off_x: 0,
|
||||
desk_off_y: 0,
|
||||
screen_h: 0,
|
||||
panel_h: 40,
|
||||
windows: [],
|
||||
@@ -513,7 +526,9 @@ pub fn DesktopShell::cursor_at(self : DesktopShell, x : Int, y : Int) -> UInt {
|
||||
_ => 3U
|
||||
}
|
||||
}
|
||||
if self.drag_active {
|
||||
if self.desk_drag {
|
||||
17U
|
||||
} else if self.drag_active {
|
||||
17U // grabbing
|
||||
} else if self.menu_open && inside(self.menu_rect, x, y) {
|
||||
if self.menu_hover >= 0 { 4U } else { 1U }
|
||||
@@ -594,6 +609,10 @@ fn DesktopShell::reorder_dragged(self : DesktopShell, x : Int) -> Unit {
|
||||
|
||||
///| Pointer release: ends a widget drag, or clicks the widget if it never moved. True when a press was pending.
|
||||
pub fn DesktopShell::pointer_up(self : DesktopShell) -> Bool {
|
||||
if self.desk_drag {
|
||||
self.desk_drag = false
|
||||
return true
|
||||
}
|
||||
let slot = self.drag_slot
|
||||
let was_drag = self.drag_active
|
||||
self.drag_slot = ""
|
||||
@@ -614,6 +633,15 @@ pub fn DesktopShell::pointer_up(self : DesktopShell) -> Bool {
|
||||
|
||||
///| Pointer motion; returns true when over a popup or the menu (so windows don't see it).
|
||||
pub fn DesktopShell::pointer_move(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
if self.desk_drag {
|
||||
self.desk_set = true
|
||||
self.desk_x = x - self.desk_off_x
|
||||
self.desk_y = y - self.desk_off_y
|
||||
let (cx, cy) = self.desk_pos()
|
||||
self.desk_x = cx
|
||||
self.desk_y = cy
|
||||
return true
|
||||
}
|
||||
if self.drag_slot != "" {
|
||||
if !self.drag_active && (x - self.drag_x0 > 4 || self.drag_x0 - x > 4) {
|
||||
self.drag_active = true
|
||||
@@ -685,7 +713,8 @@ pub fn DesktopShell::render(
|
||||
}
|
||||
let bg : Array[@scene.DrawOp] = []
|
||||
translate(@libshell.render_background(@ui.size(w, h), tokens), 0, 0, bg)
|
||||
render_desktop_widget(w, tokens, now(), bg)
|
||||
let (dx, dy) = self.desk_pos()
|
||||
render_desktop_widget(dx, dy, tokens, now(), bg)
|
||||
|
||||
let panel_ops : Array[@scene.DrawOp] = []
|
||||
self.comps.clear()
|
||||
|
||||
Reference in new issue
Block a user