From b368d43531948c02f766cebcc1f11a68988d7e98 Mon Sep 17 00:00:00 2001 From: Naman Agrawal Date: Fri, 22 Aug 2025 15:52:48 +0530 Subject: [PATCH] feat: keyboard input and input region --- .gitignore | 1 + examples/layer_shell_window.rs | 186 ++++++++++++- src/input_handler.rs | 62 ----- src/input_handler/keyboard.rs | 460 +++++++++++++++++++++++++++++++++ src/input_handler/mod.rs | 98 +++++++ src/input_handler/pointer.rs | 108 ++++++++ src/input_region.rs | 44 ++++ src/layer_shell.rs | 136 ++++++++-- src/lib.rs | 6 +- src/surface_handler.rs | 8 +- 10 files changed, 1020 insertions(+), 89 deletions(-) delete mode 100644 src/input_handler.rs create mode 100644 src/input_handler/keyboard.rs create mode 100644 src/input_handler/mod.rs create mode 100644 src/input_handler/pointer.rs create mode 100644 src/input_region.rs diff --git a/.gitignore b/.gitignore index ad67955..276b8cc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # will have compiled files and executables debug target +logs.txt # These are backup files generated by rustfmt **/*.rs.bk diff --git a/examples/layer_shell_window.rs b/examples/layer_shell_window.rs index d3b1567..aa2ec7d 100644 --- a/examples/layer_shell_window.rs +++ b/examples/layer_shell_window.rs @@ -1,18 +1,192 @@ -use bevy::{prelude::*, winit::WinitPlugin}; -use bevy_wayland::{layer_shell::LayerShellWindow, WaylandPlugin}; +use std::time::Duration; + +use bevy::{ + color::palettes::basic::*, + prelude::*, + window::{WindowCreated, WindowResolution}, + winit::WinitPlugin, +}; +use bevy_wayland::{layer_shell::LayerShellSettings, WaylandPlugin}; +use smithay_client_toolkit::shell::wlr_layer::{Anchor, Layer}; + +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::(), + DefaultPlugins + .build() + .disable::() + .set(WindowPlugin { + primary_window: Some(Window { + resolution: WindowResolution::new(400.0, 400.0), + ..Default::default() + }), + ..Default::default() + }), WaylandPlugin, )) + .init_resource::() .add_systems(Startup, setup) + .add_systems(Update, (button_system, setup_new_window, spawn_window)) .run(); } -fn setup(mut commands: Commands, windows: Query>) { - for entity in &windows { - commands.entity(entity).insert(LayerShellWindow::default()); +#[allow(clippy::type_complexity)] +fn button_system( + mut interaction_query: Query< + ( + &Interaction, + &mut BackgroundColor, + &mut BorderColor, + &Children, + ), + (Changed, With