mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
Merge fix/close-app-windows: close the focused window on Alt+F4 and let the Servo hosts exit without crashing (#22)
This commit is contained in:
commit
3577b3ee1a
7 changed files with 106 additions and 3 deletions
|
|
@ -431,6 +431,19 @@ impl App {
|
|||
}
|
||||
|
||||
impl ApplicationHandler<ServoWake> for App {
|
||||
/// Releases everything that holds Wayland objects of winit's display
|
||||
/// (Servo, the rendering context, whose software and EGL paths keep
|
||||
/// their own proxies on it, the shell protocol client and the window)
|
||||
/// while that display is still connected; dropped after the event loop,
|
||||
/// they would be destroyed on a display that is gone. A panic unwinding
|
||||
/// out of a handler skips this.
|
||||
fn exiting(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
self.shut_down();
|
||||
self.rendering_context = None;
|
||||
self.shell_client = None;
|
||||
self.window = None;
|
||||
}
|
||||
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
if self.window.is_some() {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -48,14 +48,35 @@ fn handle_keyboard<B: InputBackend>(state: &mut WeftCompositorState, event: B::K
|
|||
let key_state = event.state();
|
||||
|
||||
if let Some(keyboard) = state.seat.get_keyboard() {
|
||||
keyboard.input::<(), _>(
|
||||
// Alt+F4 belongs to the compositor: it asks the focused application
|
||||
// window to close, and the key never reaches a client.
|
||||
let close = keyboard.input::<bool, _>(
|
||||
state,
|
||||
event.key_code(),
|
||||
key_state,
|
||||
serial,
|
||||
time,
|
||||
|_state, _mods, _keysym| FilterResult::Forward,
|
||||
|state, mods, keysym| {
|
||||
// A release is taken only when its press was, so no client
|
||||
// sees half of a key.
|
||||
let code = keysym.raw_code().raw();
|
||||
if key_state == smithay::backend::input::KeyState::Pressed {
|
||||
if mods.alt
|
||||
&& keysym.modified_sym() == smithay::input::keyboard::keysyms::KEY_F4.into()
|
||||
{
|
||||
state.suppressed_keys.push(code);
|
||||
return FilterResult::Intercept(true);
|
||||
}
|
||||
} else if let Some(i) = state.suppressed_keys.iter().position(|&k| k == code) {
|
||||
state.suppressed_keys.remove(i);
|
||||
return FilterResult::Intercept(false);
|
||||
}
|
||||
FilterResult::Forward
|
||||
},
|
||||
);
|
||||
if close == Some(true) {
|
||||
state.close_focused_window();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,6 +98,9 @@ pub struct WeftCompositorState {
|
|||
pub loop_signal: LoopSignal,
|
||||
pub loop_handle: LoopHandle<'static, WeftCompositorState>,
|
||||
pub gesture_state: GestureState,
|
||||
/// Keycodes whose press a compositor shortcut took, so their release is
|
||||
/// taken as well and no client sees half of a key.
|
||||
pub suppressed_keys: Vec<u32>,
|
||||
|
||||
pub compositor_state: CompositorState,
|
||||
pub xdg_shell_state: XdgShellState,
|
||||
|
|
@ -196,6 +199,7 @@ impl WeftCompositorState {
|
|||
dmabuf_global: None,
|
||||
running: true,
|
||||
gesture_state: GestureState::default(),
|
||||
suppressed_keys: Vec::new(),
|
||||
#[cfg(unix)]
|
||||
appd_ipc: None,
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
|
|||
|
|
@ -58,6 +58,31 @@ impl WeftCompositorState {
|
|||
}
|
||||
}
|
||||
|
||||
/// Asks the focused application window to close. Its client decides
|
||||
/// how to end; for an app shell that ends the session. The panel is not
|
||||
/// closed this way.
|
||||
pub fn close_focused_window(&mut self) {
|
||||
let Some(focus) = self
|
||||
.seat
|
||||
.get_keyboard()
|
||||
.and_then(|keyboard| keyboard.current_focus())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if self.is_panel_surface(&focus) {
|
||||
return;
|
||||
}
|
||||
let window = self
|
||||
.space
|
||||
.elements()
|
||||
.find(|window| window.wl_surface().is_some_and(|s| *s == focus))
|
||||
.cloned();
|
||||
if let Some(toplevel) = window.as_ref().and_then(|w| w.toplevel()) {
|
||||
tracing::info!(session = ?window.as_ref().and_then(window_session), "closing the focused window");
|
||||
toplevel.send_close();
|
||||
}
|
||||
}
|
||||
|
||||
/// Activates the topmost window of `session_id`; returns whether the
|
||||
/// session has one.
|
||||
pub fn activate_session(&mut self, session_id: u64) -> bool {
|
||||
|
|
|
|||
|
|
@ -346,6 +346,19 @@ impl App {
|
|||
}
|
||||
|
||||
impl ApplicationHandler<ServoWake> for App {
|
||||
/// Releases everything that holds Wayland objects of winit's display
|
||||
/// (Servo, the rendering context, whose software and EGL paths keep
|
||||
/// their own proxies on it, the shell protocol client and the window)
|
||||
/// while that display is still connected; dropped after the event loop,
|
||||
/// they would be destroyed on a display that is gone. A panic unwinding
|
||||
/// out of a handler skips this.
|
||||
fn exiting(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
self.shut_down();
|
||||
self.rendering_context = None;
|
||||
self.shell_client = None;
|
||||
self.window = None;
|
||||
}
|
||||
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
if self.window.is_some() {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ WEFT OS is a Wayland compositor and application runtime where every app is a Web
|
|||
|
||||
### weft-compositor
|
||||
|
||||
Smithay-based Wayland compositor. Implements the `zweft-shell-unstable-v1` protocol extension, which allows shell clients (servo-shell, app-shell) to register their surfaces as typed shell slots. Each application session's Wayland connection is handed to the compositor by weft-appd, which binds the client to that session (see `security.md`). The compositor owns stacking and focus: the system shell's panel is sized to the output and starts beneath application windows, and clicking it brings it to the front as the shell's home, with its launcher, until an application is activated or opens its first window; layout changes keep the stacking order, and a window that maps without taking focus goes beneath the window in front; a session's first window, a clicked window and an activated one are raised, marked activated and given keyboard focus, and when the focused window closes the topmost remaining application window gets focus. A session's later windows are shown without taking focus. The panel reserves a strip along an output edge for the taskbar with `set_exclusive_zone` (weft-servo-shell reserves 48 logical pixels at the bottom), and the compositor lays every application window out to fill the remaining work area. weft-appd's `ACTIVATE_APP` request, which the taskbar sends, asks the compositor to activate a running session's window. Supports DRM/KMS and winit (software/dev) backends.
|
||||
Smithay-based Wayland compositor. Implements the `zweft-shell-unstable-v1` protocol extension, which allows shell clients (servo-shell, app-shell) to register their surfaces as typed shell slots. Each application session's Wayland connection is handed to the compositor by weft-appd, which binds the client to that session (see `security.md`). The compositor owns stacking and focus: the system shell's panel is sized to the output and starts beneath application windows, and clicking it brings it to the front as the shell's home, with its launcher, until an application is activated or opens its first window; layout changes keep the stacking order, and a window that maps without taking focus goes beneath the window in front; a session's first window, a clicked window and an activated one are raised, marked activated and given keyboard focus, and when the focused window closes the topmost remaining application window gets focus. Alt+F4 is the compositor's: it asks the focused application window to close (never the panel), and the app shell then exits and its session ends. A session's later windows are shown without taking focus. The panel reserves a strip along an output edge for the taskbar with `set_exclusive_zone` (weft-servo-shell reserves 48 logical pixels at the bottom), and the compositor lays every application window out to fill the remaining work area. weft-appd's `ACTIVATE_APP` request, which the taskbar sends, asks the compositor to activate a running session's window. Supports DRM/KMS and winit (software/dev) backends.
|
||||
|
||||
### weft-servo-shell
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ colour and a lighter shade on every key press. In the presented pixels:
|
|||
- clicking the taskbar strip brings the panel, the shell's home, over the
|
||||
applications, and activating an application brings it back;
|
||||
- when the focused application ends, the remaining one gets keyboard focus;
|
||||
- Alt+F4 asks the focused application window to close; its app shell exits
|
||||
cleanly and the session ends; Alt+F4 does not close the shell's panel;
|
||||
- ACTIVATE_APP for a session that is not running is refused.
|
||||
|
||||
The applications are unsigned test packages, recorded as development content
|
||||
|
|
@ -209,6 +211,31 @@ def run(args, desktop, store, home):
|
|||
key("a")
|
||||
shown(red)
|
||||
|
||||
# Alt+F4 closes the focused application window, which ends its session;
|
||||
# with the panel focused, it closes nothing.
|
||||
key("alt+F4")
|
||||
try:
|
||||
appd.wait_for(lambda m: m.get("type") == "APP_STATE" and m.get("state") == "stopped"
|
||||
and m.get("session_id") == sessions[red], 20)
|
||||
except TimeoutError:
|
||||
raise AssertionError("Alt+F4 did not end the focused application's session")
|
||||
# The app shell ended by closing, with exit status 0, not by a crash.
|
||||
clean = (f'stopping session session_id={sessions[red]} '
|
||||
'reason="app shell exited (Ok(ExitStatus(unix_wait_status(0))))"')
|
||||
if clean not in desktop.log_text("appd"):
|
||||
raise AssertionError("the closed app shell did not exit cleanly; see appd.log")
|
||||
deadline = time.monotonic() + 20
|
||||
while any(area(desktop.capture(), c)[0] is not None for cs in APPS.values() for c in cs):
|
||||
if time.monotonic() > deadline:
|
||||
raise AssertionError("the closed application is still shown")
|
||||
time.sleep(0.3)
|
||||
key("alt+F4")
|
||||
deadline = time.monotonic() + 6
|
||||
while time.monotonic() < deadline:
|
||||
if area(desktop.capture(), GREEN)[0] != panel:
|
||||
raise AssertionError("Alt+F4 closed or moved the shell's panel")
|
||||
time.sleep(0.5)
|
||||
|
||||
appd.send({"type": "ACTIVATE_APP", "session_id": 999})
|
||||
reply = appd.wait_for(lambda m: m.get("type") == "ERROR", 10)
|
||||
if reply.get("code") != 404:
|
||||
|
|
|
|||
Loading…
Reference in a new issue