From cc22fe69a68e0fff027d833029aea850976488c8 Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Fri, 15 Aug 2025 23:22:00 +0200 Subject: Add real desktop icons plus right-click desktop/icon context menus Closes "right-click on bare desktop" - previously a true no-op, nothing rendered above the wallpaper at all. Requested directly: a real desktop "just like windows does" - Home/Computer/Trash plus one icon per real ~/Desktop entry, individually draggable with persisted grid positions, double-click to open, right-click menus (per-icon "Open" plus "Set as Wallpaper" for image files when general.wallpaper_command is set; bare desktop "New Folder"/"Refresh"). Architecture mirrors the existing context_menu.rs/snap_flyout.rs "compositor-owned floating UI" pattern: desktop_icons.rs (data model, grid layout, filesystem scan, hit-test), desktop_icons_state.rs (JSON persistence, same shape as monitor_layout.rs), desktop_menu.rs (the new right-click menu, reusing decoration::render_context_menu's existing rasterizer), state/desktop_icons.rs (CompState glue: rescan/select/drag/ open/persist), and a new decoration::render_desktop_icon rasterizer -- hand-drawn glyphs, since no PNG/SVG decoding capability exists anywhere in this workspace. Wired into both render loops (udev and winit) above the wallpaper and below every window, and into input/pointer.rs's button/ motion handlers for selection, drag, double-click, and both menus. Four new config keys: general.desktop_icons (default true - a directly requested, purely visual feature, unlike the opt-in-while-experimental general.gpu), general.file_manager, general.desktop_icon_single_click, general.wallpaper_command (all default off/empty). Deliberately out of scope for this pass, stated up front: move-to-trash and "Empty Trash" (destructive, no confirmation-dialog primitive to gate them on yet), filesystem watching, multi-select, per-mimetype icon art, icons on any monitor but the primary one. 124 wayland-crate tests (up from 106), full workspace build and clippy clean. --- crates/wayland/src/input/pointer.rs | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'crates/wayland/src/input/pointer.rs') diff --git a/crates/wayland/src/input/pointer.rs b/crates/wayland/src/input/pointer.rs index d4c5678..f0e034e 100644 --- a/crates/wayland/src/input/pointer.rs +++ b/crates/wayland/src/input/pointer.rs @@ -228,6 +228,10 @@ pub(crate) fn handle_pointer_position(state: &mut CompState, pos: Point { + let single_click_opens = state.wm.borrow().desktop_icon_single_click; + if single_click_opens || state.is_double_click_icon(&id, time) { + state.select_desktop_icon(Some(&id)); + state.open_desktop_icon(&id); + } else { + state.select_desktop_icon(Some(&id)); + state.start_desktop_icon_drag(&id, (pos.x as i32, pos.y as i32)); + } + } + None => state.select_desktop_icon(None), + } } } } else if pressed && (button == BTN_RIGHT || button == BTN_MIDDLE) { @@ -635,9 +671,32 @@ pub(crate) fn handle_pointer_button(state: &mut CompState, pos: Point state.open_snap_flyout(id, (pos.x as i32, pos.y as i32)), + // Right-click bare desktop (no titlebar/border hit, no window + // content, no bar/dock layer surface - same "genuinely bare" + // definition the left-click branch above uses): a desktop + // icon's own menu if the click landed on one, otherwise the + // "New Folder"/"Refresh" desktop menu. Previously a true + // no-op, the actual gap this whole feature exists to close -- + // see this session's own TODO.md entry. + (BTN_RIGHT, None) + if layer_surface_under(state, pos).is_none() && !state.space.element_under(pos).is_some_and(|(w, _)| dwindow_is_visible(state, w)) => + { + let icon_hit = state.desktop_icons.as_ref().and_then(|icons| icons.icon_at(pos.x as i32, pos.y as i32).map(|i| icons.icons[i].id.clone())); + match icon_hit { + Some(id) => { + state.select_desktop_icon(Some(&id)); + state.open_desktop_icon_menu(&id, (pos.x as i32, pos.y as i32)); + } + None => state.open_desktop_menu((pos.x as i32, pos.y as i32)), + } + } _ => {} } } else if !pressed { + // A no-op via `Option::take()` when no icon drag was active -- + // always checked on release, same as `was_dragging`/`was_resizing` + // below, just for a desktop icon instead of a window. + state.end_desktop_icon_drag(); let mut wm = state.wm.borrow_mut(); let was_dragging = wm.is_dragging(); let was_resizing = wm.is_resizing(); -- cgit v1.2.3