-
Notifications
You must be signed in to change notification settings - Fork 76
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
How to integrate with wayland-client? #434
Comments
If I directly delete
|
You probably forgot to use the |
What is the difference between state and UserData in wayland-client? Neither |
This code compiles successfully, but stackoverflow will be generated when running in weston: use smithay_client_toolkit::{
delegate_keyboard,
seat::keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers},
};
use wayland_client::{
delegate_dispatch, event_created_child,
protocol::{wl_keyboard, wl_registry, wl_surface},
Connection, Dispatch, QueueHandle,
};
use wayland_protocols::wp::input_method::zv1::client::{
zwp_input_method_context_v1,
zwp_input_method_v1::{self, EVT_ACTIVATE_OPCODE},
};
fn main() {
let conn = Connection::connect_to_env().unwrap();
let mut event_queue = conn.new_event_queue();
let qhandle = event_queue.handle();
let display = conn.display();
display.get_registry(&qhandle, ());
let mut state = AppState {
running: true,
..Default::default()
};
while state.running {
event_queue.blocking_dispatch(&mut state).unwrap();
}
}
#[derive(Default)]
struct AppState {
running: bool,
input_method: Option<zwp_input_method_v1::ZwpInputMethodV1>,
context: Option<zwp_input_method_context_v1::ZwpInputMethodContextV1>,
}
impl Dispatch<wl_registry::WlRegistry, ()> for AppState {
fn event(
state: &mut Self,
registry: &wl_registry::WlRegistry,
event: <wl_registry::WlRegistry as wayland_client::Proxy>::Event,
data: &(),
conn: &Connection,
qh: &QueueHandle<Self>,
) {
if let wl_registry::Event::Global {
name, interface, ..
} = event
{
println!("{} {}", name, interface);
match &interface[..] {
"zwp_input_method_v1" => {
let input_method = registry
.bind::<zwp_input_method_v1::ZwpInputMethodV1, _, _>(name, 1, qh, ());
state.input_method = Some(input_method);
}
_ => {}
}
}
}
}
impl Dispatch<zwp_input_method_v1::ZwpInputMethodV1, ()> for AppState {
fn event(
state: &mut Self,
proxy: &zwp_input_method_v1::ZwpInputMethodV1,
event: zwp_input_method_v1::Event,
data: &(),
conn: &Connection,
qhandle: &QueueHandle<Self>,
) {
println!("current event is {:#?}", event);
match event {
zwp_input_method_v1::Event::Activate { id } => {
println!("method activate");
id.grab_keyboard(qhandle, ());
state.context = Some(id);
println!("grab keyboard");
}
zwp_input_method_v1::Event::Deactivate { context } => {
state.context = None;
context.destroy();
println!("method inactive");
}
_ => {}
}
}
event_created_child!(AppState, zwp_input_method_v1::ZwpInputMethodV1, [
EVT_ACTIVATE_OPCODE => (zwp_input_method_context_v1::ZwpInputMethodContextV1, ()),
]);
}
impl Dispatch<zwp_input_method_context_v1::ZwpInputMethodContextV1, ()> for AppState {
fn event(
state: &mut Self,
context: &zwp_input_method_context_v1::ZwpInputMethodContextV1,
event: zwp_input_method_context_v1::Event,
data: &(),
conn: &Connection,
qhandle: &QueueHandle<Self>,
) {
println!("current content event is {:#?}", event);
match event {
zwp_input_method_context_v1::Event::SurroundingText {
text,
cursor,
anchor,
} => {
println!("{} {} {}", text, cursor, anchor);
}
_ => {}
}
}
}
impl KeyboardHandler for AppState {
fn enter(
&mut self,
_: &Connection,
_: &QueueHandle<Self>,
_: &wl_keyboard::WlKeyboard,
surface: &wl_surface::WlSurface,
_: u32,
_: &[u32],
keysyms: &[Keysym],
) {
println!("Keyboard focus on window with pressed syms: {keysyms:?}");
}
fn leave(
&mut self,
_: &Connection,
_: &QueueHandle<Self>,
_: &wl_keyboard::WlKeyboard,
surface: &wl_surface::WlSurface,
_: u32,
) {
println!("Release keyboard focus on window");
}
fn press_key(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_: &wl_keyboard::WlKeyboard,
_: u32,
event: KeyEvent,
) {
println!("Key press: {event:?}");
}
fn release_key(
&mut self,
_: &Connection,
_: &QueueHandle<Self>,
_: &wl_keyboard::WlKeyboard,
_: u32,
event: KeyEvent,
) {
println!("Key release: {event:?}");
}
fn update_modifiers(
&mut self,
conn: &Connection,
qh: &QueueHandle<Self>,
keyboard: &wl_keyboard::WlKeyboard,
serial: u32,
modifiers: Modifiers,
) {
println!("update");
}
}
delegate_dispatch!(AppState: [wl_keyboard::WlKeyboard: ()] => AppState); |
Grab keyboard in zwp-input-method
how to use client-toolkit's
KeyboardHandler
instead of dispatch wl_keyboar?The text was updated successfully, but these errors were encountered: