input: Only use common state
This commit is contained in:
parent
c413bb8052
commit
ef9e3d3c7c
3 changed files with 53 additions and 65 deletions
|
|
@ -101,7 +101,6 @@ impl X11State {
|
|||
{
|
||||
if let Err(err) = surface.render_output(
|
||||
&mut *x11_state.renderer.borrow_mut(),
|
||||
&output_ref,
|
||||
&mut state.common,
|
||||
) {
|
||||
slog_scope::error!("Error rendering: {}", err);
|
||||
|
|
@ -140,7 +139,6 @@ impl Surface {
|
|||
pub fn render_output(
|
||||
&mut self,
|
||||
renderer: &mut Gles2Renderer,
|
||||
output: &Output,
|
||||
state: &mut Common,
|
||||
) -> Result<()> {
|
||||
#[allow(unused_mut)]
|
||||
|
|
@ -148,7 +146,7 @@ impl Surface {
|
|||
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
let space = state.spaces.active_space(output);
|
||||
let space = state.spaces.active_space(&self.output);
|
||||
let size = space.output_geometry(&self.output).unwrap();
|
||||
let scale = space.output_scale(&self.output).unwrap();
|
||||
let frame = debug_ui(state, &self.fps, size, scale, true);
|
||||
|
|
@ -157,7 +155,7 @@ impl Surface {
|
|||
);
|
||||
}
|
||||
|
||||
let space = state.spaces.active_space_mut(output);
|
||||
let space = state.spaces.active_space_mut(&self.output);
|
||||
let (buffer, age) = self
|
||||
.surface
|
||||
.buffer()
|
||||
|
|
@ -347,6 +345,6 @@ impl State {
|
|||
_ => {}
|
||||
};
|
||||
|
||||
self.process_input_event(event);
|
||||
self.common.process_input_event(event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::state::State;
|
||||
use crate::state::Common;
|
||||
use smithay::{
|
||||
backend::input::{Device, DeviceCapability, InputBackend, InputEvent},
|
||||
desktop::{layer_map_for_output, Space},
|
||||
|
|
@ -91,13 +91,12 @@ pub fn add_seat(display: &mut Display, name: String) -> Seat {
|
|||
seat
|
||||
}
|
||||
|
||||
pub fn active_output(seat: &Seat, state: &State) -> Output {
|
||||
pub fn active_output(seat: &Seat, state: &Common) -> Output {
|
||||
seat.user_data()
|
||||
.get::<ActiveOutput>()
|
||||
.map(|x| x.0.borrow().clone())
|
||||
.unwrap_or_else(|| {
|
||||
state
|
||||
.common
|
||||
.spaces
|
||||
.outputs()
|
||||
.next()
|
||||
|
|
@ -120,13 +119,13 @@ pub fn set_active_output(seat: &Seat, output: &Output) {
|
|||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
impl Common {
|
||||
pub fn process_input_event<B: InputBackend>(&mut self, event: InputEvent<B>) {
|
||||
use smithay::backend::input::Event;
|
||||
|
||||
match event {
|
||||
InputEvent::DeviceAdded { device } => {
|
||||
let seat = &mut self.common.last_active_seat;
|
||||
let seat = &mut self.last_active_seat;
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
for cap in devices.add_device(&device) {
|
||||
|
|
@ -142,7 +141,6 @@ impl State {
|
|||
}
|
||||
DeviceCapability::Pointer => {
|
||||
let output = self
|
||||
.common
|
||||
.spaces
|
||||
.outputs()
|
||||
.next()
|
||||
|
|
@ -168,7 +166,7 @@ impl State {
|
|||
}
|
||||
}
|
||||
InputEvent::DeviceRemoved { device } => {
|
||||
for seat in &mut self.common.seats {
|
||||
for seat in &mut self.seats {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
|
|
@ -195,7 +193,7 @@ impl State {
|
|||
use smithay::backend::input::KeyboardKeyEvent;
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.seats.clone().iter() {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
|
|
@ -218,23 +216,23 @@ impl State {
|
|||
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
self.common.egui.modifiers = modifiers.clone();
|
||||
if self.common.seats.iter().position(|x| x == seat).unwrap()
|
||||
self.egui.modifiers = modifiers.clone();
|
||||
if self.seats.iter().position(|x| x == seat).unwrap()
|
||||
== 0
|
||||
&& modifiers.logo
|
||||
&& handle.raw_syms().contains(&keysyms::KEY_Escape)
|
||||
&& state == KeyState::Pressed
|
||||
{
|
||||
self.common.egui.active = !self.common.egui.active;
|
||||
self.egui.active = !self.egui.active;
|
||||
userdata.get::<SupressedKeys>().unwrap().add(&handle);
|
||||
return FilterResult::Intercept(());
|
||||
}
|
||||
if self.common.seats.iter().position(|x| x == seat).unwrap()
|
||||
if self.seats.iter().position(|x| x == seat).unwrap()
|
||||
== 0
|
||||
&& self.common.egui.active
|
||||
&& self.common.egui.state.wants_keyboard()
|
||||
&& self.egui.active
|
||||
&& self.egui.state.wants_keyboard()
|
||||
{
|
||||
self.common.egui.state.handle_keyboard(
|
||||
self.egui.state.handle_keyboard(
|
||||
&handle,
|
||||
state == KeyState::Pressed,
|
||||
modifiers.clone(),
|
||||
|
|
@ -255,7 +253,7 @@ impl State {
|
|||
use smithay::backend::input::PointerMotionEvent;
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.seats.clone().iter() {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
|
|
@ -265,12 +263,10 @@ impl State {
|
|||
position += event.delta();
|
||||
|
||||
let output = self
|
||||
.common
|
||||
.spaces
|
||||
.outputs()
|
||||
.find(|output| {
|
||||
self.common
|
||||
.spaces
|
||||
self.spaces
|
||||
.output_geometry(output)
|
||||
.to_f64()
|
||||
.contains(position)
|
||||
|
|
@ -280,7 +276,7 @@ impl State {
|
|||
if output != current_output {
|
||||
set_active_output(seat, &output);
|
||||
}
|
||||
let output_geometry = self.common.spaces.output_geometry(&output);
|
||||
let output_geometry = self.spaces.output_geometry(&output);
|
||||
|
||||
position.x = 0.0f64
|
||||
.max(position.x)
|
||||
|
|
@ -290,17 +286,16 @@ impl State {
|
|||
.min((output_geometry.loc.y + output_geometry.size.h) as f64);
|
||||
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
let space = self.common.spaces.active_space_mut(&output);
|
||||
let under = State::surface_under(position, &output, space);
|
||||
let space = self.spaces.active_space_mut(&output);
|
||||
let under = Common::surface_under(position, &output, space);
|
||||
handle_window_movement(under.as_ref().map(|(s, _)| s), space);
|
||||
seat.get_pointer()
|
||||
.unwrap()
|
||||
.motion(position, under, serial, event.time());
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
if self.common.seats.iter().position(|x| x == seat).unwrap() == 0 {
|
||||
self.common
|
||||
.egui
|
||||
if self.seats.iter().position(|x| x == seat).unwrap() == 0 {
|
||||
self.egui
|
||||
.state
|
||||
.handle_pointer_motion(position.to_i32_round());
|
||||
}
|
||||
|
|
@ -312,26 +307,25 @@ impl State {
|
|||
use smithay::backend::input::PointerMotionAbsoluteEvent;
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.seats.clone().iter() {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
let output = active_output(seat, &self);
|
||||
let geometry = self.common.spaces.output_geometry(&output);
|
||||
let space = self.common.spaces.active_space_mut(&output);
|
||||
let geometry = self.spaces.output_geometry(&output);
|
||||
let space = self.spaces.active_space_mut(&output);
|
||||
let position =
|
||||
geometry.loc.to_f64() + event.position_transformed(geometry.size);
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
let under = State::surface_under(position, &output, space);
|
||||
let under = Common::surface_under(position, &output, space);
|
||||
handle_window_movement(under.as_ref().map(|(s, _)| s), space);
|
||||
seat.get_pointer()
|
||||
.unwrap()
|
||||
.motion(position, under, serial, event.time());
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
if self.common.seats.iter().position(|x| x == seat).unwrap() == 0 {
|
||||
self.common
|
||||
.egui
|
||||
if self.seats.iter().position(|x| x == seat).unwrap() == 0 {
|
||||
self.egui
|
||||
.state
|
||||
.handle_pointer_motion(position.to_i32_round());
|
||||
}
|
||||
|
|
@ -346,20 +340,20 @@ impl State {
|
|||
};
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.seats.clone().iter() {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
#[cfg(feature = "debug")]
|
||||
if self.common.seats.iter().position(|x| x == seat).unwrap() == 0
|
||||
&& self.common.egui.active
|
||||
&& self.common.egui.state.wants_pointer()
|
||||
if self.seats.iter().position(|x| x == seat).unwrap() == 0
|
||||
&& self.egui.active
|
||||
&& self.egui.state.wants_pointer()
|
||||
{
|
||||
if let Some(button) = event.button() {
|
||||
self.common.egui.state.handle_pointer_button(
|
||||
self.egui.state.handle_pointer_button(
|
||||
button,
|
||||
event.state() == ButtonState::Pressed,
|
||||
self.common.egui.modifiers.clone(),
|
||||
self.egui.modifiers.clone(),
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
|
@ -373,8 +367,8 @@ impl State {
|
|||
if !seat.get_pointer().unwrap().is_grabbed() {
|
||||
let output = active_output(seat, &self);
|
||||
let mut pos = seat.get_pointer().unwrap().current_location();
|
||||
let output_geo = self.common.spaces.output_geometry(&output);
|
||||
let space = self.common.spaces.active_space_mut(&output);
|
||||
let output_geo = self.spaces.output_geometry(&output);
|
||||
let space = self.spaces.active_space_mut(&output);
|
||||
let layers = layer_map_for_output(&output);
|
||||
pos -= output_geo.loc.to_f64();
|
||||
let mut under = None;
|
||||
|
|
@ -433,13 +427,13 @@ impl State {
|
|||
};
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.seats.clone().iter() {
|
||||
#[cfg(feature = "debug")]
|
||||
if self.common.seats.iter().position(|x| x == seat).unwrap() == 0
|
||||
&& self.common.egui.active
|
||||
&& self.common.egui.state.wants_pointer()
|
||||
if self.seats.iter().position(|x| x == seat).unwrap() == 0
|
||||
&& self.egui.active
|
||||
&& self.egui.state.wants_pointer()
|
||||
{
|
||||
self.common.egui.state.handle_pointer_axis(
|
||||
self.egui.state.handle_pointer_axis(
|
||||
event
|
||||
.amount_discrete(Axis::Horizontal)
|
||||
.or_else(|| event.amount(Axis::Horizontal).map(|x| x * 3.0))
|
||||
|
|
|
|||
|
|
@ -51,22 +51,21 @@ pub fn init_shell(display: &mut Display) -> ShellStates {
|
|||
let (xdg_shell_state, _xdg_global) = xdg_shell_init(
|
||||
display,
|
||||
|event, mut ddata| {
|
||||
let state = ddata.get::<State>().unwrap();
|
||||
let state = &mut ddata.get::<State>().unwrap().common;
|
||||
|
||||
match event {
|
||||
XdgRequest::NewToplevel { surface } => {
|
||||
state.common.pending_toplevels.push(surface.clone());
|
||||
state.pending_toplevels.push(surface.clone());
|
||||
|
||||
let seat = &state.common.last_active_seat;
|
||||
let output = active_output(seat, &state);
|
||||
let space = state.common.spaces.active_space_mut(&output);
|
||||
let seat = &state.last_active_seat;
|
||||
let output = active_output(seat, &*state);
|
||||
let space = state.spaces.active_space_mut(&output);
|
||||
let window = Window::new(Kind::Xdg(surface));
|
||||
space.map_window(&window, (0, 0), true);
|
||||
// We will position the window after the first commit, when we know its size
|
||||
}
|
||||
XdgRequest::NewPopup { surface, .. } => {
|
||||
state
|
||||
.common
|
||||
.shell
|
||||
.popups
|
||||
.track_popup(PopupKind::from(surface))
|
||||
|
|
@ -101,7 +100,6 @@ pub fn init_shell(display: &mut Display) -> ShellStates {
|
|||
check_grab_preconditions(&seat, surface.get_surface(), serial)
|
||||
{
|
||||
let space = state
|
||||
.common
|
||||
.spaces
|
||||
.space_for_surface(surface.get_surface().unwrap())
|
||||
.unwrap();
|
||||
|
|
@ -164,7 +162,6 @@ pub fn init_shell(display: &mut Display) -> ShellStates {
|
|||
check_grab_preconditions(&seat, surface.get_surface(), serial)
|
||||
{
|
||||
let space = state
|
||||
.common
|
||||
.spaces
|
||||
.space_for_surface(surface.get_surface().unwrap())
|
||||
.unwrap();
|
||||
|
|
@ -185,7 +182,6 @@ pub fn init_shell(display: &mut Display) -> ShellStates {
|
|||
configure: Configure::Toplevel(configure),
|
||||
} => {
|
||||
if let Some(window) = state
|
||||
.common
|
||||
.spaces
|
||||
.space_for_surface(&surface)
|
||||
.and_then(|space| space.window_for_surface(&surface))
|
||||
|
|
@ -194,9 +190,9 @@ pub fn init_shell(display: &mut Display) -> ShellStates {
|
|||
}
|
||||
}
|
||||
XdgRequest::Maximize { surface } => {
|
||||
let seat = &state.common.last_active_seat;
|
||||
let output = active_output(seat, &state);
|
||||
let space = state.common.spaces.active_space_mut(&output);
|
||||
let seat = &state.last_active_seat;
|
||||
let output = active_output(seat, &*state);
|
||||
let space = state.spaces.active_space_mut(&output);
|
||||
let window = space
|
||||
.window_for_surface(surface.get_surface().unwrap())
|
||||
.unwrap()
|
||||
|
|
@ -239,12 +235,12 @@ pub fn init_shell(display: &mut Display) -> ShellStates {
|
|||
namespace,
|
||||
..
|
||||
} => {
|
||||
let state = ddata.get::<State>().unwrap();
|
||||
let seat = &state.common.last_active_seat;
|
||||
let state = &mut ddata.get::<State>().unwrap().common;
|
||||
let seat = &state.last_active_seat;
|
||||
let output = wl_output
|
||||
.as_ref()
|
||||
.and_then(Output::from_resource)
|
||||
.unwrap_or_else(|| active_output(seat, &state));
|
||||
.unwrap_or_else(|| active_output(seat, &*state));
|
||||
|
||||
let mut map = layer_map_for_output(&output);
|
||||
map.map_layer(&LayerSurface::new(surface, namespace))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue