4
41
Fork
You've already forked tinyrwm
16

rust: don't panic on useless FocusNext #16

Merged
ifreund merged 1 commit from cattail/tinyrwm:rust-empty-rotate into main 2026年07月01日 17:05:13 +02:00
Contributor
Copy link

If Super+n is triggered while the Rust window manager is not managing any windows (for example, if it's the first keyboard shortcut triggered after startup), the window manager will crash. While it does seem silly to try to change the window focus when there aren't any windows, probably useful to do a small bit of work to prevent this. :)

This was my exact stack trace, for anyone curious:

debug(input): matched xkb binding
debug(wm): manage sequence start
thread 'main' (18005) panicked at library/alloc/src/collections/vec_deque/mod.rs:2992:9:
assertion failed: n <= self.len()
stack backtrace:
 0: __rustc::rust_begin_unwind
 at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/std/src/panicking.rs:689:5
 1: core::panicking::panic_fmt
 at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/core/src/panicking.rs:80:14
 2: core::panicking::panic
 at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/core/src/panicking.rs:150:5
 3: alloc::collections::vec_deque::VecDeque<T,A>::rotate_left
 at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/alloc/src/collections/vec_deque/mod.rs:2992:9
 4: tinyrwm::Seat::do_action
 at ./src/main.rs:427:29
 5: tinyrwm::WindowManager::manage_seats
 at ./src/main.rs:314:18
 6: tinyrwm::WindowManager::handle_manage_start
 at ./src/main.rs:150:14
 7: <tinyrwm::AppData as wayland_client::event_queue::Dispatch<tinyrwm::river::river_window_manager_v1::RiverWindowManagerV1,()>>::event
 at ./src/main.rs:612:26
 8: wayland_client::event_queue::queue_callback
 at /home/xxx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wayland-client-0.31.14/src/event_queue.rs:660:5
 9: wayland_client::event_queue::EventQueue<State>::dispatching_impl
 at /home/xxx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wayland-client-0.31.14/src/event_queue.rs:482:13
 10: wayland_client::event_queue::EventQueue<State>::dispatch_pending
 at /home/xxx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wayland-client-0.31.14/src/event_queue.rs:388:9
 11: wayland_client::event_queue::EventQueue<State>::blocking_dispatch
 at /home/xxx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wayland-client-0.31.14/src/event_queue.rs:410:14
 12: tinyrwm::main
 at ./src/main.rs:805:21
 13: core::ops::function::FnOnce::call_once
 at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
If `Super`+`n` is triggered while the Rust window manager is not managing any windows (for example, if it's the first keyboard shortcut triggered after startup), the window manager will crash. While it does seem silly to try to change the window focus when there aren't any windows, probably useful to do a small bit of work to prevent this. :) This was my exact stack trace, for anyone curious: ``` debug(input): matched xkb binding debug(wm): manage sequence start thread 'main' (18005) panicked at library/alloc/src/collections/vec_deque/mod.rs:2992:9: assertion failed: n <= self.len() stack backtrace: 0: __rustc::rust_begin_unwind at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/std/src/panicking.rs:689:5 1: core::panicking::panic_fmt at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/core/src/panicking.rs:80:14 2: core::panicking::panic at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/core/src/panicking.rs:150:5 3: alloc::collections::vec_deque::VecDeque<T,A>::rotate_left at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/alloc/src/collections/vec_deque/mod.rs:2992:9 4: tinyrwm::Seat::do_action at ./src/main.rs:427:29 5: tinyrwm::WindowManager::manage_seats at ./src/main.rs:314:18 6: tinyrwm::WindowManager::handle_manage_start at ./src/main.rs:150:14 7: <tinyrwm::AppData as wayland_client::event_queue::Dispatch<tinyrwm::river::river_window_manager_v1::RiverWindowManagerV1,()>>::event at ./src/main.rs:612:26 8: wayland_client::event_queue::queue_callback at /home/xxx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wayland-client-0.31.14/src/event_queue.rs:660:5 9: wayland_client::event_queue::EventQueue<State>::dispatching_impl at /home/xxx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wayland-client-0.31.14/src/event_queue.rs:482:13 10: wayland_client::event_queue::EventQueue<State>::dispatch_pending at /home/xxx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wayland-client-0.31.14/src/event_queue.rs:388:9 11: wayland_client::event_queue::EventQueue<State>::blocking_dispatch at /home/xxx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wayland-client-0.31.14/src/event_queue.rs:410:14 12: tinyrwm::main at ./src/main.rs:805:21 13: core::ops::function::FnOnce::call_once at /builddir/build/BUILD/rust-1.96.0-build/rustc-1.96.0-src/library/core/src/ops/function.rs:250:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```
rust: don't panic on useless FocusNext
All checks were successful
builds.sr.ht/alpine Job completed
builds.sr.ht/archlinux Job completed
b7ebb0c097
https://doc.rust-lang.org/std/vec/struct.Vec.html#method.rotate_left
> This function will panic if `mid` is greater than the length of
> the slice.
If `FocusNext` is triggered while the window manager is not managing
any windows, the window manager will crash. Silly, but not ideal.
ifreund left a comment
Copy link

Thanks for the fix!

Thanks for the fix!
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
river/tinyrwm!16
Reference in a new issue
river/tinyrwm
No description provided.
Delete branch "cattail/tinyrwm:rust-empty-rotate"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?