got a few low hanging fruit xdg/wl protocols out of the way
This commit is contained in:
parent
4c64d9c266
commit
219ede738e
9 changed files with 147 additions and 22 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
mod compositor;
|
mod compositor;
|
||||||
|
mod xdg_activation;
|
||||||
|
mod xdg_decoration;
|
||||||
|
mod xdg_icon;
|
||||||
mod xdg_shell;
|
mod xdg_shell;
|
||||||
|
mod xdg_system_bell;
|
||||||
|
mod xdg_tag;
|
||||||
|
|
||||||
use crate::State;
|
use crate::State;
|
||||||
|
|
||||||
|
|
|
||||||
45
src/handlers/xdg_activation.rs
Normal file
45
src/handlers/xdg_activation.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
use smithay::{desktop::WindowSurface, wayland::xdg_activation::XdgActivationHandler};
|
||||||
|
use wayland_server::protocol::wl_surface::WlSurface;
|
||||||
|
|
||||||
|
use crate::State;
|
||||||
|
use smithay::desktop::space::SpaceElement;
|
||||||
|
|
||||||
|
impl XdgActivationHandler for State {
|
||||||
|
fn activation_state(&mut self) -> &mut smithay::wayland::xdg_activation::XdgActivationState {
|
||||||
|
&mut self.xdg_activation_state
|
||||||
|
}
|
||||||
|
|
||||||
|
fn request_activation(
|
||||||
|
&mut self,
|
||||||
|
token: smithay::wayland::xdg_activation::XdgActivationToken,
|
||||||
|
token_data: smithay::wayland::xdg_activation::XdgActivationTokenData,
|
||||||
|
surface: WlSurface,
|
||||||
|
) {
|
||||||
|
let mut raised_element = None;
|
||||||
|
|
||||||
|
{
|
||||||
|
for element in self.space.elements() {
|
||||||
|
match element.underlying_surface() {
|
||||||
|
WindowSurface::Wayland(wl) => {
|
||||||
|
if *wl.wl_surface() == surface {
|
||||||
|
raised_element = Some(element);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WindowSurface::X11(x) => {
|
||||||
|
if let Some(wl_surface) = x.wl_surface() {
|
||||||
|
if wl_surface == surface {
|
||||||
|
raised_element = Some(element);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(element) = raised_element {
|
||||||
|
element.set_activate(true);
|
||||||
|
// self.space.activ(element, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/handlers/xdg_decoration.rs
Normal file
24
src/handlers/xdg_decoration.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
use crate::State;
|
||||||
|
use smithay::wayland::shell::xdg::decoration::XdgDecorationHandler;
|
||||||
|
use wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1::Mode;
|
||||||
|
|
||||||
|
impl XdgDecorationHandler for State {
|
||||||
|
fn new_decoration(&mut self, toplevel: smithay::wayland::shell::xdg::ToplevelSurface) {
|
||||||
|
println!("new_decoration");
|
||||||
|
// todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn request_mode(
|
||||||
|
&mut self,
|
||||||
|
toplevel: smithay::wayland::shell::xdg::ToplevelSurface,
|
||||||
|
mode: Mode,
|
||||||
|
) {
|
||||||
|
println!("request_mode");
|
||||||
|
// todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unset_mode(&mut self, toplevel: smithay::wayland::shell::xdg::ToplevelSurface) {
|
||||||
|
println!("unset_mode");
|
||||||
|
// todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
5
src/handlers/xdg_icon.rs
Normal file
5
src/handlers/xdg_icon.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
use smithay::wayland::xdg_toplevel_icon::XdgToplevelIconHandler;
|
||||||
|
|
||||||
|
use crate::State;
|
||||||
|
|
||||||
|
impl XdgToplevelIconHandler for State {}
|
||||||
9
src/handlers/xdg_system_bell.rs
Normal file
9
src/handlers/xdg_system_bell.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
use crate::State;
|
||||||
|
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
|
||||||
|
use smithay::wayland::xdg_system_bell::XdgSystemBellHandler;
|
||||||
|
|
||||||
|
impl XdgSystemBellHandler for State {
|
||||||
|
fn ring(&mut self, surface: Option<WlSurface>) {
|
||||||
|
println!("{:?} ringed!", surface);
|
||||||
|
}
|
||||||
|
}
|
||||||
5
src/handlers/xdg_tag.rs
Normal file
5
src/handlers/xdg_tag.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
use smithay::wayland::xdg_toplevel_tag::XdgToplevelTagHandler;
|
||||||
|
|
||||||
|
use crate::State;
|
||||||
|
|
||||||
|
impl XdgToplevelTagHandler for State {}
|
||||||
|
|
@ -8,7 +8,7 @@ mod state;
|
||||||
mod winit;
|
mod winit;
|
||||||
mod xwayland;
|
mod xwayland;
|
||||||
|
|
||||||
use smithay::reexports::{calloop::EventLoop, wayland_server::Display, winit::event_loop};
|
use smithay::reexports::{calloop::EventLoop, wayland_server::Display};
|
||||||
pub use state::State;
|
pub use state::State;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
@ -17,7 +17,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut event_loop = EventLoop::try_new()?;
|
let mut event_loop = EventLoop::try_new()?;
|
||||||
let display: Display<State> = Display::new()?;
|
let display: Display<State> = Display::new()?;
|
||||||
|
|
||||||
let mut state = State::new(display, event_loop.handle());
|
let mut state = State::new(display, event_loop.handle())?;
|
||||||
|
|
||||||
// Open a Wayland/X11 window for our nested compositor
|
// Open a Wayland/X11 window for our nested compositor
|
||||||
crate::winit::init_winit(&mut state)?;
|
crate::winit::init_winit(&mut state)?;
|
||||||
|
|
@ -53,7 +53,8 @@ fn spawn_client() {
|
||||||
// std::process::Command::new(command).spawn().ok();
|
// std::process::Command::new(command).spawn().ok();
|
||||||
// }
|
// }
|
||||||
_ => {
|
_ => {
|
||||||
std::process::Command::new("weston-terminal").spawn().ok();
|
std::process::Command::new("startmde").spawn().ok();
|
||||||
|
std::process::Command::new("konsole").spawn().ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
68
src/state.rs
68
src/state.rs
|
|
@ -1,13 +1,10 @@
|
||||||
use std::{ffi::OsString, sync::Arc, time::Duration};
|
use std::{ffi::OsString, sync::Arc};
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
|
||||||
use smithay::{
|
use smithay::{
|
||||||
desktop::{PopupManager, Space, Window, WindowSurfaceType},
|
desktop::{PopupManager, Space, Window, WindowSurfaceType},
|
||||||
input::{Seat, SeatState},
|
input::{Seat, SeatState},
|
||||||
reexports::{
|
reexports::{
|
||||||
calloop::{
|
calloop::{generic::Generic, Interest, LoopHandle, Mode, PostAction},
|
||||||
generic::Generic, EventLoop, Interest, LoopHandle, LoopSignal, Mode, PostAction,
|
|
||||||
},
|
|
||||||
wayland_server::{
|
wayland_server::{
|
||||||
backend::{ClientData, ClientId, DisconnectReason},
|
backend::{ClientData, ClientId, DisconnectReason},
|
||||||
protocol::wl_surface::WlSurface,
|
protocol::wl_surface::WlSurface,
|
||||||
|
|
@ -17,11 +14,16 @@ use smithay::{
|
||||||
utils::{Logical, Point},
|
utils::{Logical, Point},
|
||||||
wayland::{
|
wayland::{
|
||||||
compositor::{CompositorClientState, CompositorState},
|
compositor::{CompositorClientState, CompositorState},
|
||||||
|
fixes::FixesState,
|
||||||
output::OutputManagerState,
|
output::OutputManagerState,
|
||||||
selection::data_device::DataDeviceState,
|
selection::data_device::DataDeviceState,
|
||||||
shell::xdg::XdgShellState,
|
shell::xdg::{decoration::XdgDecorationState, XdgShellState},
|
||||||
shm::ShmState,
|
shm::ShmState,
|
||||||
socket::ListeningSocketSource,
|
socket::ListeningSocketSource,
|
||||||
|
xdg_activation::XdgActivationState,
|
||||||
|
xdg_system_bell::XdgSystemBellState,
|
||||||
|
xdg_toplevel_icon::XdgToplevelIconManager,
|
||||||
|
xdg_toplevel_tag::XdgToplevelTagManager,
|
||||||
xwayland_shell::XWaylandShellState,
|
xwayland_shell::XWaylandShellState,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -35,24 +37,34 @@ pub struct State {
|
||||||
|
|
||||||
pub space: Space<Window>,
|
pub space: Space<Window>,
|
||||||
pub handle: LoopHandle<'static, Self>,
|
pub handle: LoopHandle<'static, Self>,
|
||||||
// pub loop_signal: LoopSignal,
|
pub popups: PopupManager,
|
||||||
|
pub seat: Seat<Self>,
|
||||||
|
|
||||||
// Smithay State
|
// core
|
||||||
pub compositor_state: CompositorState,
|
pub compositor_state: CompositorState,
|
||||||
pub xdg_shell_state: XdgShellState,
|
|
||||||
pub shm_state: ShmState,
|
pub shm_state: ShmState,
|
||||||
pub output_manager_state: OutputManagerState,
|
|
||||||
pub seat_state: SeatState<State>,
|
pub seat_state: SeatState<State>,
|
||||||
pub data_device_state: DataDeviceState,
|
pub data_device_state: DataDeviceState,
|
||||||
pub popups: PopupManager,
|
pub wl_fixes_state: FixesState,
|
||||||
|
|
||||||
pub seat: Seat<Self>,
|
// xdg
|
||||||
|
pub xdg_shell_state: XdgShellState,
|
||||||
|
pub xdg_decoration_state: XdgDecorationState,
|
||||||
|
pub xdg_activation_state: XdgActivationState,
|
||||||
|
pub xdg_toplevel_icon_manager_state: XdgToplevelIconManager,
|
||||||
|
pub xdg_toplevel_tag_manager_state: XdgToplevelTagManager,
|
||||||
|
pub xdg_system_bell_state: XdgSystemBellState,
|
||||||
|
|
||||||
|
pub output_manager_state: OutputManagerState,
|
||||||
|
|
||||||
pub xwayland_state: XWaylandState,
|
pub xwayland_state: XWaylandState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
pub fn new(display: Display<Self>, handle: LoopHandle<'static, Self>) -> Self {
|
pub fn new(
|
||||||
|
display: Display<Self>,
|
||||||
|
handle: LoopHandle<'static, Self>,
|
||||||
|
) -> Result<Self, Box<dyn std::error::Error>> {
|
||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
|
|
||||||
let dh = display.handle();
|
let dh = display.handle();
|
||||||
|
|
@ -64,6 +76,16 @@ impl State {
|
||||||
// Initialize protocols needed for displaying windows
|
// Initialize protocols needed for displaying windows
|
||||||
let compositor_state = CompositorState::new::<Self>(&dh);
|
let compositor_state = CompositorState::new::<Self>(&dh);
|
||||||
let xdg_shell_state = XdgShellState::new::<Self>(&dh);
|
let xdg_shell_state = XdgShellState::new::<Self>(&dh);
|
||||||
|
|
||||||
|
let xdg_decoration_state = XdgDecorationState::new::<Self>(&dh);
|
||||||
|
|
||||||
|
let xdg_shell_state = XdgShellState::new::<Self>(&dh);
|
||||||
|
let xdg_decoration_state = XdgDecorationState::new::<Self>(&dh);
|
||||||
|
let xdg_activation_state = XdgActivationState::new::<Self>(&dh);
|
||||||
|
let xdg_toplevel_icon_manager_state = XdgToplevelIconManager::new::<Self>(&dh);
|
||||||
|
let xdg_toplevel_tag_manager_state = XdgToplevelTagManager::new::<Self>(&dh);
|
||||||
|
let xdg_system_bell_state = XdgSystemBellState::new::<Self>(&dh);
|
||||||
|
|
||||||
let shm_state = ShmState::new::<Self>(&dh, vec![]);
|
let shm_state = ShmState::new::<Self>(&dh, vec![]);
|
||||||
let popups = PopupManager::default();
|
let popups = PopupManager::default();
|
||||||
|
|
||||||
|
|
@ -72,6 +94,8 @@ impl State {
|
||||||
// Data device is responsible for clipboard and drag-and-drop
|
// Data device is responsible for clipboard and drag-and-drop
|
||||||
let data_device_state = DataDeviceState::new::<Self>(&dh);
|
let data_device_state = DataDeviceState::new::<Self>(&dh);
|
||||||
|
|
||||||
|
let wl_fixes_state = FixesState::new::<Self>(&dh);
|
||||||
|
|
||||||
// A seat is a group of keyboards, pointer and touch devices.
|
// A seat is a group of keyboards, pointer and touch devices.
|
||||||
// A seat typically has a pointer and maintains a keyboard focus and a pointer focus.
|
// A seat typically has a pointer and maintains a keyboard focus and a pointer focus.
|
||||||
let mut seat_state = SeatState::new();
|
let mut seat_state = SeatState::new();
|
||||||
|
|
@ -90,7 +114,7 @@ impl State {
|
||||||
// Windows get a position and stacking order through mapping.
|
// Windows get a position and stacking order through mapping.
|
||||||
// Outputs become views of a part of the Space and can be rendered via Space::render_output.
|
// Outputs become views of a part of the Space and can be rendered via Space::render_output.
|
||||||
let space = Space::default();
|
let space = Space::default();
|
||||||
Self::setup_xwayland(display.handle(), handle.clone());
|
Self::setup_xwayland(display.handle(), handle.clone())?;
|
||||||
|
|
||||||
let socket_name = Self::init_wayland_listener(display, handle.clone());
|
let socket_name = Self::init_wayland_listener(display, handle.clone());
|
||||||
|
|
||||||
|
|
@ -99,7 +123,7 @@ impl State {
|
||||||
xwayland_shell_state: XWaylandShellState::new::<State>(&dh),
|
xwayland_shell_state: XWaylandShellState::new::<State>(&dh),
|
||||||
};
|
};
|
||||||
|
|
||||||
Self {
|
Ok(Self {
|
||||||
start_time,
|
start_time,
|
||||||
display_handle: dh,
|
display_handle: dh,
|
||||||
|
|
||||||
|
|
@ -109,14 +133,22 @@ impl State {
|
||||||
compositor_state,
|
compositor_state,
|
||||||
xdg_shell_state,
|
xdg_shell_state,
|
||||||
shm_state,
|
shm_state,
|
||||||
output_manager_state,
|
|
||||||
seat_state,
|
seat_state,
|
||||||
data_device_state,
|
data_device_state,
|
||||||
|
wl_fixes_state,
|
||||||
|
output_manager_state,
|
||||||
|
|
||||||
|
xdg_decoration_state,
|
||||||
|
xdg_activation_state,
|
||||||
|
xdg_toplevel_icon_manager_state,
|
||||||
|
xdg_toplevel_tag_manager_state,
|
||||||
|
xdg_system_bell_state,
|
||||||
|
|
||||||
|
xwayland_state,
|
||||||
popups,
|
popups,
|
||||||
seat,
|
seat,
|
||||||
xwayland_state,
|
|
||||||
handle,
|
handle,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_wayland_listener(
|
fn init_wayland_listener(
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ use smithay::{
|
||||||
winit::{self, WinitEvent},
|
winit::{self, WinitEvent},
|
||||||
},
|
},
|
||||||
output::{Mode, Output, PhysicalProperties, Subpixel},
|
output::{Mode, Output, PhysicalProperties, Subpixel},
|
||||||
reexports::calloop::EventLoop,
|
|
||||||
utils::{Rectangle, Transform},
|
utils::{Rectangle, Transform},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue