From 6a721bb62aa56699bab3710b8f0e4dc136f3dd12 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Tue, 27 Jun 2017 07:36:55 +0000 Subject: [PATCH] renamed get_event to get_llevent in X11 --- moo/kernel/X11.moo | 43 +++++++++++++++++++++---------------------- moo/mod/_x11.h | 2 +- moo/mod/x11.c | 21 +++++++++++++++------ 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/moo/kernel/X11.moo b/moo/kernel/X11.moo index eace872..cc4905b 100644 --- a/moo/kernel/X11.moo +++ b/moo/kernel/X11.moo @@ -7,7 +7,6 @@ class X11(Object) from 'x11' ## definition struct x11_t defined in _x11.h ## --------------------------------------------------------------------- var display_base := nil. - var llevent. var expose_event. var key_event. var mouse_event. @@ -23,7 +22,7 @@ class X11(Object) from 'x11' method(#primitive,#liberal) _open_display(name). method(#primitive) _close_display. method(#primitive) _get_fd. - method(#primitive) _get_event. + method(#primitive) _get_llevent(llevent). method(#primitive) _create_window(parent_window, x, y, width, height, fgcolor, bgcolor). method(#primitive) _destroy_window(window). @@ -404,7 +403,6 @@ extend X11 { super initialize. - self.llevent := self.LLEvent new. self.expose_event := self.ExposeEvent new. self.key_event := self.KeyEvent new. self.mouse_event := self.MouseEvent new. @@ -471,8 +469,9 @@ extend X11 self.event_loop_sem := Semaphore new. Processor signal: self.event_loop_sem onInput: (self _get_fd). self.event_loop_proc := [ - | evtbuf event ongoing | + | llevtbuf llevent ongoing | + llevtbuf := X11.LLEvent new. ongoing := true. while (self.shell_container childrenCount > 0) { @@ -480,9 +479,9 @@ extend X11 self.event_loop_sem wait. if (ongoing not) { break }. - while ((event := self _get_event) notNil) + while ((llevent := self _get_llevent(llevtbuf)) notNil) { - if (event isError) + if (llevent isError) { ##System logNl: ('Error while getting a event from server ' & self.cid asString). ongoing := false. @@ -490,7 +489,7 @@ extend X11 } else { - self __dispatch_event: event. + self __dispatch_llevent: llevent. }. }. }. @@ -519,26 +518,26 @@ extend X11 self.event_loop_sem signal. } - method __dispatch_event: event + method __dispatch_llevent: llevent { - (* - | type mthname | + | widget mthname | + widget := self.window_registrar at: llevent window. + if (widget isError) + { + System logNl: 'Event on unknown widget - ' & (llevent window asString). + ^nil + }. - ##type := System _getUint8(event, 0). - type := event getUint8(0). - - mthname := self.llevent_blocks at: (type bitAnd: 16r7F). + mthname := self.llevent_blocks at: llevent type. if (mthname isError) { -('IGNORING UNKNOWN LL-EVENT TYPE ' & type asString) dump. - } - else - { - ^self perform (mthname, event). - ##^self perform: mthname with: event. - } - *) + System logNl: 'Uknown event type ' & (llevent type asString). + ^nil + }. + +(llevent window asString) dump. + ^self perform (mthname, llevent). } method __handle_notify: type diff --git a/moo/mod/_x11.h b/moo/mod/_x11.h index dc57f98..b7f5eed 100644 --- a/moo/mod/_x11.h +++ b/moo/mod/_x11.h @@ -60,7 +60,7 @@ struct x11_t MOO_OBJ_HEADER; moo_oop_t display; /* SMPTR of Display */ - oop_x11_llevent_t llevent; + moo_oop_t expose_event; moo_oop_t key_event; moo_oop_t mouse_event; diff --git a/moo/mod/x11.c b/moo/mod/x11.c index 18ef60e..4e9c899 100644 --- a/moo/mod/x11.c +++ b/moo/mod/x11.c @@ -154,7 +154,7 @@ static moo_pfrc_t pf_get_fd (moo_t* moo, moo_ooi_t nargs) return MOO_PF_SUCCESS; } -static moo_pfrc_t pf_get_event (moo_t* moo, moo_ooi_t nargs) +static moo_pfrc_t pf_get_llevent (moo_t* moo, moo_ooi_t nargs) { oop_x11_t x11; x11_trailer_t* tr; @@ -175,13 +175,14 @@ static moo_pfrc_t pf_get_event (moo_t* moo, moo_ooi_t nargs) XNextEvent (disp, event); - e = x11->llevent; + e = (oop_x11_llevent_t)MOO_STACK_GETARG(moo, nargs, 0); + /* TOOD: check if e is an instance of X11.LLEvent */ e->type = MOO_SMOOI_TO_OOP(event->type); e->window = MOO_SMOOI_TO_OOP(0); - /* [NOTE] When creating the low-level event object, ensure not to - * trigger GC directly or indirectly as the GC might be a - * copying collector which move objects around during collection */ + /* if the following is going to trigger GC directly or indirectly, + * e must be proteced with moo_pushtmp() first */ + switch (event->type) { case ClientMessage: @@ -203,6 +204,14 @@ static moo_pfrc_t pf_get_event (moo_t* moo, moo_ooi_t nargs) break; } + case ButtonPress: + case ButtonRelease: + { + e->window = MOO_SMOOI_TO_OOP(event->xbutton.window); + e->x = MOO_SMOOI_TO_OOP(event->xbutton.x); + e->y = MOO_SMOOI_TO_OOP(event->xbutton.y); + break; + } } MOO_STACK_SETRET (moo, nargs, (moo_oop_t)e); @@ -448,8 +457,8 @@ static moo_pfinfo_t x11_pfinfo[] = { MI, { '_','d','e','s','t','r','o','y','_','w','i','n','d','o','w','\0' }, 0, { pf_destroy_window, 1, 1 } }, { MI, { '_','d','r','a','w','_','r','e','c','t','a','n','g','l','e','\0' }, 0, { pf_draw_rectangle, 6, 6 } }, //{ MI, { '_','f','i','l','l','_','r','e','c','t','a','n','g','l','e','\0' }, 0, { pf_fill_rectangle, 6, 6 } }, - { MI, { '_','g','e','t','_','e','v','e','n','t','\0'}, 0, { pf_get_event, 0, 0 } }, { MI, { '_','g','e','t','_','f','d','\0' }, 0, { pf_get_fd, 0, 0 } }, + { MI, { '_','g','e','t','_','l','l','e','v','e','n','t','\0'}, 0, { pf_get_llevent, 1, 1 } }, { MI, { '_','o','p','e','n','_','d','i','s','p','l','a','y','\0' }, 0, { pf_open_display, 0, 1 } } };