Move Backend definition

This commit is contained in:
Ottatop 2023-10-02 14:06:39 -05:00
parent 8eeca5cc76
commit acd846f5bc
5 changed files with 41 additions and 37 deletions

View file

@ -28,13 +28,46 @@ use smithay::{
}; };
use crate::{ use crate::{
state::{Backend, State, SurfaceDmabufFeedback}, state::{State, SurfaceDmabufFeedback},
window::WindowElement, window::WindowElement,
}; };
use self::{udev::Udev, winit::Winit};
pub mod udev; pub mod udev;
pub mod winit; pub mod winit;
pub enum Backend {
/// The compositor is running in a Winit window
Winit(Winit),
/// The compositor is running in a tty
Udev(Udev),
}
impl Backend {
pub fn seat_name(&self) -> String {
match self {
Backend::Winit(winit) => winit.seat_name(),
Backend::Udev(udev) => udev.seat_name(),
}
}
pub fn early_import(&mut self, surface: &WlSurface) {
match self {
Backend::Winit(winit) => winit.early_import(surface),
Backend::Udev(udev) => udev.early_import(surface),
}
}
/// Returns `true` if the backend is [`Winit`].
///
/// [`Winit`]: Backend::Winit
#[must_use]
pub fn is_winit(&self) -> bool {
matches!(self, Self::Winit(..))
}
}
/// A trait defining common methods for each available backend: winit and tty-udev /// A trait defining common methods for each available backend: winit and tty-udev
pub trait BackendData: 'static { pub trait BackendData: 'static {
fn seat_name(&self) -> String; fn seat_name(&self) -> String;

View file

@ -88,13 +88,14 @@ use smithay_drm_extras::{
}; };
use crate::{ use crate::{
backend::Backend,
config::{ config::{
api::msg::{Args, OutgoingMsg}, api::msg::{Args, OutgoingMsg},
ConnectorSavedState, ConnectorSavedState,
}, },
output::OutputName, output::OutputName,
render::{pointer::PointerElement, take_presentation_feedback, CustomRenderElements}, render::{pointer::PointerElement, take_presentation_feedback, CustomRenderElements},
state::{Backend, CalloopData, State, SurfaceDmabufFeedback, WithState}, state::{CalloopData, State, SurfaceDmabufFeedback, WithState},
window::WindowElement, window::WindowElement,
}; };

View file

@ -35,11 +35,11 @@ use smithay::{
use crate::{ use crate::{
render::{pointer::PointerElement, take_presentation_feedback}, render::{pointer::PointerElement, take_presentation_feedback},
state::{Backend, CalloopData, State, WithState}, state::{CalloopData, State, WithState},
window::WindowElement, window::WindowElement,
}; };
use super::BackendData; use super::{Backend, BackendData};
pub struct Winit { pub struct Winit {
pub backend: WinitGraphicsBackend<GlesRenderer>, pub backend: WinitGraphicsBackend<GlesRenderer>,

View file

@ -3,9 +3,10 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::{ use crate::{
backend::Backend,
config::api::msg::{CallbackId, Modifier, ModifierMask, MouseEdge, OutgoingMsg}, config::api::msg::{CallbackId, Modifier, ModifierMask, MouseEdge, OutgoingMsg},
focus::FocusTarget, focus::FocusTarget,
state::{Backend, WithState}, state::WithState,
window::WindowElement, window::WindowElement,
}; };
use smithay::{ use smithay::{

View file

@ -5,7 +5,7 @@ mod api_handlers;
use std::{cell::RefCell, os::fd::AsRawFd, sync::Arc, time::Duration}; use std::{cell::RefCell, os::fd::AsRawFd, sync::Arc, time::Duration};
use crate::{ use crate::{
backend::{udev::Udev, winit::Winit, BackendData}, backend::Backend,
config::{ config::{
api::{msg::Msg, ApiState}, api::{msg::Msg, ApiState},
Config, Config,
@ -48,37 +48,6 @@ use smithay::{
use crate::input::InputState; use crate::input::InputState;
pub enum Backend {
/// The compositor is running in a Winit window
Winit(Winit),
/// The compositor is running in a tty
Udev(Udev),
}
impl Backend {
pub fn seat_name(&self) -> String {
match self {
Backend::Winit(winit) => winit.seat_name(),
Backend::Udev(udev) => udev.seat_name(),
}
}
pub fn early_import(&mut self, surface: &WlSurface) {
match self {
Backend::Winit(winit) => winit.early_import(surface),
Backend::Udev(udev) => udev.early_import(surface),
}
}
/// Returns `true` if the backend is [`Winit`].
///
/// [`Winit`]: Backend::Winit
#[must_use]
pub fn is_winit(&self) -> bool {
matches!(self, Self::Winit(..))
}
}
/// The main state of the application. /// The main state of the application.
pub struct State { pub struct State {
/// Which backend is currently running /// Which backend is currently running