Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b1e07f9
New keyboard API for Windows (#1788)
ArturKovacs Apr 25, 2021
4dfd612
Fix the `drag_window` example
ArturKovacs May 9, 2021
d791053
Get stuff to compile
maroider Mar 19, 2021
a24b543
fixup! Get stuff to compile
maroider Jan 10, 2022
3ef7f7f
WIP
maroider Mar 19, 2021
488e65d
Add some keysym mappings and move the keymap.rs file
maroider Mar 28, 2021
22cba39
Add key location and some minor corrections
maroider Mar 29, 2021
75ddf1d
Use xkbcommon-dl rather than xkbcommon
maroider Mar 29, 2021
2ee35f4
Hoist keyboard handling code from sctk into Winit
maroider Mar 31, 2021
cddf0f5
fixup! Hoist keyboard handling code from sctk into Winit
maroider Jan 10, 2022
e49feae
Wire up the new events properly
maroider Apr 1, 2021
a60af09
Fix creation of key value strings
maroider Apr 1, 2021
142e435
Add missing keysym mapping
maroider Apr 1, 2021
a9b5b36
Fix `key_without_modifiers`
maroider Apr 1, 2021
e0367a9
Feature-gate things which depend on memmap2
maroider Apr 1, 2021
16dd044
Be more consistent with what `keycode` means
maroider Apr 1, 2021
db30340
Wire up Wayland IME again
maroider Apr 1, 2021
afbb077
Improve key string handling
maroider Apr 1, 2021
ec028ba
Add initial X11 support
maroider Apr 24, 2021
1a293b6
Address compilation errors
maroider Apr 25, 2021
68c95f7
Improve debug printing of `NativeKeyCode`
maroider Apr 24, 2021
ea646f7
Hook up X11 XKB modifier keys
maroider Apr 28, 2021
d267299
Use XInput2 for regular key events
maroider May 1, 2021
14dd7d3
Implement dead-key handling
maroider May 7, 2021
fba2b1b
Remove unused module
maroider May 7, 2021
8e6860b
Update xkbcommon-dl
ArturKovacs May 10, 2021
ed47b6b
Update xkbcommon-dl again
maroider May 16, 2021
ec7e9f1
Remove accidentally included attribute
maroider May 16, 2021
9067217
Use `as u32` to cast `i32`s to `u32`s
maroider May 16, 2021
141d7ad
Put more things behind the "wayland" feature
maroider May 16, 2021
df0fd07
Remove superfluous scope
maroider May 16, 2021
167b40c
Separate out loading of the X11 keymap
maroider Jun 16, 2021
4709908
Wire up X11 IME support
maroider Jun 16, 2021
75d1cee
Use the currently active keyboard layout on X11
ArturKovacs Jul 4, 2021
10b424b
fixup! Wire up X11 IME support
maroider Jul 4, 2021
1d24616
Enable keysym mapping for "Alt Graph"
maroider Aug 3, 2021
ea9a4d6
Actually respect keyboard layout changes
maroider Aug 4, 2021
91a3b10
Make `xkb_state` more internally consistent
maroider Aug 5, 2021
67cb19a
Improve the safety of `KbState`
maroider Aug 5, 2021
494a1e5
Make a decision on control characters and dead keys
maroider Aug 5, 2021
df9a96a
Store keycodes with X11's keycode offset
maroider Aug 5, 2021
a2c33d6
Log an error if we can't select XKB events
maroider Aug 5, 2021
b2c73be
Remove superfluous call to `Vec::set_len`
maroider Aug 5, 2021
dd3fff8
Send a warning if the server doesn't send a keymap
maroider Aug 11, 2021
8c7001c
Implement `KeyCodeExtScancode` on Wayland and X11
maroider Aug 24, 2021
1c3813e
Implement `reset_dead_keys` (poorly)
maroider Aug 24, 2021
22c0907
Split the native XKB keycode enum variant in two
maroider Sep 9, 2021
069da08
Add a TODO regarding the `ModifiersChanged` event.
maroider Sep 9, 2021
5f59244
fix: meta mod key on focus handling for gnome/x11
rti Sep 9, 2021
fd06cbd
Remove the `XkbStateNotify` handler
maroider Oct 6, 2021
e6ad0fb
X11: Only fetch virtual keyboard events from master devices
mahkoh Oct 21, 2021
f3cbfe3
Add dead-key mappings for keysyms
ArturKovacs Jan 13, 2022
2095e40
Remove unnecessary stuff
ArturKovacs Jan 13, 2022
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
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ targets = ["i686-pc-windows-msvc", "x86_64-pc-windows-msvc", "i686-unknown-linux

[features]
default = ["x11", "wayland", "wayland-dlopen"]
x11 = ["x11-dl", "mio", "percent-encoding", "parking_lot"]
wayland = ["wayland-client", "wayland-protocols", "sctk"]
x11 = ["x11-dl", "mio", "percent-encoding", "parking_lot", "xkbcommon-dl/x11"]
wayland = ["wayland-client", "wayland-protocols", "sctk", "memmap2"]
wayland-dlopen = ["sctk/dlopen", "wayland-client/dlopen"]

[dependencies]
Expand All @@ -30,6 +30,7 @@ serde = { version = "1", optional = true, features = ["serde_derive"] }
raw-window-handle = "0.4.2"
bitflags = "1"
mint = { version = "0.5.6", optional = true }
nameof = "1"

[dev-dependencies]
image = "0.23.12"
Expand All @@ -56,6 +57,7 @@ features = ["display_link"]

[target.'cfg(target_os = "windows")'.dependencies]
parking_lot = "0.11"
unicode-segmentation = "1.7.1"

[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.9"
Expand All @@ -79,6 +81,7 @@ features = [
"winerror",
"wingdi",
"winnt",
"winnls",
"winuser",
"mmsystem",
"timeapi"
Expand All @@ -93,6 +96,8 @@ x11-dl = { version = "2.18.5", optional = true }
percent-encoding = { version = "2.0", optional = true }
parking_lot = { version = "0.11.0", optional = true }
libc = "0.2.64"
memmap2 = { version = "0.2.1", optional = true }
xkbcommon-dl = { git = "https://github.com/maroider/xkbcommon-dl", rev = "900832888ad6f11011d1369befb344a9aa8a9610" }

[target.'cfg(target_arch = "wasm32")'.dependencies.web_sys]
package = "web-sys"
Expand Down
25 changes: 14 additions & 11 deletions examples/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::{thread, time};

use simple_logger::SimpleLogger;
use winit::{
event::{Event, KeyboardInput, WindowEvent},
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::Key,
window::WindowBuilder,
};

Expand Down Expand Up @@ -38,7 +39,7 @@ fn main() {
let mut close_requested = false;

event_loop.run(move |event, _, control_flow| {
use winit::event::{ElementState, StartCause, VirtualKeyCode};
use winit::event::StartCause;
println!("{:?}", event);
match event {
Event::NewEvents(start_cause) => {
Expand All @@ -52,31 +53,33 @@ fn main() {
close_requested = true;
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(virtual_code),
event:
KeyEvent {
logical_key: key,
state: ElementState::Pressed,
..
},
..
} => match virtual_code {
VirtualKeyCode::Key1 => {
} => match key {
// WARNING: Consider using `key_without_modifers()` if available on your platform.
// See the `key_binding` example
Key::Character("1") => {
mode = Mode::Wait;
println!("\nmode: {:?}\n", mode);
}
VirtualKeyCode::Key2 => {
Key::Character("2") => {
mode = Mode::WaitUntil;
println!("\nmode: {:?}\n", mode);
}
VirtualKeyCode::Key3 => {
Key::Character("3") => {
mode = Mode::Poll;
println!("\nmode: {:?}\n", mode);
}
VirtualKeyCode::R => {
Key::Character("r") => {
request_redraw = !request_redraw;
println!("\nrequest_redraw: {}\n", request_redraw);
}
VirtualKeyCode::Escape => {
Key::Escape => {
close_requested = true;
}
_ => (),
Expand Down
6 changes: 3 additions & 3 deletions examples/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use simple_logger::SimpleLogger;
use winit::{
event::{ElementState, Event, KeyboardInput, WindowEvent},
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::{CursorIcon, WindowBuilder},
};
Expand All @@ -21,8 +21,8 @@ fn main() {
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
input:
KeyboardInput {
event:
KeyEvent {
state: ElementState::Pressed,
..
},
Expand Down
21 changes: 13 additions & 8 deletions examples/cursor_grab.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use simple_logger::SimpleLogger;
use winit::{
event::{DeviceEvent, ElementState, Event, KeyboardInput, ModifiersState, WindowEvent},
event::{DeviceEvent, ElementState, Event, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::{Key, ModifiersState},
window::WindowBuilder,
};

Expand All @@ -23,19 +24,23 @@ fn main() {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
input:
KeyboardInput {
event:
KeyEvent {
logical_key: key,
state: ElementState::Released,
virtual_keycode: Some(key),
..
},
..
} => {
use winit::event::VirtualKeyCode::*;
// WARNING: Consider using `key_without_modifers()` if available on your platform.
// See the `key_binding` example
match key {
Escape => *control_flow = ControlFlow::Exit,
G => window.set_cursor_grab(!modifiers.shift()).unwrap(),
H => window.set_cursor_visible(modifiers.shift()),
Key::Escape => *control_flow = ControlFlow::Exit,
Key::Character(ch) => match ch.to_lowercase().as_str() {
"g" => window.set_cursor_grab(!modifiers.shift_key()).unwrap(),
"h" => window.set_cursor_visible(modifiers.shift_key()),
_ => (),
},
_ => (),
}
}
Expand Down
11 changes: 5 additions & 6 deletions examples/drag_window.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use simple_logger::SimpleLogger;
use winit::{
event::{
ElementState, Event, KeyboardInput, MouseButton, StartCause, VirtualKeyCode, WindowEvent,
},
event::{ElementState, Event, KeyEvent, MouseButton, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::Key,
window::{Window, WindowBuilder, WindowId},
};

Expand Down Expand Up @@ -43,10 +42,10 @@ fn main() {
name_windows(entered_id, switched, &window_1, &window_2)
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
event:
KeyEvent {
state: ElementState::Released,
virtual_keycode: Some(VirtualKeyCode::X),
logical_key: Key::Character("x"),
..
},
..
Expand Down
26 changes: 15 additions & 11 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::io::{stdin, stdout, Write};

use simple_logger::SimpleLogger;
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
use winit::event::{ElementState, Event, KeyEvent, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::keyboard::Key;
use winit::monitor::{MonitorHandle, VideoMode};
use winit::window::{Fullscreen, WindowBuilder};

Expand Down Expand Up @@ -38,30 +39,33 @@ fn main() {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(virtual_code),
state,
event:
KeyEvent {
logical_key: key,
state: ElementState::Pressed,
..
},
..
} => match (virtual_code, state) {
(VirtualKeyCode::Escape, _) => *control_flow = ControlFlow::Exit,
(VirtualKeyCode::F, ElementState::Pressed) => {
} => match key {
Key::Escape => *control_flow = ControlFlow::Exit,

// WARNING: Consider using `key_without_modifers()` if available on your platform.
// See the `key_binding` example
Key::Character("f") => {
if window.fullscreen().is_some() {
window.set_fullscreen(None);
} else {
window.set_fullscreen(fullscreen.clone());
}
}
(VirtualKeyCode::S, ElementState::Pressed) => {
Key::Character("s") => {
println!("window.fullscreen {:?}", window.fullscreen());
}
(VirtualKeyCode::M, ElementState::Pressed) => {
Key::Character("m") => {
let is_maximized = window.is_maximized();
window.set_maximized(!is_maximized);
}
(VirtualKeyCode::D, ElementState::Pressed) => {
Key::Character("d") => {
decorations = !decorations;
window.set_decorations(decorations);
}
Expand Down
23 changes: 11 additions & 12 deletions examples/handling_close.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use simple_logger::SimpleLogger;
use winit::{
event::{Event, KeyboardInput, WindowEvent},
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::Key,
window::WindowBuilder,
};

Expand All @@ -17,10 +18,6 @@ fn main() {
let mut close_requested = false;

event_loop.run(move |event, _, control_flow| {
use winit::event::{
ElementState::Released,
VirtualKeyCode::{N, Y},
};
*control_flow = ControlFlow::Wait;

match event {
Expand All @@ -44,16 +41,18 @@ fn main() {
// the Y key.
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(virtual_code),
state: Released,
event:
KeyEvent {
logical_key: key,
state: ElementState::Released,
..
},
..
} => {
match virtual_code {
Y => {
// WARNING: Consider using `key_without_modifers()` if available on your platform.
// See the `key_binding` example
match key {
Key::Character("y") => {
if close_requested {
// This is where you'll want to do any cleanup you need.
println!("Buh-bye!");
Expand All @@ -66,7 +65,7 @@ fn main() {
*control_flow = ControlFlow::Exit;
}
}
N => {
Key::Character("n") => {
if close_requested {
println!("Your window will continue to stay by your side.");
close_requested = false;
Expand Down
58 changes: 58 additions & 0 deletions examples/key_binding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use simple_logger::SimpleLogger;
use winit::{
dpi::LogicalSize,
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::{Key, ModifiersState},
window::WindowBuilder,
};

/////////////////////////////////////////////////////////////////////////////
// WARNING: This is not available on all platforms (for example on the web).
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement;
/////////////////////////////////////////////////////////////////////////////

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let _window = WindowBuilder::new()
.with_inner_size(LogicalSize::new(400.0, 200.0))
.build(&event_loop)
.unwrap();

let mut modifiers = ModifiersState::default();

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::ModifiersChanged(new_state) => {
modifiers = new_state;
}
WindowEvent::KeyboardInput { event, .. } => {
handle_key_event(modifiers, event);
}
_ => (),
},
_ => (),
};
});
}

fn handle_key_event(modifiers: ModifiersState, event: KeyEvent) {
if event.state == ElementState::Pressed && !event.repeat {
match event.key_without_modifiers() {
Key::Character("1") => {
if modifiers.shift_key() {
println!("Shift + 1 | logical_key: {:?}", event.logical_key);
} else {
println!("1");
}
}
_ => (),
}
}
}
12 changes: 8 additions & 4 deletions examples/minimize.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
extern crate winit;

use simple_logger::SimpleLogger;
use winit::event::{Event, VirtualKeyCode, WindowEvent};

use winit::event::{Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::keyboard::Key;
use winit::window::WindowBuilder;

fn main() {
Expand All @@ -25,12 +27,14 @@ fn main() {

// Keyboard input event to handle minimize via a hotkey
Event::WindowEvent {
event: WindowEvent::KeyboardInput { input, .. },
event: WindowEvent::KeyboardInput { event, .. },
window_id,
} => {
if window_id == window.id() {
// Pressing the 'M' key will minimize the window
if input.virtual_keycode == Some(VirtualKeyCode::M) {
// Pressing the 'm' key will minimize the window
// WARNING: Consider using `key_without_modifers()` if available on your platform.
// See the `key_binding` example
if let Key::Character("m") = event.logical_key {
window.set_minimized(true);
}
}
Expand Down
Loading