static void SendMouseEvent(GSourceListener	*psl, GMouse *m, GMouseReading *r) {
	GEventMouse		*pe;

	// If there is no event buffer just mark a missed event
	if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) {
		// This listener is missing - save the meta events that have happened
		psl->srcflags |= ((r->buttons & GMETA_MASK)|GINPUT_MISSED_MOUSE_EVENT);
		return;
	}

	// If we haven't really moved (and there are no meta events) don't bother sending the event
	if (!(r->buttons & GMETA_MASK) && !psl->srcflags && !(psl->listenflags & GLISTEN_MOUSENOFILTER)
			&& r->x == m->r.x && r->y == m->r.y && (r->buttons & GINPUT_MOUSE_BTN_MASK) == (m->r.buttons & GINPUT_MOUSE_BTN_MASK))
		return;

	// Send the event only if we are listening for it
	if (!((r->buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES))
			&& !(!(r->buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES))
			&& !((r->buttons & GMETA_MASK) && (psl->listenflags & GLISTEN_MOUSEMETA)))
		return;

	#if !GINPUT_TOUCH_NOTOUCH
		pe->type = (gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH) ? GEVENT_TOUCH : GEVENT_MOUSE;
	#else
		pe->type = GEVENT_MOUSE;
	#endif
	pe->x = r->x;
	pe->y = r->y;
	pe->z = r->z;
	pe->buttons = r->buttons | psl->srcflags;
	psl->srcflags = 0;
	pe->display = m->display;
	geventSendEvent(psl);
}
Esempio n. 2
0
// The reading callback function
static void DialCallback(uint16_t instance, uint16_t rawvalue) {
	struct DialStatus_t *pds;
	GSourceListener		*psl;
	GEventDial			*pe;

	/* Get the information we need */
	pds = DialStatus+instance;

	/* Range scale - if needed */
	if (pds->max != GINPUT_DIAL_MAX_VALUE)
		rawvalue = (uint16_t)((uint32_t)rawvalue * pds->max / GINPUT_DIAL_MAX_VALUE);

	/* Forget about changes below our sensitivity threshold */
	if (rawvalue >= pds->lastvalue) {
		if (rawvalue - pds->lastvalue < pds->sensitivity) return;
	} else {
		if (pds->lastvalue - rawvalue < pds->sensitivity) return;
	}

	/* Save the value */
	pds->lastvalue = rawvalue;

	// Send the event to the listeners that are interested.
	psl = 0;
	while ((psl = geventGetSourceListener((GSourceHandle)(DialStatus+instance), psl))) {
		if (!(pe = (GEventDial *)geventGetEventBuffer(psl)))
			continue;
		pe->type = GEVENT_DIAL;
		pe->instance = instance;
		pe->value = pds->lastvalue;
		geventSendEvent(psl);
	}
}
Esempio n. 3
0
void _gwinSendEvent(GHandle gh, GEventType type) {
	GSourceListener	*	psl;
	GEventGWin *		pge;

	// Trigger a GWIN Event
	psl = 0;
	while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) {
		if (!(pge = (GEventGWin *)geventGetEventBuffer(psl)))
			continue;
		pge->type = type;
		pge->gwin = gh;
		#if GWIN_WIDGET_TAGS
			pge->tag = (gh->flags & GWIN_FLG_WIDGET) ? ((GWidgetObject *)gh)->tag : 0;
		#endif
		geventSendEvent(psl);
	}
}
Esempio n. 4
0
// Send the button event
static void SendButtonEvent(GWidgetObject *gw) {
	GSourceListener	*	psl;
	GEvent *			pe;
	#define pbe			((GEventGWinButton *)pe)

	// Trigger a GWIN Button Event
	psl = 0;
	while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) {
		if (!(pe = geventGetEventBuffer(psl)))
			continue;
		pbe->type = GEVENT_GWIN_BUTTON;
		pbe->button = (GHandle)gw;
		geventSendEvent(psl);
	}

	#undef pbe
}
Esempio n. 5
0
// Send the checkbox event
static void SendCheckboxEvent(GWidgetObject *gw) {
	GSourceListener	*	psl;
	GEvent *			pe;
	#define pce			((GEventGWinCheckbox *)pe)

	// Trigger a GWIN Checkbox Event
	psl = 0;
	while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) {
		if (!(pe = geventGetEventBuffer(psl)))
			continue;
		pce->type = GEVENT_GWIN_CHECKBOX;
		pce->checkbox = &gw->g;
		pce->isChecked = (gw->g.flags & GCHECKBOX_FLG_CHECKED) ? TRUE : FALSE;
		geventSendEvent(psl);
	}

	#undef pce
}
Esempio n. 6
0
static void SendKeyboardEventToListener(GSourceListener	*psl, GKeyboard *k) {
    GEventKeyboard		*pe;
    int					i;

    // If there is no event buffer just mark a missed event
    if (!(pe = (GEventKeyboard *)geventGetEventBuffer(psl))) {
        // This listener is missing - save the meta events that have happened
        psl->srcflags |= GKEYSTATE_MISSED_EVENT;
        return;
    }

    if ((psl->listenflags & GLISTEN_KEYRAW)) {
        pe->type = GEVENT_KEYBOARD;
        pe->bytecount = k->cntsc;
        for(i = 0; i < k->cntsc; i++)	pe->c[i] = k->sc[i];
        for(; i < 8; i++)				pe->c[i] = 0;
        pe->keystate = k->keystate | psl->srcflags | GKEYSTATE_RAW;
        psl->srcflags = 0;
        return;
    }

    if ((psl->listenflags & GLISTEN_KEYREPEATSOFF) && (k->keystate & GKEYSTATE_REPEAT))
        return;

    if ((psl->listenflags & GLISTEN_KEYNOSPECIALS) && (k->keystate & GKEYSTATE_SPECIAL))
        return;

    if (!(psl->listenflags & GLISTEN_KEYUP) && (k->keystate & GKEYSTATE_KEYUP))
        k->cntc = 0;

    if (!(psl->listenflags & GLISTEN_KEYTRANSITIONS) && !k->cntc)
        return;

    pe->type = GEVENT_KEYBOARD;
    pe->bytecount = k->cntc;
    for(i = 0; i < k->cntc; i++)	pe->c[i] = k->c[i];
    for(; i < 8; i++)				pe->c[i] = 0;
    pe->keystate = k->keystate | psl->srcflags;
    psl->srcflags = 0;
    geventSendEvent(psl);
}
Esempio n. 7
0
// Send the button event
static void SendRadioEvent(GWidgetObject *gw) {
	GSourceListener	*	psl;
	GEvent *			pe;
	#define pbe			((GEventGWinRadio *)pe)

	// Trigger a GWIN Button Event
	psl = 0;
	while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) {
		if (!(pe = geventGetEventBuffer(psl)))
			continue;
		pbe->type = GEVENT_GWIN_RADIO;
		pbe->gwin = (GHandle)gw;
		pbe->group = ((GRadioObject *)gw)->group;
		#if GWIN_WIDGET_TAGS
			pbe->tag = gw->tag;
		#endif
		geventSendEvent(psl);
	}

	#undef pbe
}
Esempio n. 8
0
static void sendListEvent(GWidgetObject *gw, int item) {
	GSourceListener*	psl;
	GEvent*				pe;

	// Trigger a GWIN list event
	psl = 0;

	while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) {
		if (!(pe = geventGetEventBuffer(psl)))
			continue;

		ple->type = GEVENT_GWIN_LIST;
		ple->gwin = (GHandle)gw;
		ple->item = item;
		#if GWIN_WIDGET_TAGS
			ple->tag = gw->tag;
		#endif

		geventSendEvent(psl);
	}
}
Esempio n. 9
0
	static void HighSpeedGTimerCallback(void *param) {
		(void) param;
		GSourceListener	*psl;
		GEventADC		*pe;

		psl = 0;
		while ((psl = geventGetSourceListener((GSourceHandle)(&HighSpeedGTimer), psl))) {
			if (!(pe = (GEventADC *)geventGetEventBuffer(psl))) {
				// This listener is missing - save this.
				psl->srcflags |= GADC_HSADC_LOSTEVENT;
				continue;
			}

			pe->type = GEVENT_ADC;
			pe->count = hs.lastcount;
			pe->buffer = hs.lastbuffer;
			pe->flags = hs.lastflags | psl->srcflags;
			psl->srcflags = 0;
			geventSendEvent(psl);
		}
	}
Esempio n. 10
0
	static void AudGTimerCallback(void *param) {
		(void) param;
		GSourceListener	*psl;
		GEventADC		*pe;

		psl = 0;
		while ((psl = geventGetSourceListener((GSourceHandle)(&aud), psl))) {
			if (!(pe = (GEventAudioIn *)geventGetEventBuffer(psl))) {
				// This listener is missing - save this.
				psl->srcflags |= GADC_AUDIO_IN_LOSTEVENT;
				continue;
			}

			pe->type = GEVENT_AUDIO_IN;
			pe->channel = aud.channel;
			pe->count = lastcount;
			pe->buffer = lastbuffer;
			pe->flags = psl->srcflags;
			psl->srcflags = 0;
			geventSendEvent(psl);
		}
	}
Esempio n. 11
0
static void MousePoll(void *param) {
	(void) param;
	GSourceListener	*psl;
	GEventMouse		*pe;
	unsigned 		meta;
	uint16_t		tbtns;
	uint32_t		cdiff;
	uint32_t		mdiff;

	// Save the last mouse state
	MouseConfig.last_buttons = MouseConfig.t.buttons;

	// Get the new mouse reading
	get_calibrated_reading(&MouseConfig.t);

	// Calculate out new event meta value and handle CLICK and CXTCLICK
	meta = GMETA_NONE;

	// Calculate the position difference from our movement reference (update the reference if out of range)
	mdiff = (MouseConfig.t.x - MouseConfig.movepos.x) * (MouseConfig.t.x - MouseConfig.movepos.x) +
		(MouseConfig.t.y - MouseConfig.movepos.y) * (MouseConfig.t.y - MouseConfig.movepos.y);
	if (mdiff > GINPUT_MOUSE_MAX_MOVE_JITTER * GINPUT_MOUSE_MAX_MOVE_JITTER) {
		MouseConfig.movepos.x = MouseConfig.t.x;
		MouseConfig.movepos.y = MouseConfig.t.y;
	}
	
	// Check if the click has moved outside the click area and if so cancel the click
	if ((MouseConfig.flags & FLG_CLICK_TIMER)) {
		cdiff = (MouseConfig.t.x - MouseConfig.clickpos.x) * (MouseConfig.t.x - MouseConfig.clickpos.x) +
			(MouseConfig.t.y - MouseConfig.clickpos.y) * (MouseConfig.t.y - MouseConfig.clickpos.y);
		if (cdiff > GINPUT_MOUSE_MAX_CLICK_JITTER * GINPUT_MOUSE_MAX_CLICK_JITTER)
			MouseConfig.flags &= ~FLG_CLICK_TIMER;
	}

	// Mouse down
	tbtns = MouseConfig.t.buttons & ~MouseConfig.last_buttons;
	if ((tbtns & GINPUT_MOUSE_BTN_LEFT))
		meta |= GMETA_MOUSE_DOWN;
	if ((tbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) {
		MouseConfig.clickpos.x = MouseConfig.t.x;
		MouseConfig.clickpos.y = MouseConfig.t.y;
		MouseConfig.clicktime = chTimeNow();
		MouseConfig.flags |= FLG_CLICK_TIMER;
	}

	// Mouse up
	tbtns = ~MouseConfig.t.buttons & MouseConfig.last_buttons;
	if ((tbtns & GINPUT_MOUSE_BTN_LEFT))
		meta |= GMETA_MOUSE_UP;
	if ((tbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) {
		if ((MouseConfig.flags & FLG_CLICK_TIMER)) {
			if ((tbtns & GINPUT_MOUSE_BTN_LEFT)
					#if GINPUT_MOUSE_CLICK_TIME != TIME_INFINITE
						&& chTimeNow() - MouseConfig.clicktime < MS2ST(GINPUT_MOUSE_CLICK_TIME)
					#endif
					)
				meta |= GMETA_MOUSE_CLICK;
			else
				meta |= GMETA_MOUSE_CXTCLICK;
			MouseConfig.flags &= ~FLG_CLICK_TIMER;
		}
	}

	// Send the event to the listeners that are interested.
	psl = 0;
	while ((psl = geventGetSourceListener((GSourceHandle)(&MouseConfig), psl))) {
		if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) {
			// This listener is missing - save the meta events that have happened
			psl->srcflags |= meta;
			continue;
		}

		// If we haven't really moved (and there are no meta events) don't bother sending the event
		if (mdiff <= GINPUT_MOUSE_MAX_MOVE_JITTER * GINPUT_MOUSE_MAX_MOVE_JITTER && !psl->srcflags && !meta && !(psl->listenflags & GLISTEN_MOUSENOFILTER))
			continue;

		// Send the event if we are listening for it
		if (((MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES))
				|| (!(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES))
				|| (meta && (psl->listenflags & GLISTEN_MOUSEMETA))) {
			pe->type = GINPUT_MOUSE_EVENT_TYPE;
			pe->instance = 0;
			pe->x = MouseConfig.t.x;
			pe->y = MouseConfig.t.y;
			pe->z = MouseConfig.t.z;
			pe->current_buttons = MouseConfig.t.buttons;
			pe->last_buttons = MouseConfig.last_buttons;
			pe->meta = meta;
			if (psl->srcflags) {
				pe->current_buttons |= GINPUT_MISSED_MOUSE_EVENT;
				pe->meta |= psl->srcflags;
				psl->srcflags = 0;
			}
			geventSendEvent(psl);
		}
	}
}
Esempio n. 12
0
	static void mouseDown(GWidgetObject *gw, coord_t mx, coord_t my) {
		GHandle		ph, gh;
		int			cnt;

		if (my < 0 || my > ((GTabsetObject *)gw)->border_top)
			return;

		// Work out which tab was pressed
		{
			coord_t		x, w, y;

			cnt = 0;
			x = w = 0;
			y = GWIN_TABSET_TABHEIGHT;
			gh = 0;
			for(ph = gwinGetFirstChild(&gw->g); ph; ph = gwinGetSibling(ph)) {
				if (ph->vmt == (gwinVMT *)&tabpageVMT) {
					w = gdispGetStringWidth(((GWidgetObject *)ph)->text, gw->g.font) + TEXT_PADDING*2;
					x += w;
					if (x > gw->g.width) {
						y += GWIN_TABSET_TABHEIGHT;
						x = w;
					}
					if (my < y && mx < x) {
						gh = ph;
						break;
					}
					cnt++;
				}
			}
			if (!gh || (gh->flags & GWIN_FLG_VISIBLE))
				return;
		}

		// Mark the existing tab as not visible
		for(ph = gwinGetFirstChild(&gw->g); ph; ph = gwinGetSibling(ph)) {
			if (ph->vmt == (gwinVMT *)&tabpageVMT && (ph->flags & GWIN_FLG_VISIBLE)) {
				// Mark this page invisible
				ph->flags &= ~GWIN_FLG_VISIBLE;
				break;
			}
		}

		// Mark this tab as visible
		gh->flags |= GWIN_FLG_VISIBLE;
		_gwinRippleVisibility();

		// Force a redraw of the whole tabset
		_gwinUpdate(&gw->g);

		// Send the Tabset Event
		{
			GSourceListener	*	psl;
			GEventGWinTabset *	pge;

			psl = 0;
			while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) {
				if (!(pge = (GEventGWinTabset *)geventGetEventBuffer(psl)))
					continue;
				pge->type = GEVENT_GWIN_TABSET;
				pge->gwin = &gw->g;
				#if GWIN_WIDGET_TAGS
					pge->tag = gw->tag;
				#endif
				pge->ghPage = gh;
				pge->nPage = cnt;
				geventSendEvent(psl);
			}
		}
	}