it works!

This commit is contained in:
Simeon Schaub 2021-06-19 10:18:11 +02:00
parent 84f3a4e2d7
commit 11f5f44ae6
No known key found for this signature in database
GPG Key ID: EB2EE6B6F3725876
3 changed files with 75 additions and 38 deletions

View File

@ -63,7 +63,7 @@ static const int natural_scrolling = 0;
/* commands */
static const char *termcmd[] = { "alacritty", NULL };
static const char *menucmd[] = { "bemenu-run", NULL };
static const char *menucmd[] = { "dmenu_run", NULL };
const Key keys[] = {
/* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */

38
dwl.c
View File

@ -238,16 +238,16 @@ static void destroylayersurfacenotify(struct wl_listener *listener, void *data);
static void destroynotify(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
void focusmon(const Arg *arg);
void focusstack(const Arg *arg);
static void fullscreennotify(struct wl_listener *listener, void *data);
static Client *focustop(Monitor *m);
static void incnmaster(const Arg *arg);
void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym);
static void keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data);
static void killclient(const Arg *arg);
void killclient(const Arg *arg);
static void maplayersurfacenotify(struct wl_listener *listener, void *data);
static void mapnotify(struct wl_listener *listener, void *data);
static void monocle(Monitor *m);
@ -261,7 +261,7 @@ static void outputmgrtest(struct wl_listener *listener, void *data);
static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
static void printstatus(void);
static void quit(const Arg *arg);
void quit(const Arg *arg);
static void quitsignal(int signo);
static void render(struct wlr_surface *surface, int sx, int sy, void *data);
static void renderclients(Monitor *m, struct timespec *now);
@ -276,31 +276,31 @@ static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating);
static void setfullscreen(Client *c, int fullscreen);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
void setlayout(const Arg *arg);
void setmfact(const Arg *arg);
static void setmon(Client *c, Monitor *m, unsigned int newtags);
static void setup(void);
static void sigchld(int unused);
static void spawn(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
void spawn(const Arg *arg);
void tag(const Arg *arg);
void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
void togglefloating(const Arg *arg);
void togglefullscreen(const Arg *arg);
void toggletag(const Arg *arg);
void toggleview(const Arg *arg);
static void unmaplayersurface(LayerSurface *layersurface);
static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
static void unmapnotify(struct wl_listener *listener, void *data);
static void updatemons(struct wl_listener *listener, void *data);
static void updatetitle(struct wl_listener *listener, void *data);
static void view(const Arg *arg);
void view(const Arg *arg);
static void virtualkeyboard(struct wl_listener *listener, void *data);
static Client *xytoclient(double x, double y);
static struct wlr_surface *xytolayersurface(struct wl_list *layer_surfaces,
double x, double y, double *sx, double *sy);
static Monitor *xytomon(double x, double y);
static void zoom(const Arg *arg);
void zoom(const Arg *arg);
/* variables */
static const char broken[] = "broken";
@ -1202,8 +1202,6 @@ inputdevice(struct wl_listener *listener, void *data)
}
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
@ -1224,8 +1222,10 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
// }
//}
//return handled;
//printf("%x\n", sym);
void *ptr[] = {&mods, &sym};
return jl_unbox_int32(jl_call1(keybinding_julia, jl_box_voidpointer(ptr)));
//return jl_unbox_int32(jl_call1(keybinding_julia, jl_box_voidpointer(ptr)));
return jl_unbox_int32(jl_call2(keybinding_julia, jl_box_uint32(mods), jl_box_uint32(sym)));
}
void

73
dwl.jl
View File

@ -1,8 +1,9 @@
module DWL
struct xkb_keysym_t
x::UInt32
end
const xkb_keysym_t = UInt32
#struct xkb_keysym_t
# x::UInt32
#end
struct Arg
x::UInt
@ -15,24 +16,60 @@ struct Key
arg::Arg
end
const keys = @show unsafe_wrap(Array, cglobal(:keys, Key), unsafe_load(cglobal(:KEYS_LEN, Cint)))
keysym(x) = ccall((:XStringToKeysym, "libxkbfile"), xkb_keysym_t, (Cstring,), string(x))
# from wlr_keyboard.h
const WLR_MODIFIER_SHIFT = xkb_keysym_t(1 << 0)
const WLR_MODIFIER_CAPS = xkb_keysym_t(1 << 1)
const WLR_MODIFIER_CTRL = xkb_keysym_t(1 << 2)
const WLR_MODIFIER_ALT = xkb_keysym_t(1 << 3)
const WLR_MODIFIER_MOD2 = xkb_keysym_t(1 << 4)
const WLR_MODIFIER_MOD3 = xkb_keysym_t(1 << 5)
const WLR_MODIFIER_LOGO = xkb_keysym_t(1 << 6)
const WLR_MODIFIER_MOD5 = xkb_keysym_t(1 << 7)
const WLR_MODIFIER_CAPS = @show unsafe_load(cglobal(:_WLR_MODIFIER_CAPS, UInt32))
const MODKEY = WLR_MODIFIER_ALT
#const keys = @show unsafe_wrap(Array, cglobal(:keys, Key), unsafe_load(cglobal(:KEYS_LEN, Cint)))
function spawn(cmd::Vector{String})
cmd = Base.cconvert.(Cstring, cmd)
ptrs = push!(pointer.(cmd), C_NULL)
@ccall spawn(pointer(ptrs)::Ref{Ptr{Cstring}})::Cvoid
GC.@preserve cmd ptrs
end
focusstack(x::Int) = @ccall focusstack(x::Ref{Cint})::Cvoid
killclient() = @ccall killclient(C_NULL::Ptr{Cvoid})::Cvoid
quit() = @ccall quit(C_NULL::Ptr{Cvoid})::Cvoid
const keys = Dict{Tuple{UInt32, xkb_keysym_t}, Any}(
(MODKEY, keysym(:p)) => () -> spawn(["dmenu_run"]),
(MODKEY | WLR_MODIFIER_SHIFT, keysym(:Return)) => () -> spawn(["alacritty"]),
(MODKEY, keysym(:j)) => () -> focusstack(+1),
(MODKEY, keysym(:k)) => () -> focusstack(-1),
(MODKEY | WLR_MODIFIER_SHIFT, keysym(:C)) => killclient,
(MODKEY | WLR_MODIFIER_SHIFT, keysym(:Q)) => quit,
)
#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
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
f = get(keys, (cleanmask(mods), sym), nothing)
f === nothing && return false
try Base.invokelatest(f) catch e; @show e end
return true
# 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 @show handled
end
end