From 84f3a4e2d7f97a79ffa2aa3657a4faba586a6904 Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Thu, 17 Jun 2021 13:28:33 +0200 Subject: [PATCH] wip --- dwl.c | 29 +++++++++++++++++++---------- dwl.jl | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 dwl.jl diff --git a/dwl.c b/dwl.c index 2d6d6c0..bc37614 100644 --- a/dwl.c +++ b/dwl.c @@ -1201,6 +1201,11 @@ inputdevice(struct wl_listener *listener, void *data) wlr_seat_set_capabilities(seat, caps); } +const int KEYS_LEN = LENGTH(keys); +//const wlr_keyboard_modifier _WLR_MODIFIER_CAPS = WLR_MODIFIER_CAPS; +const uint32_t _WLR_MODIFIER_CAPS = WLR_MODIFIER_CAPS; +static jl_function_t* keybinding_julia; + int keybinding(uint32_t mods, xkb_keysym_t sym) { @@ -1209,16 +1214,18 @@ keybinding(uint32_t mods, xkb_keysym_t sym) * processing keys, rather than passing them on to the client for its own * processing. */ - int handled = 0; - const Key *k; - for (k = keys; k < END(keys); k++) { - if (CLEANMASK(mods) == CLEANMASK(k->mod) && - sym == k->keysym && k->func) { - k->func(&k->arg); - handled = 1; - } - } - return handled; + //int handled = 0; + //const Key *k; + //for (k = keys; k < END(keys); k++) { + // if (CLEANMASK(mods) == CLEANMASK(k->mod) && + // sym == k->keysym && k->func) { + // k->func(&k->arg); + // handled = 1; + // } + //} + //return handled; + void *ptr[] = {&mods, &sym}; + return jl_unbox_int32(jl_call1(keybinding_julia, jl_box_voidpointer(ptr))); } void @@ -2577,6 +2584,8 @@ main(int argc, char *argv[]) /* required: setup the Julia context */ jl_init(); jl_eval_string("@show(cglobal(:keys))"); + jl_module_t* DWL_julia = (jl_module_t*)jl_load(jl_main_module, "dwl.jl"); + keybinding_julia = jl_get_function(DWL_julia, "keybinding"); // Wayland requires XDG_RUNTIME_DIR for creating its communications // socket diff --git a/dwl.jl b/dwl.jl new file mode 100644 index 0000000..ca96224 --- /dev/null +++ b/dwl.jl @@ -0,0 +1,38 @@ +module DWL + +struct xkb_keysym_t + x::UInt32 +end + +struct Arg + x::UInt +end + +struct Key + mod::UInt32 + keysym::xkb_keysym_t + func::Ptr{Cvoid} + arg::Arg +end + +const keys = @show unsafe_wrap(Array, cglobal(:keys, Key), unsafe_load(cglobal(:KEYS_LEN, Cint))) + +const WLR_MODIFIER_CAPS = @show unsafe_load(cglobal(:_WLR_MODIFIER_CAPS, UInt32)) +cleanmask(x) = x & ~WLR_MODIFIER_CAPS + +#function keybinding(mods::UInt32, sym::xkb_keysym_t)::Cint +function keybinding(ptr::Ptr{Cvoid})::Cint + mods = unsafe_load(unsafe_load(Ptr{Ptr{UInt32}}(ptr)), 1) + sym = unsafe_load(unsafe_load(Ptr{Ptr{xkb_keysym_t}}(ptr)), 2) + @show mods sym + handled = false + for k in keys + if cleanmask(mods) == cleanmask(k.mod) && sym == k.keysym && k.func != C_NULL + ccall(k.func, Cvoid, (Ptr{Arg},), Ref(k.arg)) + handled = true + end + end + return handled +end + +end