From df1619bf7deb8ba63f0182ed104af02408f7224c Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Fri, 24 Mar 2017 18:09:34 +0000 Subject: [PATCH] added more experimental xcb code --- moo/kernel/Mill.moo | 6 +-- moo/kernel/System.moo | 26 ---------- moo/lib/exec.c | 8 +-- moo/mod/x11.c | 113 +++++++++++++++++++++--------------------- 4 files changed, 60 insertions(+), 93 deletions(-) diff --git a/moo/kernel/Mill.moo b/moo/kernel/Mill.moo index d39ed37..7a88957 100644 --- a/moo/kernel/Mill.moo +++ b/moo/kernel/Mill.moo @@ -269,11 +269,7 @@ class MyObject(Object) method(#class) main { |a i| - - System _getUint8(1,2). - 'JJJJJJJJJJ' dump. - - + a := 100. ## PROBLEM: the following double loop will exhaust the stack (* diff --git a/moo/kernel/System.moo b/moo/kernel/System.moo index 9f5ba71..1f18280 100644 --- a/moo/kernel/System.moo +++ b/moo/kernel/System.moo @@ -120,31 +120,5 @@ extend System method(#class,#primitive) _putUint32 (rawptr, offset, value). method(#class,#primitive) _putUint64 (rawptr, offset, value), *) - - (* - method(#class) getUint8: rawptr at: offset - { - - } - - method(#class) getUint16: rawptr at: offset - { - - } - - method(#class) getUint32: rawptr at: offset - { - - } - - method(#class) getUint64: rawptr at: offset - { - - } - - method(#class) putUint8: value rawptr: rawptr at: offset - { - - }*) } diff --git a/moo/lib/exec.c b/moo/lib/exec.c index ee308e8..7ebb6d3 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -1791,11 +1791,9 @@ static moo_pfrc_t _get_raw_uint (moo_t* moo, moo_ooi_t nargs, int size) moo_oow_t value; moo_oop_t result; -MOO_DEBUG1 (moo, "get_raw_uint ..%d\n", size); if (moo_inttooow (moo, MOO_STACK_GETARG(moo, nargs, 0), (moo_oow_t*)&rawptr) <= 0 || moo_inttooow (moo, MOO_STACK_GETARG(moo, nargs, 1), &offset) <= 0) { -MOO_DEBUG0 (moo, "get_raw_uint failure...\n"); moo->errnum = MOO_EINVAL; return MOO_PF_FAILURE; } @@ -1826,7 +1824,6 @@ MOO_DEBUG0 (moo, "get_raw_uint failure...\n"); result = moo_oowtoint (moo, value); if (!result) return MOO_PF_FAILURE; -MOO_DEBUG1 (moo, "get_raw_uint failure..%O.\n", result); MOO_STACK_SETRET (moo, nargs, result); return MOO_PF_SUCCESS; } @@ -1917,11 +1914,10 @@ static moo_pfrc_t pf_perform (moo_t* moo, moo_ooi_t nargs) /* remove the selector from the stack */ ssp = MOO_STACK_GETARGSP (moo, nargs, 0); esp = MOO_STACK_GETARGSP (moo, nargs, nargs - 1); - for (i = ssp; i < esp;) + for (i = ssp; i < esp; i++) { moo_oop_t t; - t = MOO_STACK_GET (moo, i); - i++; + t = MOO_STACK_GET (moo, i + 1); MOO_STACK_SET(moo, i, t); } MOO_STACK_POP (moo); diff --git a/moo/mod/x11.c b/moo/mod/x11.c index 58ba5fd..14933cd 100644 --- a/moo/mod/x11.c +++ b/moo/mod/x11.c @@ -34,6 +34,21 @@ #define C MOO_METHOD_CLASS #define I MOO_METHOD_INSTANCE + +/** + * @brief Bit mask to find event type regardless of event source. + * + * Each event in the X11 protocol contains an 8-bit type code. + * The most-significant bit in this code is set if the event was + * generated from a SendEvent request. This mask can be used to + * determine the type of event regardless of how the event was + * generated. See the X11R6 protocol specification for details. + */ +#define XCB_EVENT_RESPONSE_TYPE_MASK (0x7f) +#define XCB_EVENT_RESPONSE_TYPE(e) (e->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) +#define XCB_EVENT_SENT(e) (e->response_type & ~XCB_EVENT_RESPONSE_TYPE_MASK) + + typedef struct x11_modctx_t x11_modctx_t; struct x11_modctx_t { @@ -55,7 +70,7 @@ typedef struct x11_win_t x11_win_t; struct x11_win_t { xcb_window_t id; - xcb_intern_atom_reply_t* dwcr; + xcb_intern_atom_reply_t* dwar; }; @@ -171,54 +186,21 @@ static moo_pfrc_t pf_getevent (moo_t* moo, moo_ooi_t nargs) if (evt) { - uint8_t evttype = evt->response_type & 0x7F; + moo_oop_t llevt; + uint8_t evttype; + evttype = evt->response_type & 0x7F; x11->curevt = evt; - if (evttype == XCB_CLIENT_MESSAGE) + + llevt = moo_oowtoint (moo, (moo_oow_t)evt); + if (!llevt) { - MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(9999)); /* TODO: translate evt to the event object */ - } - else - { - MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(evttype)); /* TODO: translate evt to the event object */ + llevt = MOO_ERROR_TO_OOP(moo->errnum); + free (evt); + x11->curevt = MOO_NULL; } -#if 0 - switch (evttype) - { - case XCB_CLIENT_MESSAGE: - #if 0 - if (((xcb_client_message_event_t*)evt)->data.data32[0] == x11->dwcr->atom) - { - xcb_unmap_window (x11->c, x11->w); - xcb_destroy_window (x11->c, x11->w); - xcb_flush (x11->c); - } - #endif - MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(9999)); /* TODO: translate evt to the event object */ - - break; - - - case XCB_BUTTON_PRESS: - case XCB_BUTTON_RELEASE: - { - xcb_button_press_event_t* bpe = (xcb_button_press_event_t*)evt; - - - MOO_STACK_SETRET (moo, nargs, e); - break; - } - - default: - MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(evttype)); /* TODO: translate evt to the event object */ - break; - } - - - free (evt); -#endif - + MOO_STACK_SETRET (moo, nargs, llevt); } else if (xcb_connection_has_error(x11->c)) { @@ -227,6 +209,7 @@ static moo_pfrc_t pf_getevent (moo_t* moo, moo_ooi_t nargs) } else { + /* nil if there is no event */ MOO_STACK_SETRET (moo, nargs, moo->_nil); } @@ -235,6 +218,21 @@ static moo_pfrc_t pf_getevent (moo_t* moo, moo_ooi_t nargs) /* ------------------------------------------------------------------------ */ +static moo_pfrc_t pf_win_get_dwatom (moo_t* moo, moo_ooi_t nargs) +{ + x11_win_t* win; + moo_oop_t x; + + win = (x11_win_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL); + + x = moo_oowtoint (moo, win->dwar->atom); + if (!x) return MOO_PF_HARD_FAILURE; + + MOO_STACK_SETRET (moo, nargs, x); + return MOO_PF_SUCCESS; + +} + static moo_pfrc_t pf_win_get_id (moo_t* moo, moo_ooi_t nargs) { x11_win_t* win; @@ -247,7 +245,6 @@ static moo_pfrc_t pf_win_get_id (moo_t* moo, moo_ooi_t nargs) MOO_STACK_SETRET (moo, nargs, x); return MOO_PF_SUCCESS; - } static moo_pfrc_t pf_win_kill_on (moo_t* moo, moo_ooi_t nargs) @@ -287,15 +284,12 @@ static moo_pfrc_t pf_win_make_on (moo_t* moo, moo_ooi_t nargs) MOO_DEBUG0 (moo, " %p\n"); - x11 = (x11_t*)moo_getobjtrailer(moo, MOO_STACK_GETARG(moo, nargs, 0), MOO_NULL); win = (x11_win_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL); - if (!x11->c) - { - MOO_STACK_SETRETTOERROR (moo, nargs); /* TODO: be more specific about error */ - return MOO_PF_SUCCESS; - } + if (MOO_STACK_GETARG(moo, nargs, 0) == moo->_nil) goto reterr; + x11 = (x11_t*)moo_getobjtrailer(moo, MOO_STACK_GETARG(moo, nargs, 0), MOO_NULL); + if (!x11->c) goto reterr; win->id = xcb_generate_id (x11->c); id = moo_oowtoint (moo, win->id); @@ -305,6 +299,8 @@ MOO_DEBUG0 (moo, " %p\n"); values[0] = x11->screen->white_pixel; values[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS | + XCB_EVENT_MASK_BUTTON_RELEASE | + /*XCB_EVENT_MASK_BUTTON_MOTION |*/ XCB_EVENT_MASK_EXPOSURE | /*XCB_EVENT_MASK_POINTER_MOTION |*/ XCB_EVENT_MASK_ENTER_WINDOW | @@ -324,9 +320,9 @@ MOO_DEBUG0 (moo, " %p\n"); reply = xcb_intern_atom_reply(x11->c, cookie, 0); cookie = xcb_intern_atom(x11->c, 0, 16, "WM_DELETE_WINDOW"); - win->dwcr = xcb_intern_atom_reply(x11->c, cookie, 0); + win->dwar = xcb_intern_atom_reply(x11->c, cookie, 0); - xcb_change_property(x11->c, XCB_PROP_MODE_REPLACE, win->id, reply->atom, 4, 32, 1, &win->dwcr->atom); + xcb_change_property(x11->c, XCB_PROP_MODE_REPLACE, win->id, reply->atom, 4, 32, 1, &win->dwar->atom); /*TODO: use xcb_request_check() for error handling. you need to call create_x11->wdwo_checked(). xxx_checked()... */ xcb_map_window (x11->c, win->id); @@ -334,6 +330,10 @@ MOO_DEBUG0 (moo, " %p\n"); MOO_STACK_SETRET (moo, nargs, id); return MOO_PF_SUCCESS; + +reterr: + MOO_STACK_SETRETTOERROR (moo, nargs); /* TODO: be more specific about error */ + return MOO_PF_SUCCESS; } @@ -440,9 +440,10 @@ int moo_mod_x11 (moo_t* moo, moo_mod_t* mod) static moo_pfinfo_t x11_win_pfinfo[] = { - { I, { '_','g','e','t','_','i','d','\0' }, 0, pf_win_get_id }, - { I, { '_','k','i','l','l','_','o','n',':','\0' }, 0, pf_win_kill_on }, - { I, { '_','m','a','k','e','_','o','n',':','\0' }, 0, pf_win_make_on } + { I, { '_','g','e','t','_','d','w','a','t','o','m','\0'}, 0, pf_win_get_dwatom }, + { I, { '_','g','e','t','_','i','d','\0' }, 0, pf_win_get_id }, + { I, { '_','k','i','l','l','_','o','n',':','\0' }, 0, pf_win_kill_on }, + { I, { '_','m','a','k','e','_','o','n',':','\0' }, 0, pf_win_make_on } }; static int x11_win_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)