From acf9fd122f05f85ac04eea7df42ce3c5c92d6b1c Mon Sep 17 00:00:00 2001 From: Naman Agrawal Date: Mon, 1 Sep 2025 10:57:24 +0530 Subject: [PATCH] feat: Add basic support for foreign top level management. - Allow users to minimize other applications by sending a `ForeignToplevelEvent`. --- Cargo.lock | 1 + Cargo.toml | 1 + examples/foreign_toplevel.rs | 122 ++++++++++++++++++++++++++++++++ src/foreign_toplevel_manager.rs | 96 +++++++++++++++++++++++++ src/lib.rs | 3 +- 5 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 examples/foreign_toplevel.rs create mode 100644 src/foreign_toplevel_manager.rs diff --git a/Cargo.lock b/Cargo.lock index 1e6152c..90e5f08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1101,6 +1101,7 @@ dependencies = [ "raw-window-handle", "smithay-client-toolkit 0.20.0", "wayland-backend", + "wayland-protocols-wlr", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 514d734..c31619d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,4 @@ lazy_static = "1.5.0" raw-window-handle = "0.6.2" smithay-client-toolkit = "0.20.0" wayland-backend = { version = "0.3.11", features = ["client_system"] } +wayland-protocols-wlr = "0.3.9" diff --git a/examples/foreign_toplevel.rs b/examples/foreign_toplevel.rs new file mode 100644 index 0000000..a375225 --- /dev/null +++ b/examples/foreign_toplevel.rs @@ -0,0 +1,122 @@ +use bevy::{color::palettes::basic::*, prelude::*, window::WindowResolution, winit::WinitPlugin}; +use bevy_wayland::{foreign_toplevel_manager::ForeignToplevelEvent, prelude::*}; + +const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15); +const HOVERED_BUTTON: Color = Color::srgb(0.25, 0.25, 0.25); +const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35); + +fn main() { + App::new() + .add_plugins(( + DefaultPlugins + .build() + .disable::() + .set(WindowPlugin { + primary_window: Some(Window { + resolution: WindowResolution::new(400.0, 400.0), + present_mode: bevy::window::PresentMode::AutoVsync, + ..Default::default() + }), + ..Default::default() + }), + WaylandPlugin, + )) + .add_systems(Startup, setup) + .add_systems(Update, (button_system, exit_on_esc)) + .run(); +} + +#[allow(clippy::type_complexity)] +fn button_system( + mut interaction_query: Query< + ( + &Interaction, + &mut BackgroundColor, + &mut BorderColor, + &Children, + ), + (Changed, With