mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-13 12:23:38 +01:00
feat(e2e): give the macOS test window a class by its accessibility subrole
--class was accepted and ignored on macOS, so the scenarios that match a window by a class could not run. The test window now sets its accessibility subrole to the class (NSWindow setAccessibilitySubrole), and the host passes the app id of spawn as --class.
This commit is contained in:
1 parent
1849547153
commit
bb3c986f26
4 files changed
+15
-2
No files matched your search
@@ -23,6 +23,9 @@ objc2-app-kit = { version = "0.3", default-features = false, features = [
|
||||
"NSScreen",
|
||||
"NSGraphics",
|
||||
"NSEvent",
|
||||
"NSAccessibility",
|
||||
"NSAccessibilityConstants",
|
||||
"NSAccessibilityProtocols",
|
||||
"NSRunningApplication",
|
||||
"objc2-core-foundation",
|
||||
"libc",
|
||||
|
||||
@@ -15,6 +15,7 @@ use std::time::Instant;
|
||||
use objc2::MainThreadMarker;
|
||||
use objc2::MainThreadOnly;
|
||||
use objc2::rc::Retained;
|
||||
use objc2_app_kit::NSAccessibility;
|
||||
use objc2_app_kit::NSApplication;
|
||||
use objc2_app_kit::NSApplicationActivationPolicy;
|
||||
use objc2_app_kit::NSBackingStoreType;
|
||||
@@ -154,6 +155,11 @@ pub fn run(options: cli::Options) {
|
||||
// SAFETY: this program owns the window, so a close does not release it a second time.
|
||||
unsafe { window.setReleasedWhenClosed(false) };
|
||||
window.setTitle(&NSString::from_str(&options.title));
|
||||
if let Some(class) = &options.class {
|
||||
// a macOS window has no class: the daemon takes the accessibility subrole of a window for
|
||||
// it, which a program is free to name as it likes
|
||||
window.setAccessibilitySubrole(Some(&NSString::from_str(class)));
|
||||
}
|
||||
if let Some(rgb) = options.color {
|
||||
window.setBackgroundColor(Some(&color(rgb)));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ pub struct Options {
|
||||
pub title: String,
|
||||
/// The size of the window, in pixels (points on macOS).
|
||||
pub size: (i32, i32),
|
||||
/// The window class on Windows; no other platform has one, and ignores it.
|
||||
/// The window class on Windows; on macOS, which has none, the accessibility subrole of the
|
||||
/// window, which is what the daemon takes for one; no other platform has one, and ignores it.
|
||||
pub class: Option<String>,
|
||||
/// `0xRRGGBB`.
|
||||
pub color: Option<u32>,
|
||||
|
||||
@@ -254,8 +254,11 @@ class MacosPlatform:
|
||||
rename_to: str | None = None,
|
||||
after: float = 0,
|
||||
) -> Client:
|
||||
# `app_id` is a window class, which a macOS window does not have: it is not passed
|
||||
args = ["--title", title]
|
||||
if app_id is not None:
|
||||
# a macOS window has no class: the daemon takes its accessibility subrole for one, which
|
||||
# the test window is given as this
|
||||
args += ["--class", app_id]
|
||||
if rename_to is not None:
|
||||
# the window gives itself this title `after` seconds from now
|
||||
args += ["--rename-to", rename_to, "--after", str(after)]
|
||||
|
||||
Reference in new issue
Block a user