mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
ui-contract: a shell without Caps::SYSTEM_CURSOR keeps the system pointer under a painted cursor and paints none, nor hands the window an image: a host on Wayland with no cursor theme, where a hidden pointer never comes back, could not keep it
This commit is contained in:
@@ -146,7 +146,9 @@ bitflags::bitflags! {
|
||||
const THREADS = 1 << 3;
|
||||
/// Screen capture.
|
||||
const SCREEN_CAPTURE = 1 << 4;
|
||||
/// The app sets the system cursor.
|
||||
/// The app sets the system cursor. A host that cannot (Wayland with no cursor theme, where winit sets no
|
||||
/// pointer and a hidden one never comes back) leaves it out: the system pointer stays, and no painted cursor
|
||||
/// shows in its place.
|
||||
const SYSTEM_CURSOR = 1 << 5;
|
||||
/// A native menu bar.
|
||||
const NATIVE_MENU_BAR = 1 << 6;
|
||||
|
||||
@@ -97,7 +97,7 @@ pub fn painter(ctx: &Context) -> egui::Painter {
|
||||
/// The painted pointer the cursor service settled on: the window's cursor image where the window takes one at its
|
||||
/// size, else painted at the pointer. A brush tip too large for an image hands its centre cross and badge to the
|
||||
/// window and paints only its ring, so the pointer itself still moves with the hardware. A badged system cursor keeps
|
||||
/// the system's arrow and has only its badge painted.
|
||||
/// the system's arrow and has only its badge painted. Where the shell cannot set the system cursor nothing is painted.
|
||||
///
|
||||
/// A tip outline requested within a region (`cursor::request_within`: a canvas's view on the canvas's layer) is a
|
||||
/// mark on that canvas: the whole outline goes to the window only while it lies inside the region with no layer above
|
||||
@@ -106,7 +106,7 @@ pub fn painter(ctx: &Context) -> egui::Painter {
|
||||
fn paint_pointer(ctx: &Context, env: &Env, painter: &egui::Painter) {
|
||||
use craft_behavior::{Cursor, PaintedCursor};
|
||||
let Some(at) = areas::pointer_pos(ctx) else { return };
|
||||
let Some(Cursor::Painted(cursor)) = cursor::current(ctx) else { return };
|
||||
let Some(Cursor::Painted(cursor)) = cursor::current(ctx).filter(|_| cursor::paints(ctx)) else { return };
|
||||
let closed = pointer::frame_raw(ctx).buttons.contains(craft_behavior::Buttons::PRIMARY);
|
||||
let tip = matches!(cursor, PaintedCursor::Circle { .. } | PaintedCursor::Outline { .. });
|
||||
let whole = pointer_art(env, &cursor, closed, false);
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::runtime::frame::PerViewport;
|
||||
use crate::runtime::windows;
|
||||
use craft_behavior::cursor::pick_index;
|
||||
use craft_behavior::{Cursor, CursorIcon, CursorPriority, PaintedCursor};
|
||||
use craft_host::target::Os;
|
||||
use craft_host::target::{Caps, Os};
|
||||
use egui::{Context, Rect, ViewportId};
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
@@ -96,10 +96,12 @@ fn push(ctx: &Context, cursor: Cursor, priority: CursorPriority, region: Option<
|
||||
/// system cursor, which keeps its base and has only the badge painted. The window's image from the last pass is
|
||||
/// cleared: egui keeps it until it is replaced. Over the resize areas of a window the OS resizes from its own frame
|
||||
/// the cursor is the default whatever was requested: the OS shows its resize cursor there, and any other fights it.
|
||||
/// Where the shell cannot set the system cursor ([`paints`]) a painted winner leaves the system pointer showing.
|
||||
pub(crate) fn end_pass(ctx: &Context) {
|
||||
let blocked = windows::blocking_modal(ctx).is_some();
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
let to_os = !blocked && over_os_resize_area(ctx, viewport);
|
||||
let hides = paints(ctx);
|
||||
let won = PerViewport::<State>::with(ctx, viewport, |state| {
|
||||
let (won, region) = match pick_index(&state.requests) {
|
||||
_ if blocked => (Some(Cursor::System(CursorIcon::NotAllowed)), None),
|
||||
@@ -120,11 +122,19 @@ pub(crate) fn end_pass(ctx: &Context) {
|
||||
match won {
|
||||
Some(Cursor::System(icon)) => output::set_cursor(ctx, icon),
|
||||
Some(Cursor::Painted(PaintedCursor::Badged { base, .. })) => output::set_cursor(ctx, base),
|
||||
Some(_) if !hides => output::set_cursor(ctx, CursorIcon::Default),
|
||||
Some(_) => output::set_cursor(ctx, CursorIcon::None),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a painted cursor shows in place of the system pointer: only where the shell sets the system cursor
|
||||
/// ([`Caps::SYSTEM_CURSOR`]). A host without it (Wayland with no cursor theme, where a hidden pointer never comes
|
||||
/// back) keeps the system pointer, and no painted cursor is drawn or handed to the window.
|
||||
pub(crate) fn paints(ctx: &Context) -> bool {
|
||||
windows::base_shell(ctx).caps.contains(Caps::SYSTEM_CURSOR)
|
||||
}
|
||||
|
||||
/// Whether the pointer lies in the resize areas of `viewport`'s window where the OS resizes it from its own frame
|
||||
/// (`windows::os_resizes`).
|
||||
fn over_os_resize_area(ctx: &Context, viewport: ViewportId) -> bool {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! one at its size, and is painted at the pointer otherwise.
|
||||
|
||||
use craft_behavior::{CountMark, Cursor, CursorBadge, CursorIcon, CursorPriority, IconId, PaintedCursor, PointerGlyph};
|
||||
use craft_host::target::{Backend, Os, Runtime, ShellInfo};
|
||||
use craft_host::target::{Backend, Caps, Os, Runtime, ShellInfo};
|
||||
use craft_ui::runtime::cursor;
|
||||
use craft_ui::testing::pointer::moved;
|
||||
use craft_ui::testing::{Frames, install_spec, trial};
|
||||
@@ -159,6 +159,26 @@ fn a_painted_pointer_is_the_window_cursor_image_where_the_window_takes_one() {
|
||||
assert!(hidden.image.is_none() && hidden.shapes == 0 && hidden.icon == egui::CursorIcon::None);
|
||||
}
|
||||
|
||||
/// Sa-9 (4): a shell that cannot set the system cursor (Wayland with no cursor theme, where a hidden pointer never
|
||||
/// comes back) keeps the system pointer under every painted cursor and paints none, in the main window and another.
|
||||
#[trial]
|
||||
fn a_shell_that_cannot_set_the_system_cursor_keeps_the_system_pointer() {
|
||||
let wayland = linux().backend(Backend::Wayland);
|
||||
let without = wayland.clone().caps(wayland.caps.difference(Caps::SYSTEM_CURSOR));
|
||||
for cursor in [PaintedCursor::circle(20.0), PaintedCursor::circle(300.0), PaintedCursor::Hand, PaintedCursor::Hidden] {
|
||||
let mut with = frames(wayland.clone(), 1.25);
|
||||
let seen = painted(&mut with, cursor.clone());
|
||||
assert_eq!(seen.icon, egui::CursorIcon::None, "{cursor:?}: with the system cursor the painted one stands in for it");
|
||||
|
||||
let mut kept = frames(without.clone(), 1.0);
|
||||
for viewport in [ViewportId::ROOT, ViewportId::from_hash_of("child window")] {
|
||||
let seen = frame_in(&mut kept, viewport, &[(Cursor::Painted(cursor.clone()), CursorPriority::Tool)]);
|
||||
assert_ne!(seen.icon, egui::CursorIcon::None, "{cursor:?} in {viewport:?}: the system pointer stays");
|
||||
assert!(seen.image.is_none() && seen.shapes == 0, "{cursor:?} in {viewport:?}: no tool cursor is drawn");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A tool icon rides below and right of its pointer: beside the plain pointer, the image's marks reach as far left and up
|
||||
/// from the hotspot (the arrow's tip, the crosshair's centre) and farther right and down; an icon the catalog lacks
|
||||
/// leaves the plain pointer.
|
||||
|
||||
Reference in New Issue
Block a user