Skip to content

Commit

Permalink
Merge pull request #378 from forkgull/xkeysym
Browse files Browse the repository at this point in the history
Use xkeysym for keyboard handling
  • Loading branch information
PolyMeilex authored Sep 11, 2023
2 parents 2854623 + aedfe58 commit a85f977
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 3,028 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `CursorIcon` from `cursor-icon` crate is now used for `set_cursor` and `Frame`.
- `wayland-csd-frame` is now used for CSD types like `WindowState`, `DecorationsFrame`, etc.
- Added `CompositorHandle::transform_changed` to listen for transform changes.
- `xkeysym::Keysym` is used as a keyboard key representation instead of `u32`

#### Fixed

Expand Down
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
bitflags = "1.0"
bytemuck = { version = "1.13.0", optional = true }
cursor-icon = "1.0.0"
dlib = "0.5"
log = "0.4"
Expand All @@ -31,13 +32,14 @@ wayland-protocols-wlr = { version = "0.1.0", features = ["client"] }
wayland-scanner = "0.30.0"
wayland-csd-frame = { version = "0.2.2", default-features = false, features = ["wayland-backend_0_1"] }

xkbcommon = { version = "0.5", optional = true, features = ["wayland"] }
xkbcommon = { version = "0.5.0", optional = true, features = ["wayland"] }
calloop = { version = "0.10.5", optional = true }
xkeysym = "0.2.0"

[features]
default = ["calloop", "xkbcommon"]
calloop = ["dep:calloop", "wayland-client/calloop"]
xkbcommon = ["dep:xkbcommon", "pkg-config"]
xkbcommon = ["dep:xkbcommon", "bytemuck", "pkg-config", "xkeysym/bytemuck"]

[build-dependencies]
pkg-config = { version = "0.3", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions examples/data_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use smithay_client_toolkit::{
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{
keyboard::{KeyEvent, KeyboardHandler, Modifiers},
keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers},
pointer::{PointerEvent, PointerEventKind, PointerHandler, BTN_LEFT},
Capability, SeatHandler, SeatState,
},
Expand Down Expand Up @@ -351,7 +351,7 @@ impl KeyboardHandler for DataDeviceWindow {
surface: &wl_surface::WlSurface,
_: u32,
_: &[u32],
_keysyms: &[u32],
_keysyms: &[Keysym],
) {
if self.window.wl_surface() == surface {
self.keyboard_focus = true;
Expand Down
3 changes: 2 additions & 1 deletion examples/generic_simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use wayland_client::{
protocol::{wl_keyboard, wl_output, wl_pointer, wl_seat, wl_shm, wl_surface},
Connection, QueueHandle,
};
use xkeysym::Keysym;

fn main() {
env_logger::init();
Expand Down Expand Up @@ -277,7 +278,7 @@ impl<T: Test + 'static> KeyboardHandler for SimpleWindow<T> {
surface: &wl_surface::WlSurface,
_: u32,
_: &[u32],
keysyms: &[u32],
keysyms: &[Keysym],
) {
if self.window.wl_surface() == surface {
println!("Keyboard focus on window with pressed syms: {keysyms:?}");
Expand Down
7 changes: 3 additions & 4 deletions examples/simple_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use smithay_client_toolkit::{
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{
keyboard::{KeyEvent, KeyboardHandler, Modifiers},
keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers},
pointer::{PointerEvent, PointerEventKind, PointerHandler},
Capability, SeatHandler, SeatState,
},
Expand All @@ -28,7 +28,6 @@ use wayland_client::{
protocol::{wl_keyboard, wl_output, wl_pointer, wl_seat, wl_shm, wl_surface},
Connection, QueueHandle,
};
use xkbcommon::xkb::keysyms;

fn main() {
env_logger::init();
Expand Down Expand Up @@ -270,7 +269,7 @@ impl KeyboardHandler for SimpleLayer {
surface: &wl_surface::WlSurface,
_: u32,
_: &[u32],
keysyms: &[u32],
keysyms: &[Keysym],
) {
if self.layer.wl_surface() == surface {
println!("Keyboard focus on window with pressed syms: {keysyms:?}");
Expand Down Expand Up @@ -302,7 +301,7 @@ impl KeyboardHandler for SimpleLayer {
) {
println!("Key press: {event:?}");
// press 'esc' to exit
if event.keysym == keysyms::KEY_Escape {
if event.keysym == Keysym::Escape {
self.exit = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use smithay_client_toolkit::{
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{
keyboard::{KeyEvent, KeyboardHandler, Modifiers},
keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers},
pointer::{PointerEvent, PointerEventKind, PointerHandler},
Capability, SeatHandler, SeatState,
},
Expand Down Expand Up @@ -287,7 +287,7 @@ impl KeyboardHandler for SimpleWindow {
surface: &wl_surface::WlSurface,
_: u32,
_: &[u32],
keysyms: &[u32],
keysyms: &[Keysym],
) {
if self.window.wl_surface() == surface {
println!("Keyboard focus on window with pressed syms: {keysyms:?}");
Expand Down
7 changes: 3 additions & 4 deletions examples/themed_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use smithay_client_toolkit::reexports::csd_frame::{
DecorationsFrame, FrameAction, FrameClick, ResizeEdge,
};
use smithay_client_toolkit::reexports::protocols::xdg::shell::client::xdg_toplevel::ResizeEdge as XdgResizeEdge;
use smithay_client_toolkit::seat::keyboard::keysyms;
use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState},
delegate_compositor, delegate_keyboard, delegate_output, delegate_pointer, delegate_registry,
Expand All @@ -20,7 +19,7 @@ use smithay_client_toolkit::{
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{
keyboard::{KeyEvent, KeyboardHandler, Modifiers},
keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers},
pointer::{
CursorIcon, PointerData, PointerEvent, PointerEventKind, PointerHandler, ThemeSpec,
ThemedPointer,
Expand Down Expand Up @@ -410,7 +409,7 @@ impl KeyboardHandler for SimpleWindow {
surface: &wl_surface::WlSurface,
_: u32,
_: &[u32],
keysyms: &[u32],
keysyms: &[Keysym],
) {
if self.window.wl_surface() == surface {
println!("Keyboard focus on window with pressed syms: {keysyms:?}");
Expand Down Expand Up @@ -439,7 +438,7 @@ impl KeyboardHandler for SimpleWindow {
_: u32,
event: KeyEvent,
) {
if event.keysym == keysyms::XKB_KEY_n {
if event.keysym == Keysym::N {
// Cycle through cursor icons.
self.window_cursor_icon_idx = (self.window_cursor_icon_idx + 1) % CURSORS.len();
println!("Setting cursor icon to: {}", CURSORS[self.window_cursor_icon_idx].name());
Expand Down
Loading

0 comments on commit a85f977

Please sign in to comment.