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

X11 Fix keysym translation using official libxkbcommon #456

Merged
merged 3 commits into from
Jun 21, 2024
Merged
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
3 changes: 2 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -7,12 +7,13 @@ in pkgs.mkShell {
libGL
xorg.libX11
xorg.libXi
libxkbcommon
];

shellHook = ''
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${
with pkgs;
pkgs.lib.makeLibraryPath [ libGL xorg.libX11 xorg.libXi ]
pkgs.lib.makeLibraryPath [ libGL xorg.libX11 xorg.libXi libxkbcommon ]
}"
'';
}
5 changes: 4 additions & 1 deletion src/native/linux_x11.rs
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ use std::collections::HashMap;

pub struct X11Display {
libx11: LibX11,
libxkbcommon: LibXkbCommon,
libxi: xi_input::LibXi,
display: *mut Display,
root: Window,
@@ -47,7 +48,7 @@ impl X11Display {
&mut keysym,
std::ptr::null_mut(),
);
let chr = keycodes::keysym_to_unicode(keysym);
let chr = keycodes::keysym_to_unicode(&mut self.libxkbcommon, keysym);
if chr > 0 {
if let Some(chr) = std::char::from_u32(chr as u32) {
event_handler.char_event(chr, mods, repeat);
@@ -547,6 +548,7 @@ where
{
unsafe {
let mut libx11 = LibX11::try_load()?;
let libxkbcommon = LibXkbCommon::try_load()?;
let libxi = xi_input::LibXi::try_load()?;

(libx11.XInitThreads)();
@@ -581,6 +583,7 @@ where
root: x11_root,
window: 0,
libx11,
libxkbcommon,
libxi,
repeated_keycodes: [false; 256],
cursor_cache: HashMap::new(),
931 changes: 3 additions & 928 deletions src/native/linux_x11/keycodes.rs

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/native/linux_x11/libx11.rs
Original file line number Diff line number Diff line change
@@ -1133,3 +1133,23 @@ impl LibX11 {
};
}
}

pub type XKbKeySymToUtf32 = unsafe extern "C" fn(_: u32) -> u32;

#[derive(Clone)]
pub struct LibXkbCommon {
pub module: std::rc::Rc<module::Module>,
pub xkb_keysym_to_utf32: XKbKeySymToUtf32,
}

impl LibXkbCommon {
pub fn try_load() -> Option<Self> {
crate::native::module::Module::load("libxkbcommon.so")
.or_else(|_| crate::native::module::Module::load("libxkbcommon.so.6"))
.map(|module| LibXkbCommon {
xkb_keysym_to_utf32: module.get_symbol("xkb_keysym_to_utf32").unwrap(),
module: std::rc::Rc::new(module),
})
.ok()
}
}

Unchanged files with check annotations Beta

class,
declare::ClassDecl,
msg_send,
runtime::{Class, Object, Protocol, Sel, BOOL, NO, YES},

Check warning on line 17 in src/native/apple/frameworks.rs

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unused imports: `Protocol`, `os::raw::c_ulong`

Check warning on line 17 in src/native/apple/frameworks.rs

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unused imports: `Protocol`, `os::raw::c_ulong`

Check warning on line 17 in src/native/apple/frameworks.rs

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unused imports: `Protocol`, `os::raw::c_ulong`
sel, sel_impl, Encode, Encoding,
},
std::{ffi::c_void, os::raw::c_ulong, ptr::NonNull},
}
#[derive(Clone, Copy, Debug, PartialEq)]
struct ShaderUniform {

Check warning on line 214 in src/graphics/metal.rs

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

struct `ShaderUniform` is never constructed

Check warning on line 214 in src/graphics/metal.rs

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

struct `ShaderUniform` is never constructed

Check warning on line 214 in src/graphics/metal.rs

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

struct `ShaderUniform` is never constructed
size: u64,
offset: u64,
format: MTLVertexFormat,
fn process_request(&mut self, request: Request) {
use Request::*;
unsafe {

Check warning on line 826 in src/native/windows.rs

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unnecessary `unsafe` block

Check warning on line 826 in src/native/windows.rs

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unnecessary `unsafe` block
match request {
ScheduleUpdate => {
self.update_requested = true;
} => self.set_window_size(new_width as _, new_height as _),
SetWindowPosition { new_x, new_y } => self.set_window_position(new_x, new_y),
SetFullscreen(fullscreen) => self.set_fullscreen(fullscreen),
ShowKeyboard(show) => {

Check warning on line 840 in src/native/windows.rs

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unused variable: `show`

Check warning on line 840 in src/native/windows.rs

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unused variable: `show`
eprintln!("Not implemented for windows")
}
}