bugfix: keyboard input was causing the application to crash.
This commit is contained in:
@@ -6,7 +6,7 @@ use bevy::{
|
||||
window::{WindowCreated, WindowResolution},
|
||||
winit::WinitPlugin,
|
||||
};
|
||||
use bevy_wayland::{layer_shell::LayerShellSettings, WaylandPlugin};
|
||||
use bevy_wayland::{input_region::InputRegion, 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);
|
||||
@@ -30,7 +30,10 @@ fn main() {
|
||||
))
|
||||
.init_resource::<NewWindowInfo>()
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, (button_system, setup_new_window, spawn_window))
|
||||
.add_systems(
|
||||
Update,
|
||||
(button_system, spawn_window, setup_new_window, exit_on_esc),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
@@ -75,11 +78,11 @@ fn setup(mut commands: Commands, assets: Res<AssetServer>, windows: Query<Entity
|
||||
for entity in &windows {
|
||||
commands.entity(entity).insert((
|
||||
LayerShellSettings {
|
||||
anchor: Anchor::all(),
|
||||
anchor: Anchor::TOP | Anchor::LEFT,
|
||||
layer: Layer::Bottom,
|
||||
..Default::default()
|
||||
},
|
||||
WindowTimer(Timer::new(Duration::from_secs(5), TimerMode::Once)),
|
||||
InputRegion(Rect::new(0., 0., 200., 200.)),
|
||||
));
|
||||
}
|
||||
// ui camera
|
||||
@@ -87,36 +90,39 @@ fn setup(mut commands: Commands, assets: Res<AssetServer>, windows: Query<Entity
|
||||
commands.spawn(button(&assets));
|
||||
}
|
||||
|
||||
fn exit_on_esc(keys: Res<ButtonInput<KeyCode>>) {
|
||||
if keys.just_pressed(KeyCode::Escape) {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_window(
|
||||
mut commands: Commands,
|
||||
mut windows: Query<(Entity, &mut WindowTimer)>,
|
||||
mut new_window_info: ResMut<NewWindowInfo>,
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
for (entity, mut timer) in &mut windows {
|
||||
timer.tick(time.delta());
|
||||
if keys.pressed(KeyCode::KeyN) {
|
||||
println!("Pressed");
|
||||
let new_window_entity = commands
|
||||
.spawn((
|
||||
Window {
|
||||
title: "UI Only Window".to_string(),
|
||||
resolution: (400., 50.).into(),
|
||||
..default()
|
||||
},
|
||||
LayerShellSettings {
|
||||
layer: Layer::Top,
|
||||
anchor: Anchor::TOP | Anchor::LEFT,
|
||||
..default()
|
||||
},
|
||||
WindowTimer(Timer::new(Duration::from_secs(5), TimerMode::Once)),
|
||||
))
|
||||
.id();
|
||||
|
||||
if timer.finished() {
|
||||
commands.entity(entity).remove::<WindowTimer>();
|
||||
let new_window_entity = commands
|
||||
.spawn((
|
||||
Window {
|
||||
title: "UI Only Window".to_string(),
|
||||
resolution: (400., 50.).into(),
|
||||
..default()
|
||||
},
|
||||
LayerShellSettings {
|
||||
layer: Layer::Top,
|
||||
anchor: Anchor::TOP | Anchor::LEFT,
|
||||
..default()
|
||||
},
|
||||
WindowTimer(Timer::new(Duration::from_secs(5), TimerMode::Once)),
|
||||
))
|
||||
.id();
|
||||
|
||||
new_window_info.entity = Some(new_window_entity);
|
||||
new_window_info.is_setup_pending = true;
|
||||
}
|
||||
new_window_info.entity = Some(new_window_entity);
|
||||
new_window_info.is_setup_pending = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -409,6 +409,7 @@ impl KeyboardHandler for WaylandState {
|
||||
let active_window_entity = **self.world().resource::<ActiveWindow>();
|
||||
let keyboard_event =
|
||||
convert_keyboard_event(event, active_window_entity, ButtonState::Pressed);
|
||||
self.world_mut().send_event(keyboard_event.clone());
|
||||
self.world_mut()
|
||||
.send_event(WindowEvent::KeyboardInput(keyboard_event));
|
||||
}
|
||||
@@ -425,6 +426,7 @@ impl KeyboardHandler for WaylandState {
|
||||
let mut keyboard_event =
|
||||
convert_keyboard_event(event, active_window_entity, ButtonState::Pressed);
|
||||
keyboard_event.repeat = true;
|
||||
self.world_mut().send_event(keyboard_event.clone());
|
||||
self.world_mut()
|
||||
.send_event(WindowEvent::KeyboardInput(keyboard_event));
|
||||
}
|
||||
@@ -440,6 +442,7 @@ impl KeyboardHandler for WaylandState {
|
||||
let active_window_entity = **self.world().resource::<ActiveWindow>();
|
||||
let keyboard_event =
|
||||
convert_keyboard_event(event, active_window_entity, ButtonState::Released);
|
||||
self.world_mut().send_event(keyboard_event.clone());
|
||||
self.world_mut()
|
||||
.send_event(WindowEvent::KeyboardInput(keyboard_event));
|
||||
}
|
||||
@@ -454,7 +457,6 @@ impl KeyboardHandler for WaylandState {
|
||||
_raw_modifiers: smithay_client_toolkit::seat::keyboard::RawModifiers,
|
||||
_layout: u32,
|
||||
) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
delegate_keyboard!(WaylandState);
|
||||
|
||||
@@ -47,11 +47,11 @@ impl SeatHandler for WaylandState {
|
||||
capability: smithay_client_toolkit::seat::Capability,
|
||||
) {
|
||||
if capability == Capability::Keyboard {
|
||||
//let mut seat_state = self.world_mut().non_send_resource_mut::<SeatState>();
|
||||
//let wl_keyboard = seat_state
|
||||
// .get_keyboard(qh, &seat, None)
|
||||
// .expect("error while attaching keyboard!");
|
||||
//self.world_mut().insert_non_send_resource(wl_keyboard);
|
||||
let mut seat_state = self.world_mut().non_send_resource_mut::<SeatState>();
|
||||
let wl_keyboard = seat_state
|
||||
.get_keyboard(qh, &seat, None)
|
||||
.expect("error while attaching keyboard!");
|
||||
self.world_mut().insert_non_send_resource(wl_keyboard);
|
||||
info!("Keyboard Attached");
|
||||
}
|
||||
if capability == Capability::Pointer {
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ use smithay_client_toolkit::{
|
||||
use crate::{input_region, surface_handler::WaylandSurfaces, WaylandState};
|
||||
|
||||
#[derive(Component, Deref)]
|
||||
pub struct InputRegion(Rect);
|
||||
pub struct InputRegion(pub Rect);
|
||||
|
||||
pub struct InputRegionPlugin;
|
||||
impl Plugin for InputRegionPlugin {
|
||||
@@ -27,7 +27,7 @@ fn update_input_region(
|
||||
let region = Region::new(compositor.as_ref()).unwrap();
|
||||
region.add(
|
||||
input_region.min.x as i32,
|
||||
input_region.max.y as i32,
|
||||
input_region.min.y as i32,
|
||||
input_region.width() as i32,
|
||||
input_region.height() as i32,
|
||||
);
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
use bevy::{platform::collections::HashMap, prelude::*, ui::update};
|
||||
use smithay_client_toolkit::{
|
||||
delegate_layer,
|
||||
reexports::client::{globals::GlobalList, Proxy, QueueHandle},
|
||||
reexports::client::{globals::GlobalList, Connection, Proxy, QueueHandle},
|
||||
shell::{
|
||||
wlr_layer::{
|
||||
Anchor, KeyboardInteractivity, Layer, LayerShell, LayerShellHandler, LayerSurface,
|
||||
@@ -43,7 +43,7 @@ impl LayerShellWindow {
|
||||
.set_exclusive_zone(self.layer_shell_settings.exclusive_zone);
|
||||
|
||||
let (width, height) = self.layer_shell_settings.size;
|
||||
self.layer_surface.set_size(width, height);
|
||||
self.layer_surface.set_size(400, 400);
|
||||
|
||||
let (top, right, bottom, left) = self.layer_shell_settings.margin;
|
||||
self.layer_surface.set_margin(top, right, bottom, left);
|
||||
@@ -95,7 +95,7 @@ impl Default for LayerShellSettings {
|
||||
size: Default::default(),
|
||||
exclusive_zone: Default::default(),
|
||||
margin: Default::default(),
|
||||
keyboard_interactivity: Default::default(),
|
||||
keyboard_interactivity: KeyboardInteractivity::OnDemand,
|
||||
layer: Layer::Top,
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -60,11 +60,10 @@ pub fn runner(mut app: App, mut event_loop: EventLoop<'_, WaylandState>) -> AppE
|
||||
let mut state = WaylandState(app);
|
||||
loop {
|
||||
// TODO: Error handling
|
||||
let _ = event_loop.dispatch(None, &mut state);
|
||||
|
||||
if state.plugins_state() == PluginsState::Cleaned {
|
||||
state.update();
|
||||
}
|
||||
let _ = event_loop.dispatch(None, &mut state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user