#include <stdio.h>
#include <X11/Xlib.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

enum {
    spacing = 20,
    box_w = 320,
    box_h = 120,
    font_size = 22,
    win_w = box_w + 2 * spacing,
    win_h = box_h + 2 * spacing
};

static int system_handler(void *event, void *data)
{
    XEvent *xevent = static_cast<XEvent*>(event);

    if (xevent->type == ButtonPress)
        puts("X11: ButtonPress");

    if (xevent->type == KeyPress)
        puts("X11: KeyPress");

    return 0;
}

static int dispatch(int event, Fl_Window *win)
{
    if (event == FL_PUSH)
        puts("FLTK: FL_PUSH");

    if (event == FL_KEYDOWN)
        puts("FLTK: FL_KEYDOWN");

    fflush(stdout);

    return Fl::handle_(event, win);
}

int main()
{
    Fl_Window win(win_w, win_h, "Event interception");

    Fl_Box box(spacing, spacing, box_w, box_h, "Click or press a key");
    box.box(FL_DOWN_BOX);
    box.labelsize(font_size);

    Fl::add_system_handler(system_handler, 0);
    Fl::event_dispatch(dispatch);

    win.end();
    win.show();

    return Fl::run();
}
