2016-11-28 16:49:07 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <mruby.h>
|
|
|
|
|
2016-11-29 11:15:39 +00:00
|
|
|
extern mrb_value mrb_wrap_x_display(mrb_state *mrb, Display *display);
|
|
|
|
|
2016-11-28 16:49:07 +00:00
|
|
|
mrb_value
|
|
|
|
new_event_handler(mrb_state *mrb, mrb_value config, Display *display)
|
|
|
|
{
|
2016-11-28 19:02:31 +00:00
|
|
|
struct RClass *mXkremap = mrb_module_get(mrb, "Xkremap");
|
|
|
|
struct RClass *cEventHandler = mrb_class_get_under(mrb, mXkremap, "EventHandler");
|
2016-11-29 11:15:39 +00:00
|
|
|
mrb_value display_obj = mrb_wrap_x_display(mrb, display);
|
|
|
|
return mrb_funcall(mrb, mrb_obj_value(cEventHandler), "new", 2, config, display_obj);
|
2016-11-28 16:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-28 19:02:31 +00:00
|
|
|
handle_key_press(mrb_state *mrb, mrb_value event_handler, unsigned int keycode, unsigned int state)
|
2016-11-28 16:49:07 +00:00
|
|
|
{
|
2016-11-28 19:02:31 +00:00
|
|
|
mrb_funcall(mrb, event_handler, "handle_key_press", 2,
|
|
|
|
mrb_fixnum_value(keycode), mrb_fixnum_value(state));
|
|
|
|
if (mrb->exc) {
|
|
|
|
mrb_print_error(mrb);
|
|
|
|
}
|
2016-11-28 16:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-28 19:02:31 +00:00
|
|
|
handle_property_notify(mrb_state *mrb, mrb_value event_handler)
|
2016-11-28 16:49:07 +00:00
|
|
|
{
|
2016-11-28 19:02:31 +00:00
|
|
|
mrb_funcall(mrb, event_handler, "handle_property_notify", 0);
|
|
|
|
if (mrb->exc) {
|
|
|
|
mrb_print_error(mrb);
|
|
|
|
}
|
2016-11-28 16:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-28 19:02:31 +00:00
|
|
|
handle_mapping_notify(mrb_state *mrb, mrb_value event_handler)
|
2016-11-28 16:49:07 +00:00
|
|
|
{
|
2016-11-28 19:02:31 +00:00
|
|
|
mrb_funcall(mrb, event_handler, "handle_mapping_notify", 0);
|
|
|
|
if (mrb->exc) {
|
|
|
|
mrb_print_error(mrb);
|
|
|
|
}
|
2016-11-28 16:49:07 +00:00
|
|
|
}
|