mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
fix(compositor): show the shell on a Super key tap
From an application window there was no keyboard path to the system shell: only a pointer click on the taskbar strip raised the panel. The Super keys now belong to the compositor and are never delivered to an application. A tap, Super pressed and released without another key, activates the shell's panel, raising it with keyboard focus, and then delivers the tap to it so the shell can open its launcher; a key or a pointer button pressed meanwhile makes it no tap. Keys pressed while Super is held reach the focused window with the Super modifier: a client is sent the modifiers whenever a key the compositor takes changes them, so none stays held there. With several panels, the first registered one is the shell's.
This commit is contained in:
parent
d8e9b5a87a
commit
72dda72432
4 changed files with 126 additions and 38 deletions
|
|
@ -6,7 +6,7 @@ use smithay::{
|
||||||
TouchEvent,
|
TouchEvent,
|
||||||
},
|
},
|
||||||
input::{
|
input::{
|
||||||
keyboard::FilterResult,
|
keyboard::{FilterResult, KeyboardTarget},
|
||||||
pointer::{AxisFrame, ButtonEvent, MotionEvent},
|
pointer::{AxisFrame, ButtonEvent, MotionEvent},
|
||||||
},
|
},
|
||||||
utils::{Logical, Point, SERIAL_COUNTER},
|
utils::{Logical, Point, SERIAL_COUNTER},
|
||||||
|
|
@ -42,41 +42,97 @@ pub fn process_input_event<B: InputBackend>(state: &mut WeftCompositorState, eve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What the compositor does with a key instead of forwarding it.
|
||||||
|
enum Shortcut {
|
||||||
|
/// Alt+F4: close the focused application window.
|
||||||
|
Close,
|
||||||
|
/// A Super key tap: show the shell.
|
||||||
|
Shell,
|
||||||
|
/// Nothing: a suppressed key.
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_keyboard<B: InputBackend>(state: &mut WeftCompositorState, event: B::KeyboardKeyEvent) {
|
fn handle_keyboard<B: InputBackend>(state: &mut WeftCompositorState, event: B::KeyboardKeyEvent) {
|
||||||
|
use smithay::backend::input::KeyState;
|
||||||
|
use smithay::input::keyboard::keysyms;
|
||||||
|
|
||||||
let serial = SERIAL_COUNTER.next_serial();
|
let serial = SERIAL_COUNTER.next_serial();
|
||||||
let time = event.time_msec();
|
let time = event.time_msec();
|
||||||
let key_state = event.state();
|
let key_state = event.state();
|
||||||
|
let Some(keyboard) = state.seat.get_keyboard() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(keyboard) = state.seat.get_keyboard() {
|
// Alt+F4 and the Super keys belong to the compositor. Alt+F4 asks the
|
||||||
// Alt+F4 belongs to the compositor: it asks the focused application
|
// focused application window to close. Super's key events are never
|
||||||
// window to close, and the key never reaches a client.
|
// delivered to an application: tapped alone, without another key or a
|
||||||
let close = keyboard.input::<bool, _>(
|
// button, it brings the shell's panel to the front with keyboard focus
|
||||||
|
// and is then delivered to the shell, which opens or closes its
|
||||||
|
// launcher. Held, it still sets the Super modifier for other keys.
|
||||||
|
let (filtered, mods_changed) = keyboard.input_intercept::<_, _>(
|
||||||
|
state,
|
||||||
|
event.key_code(),
|
||||||
|
key_state,
|
||||||
|
|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();
|
||||||
|
let sym = keysym.modified_sym();
|
||||||
|
if key_state == KeyState::Pressed {
|
||||||
|
if mods.alt && sym == keysyms::KEY_F4.into() {
|
||||||
|
state.super_tap = None;
|
||||||
|
state.suppressed_keys.push(code);
|
||||||
|
return FilterResult::Intercept(Shortcut::Close);
|
||||||
|
}
|
||||||
|
if sym == keysyms::KEY_Super_L.into() || sym == keysyms::KEY_Super_R.into() {
|
||||||
|
state.super_tap = (!mods.ctrl && !mods.alt && !mods.shift).then_some(code);
|
||||||
|
state.suppressed_keys.push(code);
|
||||||
|
return FilterResult::Intercept(Shortcut::None);
|
||||||
|
}
|
||||||
|
state.super_tap = None;
|
||||||
|
} else if let Some(i) = state.suppressed_keys.iter().position(|&k| k == code) {
|
||||||
|
state.suppressed_keys.remove(i);
|
||||||
|
if state.super_tap.take() == Some(code) {
|
||||||
|
return FilterResult::Intercept(Shortcut::Shell);
|
||||||
|
}
|
||||||
|
return FilterResult::Intercept(Shortcut::None);
|
||||||
|
}
|
||||||
|
FilterResult::Forward
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let shortcut = match filtered {
|
||||||
|
FilterResult::Forward => {
|
||||||
|
keyboard.input_forward(
|
||||||
state,
|
state,
|
||||||
event.key_code(),
|
event.key_code(),
|
||||||
key_state,
|
key_state,
|
||||||
serial,
|
serial,
|
||||||
time,
|
time,
|
||||||
|state, mods, keysym| {
|
mods_changed,
|
||||||
// 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) {
|
return;
|
||||||
state.close_focused_window();
|
|
||||||
}
|
}
|
||||||
|
FilterResult::Intercept(shortcut) => shortcut,
|
||||||
|
};
|
||||||
|
// The focused client follows the modifiers even when the key that
|
||||||
|
// changed them is taken, so none stays held there.
|
||||||
|
if mods_changed && let Some(focus) = keyboard.current_focus() {
|
||||||
|
let seat = state.seat.clone();
|
||||||
|
focus.modifiers(&seat, state, keyboard.modifier_state(), serial);
|
||||||
|
}
|
||||||
|
match shortcut {
|
||||||
|
Shortcut::Close => state.close_focused_window(),
|
||||||
|
Shortcut::Shell => {
|
||||||
|
if state.activate_panel() {
|
||||||
|
// The tap itself, for the shell; the keyboard's own state
|
||||||
|
// already saw it.
|
||||||
|
let code = event.key_code();
|
||||||
|
keyboard.input_forward(state, code, KeyState::Pressed, serial, time, false);
|
||||||
|
let release = SERIAL_COUNTER.next_serial();
|
||||||
|
keyboard.input_forward(state, code, KeyState::Released, release, time, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Shortcut::None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,8 +200,10 @@ fn handle_pointer_button<B: InputBackend>(
|
||||||
let button_state = event.state();
|
let button_state = event.state();
|
||||||
|
|
||||||
// On press: activate the window under the pointer, which raises an
|
// On press: activate the window under the pointer, which raises an
|
||||||
// application window and focuses it.
|
// application window and focuses it. A held Super key is then no
|
||||||
|
// longer a tap.
|
||||||
if button_state == ButtonState::Pressed {
|
if button_state == ButtonState::Pressed {
|
||||||
|
state.super_tap = None;
|
||||||
let pointer_location = state.pointer_location;
|
let pointer_location = state.pointer_location;
|
||||||
let window = state
|
let window = state
|
||||||
.space
|
.space
|
||||||
|
|
@ -221,6 +279,7 @@ fn handle_pointer_axis<B: InputBackend>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_touch_down<B: InputBackend>(state: &mut WeftCompositorState, event: B::TouchDownEvent) {
|
fn handle_touch_down<B: InputBackend>(state: &mut WeftCompositorState, event: B::TouchDownEvent) {
|
||||||
|
state.super_tap = None;
|
||||||
let serial = SERIAL_COUNTER.next_serial();
|
let serial = SERIAL_COUNTER.next_serial();
|
||||||
let output = state.space.outputs().next().cloned();
|
let output = state.space.outputs().next().cloned();
|
||||||
if let Some(output) = output {
|
if let Some(output) = output {
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,9 @@ pub struct WeftCompositorState {
|
||||||
/// Keycodes whose press a compositor shortcut took, so their release is
|
/// Keycodes whose press a compositor shortcut took, so their release is
|
||||||
/// taken as well and no client sees half of a key.
|
/// taken as well and no client sees half of a key.
|
||||||
pub suppressed_keys: Vec<u32>,
|
pub suppressed_keys: Vec<u32>,
|
||||||
|
/// The Super key held down while no other key was pressed since; its
|
||||||
|
/// release is a tap that opens the shell.
|
||||||
|
pub super_tap: Option<u32>,
|
||||||
|
|
||||||
pub compositor_state: CompositorState,
|
pub compositor_state: CompositorState,
|
||||||
pub xdg_shell_state: XdgShellState,
|
pub xdg_shell_state: XdgShellState,
|
||||||
|
|
@ -200,6 +203,7 @@ impl WeftCompositorState {
|
||||||
running: true,
|
running: true,
|
||||||
gesture_state: GestureState::default(),
|
gesture_state: GestureState::default(),
|
||||||
suppressed_keys: Vec::new(),
|
suppressed_keys: Vec::new(),
|
||||||
|
super_tap: None,
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
appd_ipc: None,
|
appd_ipc: None,
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@
|
||||||
//! panel fills the output and starts beneath every application window;
|
//! panel fills the output and starts beneath every application window;
|
||||||
//! application windows fill the work area, the output less the strips the
|
//! application windows fill the work area, the output less the strips the
|
||||||
//! panel reserves. A session's first window, a clicked window (the panel
|
//! panel reserves. A session's first window, a clicked window (the panel
|
||||||
//! included, which then shows the shell's home over the applications) and
|
//! included, which then shows the shell's home over the applications), one
|
||||||
//! one appd asks to activate is raised to the top, marked activated and
|
//! appd asks to activate and the panel when a Super key is tapped are
|
||||||
//! given keyboard focus; apart from a panel being lowered when it
|
//! raised to the top, marked activated and given keyboard focus; apart
|
||||||
//! registers, nothing else changes the order, and a window that maps
|
//! from a panel being lowered when it registers, nothing else changes the
|
||||||
//! without taking focus goes beneath the window in front. When the
|
//! order, and a window that maps without taking focus goes beneath the
|
||||||
//! focused window closes, the topmost remaining application window gets
|
//! window in front. When the focused window closes, the topmost remaining
|
||||||
//! focus.
|
//! application window gets focus.
|
||||||
|
|
||||||
use smithay::desktop::Window;
|
use smithay::desktop::Window;
|
||||||
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
|
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
|
||||||
|
|
@ -58,6 +58,31 @@ impl WeftCompositorState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Activates the shell's panel; returns whether one is registered. With
|
||||||
|
/// several, the first registered is the shell's.
|
||||||
|
pub fn activate_panel(&mut self) -> bool {
|
||||||
|
let panel = self
|
||||||
|
.weft_shell_state
|
||||||
|
.panels()
|
||||||
|
.filter(|p| p.is_alive())
|
||||||
|
.find_map(|panel| {
|
||||||
|
let surface = panel
|
||||||
|
.data::<WeftShellWindowData>()
|
||||||
|
.and_then(|data| data.surface.clone())?;
|
||||||
|
self.space
|
||||||
|
.elements()
|
||||||
|
.find(|window| window.wl_surface().is_some_and(|s| *s == surface))
|
||||||
|
.cloned()
|
||||||
|
});
|
||||||
|
match panel {
|
||||||
|
Some(panel) => {
|
||||||
|
self.activate_window(&panel);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Asks the focused application window to close. Its client decides
|
/// 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
|
/// how to end; for an app shell that ends the session. The panel is not
|
||||||
/// closed this way.
|
/// closed this way.
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ For verified read-only package storage, `weft-pack build-image` produces an EROF
|
||||||
|
|
||||||
Each app shell is given exactly one Wayland connection, created for its session. weft-appd creates a connected socket pair, gives one end to the app shell as its standard input with `WAYLAND_SOCKET=0` and no `WAYLAND_DISPLAY`, and sends the other end to the compositor over the compositor IPC socket (`SCM_RIGHTS`) with the session ID and app ID. The compositor adds that end as a client bound to the session; the binding comes from appd holding the connection, never from an ID or process ID the client supplies. A session's `zweft_shell` windows carry the session's app ID whatever the client requests, and the shell-only `panel` and `overlay` roles are refused with a protocol error; layer-shell surfaces and the input-method interface are not offered to session clients at all. When the session ends, the compositor closes its client; when the client disconnects, the compositor reports it to appd; when appd's connection ends, the compositor closes every session client appd attached. The compositor accepts one appd connection at a time. A launch is refused (503) while appd is not connected to the compositor, rather than starting an app that could never show a window; if the compositor connection is lost before the session's connection is handed over, the session is stopped before the app shell starts. Frames for appd that its socket cannot take at once are queued and retried; a backlog beyond 4 MiB, from an appd that stopped reading, ends the connection and with it the sessions' clients.
|
Each app shell is given exactly one Wayland connection, created for its session. weft-appd creates a connected socket pair, gives one end to the app shell as its standard input with `WAYLAND_SOCKET=0` and no `WAYLAND_DISPLAY`, and sends the other end to the compositor over the compositor IPC socket (`SCM_RIGHTS`) with the session ID and app ID. The compositor adds that end as a client bound to the session; the binding comes from appd holding the connection, never from an ID or process ID the client supplies. A session's `zweft_shell` windows carry the session's app ID whatever the client requests, and the shell-only `panel` and `overlay` roles are refused with a protocol error; layer-shell surfaces and the input-method interface are not offered to session clients at all. When the session ends, the compositor closes its client; when the client disconnects, the compositor reports it to appd; when appd's connection ends, the compositor closes every session client appd attached. The compositor accepts one appd connection at a time. A launch is refused (503) while appd is not connected to the compositor, rather than starting an app that could never show a window; if the compositor connection is lost before the session's connection is handed over, the session is stopped before the app shell starts. Frames for appd that its socket cannot take at once are queued and retried; a backlog beyond 4 MiB, from an appd that stopped reading, ends the connection and with it the sessions' clients.
|
||||||
|
|
||||||
Not yet covered: the compositor IPC socket accepts any process of the user while no appd is connected, so the first connection after a restart is trusted as appd; close is not yet decided by the compositor per session; there is no user placement or resizing, since application windows fill the work area the panel leaves, one in front at a time; only the first window a session maps in its lifetime takes keyboard focus when it maps, and a client connected through the display socket takes focus on map only while no other such window is mapped; and the trusted system shell is identified only by connecting through the display socket, which any process of the user, including an app shell, can open.
|
Not yet covered: the compositor IPC socket accepts any process of the user while no appd is connected, so the first connection after a restart is trusted as appd; close is not yet decided by the compositor per session; there is no user placement or resizing, since application windows fill the work area the panel leaves, one in front at a time; only the first window a session maps in its lifetime takes keyboard focus when it maps, and a client connected through the display socket takes focus on map only while no other such window is mapped; and the trusted system shell is identified only by connecting through the display socket, which any process of the user, including an app shell, can open. Such a client registered as a panel would also be raised and focused by a Super tap; the compositor picks the first panel registered.
|
||||||
|
|
||||||
## JavaScript Engine (SpiderMonkey)
|
## JavaScript Engine (SpiderMonkey)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue