-
Notifications
You must be signed in to change notification settings - Fork 175
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
Wayland/virtual keyboard #720
Merged
Merged
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
4149557
wayland/virtual keyboard
ebefb0e
Added keyboard handling
9350f09
Redirecting keyboard input straight into keyboard handler
034cf7c
Fail using handle
84192bb
Merge branch 'master' into wayland/virtual_keyboard
b51a9c3
Working virtual keyboard with keymap changing
876bec0
Added filter for trusted clients
3973a07
Merge branch 'Smithay:master' into wayland/virtual_keyboard
8cff03b
Added documentation
b23b27a
removing patch crates
fc4ee2c
Merge branch 'master' into wayland/virtual_keyboard
1d63f63
Merge branch 'Smithay:master' into wayland/virtual_keyboard
560ac77
Updated wayland crates in cargo.toml
577fef6
Updated wlcs_anvil cargo.toml
27576e4
Update to beta.9
db13137
Merge branch 'wayland/virtual_keyboard' of me.github.com:rano-oss/smi…
a7554dd
removed unnecessary internal reference
ae6584f
Merge branch 'master' into wayland/virtual_keyboard
be8efbd
fixes after merging with master
8b45a50
Added extra comment
85ac5dd
Make it pub crate
a38ba4a
Merge branch 'master' into wayland/virtual_keyboard
9bf3462
convert OwnedFd to raw for xkbcommon
fbecbe6
Merge branch 'master' into wayland/virtual_keyboard
b9ed4b3
working keymap switching
ccfd754
format...
dccae17
clippy
08441d7
Change keymap is a wayland frontend feature
8f26898
All keymap change functions movced to frontend
5953712
Merge branch 'master' into wayland/virtual_keyboard
401bf7d
refactor how keyboard is changed
8f3f583
logging level set to warning instead of debug when changing keymap on…
f0c84e3
move use inside function
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
//! Utilities for virtual keyboard support | ||
//! | ||
//! This module provides you with utilities to handle virtual keyboard instances. | ||
//! It can be used standalone to implement virtual keyboards or together with | ||
//! an input method to pass through keys from the keyboard. | ||
//! | ||
//! ``` | ||
//! use smithay::{ | ||
//! delegate_seat, delegate_virtual_keyboard_manager, | ||
//! }; | ||
//! use smithay::input::{Seat, SeatState, SeatHandler, pointer::CursorImageStatus}; | ||
//! use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState; | ||
//! use smithay::reexports::wayland_server::{Display, protocol::wl_surface::WlSurface}; | ||
//! | ||
//! # struct State { seat_state: SeatState<Self> }; | ||
//! | ||
//! delegate_seat!(State); | ||
//! // Delegate virtual keyboard handling for State to VirtualKeyboardManagerState. | ||
//! delegate_virtual_keyboard_manager!(State); | ||
//! | ||
//! # let mut display = Display::<State>::new().unwrap(); | ||
//! # let display_handle = display.handle(); | ||
//! | ||
//! let seat_state = SeatState::<State>::new(); | ||
//! | ||
//! // implement the required traits | ||
//! impl SeatHandler for State { | ||
//! type KeyboardFocus = WlSurface; | ||
//! type PointerFocus = WlSurface; | ||
//! fn seat_state(&mut self) -> &mut SeatState<Self> { | ||
//! &mut self.seat_state | ||
//! } | ||
//! fn focus_changed(&mut self, seat: &Seat<Self>, focused: Option<&WlSurface>) { unimplemented!() } | ||
//! fn cursor_image(&mut self, seat: &Seat<Self>, image: CursorImageStatus) { unimplemented!() } | ||
//! } | ||
//! | ||
//! // Add the seat state to your state, create manager global and add client filter | ||
//! // to avoid untrusted clients requesting a new keyboard | ||
//! VirtualKeyboardManagerState::new::<State, _>(&display_handle, |_client| true); | ||
//! | ||
//! ``` | ||
//! | ||
|
||
use wayland_protocols_misc::zwp_virtual_keyboard_v1::server::{ | ||
zwp_virtual_keyboard_manager_v1::{self, ZwpVirtualKeyboardManagerV1}, | ||
zwp_virtual_keyboard_v1::ZwpVirtualKeyboardV1, | ||
}; | ||
use wayland_server::{backend::GlobalId, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New}; | ||
|
||
use crate::input::{Seat, SeatHandler}; | ||
|
||
use self::virtual_keyboard_handle::VirtualKeyboardHandle; | ||
|
||
const MANAGER_VERSION: u32 = 1; | ||
|
||
mod virtual_keyboard_handle; | ||
|
||
pub use virtual_keyboard_handle::VirtualKeyboardUserData; | ||
|
||
/// State of wp misc virtual keyboard protocol | ||
#[derive(Debug)] | ||
pub struct VirtualKeyboardManagerState { | ||
global: GlobalId, | ||
} | ||
|
||
/// Data associated with a VirtualKeyboardManager global. | ||
#[allow(missing_debug_implementations)] | ||
pub struct VirtualKeyboardManagerGlobalData { | ||
filter: Box<dyn for<'c> Fn(&'c Client) -> bool + Send + Sync>, | ||
} | ||
|
||
fn create_global_with_filter<D, F>(display: &DisplayHandle, filter: F) -> GlobalId | ||
where | ||
D: GlobalDispatch<ZwpVirtualKeyboardManagerV1, VirtualKeyboardManagerGlobalData> + 'static, | ||
F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, | ||
{ | ||
let data = VirtualKeyboardManagerGlobalData { | ||
filter: Box::new(filter), | ||
}; | ||
|
||
display.create_global::<D, ZwpVirtualKeyboardManagerV1, _>(MANAGER_VERSION, data) | ||
} | ||
|
||
impl VirtualKeyboardManagerState { | ||
/// Initialize a virtual keyboard manager global. | ||
pub fn new<D, F>(display: &DisplayHandle, filter: F) -> Self | ||
where | ||
D: GlobalDispatch<ZwpVirtualKeyboardManagerV1, VirtualKeyboardManagerGlobalData>, | ||
D: Dispatch<ZwpVirtualKeyboardManagerV1, ()>, | ||
D: Dispatch<ZwpVirtualKeyboardV1, VirtualKeyboardUserData<D>>, | ||
D: SeatHandler, | ||
D: 'static, | ||
F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, | ||
{ | ||
let global = create_global_with_filter::<D, F>(display, filter); | ||
|
||
Self { global } | ||
} | ||
|
||
/// Get the id of ZwpVirtualKeyboardManagerV1 global | ||
pub fn global(&self) -> GlobalId { | ||
self.global.clone() | ||
} | ||
} | ||
|
||
impl<D> GlobalDispatch<ZwpVirtualKeyboardManagerV1, VirtualKeyboardManagerGlobalData, D> | ||
for VirtualKeyboardManagerState | ||
where | ||
D: GlobalDispatch<ZwpVirtualKeyboardManagerV1, VirtualKeyboardManagerGlobalData>, | ||
D: Dispatch<ZwpVirtualKeyboardManagerV1, ()>, | ||
D: Dispatch<ZwpVirtualKeyboardV1, VirtualKeyboardUserData<D>>, | ||
D: SeatHandler, | ||
D: 'static, | ||
{ | ||
fn bind( | ||
_: &mut D, | ||
_: &DisplayHandle, | ||
_: &Client, | ||
resource: New<ZwpVirtualKeyboardManagerV1>, | ||
_: &VirtualKeyboardManagerGlobalData, | ||
data_init: &mut DataInit<'_, D>, | ||
) { | ||
data_init.init(resource, ()); | ||
} | ||
|
||
fn can_view(client: Client, global_data: &VirtualKeyboardManagerGlobalData) -> bool { | ||
(global_data.filter)(&client) | ||
} | ||
} | ||
|
||
impl<D> Dispatch<ZwpVirtualKeyboardManagerV1, (), D> for VirtualKeyboardManagerState | ||
where | ||
D: Dispatch<ZwpVirtualKeyboardManagerV1, ()>, | ||
D: Dispatch<ZwpVirtualKeyboardV1, VirtualKeyboardUserData<D>>, | ||
D: SeatHandler, | ||
D: 'static, | ||
{ | ||
fn request( | ||
_state: &mut D, | ||
_client: &Client, | ||
_resource: &ZwpVirtualKeyboardManagerV1, | ||
request: zwp_virtual_keyboard_manager_v1::Request, | ||
_data: &(), | ||
_handle: &DisplayHandle, | ||
data_init: &mut DataInit<'_, D>, | ||
) { | ||
match request { | ||
zwp_virtual_keyboard_manager_v1::Request::CreateVirtualKeyboard { seat, id } => { | ||
let seat = Seat::<D>::from_resource(&seat).unwrap(); | ||
let user_data = seat.user_data(); | ||
user_data.insert_if_missing(VirtualKeyboardHandle::default); | ||
let virtual_keyboard_handle = user_data.get::<VirtualKeyboardHandle>().unwrap(); | ||
data_init.init( | ||
id, | ||
VirtualKeyboardUserData { | ||
handle: virtual_keyboard_handle.clone(), | ||
seat: seat.clone(), | ||
}, | ||
); | ||
|
||
virtual_keyboard_handle.count_instance(); | ||
} | ||
_ => unreachable!(), | ||
} | ||
} | ||
} | ||
|
||
#[allow(missing_docs)] //TODO | ||
#[macro_export] | ||
macro_rules! delegate_virtual_keyboard_manager { | ||
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { | ||
$crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ | ||
$crate::reexports::wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1: $crate::wayland::virtual_keyboard::VirtualKeyboardManagerGlobalData | ||
] => $crate::wayland::virtual_keyboard::VirtualKeyboardManagerState); | ||
|
||
$crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ | ||
$crate::reexports::wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1: () | ||
] => $crate::wayland::virtual_keyboard::VirtualKeyboardManagerState); | ||
|
||
$crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ | ||
$crate::reexports::wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboard_v1::ZwpVirtualKeyboardV1: $crate::wayland::virtual_keyboard::VirtualKeyboardUserData<Self> | ||
] => $crate::wayland::virtual_keyboard::VirtualKeyboardManagerState); | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should rather be a warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change this, or merge and create a new shorter pr? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured I might as well 😸