mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
wip: forward wheel input to Servo in both hosts
Untested: the servo-embed build has not completed since this change. Pointer-leave forwarding is not yet done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QS8QcxvhVJwU3X2qhPamUW
This commit is contained in:
parent
2418cb636a
commit
b465215f54
6 changed files with 102 additions and 15 deletions
|
|
@ -7,7 +7,7 @@ use servo::{
|
||||||
DeviceIntRect, DeviceIntSize, DevicePoint, EventLoopWaker, InputEvent, LoadStatus,
|
DeviceIntRect, DeviceIntSize, DevicePoint, EventLoopWaker, InputEvent, LoadStatus,
|
||||||
MouseButton as ServoMouseButton, MouseButtonAction, MouseButtonEvent, MouseMoveEvent,
|
MouseButton as ServoMouseButton, MouseButtonAction, MouseButtonEvent, MouseMoveEvent,
|
||||||
NavigationRequest, RenderingContext, RgbaImage, ServoBuilder, ServoDelegate, ServoUrl,
|
NavigationRequest, RenderingContext, RgbaImage, ServoBuilder, ServoDelegate, ServoUrl,
|
||||||
UserContentManager, UserScript, WebViewBuilder, WebViewDelegate,
|
UserContentManager, UserScript, WebViewBuilder, WebViewDelegate, WheelEvent,
|
||||||
};
|
};
|
||||||
use winit::{
|
use winit::{
|
||||||
application::ApplicationHandler,
|
application::ApplicationHandler,
|
||||||
|
|
@ -695,6 +695,15 @@ impl ApplicationHandler<ServoWake> for App {
|
||||||
.notify_input_event(InputEvent::MouseMove(MouseMoveEvent::new(pt.into())));
|
.notify_input_event(InputEvent::MouseMove(MouseMoveEvent::new(pt.into())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
WindowEvent::MouseWheel { delta, .. } => {
|
||||||
|
if let Some(wv) = &self.webview {
|
||||||
|
let delta = super::keyutils::wheel_delta_from_winit(delta);
|
||||||
|
let _ = wv.notify_input_event(InputEvent::Wheel(WheelEvent::new(
|
||||||
|
delta,
|
||||||
|
self.cursor_pos.into(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
WindowEvent::MouseInput { state, button, .. } => {
|
WindowEvent::MouseInput { state, button, .. } => {
|
||||||
let btn = match button {
|
let btn = match button {
|
||||||
MouseButton::Left => ServoMouseButton::Left,
|
MouseButton::Left => ServoMouseButton::Left,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,26 @@
|
||||||
use servo::{Code, Key, KeyState, KeyboardEvent, Location, Modifiers};
|
use servo::{Code, Key, KeyState, KeyboardEvent, Location, Modifiers, WheelDelta, WheelMode};
|
||||||
use winit::event::ElementState;
|
use winit::event::{ElementState, MouseScrollDelta};
|
||||||
use winit::keyboard::{Key as WinitKey, KeyLocation, ModifiersState, NamedKey, PhysicalKey};
|
use winit::keyboard::{Key as WinitKey, KeyLocation, ModifiersState, NamedKey, PhysicalKey};
|
||||||
|
|
||||||
|
/// Pixels scrolled per wheel notch, the step servoshell uses.
|
||||||
|
const WHEEL_LINE: f64 = 76.0;
|
||||||
|
|
||||||
|
/// The wheel delta for Servo from a winit scroll, which Servo turns into a
|
||||||
|
/// `wheel` event and, unless the page cancels it, scrolls the content under
|
||||||
|
/// the pointer. A notch counts as `WHEEL_LINE` pixels.
|
||||||
|
pub fn wheel_delta_from_winit(delta: MouseScrollDelta) -> WheelDelta {
|
||||||
|
let (x, y) = match delta {
|
||||||
|
MouseScrollDelta::LineDelta(x, y) => (f64::from(x) * WHEEL_LINE, f64::from(y) * WHEEL_LINE),
|
||||||
|
MouseScrollDelta::PixelDelta(position) => (position.x, position.y),
|
||||||
|
};
|
||||||
|
WheelDelta {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z: 0.0,
|
||||||
|
mode: WheelMode::DeltaPixel,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn keyboard_event_from_winit(
|
pub fn keyboard_event_from_winit(
|
||||||
event: &winit::event::KeyEvent,
|
event: &winit::event::KeyEvent,
|
||||||
modifiers: ModifiersState,
|
modifiers: ModifiersState,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use servo::{
|
||||||
DeviceIntRect, DeviceIntSize, DevicePoint, EventLoopWaker, InputEvent,
|
DeviceIntRect, DeviceIntSize, DevicePoint, EventLoopWaker, InputEvent,
|
||||||
MouseButton as ServoMouseButton, MouseButtonAction, MouseButtonEvent, MouseMoveEvent,
|
MouseButton as ServoMouseButton, MouseButtonAction, MouseButtonEvent, MouseMoveEvent,
|
||||||
NavigationRequest, RenderingContext, RgbaImage, ServoBuilder, ServoDelegate, ServoUrl,
|
NavigationRequest, RenderingContext, RgbaImage, ServoBuilder, ServoDelegate, ServoUrl,
|
||||||
UserContentManager, UserScript, WebViewBuilder, WebViewDelegate,
|
UserContentManager, UserScript, WebViewBuilder, WebViewDelegate, WheelEvent,
|
||||||
};
|
};
|
||||||
use winit::{
|
use winit::{
|
||||||
application::ApplicationHandler,
|
application::ApplicationHandler,
|
||||||
|
|
@ -525,6 +525,15 @@ impl ApplicationHandler<ServoWake> for App {
|
||||||
.notify_input_event(InputEvent::MouseMove(MouseMoveEvent::new(pt.into())));
|
.notify_input_event(InputEvent::MouseMove(MouseMoveEvent::new(pt.into())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
WindowEvent::MouseWheel { delta, .. } => {
|
||||||
|
if let Some(wv) = &self.webview {
|
||||||
|
let delta = super::keyutils::wheel_delta_from_winit(delta);
|
||||||
|
let _ = wv.notify_input_event(InputEvent::Wheel(WheelEvent::new(
|
||||||
|
delta,
|
||||||
|
self.cursor_pos.into(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
WindowEvent::MouseInput { state, button, .. } => {
|
WindowEvent::MouseInput { state, button, .. } => {
|
||||||
let btn = match button {
|
let btn = match button {
|
||||||
MouseButton::Left => ServoMouseButton::Left,
|
MouseButton::Left => ServoMouseButton::Left,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,26 @@
|
||||||
use servo::{Code, Key, KeyState, KeyboardEvent, Location, Modifiers};
|
use servo::{Code, Key, KeyState, KeyboardEvent, Location, Modifiers, WheelDelta, WheelMode};
|
||||||
use winit::event::ElementState;
|
use winit::event::{ElementState, MouseScrollDelta};
|
||||||
use winit::keyboard::{Key as WinitKey, KeyLocation, ModifiersState, NamedKey, PhysicalKey};
|
use winit::keyboard::{Key as WinitKey, KeyLocation, ModifiersState, NamedKey, PhysicalKey};
|
||||||
|
|
||||||
|
/// Pixels scrolled per wheel notch, the step servoshell uses.
|
||||||
|
const WHEEL_LINE: f64 = 76.0;
|
||||||
|
|
||||||
|
/// The wheel delta for Servo from a winit scroll, which Servo turns into a
|
||||||
|
/// `wheel` event and, unless the page cancels it, scrolls the content under
|
||||||
|
/// the pointer. A notch counts as `WHEEL_LINE` pixels.
|
||||||
|
pub fn wheel_delta_from_winit(delta: MouseScrollDelta) -> WheelDelta {
|
||||||
|
let (x, y) = match delta {
|
||||||
|
MouseScrollDelta::LineDelta(x, y) => (f64::from(x) * WHEEL_LINE, f64::from(y) * WHEEL_LINE),
|
||||||
|
MouseScrollDelta::PixelDelta(position) => (position.x, position.y),
|
||||||
|
};
|
||||||
|
WheelDelta {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z: 0.0,
|
||||||
|
mode: WheelMode::DeltaPixel,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn keyboard_event_from_winit(
|
pub fn keyboard_event_from_winit(
|
||||||
event: &winit::event::KeyEvent,
|
event: &winit::event::KeyEvent,
|
||||||
modifiers: ModifiersState,
|
modifiers: ModifiersState,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""Check that native pointer and keyboard input reaches a page through weft-compositor.
|
"""Check that native pointer and keyboard input reaches a page through weft-compositor.
|
||||||
|
|
||||||
The harness runs weft-servo-shell with `input.html` on a nested desktop (see
|
The harness runs a Servo host with `input.html` on a nested desktop (see
|
||||||
session.py) and injects real X input into the compositor's window with
|
session.py) and injects real X input into the compositor's window with
|
||||||
xdotool (after giving that window X input focus, since Xvfb runs without a
|
xdotool (after giving that window X input focus, since Xvfb runs without a
|
||||||
window manager), which weft-compositor's winit backend receives and routes to
|
window manager), which weft-compositor's winit backend receives and routes to
|
||||||
|
|
@ -12,10 +12,16 @@ defines, as seen in the presented pixels:
|
||||||
2. Typing `a` turns the right half yellow.
|
2. Typing `a` turns the right half yellow.
|
||||||
3. Typing `Shift+a` turns the right half magenta, which checks the modifier.
|
3. Typing `Shift+a` turns the right half magenta, which checks the modifier.
|
||||||
4. A click 6 px inside the right half's left edge turns the right half white.
|
4. A click 6 px inside the right half's left edge turns the right half white.
|
||||||
|
5. Wheel notches down over the left half scroll it to the cyan block beneath,
|
||||||
|
so no green remains; notches up scroll it back to green.
|
||||||
|
|
||||||
The two clicks straddle the boundary between the halves, so a pointer
|
The two clicks straddle the boundary between the halves, so a pointer
|
||||||
position that is scaled or offset by more than a few pixels fails.
|
position that is scaled or offset by more than a few pixels fails.
|
||||||
|
|
||||||
|
`--host system` (the default) runs weft-servo-shell with the page as its
|
||||||
|
system UI; `--host app` runs weft-app-shell with the page as an
|
||||||
|
application's UI document, as check_frame.py does.
|
||||||
|
|
||||||
Requires Xvfb, xwd, ImageMagick's convert and xdotool.
|
Requires Xvfb, xwd, ImageMagick's convert and xdotool.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -27,12 +33,16 @@ import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
sys.dont_write_bytecode = True
|
sys.dont_write_bytecode = True
|
||||||
|
from check_frame import APP_ID, app_ui # noqa: E402
|
||||||
from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402
|
from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
HERE = Path(__file__).resolve().parent
|
HERE = Path(__file__).resolve().parent
|
||||||
RED, GREEN, BLUE = (255, 0, 0), (0, 255, 0), (0, 0, 255)
|
RED, GREEN, BLUE = (255, 0, 0), (0, 255, 0), (0, 0, 255)
|
||||||
WHITE, YELLOW, MAGENTA = (255, 255, 255), (255, 255, 0), (255, 0, 255)
|
WHITE, YELLOW, MAGENTA = (255, 255, 255), (255, 255, 0), (255, 0, 255)
|
||||||
|
CYAN = (0, 255, 255)
|
||||||
|
# More notches than the pane needs to reach either end.
|
||||||
|
WHEEL_NOTCHES = "30"
|
||||||
MIN_SIDE = 40
|
MIN_SIDE = 40
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -73,9 +83,9 @@ class Steps:
|
||||||
subprocess.run([self.xdotool_path, *arguments], env={"DISPLAY": self.desktop.display},
|
subprocess.run([self.xdotool_path, *arguments], env={"DISPLAY": self.desktop.display},
|
||||||
check=True, timeout=20)
|
check=True, timeout=20)
|
||||||
|
|
||||||
def click(self, x, y):
|
def click(self, x, y, button="1", repeat="1"):
|
||||||
self.xdotool("mousemove", "--sync", str(x), str(y))
|
self.xdotool("mousemove", "--sync", str(x), str(y))
|
||||||
self.xdotool("click", "1")
|
self.xdotool("click", "--repeat", repeat, "--delay", "30", button)
|
||||||
|
|
||||||
|
|
||||||
def run(steps):
|
def run(steps):
|
||||||
|
|
@ -95,19 +105,31 @@ def run(steps):
|
||||||
steps.click(right[0] + EDGE_INSET, middle)
|
steps.click(right[0] + EDGE_INSET, middle)
|
||||||
steps.expect("click near the left edge of the right half", [GREEN, WHITE],
|
steps.expect("click near the left edge of the right half", [GREEN, WHITE],
|
||||||
absent=[MAGENTA, RED])
|
absent=[MAGENTA, RED])
|
||||||
|
# X buttons 5 and 4 are wheel notches down and up.
|
||||||
|
centre = (left[0] + left[2]) // 2
|
||||||
|
steps.click(centre, middle, button="5", repeat=WHEEL_NOTCHES)
|
||||||
|
steps.expect("wheel down over the left half", [CYAN, WHITE], absent=[GREEN])
|
||||||
|
steps.click(centre, middle, button="4", repeat=WHEEL_NOTCHES)
|
||||||
|
steps.expect("wheel up over the left half", [GREEN, WHITE], absent=[CYAN])
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
parser = argparse.ArgumentParser(description=__doc__,
|
parser = argparse.ArgumentParser(description=__doc__,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
parser.add_argument("--compositor", type=Path, default=ROOT / "target/debug/weft-compositor")
|
parser.add_argument("--compositor", type=Path, default=ROOT / "target/debug/weft-compositor")
|
||||||
parser.add_argument("--shell", type=Path, default=ROOT / "target/debug/weft-servo-shell")
|
parser.add_argument("--host", choices=("system", "app"), default="system")
|
||||||
|
parser.add_argument("--shell", type=Path,
|
||||||
|
help="host binary (default: target/debug/weft-servo-shell or "
|
||||||
|
"target/debug/weft-app-shell)")
|
||||||
parser.add_argument("--page", type=Path, default=HERE / "input.html")
|
parser.add_argument("--page", type=Path, default=HERE / "input.html")
|
||||||
parser.add_argument("--timeout", type=float, default=30.0,
|
parser.add_argument("--timeout", type=float, default=30.0,
|
||||||
help="seconds to wait for each expected page state")
|
help="seconds to wait for each expected page state")
|
||||||
parser.add_argument("--output", type=Path, default=ROOT / "target/input-check",
|
parser.add_argument("--output", type=Path, default=ROOT / "target/input-check",
|
||||||
help="directory for logs and the last capture")
|
help="directory for logs and the last capture")
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
if args.shell is None:
|
||||||
|
name = "weft-servo-shell" if args.host == "system" else "weft-app-shell"
|
||||||
|
args.shell = ROOT / "target/debug" / name
|
||||||
|
|
||||||
missing = missing_tools() + [tool for tool in ("xdotool",) if shutil.which(tool) is None]
|
missing = missing_tools() + [tool for tool in ("xdotool",) if shutil.which(tool) is None]
|
||||||
missing += [str(b) for b in (args.compositor, args.shell) if not b.is_file()]
|
missing += [str(b) for b in (args.compositor, args.shell) if not b.is_file()]
|
||||||
|
|
@ -117,8 +139,13 @@ def main(argv=None):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with Desktop(args.compositor, args.output, outputs=["input.ppm"]) as desktop:
|
with Desktop(args.compositor, args.output, outputs=["input.ppm"]) as desktop:
|
||||||
shell = desktop.launch_client("shell", [args.shell],
|
if args.host == "system":
|
||||||
{"WEFT_SYSTEM_UI_HTML": str(args.page.resolve())})
|
shell = desktop.launch_client(
|
||||||
|
"shell", [args.shell], {"WEFT_SYSTEM_UI_HTML": str(args.page.resolve())})
|
||||||
|
else:
|
||||||
|
entry = app_ui(desktop.runtime / APP_ID, args.page)
|
||||||
|
shell = desktop.launch_client(
|
||||||
|
"shell", [args.shell, APP_ID, "1", "--ui", str(entry)])
|
||||||
steps = Steps(desktop, shell, args.timeout)
|
steps = Steps(desktop, shell, args.timeout)
|
||||||
try:
|
try:
|
||||||
run(steps)
|
run(steps)
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,17 @@
|
||||||
<title>WEFT input reference</title>
|
<title>WEFT input reference</title>
|
||||||
<style>
|
<style>
|
||||||
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
|
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
|
||||||
body { display: grid; grid-template-columns: 1fr 1fr; }
|
body { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 100vh; }
|
||||||
#left { background: rgb(255, 0, 0); }
|
/* The left half scrolls: its colour fills the half, and a cyan block of
|
||||||
|
the same height lies beneath it, reached with the wheel. */
|
||||||
|
#pane { overflow-y: scroll; }
|
||||||
|
#left { height: 100vh; background: rgb(255, 0, 0); }
|
||||||
|
#below { height: 100vh; background: rgb(0, 255, 255); }
|
||||||
#right { background: rgb(0, 0, 255); }
|
#right { background: rgb(0, 0, 255); }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="left"></div>
|
<div id="pane"><div id="left"></div><div id="below"></div></div>
|
||||||
<div id="right"></div>
|
<div id="right"></div>
|
||||||
<script>
|
<script>
|
||||||
// Each input the harness sends changes one half to a colour it checks for.
|
// Each input the harness sends changes one half to a colour it checks for.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue