Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server decorations #20

Merged
merged 3 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ dlib = "0.4"
lazy_static = "1"
memmap = "0.6"
tempfile = "3.0"
wayland-commons = { version = "0.20.7" }
wayland-client = { version = "0.20.7", features = ["cursor"] }
wayland-protocols = { version = "0.20.7", features = ["client", "unstable_protocols"] }
wayland-commons = { version = "0.20.11" }
wayland-client = { version = "0.20.11", features = ["cursor"] }
wayland-protocols = { version = "0.20.11", features = ["client", "unstable_protocols"] }

[dev-dependencies]
image = "0.19"
wayland-client = { version = "0.20.7", features = ["dlopen"] }
wayland-client = { version = "0.20.11", features = ["dlopen"] }
byteorder = "1.0"
6 changes: 6 additions & 0 deletions examples/compositor_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ fn main() {
}
}
});

if env.decorations_mgr.is_some() {
println!("-> Compositor supports server-side decorations.")
} else {
println!("-> Compositor does not support server-side decorations.")
}
}
3 changes: 2 additions & 1 deletion examples/image_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ fn main() {
// only provide this one, but if you don't like the (arguably ugly)
// borders it draws, you just need to implement the appropriate trait
// to create your own.
let mut window = Window::<BasicFrame>::init(
let mut window = Window::<BasicFrame>::init_with_decorations(
surface, // the wl_surface that serves as the basis of this window
image.dimensions(), // the initial internal dimensions of the window
&env.compositor, // -+
&env.subcompositor, // | The Window constructor needs access to these globals
&env.shm, // | to initialize the window
&env.shell, // -+
env.decorations_mgr.as_ref(), // to use native decorations if available
move |evt, ()| {
// This is the closure that process the Window events.
// There are 3 possible events:
Expand Down
87 changes: 45 additions & 42 deletions examples/kbd_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::sync::{Arc, Mutex};

use byteorder::{NativeEndian, WriteBytesExt};

use sctk::keyboard::{map_keyboard_auto_with_repeat, Event as KbEvent, KeyRepeatKind, KeyRepeatEvent};
use sctk::keyboard::{
map_keyboard_auto_with_repeat, Event as KbEvent, KeyRepeatEvent, KeyRepeatKind,
};
use sctk::reexports::client::protocol::wl_buffer::RequestsTrait as BufferRequests;
use sctk::reexports::client::protocol::wl_compositor::RequestsTrait as CompositorRequests;
use sctk::reexports::client::protocol::wl_display::RequestsTrait as DisplayRequests;
Expand Down Expand Up @@ -42,13 +44,14 @@ fn main() {
let next_action = Arc::new(Mutex::new(None::<WEvent>));

let waction = next_action.clone();
let mut window = Window::<BasicFrame>::init(
let mut window = Window::<BasicFrame>::init_with_decorations(
surface,
dimensions,
&env.compositor,
&env.subcompositor,
&env.shm,
&env.shell,
env.decorations_mgr.as_ref(),
move |evt, ()| {
let mut next_action = waction.lock().unwrap();
// Keep last event in priority order : Close > Configure > Refresh
Expand Down Expand Up @@ -80,49 +83,49 @@ fn main() {

window.new_seat(&seat);

let _keyboard = map_keyboard_auto_with_repeat(seat.get_keyboard().unwrap(), KeyRepeatKind::System,
move |event: KbEvent, _| {
match event {
KbEvent::Enter {
modifiers, keysyms, ..
} => {
println!(
"Gained focus while {} keys pressed and modifiers are {:?}.",
keysyms.len(),
modifiers
);
}
KbEvent::Leave { .. } => {
println!("Lost focus.");
}
KbEvent::Key {
keysym,
state,
utf8,
modifiers,
..
} => {
println!("Key {:?}: {:x}.", state, keysym);
println!(" -> Modifers are {:?}", modifiers);
if let Some(txt) = utf8 {
println!(" -> Received text \"{}\".", txt);
}
}
KbEvent::RepeatInfo { rate, delay } => {
println!(
let _keyboard = map_keyboard_auto_with_repeat(
seat.get_keyboard().unwrap(),
KeyRepeatKind::System,
move |event: KbEvent, _| match event {
KbEvent::Enter {
modifiers, keysyms, ..
} => {
println!(
"Gained focus while {} keys pressed and modifiers are {:?}.",
keysyms.len(),
modifiers
);
}
KbEvent::Leave { .. } => {
println!("Lost focus.");
}
KbEvent::Key {
keysym,
state,
utf8,
modifiers,
..
} => {
println!("Key {:?}: {:x}.", state, keysym);
println!(" -> Modifers are {:?}", modifiers);
if let Some(txt) = utf8 {
println!(" -> Received text \"{}\".", txt);
}
}
KbEvent::RepeatInfo { rate, delay } => {
println!(
"Received repeat info: start repeating every {}ms after an initial delay of {}ms",
rate, delay
);
}
}
},
move |repeat_event: KeyRepeatEvent, _| {
println!("Repeated key {:x}.", repeat_event.keysym);
println!(" -> Modifers are {:?}", repeat_event.modifiers);
if let Some(txt) = repeat_event.utf8 {
println!(" -> Received text \"{}\".", txt);
}
}
},
move |repeat_event: KeyRepeatEvent, _| {
println!("Repeated key {:x}.", repeat_event.keysym);
println!(" -> Modifers are {:?}", repeat_event.modifiers);
if let Some(txt) = repeat_event.utf8 {
println!(" -> Received text \"{}\".", txt);
}
},
);

if !env.shell.needs_configure() {
Expand All @@ -138,7 +141,7 @@ fn main() {
Some(WEvent::Refresh) => {
window.refresh();
window.surface().commit();
},
}
Some(WEvent::Configure { new_size, states }) => {
if let Some((w, h)) = new_size {
window.resize(w, h);
Expand Down
6 changes: 4 additions & 2 deletions examples/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ fn main() {
let next_action = Arc::new(Mutex::new(None::<WEvent>));

let waction = next_action.clone();
let mut window = Window::<BasicFrame>::init(
let mut window = Window::<BasicFrame>::init_with_decorations(
surface,
dimensions,
&env.compositor,
&env.subcompositor,
&env.shm,
&env.shell,
env.decorations_mgr.as_ref(),
move |evt, ()| {
let mut next_action = waction.lock().unwrap();
// Keep last event in priority order : Close > Configure > Refresh
Expand Down Expand Up @@ -88,7 +89,8 @@ fn main() {
match event {
KbEvent::Key {
state,
utf8: Some(text), ..
utf8: Some(text),
..
} => {
if text == "p" && state == KeyState::Pressed {
// pressed the 'p' key, try to read contents !
Expand Down
5 changes: 3 additions & 2 deletions src/data_device/data_device.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use wayland_client::commons::Implementation;
use wayland_client::protocol::{wl_data_device, wl_data_device_manager, wl_data_offer, wl_seat,
wl_surface};
use wayland_client::protocol::{
wl_data_device, wl_data_device_manager, wl_data_offer, wl_seat, wl_surface,
};
use wayland_client::{NewProxy, Proxy, QueueToken};

use wayland_client::protocol::wl_data_device::RequestsTrait as DeviceRequests;
Expand Down
20 changes: 18 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use std::io;
use std::sync::{Arc, Mutex};

use wayland_client::commons::Implementation;
use wayland_client::protocol::{wl_compositor, wl_data_device_manager, wl_output, wl_registry,
wl_shell, wl_shm, wl_subcompositor};
use wayland_client::protocol::{
wl_compositor, wl_data_device_manager, wl_output, wl_registry, wl_shell, wl_shm,
wl_subcompositor,
};
use wayland_client::{EventQueue, GlobalEvent, GlobalManager, NewProxy, Proxy};
use wayland_protocols::unstable::xdg_decoration::v1::client::zxdg_decoration_manager_v1;
use wayland_protocols::unstable::xdg_shell::v6::client::zxdg_shell_v6;
use wayland_protocols::xdg_shell::client::xdg_wm_base;

Expand Down Expand Up @@ -60,6 +63,8 @@ pub struct Environment {
pub data_device_manager: Proxy<wl_data_device_manager::WlDataDeviceManager>,
/// A manager for handling the advertized outputs
pub outputs: ::output::OutputMgr,
/// The decoration manager, if the server supports server-side decorations
pub decorations_mgr: Option<Proxy<zxdg_decoration_manager_v1::ZxdgDecorationManagerV1>>,
shm_formats: Arc<Mutex<Vec<wl_shm::Format>>>,
}

Expand Down Expand Up @@ -170,6 +175,16 @@ impl Environment {
panic!("Server didn't advertize neither `xdg_wm_base` nor `wl_shell`?!");
};

// try to retrieve the decoration manager
let decorations_mgr = if let Shell::Xdg(_) = shell {
manager
.instantiate_auto::<zxdg_decoration_manager_v1::ZxdgDecorationManagerV1>()
.ok()
.map(|mgr| mgr.implement(|evt, _| match evt {}))
} else {
None
};

// sync to retrieve the global events
evq.sync_roundtrip()?;

Expand All @@ -181,6 +196,7 @@ impl Environment {
shm,
shm_formats,
data_device_manager,
decorations_mgr,
outputs,
})
}
Expand Down
Loading