This commit is contained in:
Simeon Schaub 2021-06-17 13:28:33 +02:00
parent 2630a7dfe4
commit 84f3a4e2d7
No known key found for this signature in database
GPG Key ID: EB2EE6B6F3725876
2 changed files with 57 additions and 10 deletions

29
dwl.c
View File

@ -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

38
dwl.jl Normal file
View File

@ -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