X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fmouse.c;h=1f54b5cef775f3c33c44fceec3f1ab00facf2162;hb=0035771513d5c47d963858ef3f31da3ac28f7fc2;hp=7025e336bc009ecfbb5aa6283196f711721b81c8;hpb=e26270c20acfd9df67b82af594d96536cb6d202f;p=rodin%2Fchimara.git diff --git a/libchimara/mouse.c b/libchimara/mouse.c index 7025e33..1f54b5c 100644 --- a/libchimara/mouse.c +++ b/libchimara/mouse.c @@ -1,6 +1,55 @@ -#include +#include "mouse.h" +#include "magic.h" +/** + * glk_request_mouse_event: + * @win: Window on which to request a mouse input event. + * + * Requests mouse input on the window @win. + */ void glk_request_mouse_event(winid_t win) { + VALID_WINDOW(win, return); + g_return_if_fail(win != NULL); + g_return_if_fail(win->type == wintype_TextGrid || win->type == wintype_Graphics); + + g_signal_handler_unblock(win->widget, win->button_press_event_handler); +} + +/** + * glk_cancel_mouse_event: + * @win: Window with a mouse input event pending. + * + * Cancels the pending mouse input request on @win. + */ +void +glk_cancel_mouse_event(winid_t win) +{ + VALID_WINDOW(win, return); + g_return_if_fail(win != NULL); + g_return_if_fail(win->type == wintype_TextGrid || win->type == wintype_Graphics); + + g_signal_handler_block(win->widget, win->button_press_event_handler); +} + +gboolean +on_window_button_press(GtkWidget *widget, GdkEventButton *event, winid_t win) +{ + ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); + g_assert(glk); + + switch(win->type) + { + case wintype_TextGrid: + event_throw(glk, evtype_MouseInput, win, event->x/win->unit_width, event->y/win->unit_height); + break; + case wintype_Graphics: + event_throw(glk, evtype_MouseInput, win, event->x, event->y); + break; + default: + ILLEGAL_PARAM("Unknown window type: %u", win->type); + } + + return TRUE; }