Пример #1
0
void rtgui_server_handle_touch(struct rtgui_event_touch *event)
{
	if (rtgui_touch_do_calibration(event) == RT_TRUE)
	{
		struct rtgui_event_mouse emouse;

		/* convert it as a mouse event to rtgui */
		if (event->up_down == RTGUI_TOUCH_MOTION)
		{
			RTGUI_EVENT_MOUSE_MOTION_INIT(&emouse);
			emouse.x = event->x;
			emouse.y = event->y;
			emouse.button = 0;

			rtgui_server_handle_mouse_motion(&emouse);
		}
		else
		{
			RTGUI_EVENT_MOUSE_BUTTON_INIT(&emouse);
			emouse.x = event->x;
			emouse.y = event->y;
			emouse.button = RTGUI_MOUSE_BUTTON_LEFT;
			if (event->up_down == RTGUI_TOUCH_UP)
				emouse.button |= RTGUI_MOUSE_BUTTON_UP;
			else
				emouse.button |= RTGUI_MOUSE_BUTTON_DOWN;

			rtgui_server_handle_mouse_btn(&emouse);
		}
	}
}
Пример #2
0
static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object,
        struct rtgui_event *event)
{
    RT_ASSERT(object != RT_NULL);
    RT_ASSERT(event != RT_NULL);

    /* dispatch event */
    switch (event->type)
    {
    case RTGUI_EVENT_APP_CREATE:
    case RTGUI_EVENT_APP_DESTROY:
        if (rtgui_wm_application != RT_NULL)
        {
            /* forward event to wm application */
            rtgui_send(rtgui_wm_application->tid, event, sizeof(struct rtgui_event_application));
        }
        else
        {
            /* always ack with OK */
            rtgui_ack(event, RTGUI_STATUS_OK);
        }
        break;

        /* mouse and keyboard event */
    case RTGUI_EVENT_MOUSE_MOTION:
        /* handle mouse motion event */
        rtgui_server_handle_mouse_motion((struct rtgui_event_mouse *)event);
        break;

    case RTGUI_EVENT_MOUSE_BUTTON:
        /* handle mouse button */
        rtgui_server_handle_mouse_btn((struct rtgui_event_mouse *)event);
        break;

    case RTGUI_EVENT_KBD:
        /* handle keyboard event */
        rtgui_server_handle_kbd((struct rtgui_event_kbd *)event);
        break;

        /* window event */
    case RTGUI_EVENT_WIN_CREATE:
        if (rtgui_topwin_add((struct rtgui_event_win_create *)event) == RT_EOK)
            rtgui_ack(event, RTGUI_STATUS_OK);
        else
            rtgui_ack(event, RTGUI_STATUS_ERROR);
        break;

    case RTGUI_EVENT_WIN_SHOW:
        if (rtgui_topwin_show((struct rtgui_event_win *)event) == RT_EOK)
            rtgui_ack(event, RTGUI_STATUS_OK);
        else
            rtgui_ack(event, RTGUI_STATUS_ERROR);
        break;

    case RTGUI_EVENT_WIN_HIDE:
        if (rtgui_topwin_hide((struct rtgui_event_win *)event) == RT_EOK)
            rtgui_ack(event, RTGUI_STATUS_OK);
        else
            rtgui_ack(event, RTGUI_STATUS_ERROR);
        break;

    case RTGUI_EVENT_WIN_MOVE:
        if (rtgui_topwin_move((struct rtgui_event_win_move *)event) == RT_EOK)
            rtgui_ack(event, RTGUI_STATUS_OK);
        else
            rtgui_ack(event, RTGUI_STATUS_ERROR);
        break;

    case RTGUI_EVENT_WIN_MODAL_ENTER:
        if (rtgui_topwin_modal_enter((struct rtgui_event_win_modal_enter *)event) == RT_EOK)
            rtgui_ack(event, RTGUI_STATUS_OK);
        else
            rtgui_ack(event, RTGUI_STATUS_ERROR);
        break;

    case RTGUI_EVENT_WIN_ACTIVATE:
        if (rtgui_topwin_activate((struct rtgui_event_win_activate *)event) == RT_EOK)
            rtgui_ack(event, RTGUI_STATUS_OK);
        else
            rtgui_ack(event, RTGUI_STATUS_ERROR);
        break;

    case RTGUI_EVENT_WIN_DESTROY:
        if (last_monitor_topwin != RT_NULL &&
                last_monitor_topwin->wid == ((struct rtgui_event_win *)event)->wid)
            last_monitor_topwin = RT_NULL;
        if (rtgui_topwin_remove(((struct rtgui_event_win *)event)->wid) == RT_EOK)
            rtgui_ack(event, RTGUI_STATUS_OK);
        else
            rtgui_ack(event, RTGUI_STATUS_ERROR);
        break;

    case RTGUI_EVENT_WIN_RESIZE:
        rtgui_topwin_resize(((struct rtgui_event_win_resize *)event)->wid,
                            &(((struct rtgui_event_win_resize *)event)->rect));
        break;

    case RTGUI_EVENT_SET_WM:
        if (rtgui_wm_application != RT_NULL)
        {
            rtgui_ack(event, RTGUI_STATUS_ERROR);
        }
        else
        {
            struct rtgui_event_set_wm *set_wm;

            set_wm = (struct rtgui_event_set_wm *) event;
            rtgui_wm_application = set_wm->app;
            rtgui_ack(event, RTGUI_STATUS_OK);
        }
        break;

        /* other event */
    case RTGUI_EVENT_COMMAND:
        break;

    case RTGUI_EVENT_UPDATE_BEGIN:
#ifdef RTGUI_USING_MOUSE_CURSOR
        /* hide cursor */
        rtgui_mouse_hide_cursor();
#endif
        break;

    case RTGUI_EVENT_UPDATE_END:
        /* handle screen update */
        rtgui_server_handle_update((struct rtgui_event_update_end *)event);
#ifdef RTGUI_USING_MOUSE_CURSOR
        /* show cursor */
        rtgui_mouse_show_cursor();
#endif
        break;

    case RTGUI_EVENT_MONITOR_ADD:
        /* handle mouse monitor */
        rtgui_server_handle_monitor_add((struct rtgui_event_monitor *)event);
        break;
    default:
        rt_kprintf("RTGUI: wrong event sent to server: %d", event->type);
        return RT_FALSE;
    }

    return RT_TRUE;
}