Upgrade to smithay-client-toolkit 0.4 (#671)

* Upgrade to smithay-client-toolkit 0.4

* Fix PR points
This commit is contained in:
trimental 2018-10-15 07:15:43 +08:00 committed by Francesca Plebani
parent 808638fee3
commit 50008dff3d
7 changed files with 326 additions and 299 deletions

View file

@ -1,5 +1,8 @@
# Unreleased # Unreleased
- On Wayland, titles will now be displayed in the window header decoration
- On Wayland, key repetition is now ended when keyboard loses focus
- On Wayland, windows will now use more stylish and modern client side decorations.
- On Wayland, windows will use server-side decorations when available. - On Wayland, windows will use server-side decorations when available.
- Added support for F16-F24 keys. - Added support for F16-F24 keys.
- Fixed graphical glitches when resizing on Wayland. - Fixed graphical glitches when resizing on Wayland.

View file

@ -54,8 +54,8 @@ features = [
] ]
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies] [target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
wayland-client = { version = "0.20.10", features = [ "dlopen", "egl", "cursor"] } wayland-client = { version = "0.21", features = [ "dlopen", "egl", "cursor"] }
smithay-client-toolkit = "0.3.0" smithay-client-toolkit = "0.4"
x11-dl = "2.18.3" x11-dl = "2.18.3"
parking_lot = "0.6" parking_lot = "0.6"
percent-encoding = "1.0" percent-encoding = "1.0"

View file

@ -10,7 +10,6 @@ use super::window::WindowStore;
use super::WindowId; use super::WindowId;
use sctk::output::OutputMgr; use sctk::output::OutputMgr;
use sctk::reexports::client::commons::Implementation;
use sctk::reexports::client::protocol::{ use sctk::reexports::client::protocol::{
wl_keyboard, wl_output, wl_pointer, wl_registry, wl_seat, wl_touch, wl_keyboard, wl_output, wl_pointer, wl_registry, wl_seat, wl_touch,
}; };
@ -93,7 +92,7 @@ impl EventsLoopProxy {
// Update the `EventsLoop`'s `pending_wakeup` flag. // Update the `EventsLoop`'s `pending_wakeup` flag.
wakeup.store(true, Ordering::Relaxed); wakeup.store(true, Ordering::Relaxed);
// Cause the `EventsLoop` to break from `dispatch` if it is currently blocked. // Cause the `EventsLoop` to break from `dispatch` if it is currently blocked.
let _ = display.sync(); let _ = display.sync(|callback| callback.implement(|_, _| {}, ()));
display.flush().map_err(|_| EventsLoopClosed)?; display.flush().map_err(|_| EventsLoopClosed)?;
Ok(()) Ok(())
} }
@ -112,10 +111,7 @@ impl EventsLoop {
let store = Arc::new(Mutex::new(WindowStore::new())); let store = Arc::new(Mutex::new(WindowStore::new()));
let seats = Arc::new(Mutex::new(Vec::new())); let seats = Arc::new(Mutex::new(Vec::new()));
let env = Environment::from_registry_with_cb( let mut seat_manager = SeatManager {
display.get_registry().unwrap(),
&mut event_queue,
SeatManager {
sink: sink.clone(), sink: sink.clone(),
store: store.clone(), store: store.clone(),
seats: seats.clone(), seats: seats.clone(),
@ -123,6 +119,13 @@ impl EventsLoop {
display: Arc::downgrade(&display), display: Arc::downgrade(&display),
pending_wakeup: Arc::downgrade(&pending_wakeup), pending_wakeup: Arc::downgrade(&pending_wakeup),
}, },
};
let env = Environment::from_display_with_cb(
&display,
&mut event_queue,
move |event, registry| {
seat_manager.receive(event, registry)
}, },
).unwrap(); ).unwrap();
@ -280,7 +283,7 @@ struct SeatManager {
events_loop_proxy: EventsLoopProxy, events_loop_proxy: EventsLoopProxy,
} }
impl Implementation<Proxy<wl_registry::WlRegistry>, GlobalEvent> for SeatManager { impl SeatManager {
fn receive(&mut self, evt: GlobalEvent, registry: Proxy<wl_registry::WlRegistry>) { fn receive(&mut self, evt: GlobalEvent, registry: Proxy<wl_registry::WlRegistry>) {
use self::wl_registry::RequestsTrait as RegistryRequests; use self::wl_registry::RequestsTrait as RegistryRequests;
use self::wl_seat::RequestsTrait as SeatRequests; use self::wl_seat::RequestsTrait as SeatRequests;
@ -292,17 +295,22 @@ impl Implementation<Proxy<wl_registry::WlRegistry>, GlobalEvent> for SeatManager
} if interface == "wl_seat" => } if interface == "wl_seat" =>
{ {
use std::cmp::min; use std::cmp::min;
let seat = registry
.bind::<wl_seat::WlSeat>(min(version, 5), id) let mut seat_data = SeatData {
.unwrap()
.implement(SeatData {
sink: self.sink.clone(), sink: self.sink.clone(),
store: self.store.clone(), store: self.store.clone(),
pointer: None, pointer: None,
keyboard: None, keyboard: None,
touch: None, touch: None,
events_loop_proxy: self.events_loop_proxy.clone(), events_loop_proxy: self.events_loop_proxy.clone(),
}); };
let seat = registry
.bind(min(version, 5), id, move |seat| {
seat.implement(move |event, seat| {
seat_data.receive(event, seat)
}, ())
})
.unwrap();
self.store.lock().unwrap().new_seat(&seat); self.store.lock().unwrap().new_seat(&seat);
self.seats.lock().unwrap().push((id, seat)); self.seats.lock().unwrap().push((id, seat));
} }
@ -329,16 +337,15 @@ struct SeatData {
events_loop_proxy: EventsLoopProxy, events_loop_proxy: EventsLoopProxy,
} }
impl Implementation<Proxy<wl_seat::WlSeat>, wl_seat::Event> for SeatData { impl SeatData {
fn receive(&mut self, evt: wl_seat::Event, seat: Proxy<wl_seat::WlSeat>) { fn receive(&mut self, evt: wl_seat::Event, seat: Proxy<wl_seat::WlSeat>) {
use self::wl_seat::RequestsTrait as SeatRequests;
match evt { match evt {
wl_seat::Event::Name { .. } => (), wl_seat::Event::Name { .. } => (),
wl_seat::Event::Capabilities { capabilities } => { wl_seat::Event::Capabilities { capabilities } => {
// create pointer if applicable // create pointer if applicable
if capabilities.contains(wl_seat::Capability::Pointer) && self.pointer.is_none() { if capabilities.contains(wl_seat::Capability::Pointer) && self.pointer.is_none() {
self.pointer = Some(super::pointer::implement_pointer( self.pointer = Some(super::pointer::implement_pointer(
seat.get_pointer().unwrap(), &seat,
self.sink.clone(), self.sink.clone(),
self.store.clone(), self.store.clone(),
)) ))
@ -355,7 +362,7 @@ impl Implementation<Proxy<wl_seat::WlSeat>, wl_seat::Event> for SeatData {
// create keyboard if applicable // create keyboard if applicable
if capabilities.contains(wl_seat::Capability::Keyboard) && self.keyboard.is_none() { if capabilities.contains(wl_seat::Capability::Keyboard) && self.keyboard.is_none() {
self.keyboard = Some(super::keyboard::init_keyboard( self.keyboard = Some(super::keyboard::init_keyboard(
seat.get_keyboard().unwrap(), &seat,
self.sink.clone(), self.sink.clone(),
self.events_loop_proxy.clone(), self.events_loop_proxy.clone(),
)) ))
@ -372,7 +379,7 @@ impl Implementation<Proxy<wl_seat::WlSeat>, wl_seat::Event> for SeatData {
// create touch if applicable // create touch if applicable
if capabilities.contains(wl_seat::Capability::Touch) && self.touch.is_none() { if capabilities.contains(wl_seat::Capability::Touch) && self.touch.is_none() {
self.touch = Some(super::touch::implement_touch( self.touch = Some(super::touch::implement_touch(
seat.get_touch().unwrap(), &seat,
self.sink.clone(), self.sink.clone(),
self.store.clone(), self.store.clone(),
)) ))

View file

@ -5,11 +5,14 @@ use sctk::keyboard::{
self, map_keyboard_auto_with_repeat, Event as KbEvent, KeyRepeatEvent, KeyRepeatKind, self, map_keyboard_auto_with_repeat, Event as KbEvent, KeyRepeatEvent, KeyRepeatKind,
}; };
use sctk::reexports::client::protocol::wl_keyboard; use sctk::reexports::client::protocol::wl_keyboard;
use sctk::reexports::client::{NewProxy, Proxy}; use sctk::reexports::client::Proxy;
use sctk::reexports::client::protocol::wl_seat;
use sctk::reexports::client::protocol::wl_seat::RequestsTrait as SeatRequests;
use {ElementState, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent}; use {ElementState, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent};
pub fn init_keyboard( pub fn init_keyboard(
keyboard: NewProxy<wl_keyboard::WlKeyboard>, seat: &Proxy<wl_seat::WlSeat>,
sink: Arc<Mutex<EventsLoopSink>>, sink: Arc<Mutex<EventsLoopSink>>,
events_loop_proxy: EventsLoopProxy, events_loop_proxy: EventsLoopProxy,
) -> Proxy<wl_keyboard::WlKeyboard> { ) -> Proxy<wl_keyboard::WlKeyboard> {
@ -18,9 +21,11 @@ pub fn init_keyboard(
let my_sink = sink.clone(); let my_sink = sink.clone();
let repeat_sink = sink.clone(); let repeat_sink = sink.clone();
let repeat_target = target.clone(); let repeat_target = target.clone();
let modifiers = Arc::new(Mutex::new(ModifiersState::default()));
let my_modifiers = modifiers.clone();
// } // }
let ret = map_keyboard_auto_with_repeat( let ret = map_keyboard_auto_with_repeat(
keyboard, seat,
KeyRepeatKind::System, KeyRepeatKind::System,
move |evt: KbEvent, _| match evt { move |evt: KbEvent, _| match evt {
KbEvent::Enter { surface, .. } => { KbEvent::Enter { surface, .. } => {
@ -40,7 +45,6 @@ pub fn init_keyboard(
*target.lock().unwrap() = None; *target.lock().unwrap() = None;
} }
KbEvent::Key { KbEvent::Key {
modifiers,
rawkey, rawkey,
keysym, keysym,
state, state,
@ -61,7 +65,7 @@ pub fn init_keyboard(
state: state, state: state,
scancode: rawkey, scancode: rawkey,
virtual_keycode: vkcode, virtual_keycode: vkcode,
modifiers: modifiers.into(), modifiers: modifiers.lock().unwrap().clone(),
}, },
}, },
wid, wid,
@ -78,6 +82,9 @@ pub fn init_keyboard(
} }
} }
KbEvent::RepeatInfo { .. } => { /* Handled by smithay client toolkit */ } KbEvent::RepeatInfo { .. } => { /* Handled by smithay client toolkit */ }
KbEvent::Modifiers { modifiers: event_modifiers } => {
*modifiers.lock().unwrap() = event_modifiers.into()
}
}, },
move |repeat_event: KeyRepeatEvent, _| { move |repeat_event: KeyRepeatEvent, _| {
if let Some(wid) = *repeat_target.lock().unwrap() { if let Some(wid) = *repeat_target.lock().unwrap() {
@ -91,7 +98,7 @@ pub fn init_keyboard(
state: state, state: state,
scancode: repeat_event.rawkey, scancode: repeat_event.rawkey,
virtual_keycode: vkcode, virtual_keycode: vkcode,
modifiers: repeat_event.modifiers.into(), modifiers: my_modifiers.lock().unwrap().clone(),
}, },
}, },
wid, wid,
@ -108,7 +115,7 @@ pub fn init_keyboard(
match ret { match ret {
Ok(keyboard) => keyboard, Ok(keyboard) => keyboard,
Err((_, keyboard)) => { Err(_) => {
// This is a fallback impl if libxkbcommon was not available // This is a fallback impl if libxkbcommon was not available
// This case should probably never happen, as most wayland // This case should probably never happen, as most wayland
// compositors _need_ libxkbcommon anyway... // compositors _need_ libxkbcommon anyway...
@ -120,6 +127,7 @@ pub fn init_keyboard(
let mut target = None; let mut target = None;
let my_sink = sink; let my_sink = sink;
// } // }
seat.get_keyboard(|keyboard| {
keyboard.implement(move |evt, _| match evt { keyboard.implement(move |evt, _| match evt {
wl_keyboard::Event::Enter { surface, .. } => { wl_keyboard::Event::Enter { surface, .. } => {
let wid = make_wid(&surface); let wid = make_wid(&surface);
@ -158,7 +166,8 @@ pub fn init_keyboard(
} }
} }
_ => (), _ => (),
}) }, ())
}).unwrap()
} }
} }
} }

View file

@ -7,11 +7,13 @@ use super::DeviceId;
use super::event_loop::EventsLoopSink; use super::event_loop::EventsLoopSink;
use super::window::WindowStore; use super::window::WindowStore;
use sctk::reexports::client::{NewProxy, Proxy}; use sctk::reexports::client::Proxy;
use sctk::reexports::client::protocol::wl_pointer::{self, Event as PtrEvent, WlPointer}; use sctk::reexports::client::protocol::wl_pointer::{self, Event as PtrEvent, WlPointer};
use sctk::reexports::client::protocol::wl_seat;
use sctk::reexports::client::protocol::wl_seat::RequestsTrait as SeatRequests;
pub fn implement_pointer( pub fn implement_pointer(
pointer: NewProxy<WlPointer>, seat: &Proxy<wl_seat::WlSeat>,
sink: Arc<Mutex<EventsLoopSink>>, sink: Arc<Mutex<EventsLoopSink>>,
store: Arc<Mutex<WindowStore>>, store: Arc<Mutex<WindowStore>>,
) -> Proxy<WlPointer> { ) -> Proxy<WlPointer> {
@ -20,7 +22,8 @@ pub fn implement_pointer(
let mut axis_discrete_buffer = None; let mut axis_discrete_buffer = None;
let mut axis_state = TouchPhase::Ended; let mut axis_state = TouchPhase::Ended;
pointer.implement(move |evt, pointer: Proxy<_>| { seat.get_pointer(|pointer| {
pointer.implement(move |evt, pointer| {
let mut sink = sink.lock().unwrap(); let mut sink = sink.lock().unwrap();
let store = store.lock().unwrap(); let store = store.lock().unwrap();
match evt { match evt {
@ -186,5 +189,6 @@ pub fn implement_pointer(
} }
} }
} }
}) }, ())
}).unwrap()
} }

View file

@ -6,8 +6,10 @@ use super::{DeviceId, WindowId};
use super::event_loop::EventsLoopSink; use super::event_loop::EventsLoopSink;
use super::window::WindowStore; use super::window::WindowStore;
use sctk::reexports::client::{NewProxy, Proxy}; use sctk::reexports::client::Proxy;
use sctk::reexports::client::protocol::wl_touch::{Event as TouchEvent, WlTouch}; use sctk::reexports::client::protocol::wl_touch::{Event as TouchEvent, WlTouch};
use sctk::reexports::client::protocol::wl_seat;
use sctk::reexports::client::protocol::wl_seat::RequestsTrait as SeatRequests;
struct TouchPoint { struct TouchPoint {
wid: WindowId, wid: WindowId,
@ -16,11 +18,12 @@ struct TouchPoint {
} }
pub(crate) fn implement_touch( pub(crate) fn implement_touch(
touch: NewProxy<WlTouch>, seat: &Proxy<wl_seat::WlSeat>,
sink: Arc<Mutex<EventsLoopSink>>, sink: Arc<Mutex<EventsLoopSink>>,
store: Arc<Mutex<WindowStore>>, store: Arc<Mutex<WindowStore>>,
) -> Proxy<WlTouch> { ) -> Proxy<WlTouch> {
let mut pending_ids = Vec::new(); let mut pending_ids = Vec::new();
seat.get_touch(|touch| {
touch.implement(move |evt, _| { touch.implement(move |evt, _| {
let mut sink = sink.lock().unwrap(); let mut sink = sink.lock().unwrap();
let store = store.lock().unwrap(); let store = store.lock().unwrap();
@ -89,5 +92,6 @@ pub(crate) fn implement_touch(
); );
}, },
} }
}) }, ())
}).unwrap()
} }

View file

@ -6,7 +6,7 @@ use dpi::{LogicalPosition, LogicalSize};
use platform::MonitorId as PlatformMonitorId; use platform::MonitorId as PlatformMonitorId;
use window::MonitorId as RootMonitorId; use window::MonitorId as RootMonitorId;
use sctk::window::{BasicFrame, Event as WEvent, Window as SWindow}; use sctk::window::{ConceptFrame, Event as WEvent, Window as SWindow};
use sctk::reexports::client::{Display, Proxy}; use sctk::reexports::client::{Display, Proxy};
use sctk::reexports::client::protocol::{wl_seat, wl_surface, wl_output}; use sctk::reexports::client::protocol::{wl_seat, wl_surface, wl_output};
use sctk::reexports::client::protocol::wl_compositor::RequestsTrait as CompositorRequests; use sctk::reexports::client::protocol::wl_compositor::RequestsTrait as CompositorRequests;
@ -18,7 +18,7 @@ use platform::platform::wayland::event_loop::{get_available_monitors, get_primar
pub struct Window { pub struct Window {
surface: Proxy<wl_surface::WlSurface>, surface: Proxy<wl_surface::WlSurface>,
frame: Arc<Mutex<SWindow<BasicFrame>>>, frame: Arc<Mutex<SWindow<ConceptFrame>>>,
monitors: Arc<Mutex<MonitorList>>, // Monitors this window is currently on monitors: Arc<Mutex<MonitorList>>, // Monitors this window is currently on
outputs: OutputMgr, // Access to info for all monitors outputs: OutputMgr, // Access to info for all monitors
size: Arc<Mutex<(u32, u32)>>, size: Arc<Mutex<(u32, u32)>>,
@ -36,11 +36,11 @@ impl Window {
// monitor tracking // monitor tracking
let monitor_list = Arc::new(Mutex::new(MonitorList::new())); let monitor_list = Arc::new(Mutex::new(MonitorList::new()));
let surface = evlp.env.compositor.create_surface().unwrap().implement({ let surface = evlp.env.compositor.create_surface(|surface| {
let list = monitor_list.clone(); let list = monitor_list.clone();
let omgr = evlp.env.outputs.clone(); let omgr = evlp.env.outputs.clone();
let window_store = evlp.store.clone(); let window_store = evlp.store.clone();
move |event, surface: Proxy<wl_surface::WlSurface>| match event { surface.implement(move |event, surface| match event {
wl_surface::Event::Enter { output } => { wl_surface::Event::Enter { output } => {
let dpi_change = list.lock().unwrap().add_output(MonitorId { let dpi_change = list.lock().unwrap().add_output(MonitorId {
proxy: output, proxy: output,
@ -64,16 +64,16 @@ impl Window {
} }
} }
} }
} }, ())
}); }).unwrap();
let window_store = evlp.store.clone(); let window_store = evlp.store.clone();
let my_surface = surface.clone(); let my_surface = surface.clone();
let mut frame = SWindow::<BasicFrame>::init_from_env( let mut frame = SWindow::<ConceptFrame>::init_from_env(
&evlp.env, &evlp.env,
surface.clone(), surface.clone(),
(width, height), (width, height),
move |event, ()| match event { move |event| match event {
WEvent::Configure { new_size, .. } => { WEvent::Configure { new_size, .. } => {
let mut store = window_store.lock().unwrap(); let mut store = window_store.lock().unwrap();
for window in &mut store.windows { for window in &mut store.windows {
@ -324,7 +324,7 @@ struct InternalWindow {
need_frame_refresh: Arc<Mutex<bool>>, need_frame_refresh: Arc<Mutex<bool>>,
closed: bool, closed: bool,
kill_switch: Arc<Mutex<bool>>, kill_switch: Arc<Mutex<bool>>,
frame: Weak<Mutex<SWindow<BasicFrame>>>, frame: Weak<Mutex<SWindow<ConceptFrame>>>,
current_dpi: i32, current_dpi: i32,
new_dpi: Option<i32> new_dpi: Option<i32>
} }
@ -382,7 +382,7 @@ impl WindowStore {
pub fn for_each<F>(&mut self, mut f: F) pub fn for_each<F>(&mut self, mut f: F)
where where
F: FnMut(Option<(u32, u32)>, &mut (u32, u32), Option<i32>, bool, bool, bool, WindowId, Option<&mut SWindow<BasicFrame>>), F: FnMut(Option<(u32, u32)>, &mut (u32, u32), Option<i32>, bool, bool, bool, WindowId, Option<&mut SWindow<ConceptFrame>>),
{ {
for window in &mut self.windows { for window in &mut self.windows {
let opt_arc = window.frame.upgrade(); let opt_arc = window.frame.upgrade();