Пример #1
0
void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event)
{
    struct rtgui_topwin *wnd;

    /* re-init to server thread */
    RTGUI_EVENT_MOUSE_BUTTON_INIT(event);

	/* set cursor position */
	rtgui_mouse_set_position(event->x, event->y);

#ifdef RTGUI_USING_WINMOVE
    if (rtgui_winrect_is_moved() &&
        event->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP))
    {
        struct rtgui_win *win;
        rtgui_rect_t rect;

        if (rtgui_winrect_moved_done(&rect, &win) == RT_TRUE)
        {
            struct rtgui_event_win_move ewin;

            /* move window */
            RTGUI_EVENT_WIN_MOVE_INIT(&ewin);
            ewin.wid = win;
            ewin.x = rect.x1;
            ewin.y = rect.y1;

            /* send to client thread */
            rtgui_send(win->app, &(ewin.parent), sizeof(ewin));

            return;
        }
    }
#endif

    /* get the wnd which contains the mouse */
    wnd = rtgui_topwin_get_wnd_no_modaled(event->x, event->y);
    if (wnd == RT_NULL)
        return;

    event->wid = wnd->wid;

    /* only raise window if the button is pressed down */
    if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
        rtgui_topwin_get_focus() != wnd)
    {
        rtgui_topwin_activate_topwin(wnd);
    }

	/* handle gesture event */
	if (rtgui_gesture_handle(event, wnd) == 0)
        return;

    /* send mouse event to thread */
    rtgui_send(wnd->app,
               (struct rtgui_event *)event,
               sizeof(struct rtgui_event_mouse));
}
Пример #2
0
void rtgui_server_post_event(struct rtgui_event *event, rt_size_t size)
{
    if (rtgui_server_tid != RT_NULL)
        rtgui_send(rtgui_server_tid, event, size);
    else
        rt_kprintf("post when server is not running\n");
}
Пример #3
0
void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse *event)
{
    /* the topwin contains current mouse */
    struct rtgui_topwin *win    = RT_NULL;

    /* re-init mouse event */
    RTGUI_EVENT_MOUSE_MOTION_INIT(event);

    win = rtgui_topwin_get_wnd_no_modaled(event->x, event->y);
    if (win != RT_NULL && win->monitor_list.next != RT_NULL)
    {
        // FIXME:
        /* check whether the monitor exist */
        if (rtgui_mouse_monitor_contains_point(&(win->monitor_list),
                                               event->x, event->y) != RT_TRUE)
        {
            win = RT_NULL;
        }
    }

    if (last_monitor_topwin != RT_NULL)
    {
        event->wid = last_monitor_topwin->wid;
        /* send mouse motion event */
        rtgui_send(last_monitor_topwin->app,
                   &(event->parent),
                   sizeof(struct rtgui_event_mouse));
    }

    if (last_monitor_topwin != win)
    {
        last_monitor_topwin = win;
        if (last_monitor_topwin != RT_NULL)
        {
            event->wid = last_monitor_topwin->wid;

            /* send mouse motion event */
            rtgui_send(last_monitor_topwin->app,
                       &(event->parent),
                       sizeof(struct rtgui_event_mouse));
        }
    }

    /* move mouse to (x, y) */
    rtgui_mouse_moveto(event->x, event->y);
}
Пример #4
0
void rtgui_app_close(struct rtgui_app *app)
{
	struct rtgui_event_application event;

	RTGUI_EVENT_APP_DESTROY_INIT(&event);
	event.app = app;

	rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
}
Пример #5
0
void rtgui_app_activate(struct rtgui_app *app)
{
	struct rtgui_event_application event;

	RTGUI_EVENT_APP_ACTIVATE_INIT(&event);
	event.app = app;

	rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
}
Пример #6
0
static void rtgui_time_out(void *parameter)
{
    rtgui_timer_t *timer;
    rtgui_event_timer_t event;
    timer = (rtgui_timer_t *)parameter;

    /*
    * Note: event_timer can not use RTGUI_EVENT_TIMER_INIT to init, for there is no
    * thread context
    */
    event.parent.type = RTGUI_EVENT_TIMER;
    event.parent.sender = RT_NULL;

    event.timer = timer;

    rtgui_send(timer->app, &(event.parent), sizeof(rtgui_event_timer_t));
}
Пример #7
0
void rtgui_server_handle_kbd(struct rtgui_event_kbd *event)
{
    struct rtgui_topwin *wnd;

    /* re-init to server thread */
    RTGUI_EVENT_KBD_INIT(event);

    /* todo: handle input method and global shortcut */

    wnd = rtgui_topwin_get_focus();
    if (wnd != RT_NULL)
    {
        RT_ASSERT(wnd->flag & WINTITLE_ACTIVATE)

        /* send to focus window */
        event->wid = wnd->wid;

        /* send keyboard event to thread */
        rtgui_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_kbd));

        return;
    }
}
Пример #8
0
void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event)
{
    struct rtgui_topwin *wnd;

    /* re-init to server thread */
    RTGUI_EVENT_MOUSE_BUTTON_INIT(event);

	/* set cursor position */
	rtgui_mouse_set_position(event->x, event->y);

#ifdef RTGUI_USING_WINMOVE
    if (rtgui_winrect_is_moved() &&
            event->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP))
    {
        struct rtgui_topwin *topwin;
        rtgui_rect_t rect;

        if (rtgui_winrect_moved_done(&rect, &topwin) == RT_TRUE)
        {
            struct rtgui_event_win_move ewin;

            /* move window */
            RTGUI_EVENT_WIN_MOVE_INIT(&ewin);
            ewin.wid = topwin->wid;
            if (topwin->title != RT_NULL)
            {
                if (topwin->flag & WINTITLE_BORDER)
                {
                    ewin.x = rect.x1 + WINTITLE_BORDER_SIZE;
                    ewin.y = rect.y1 + WINTITLE_BORDER_SIZE;
                }
                if (!(topwin->flag & WINTITLE_NO)) ewin.y += WINTITLE_HEIGHT;
            }
            else
            {
                ewin.x = rect.x1;
                ewin.y = rect.y1;
            }

            /* send to client thread */
            rtgui_send(topwin->tid, &(ewin.parent), sizeof(ewin));

            return;
        }
    }
#endif

    /* get the wnd which contains the mouse */
    wnd = rtgui_topwin_get_wnd_no_modaled(event->x, event->y);
    if (wnd != RT_NULL)
    {
        event->wid = wnd->wid;

        if (rtgui_topwin_get_focus() != wnd)
        {
            /* raise this window */
            rtgui_topwin_activate_topwin(wnd);
        }

        if (wnd->title != RT_NULL &&
                rtgui_rect_contains_point(&(RTGUI_WIDGET(wnd->title)->extent), event->x, event->y) == RT_EOK)
        {
            rtgui_topwin_title_onmouse(wnd, event);
        }
        else
        {
            /* send mouse event to thread */
            rtgui_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_mouse));
        }
        return ;
    }
}
Пример #9
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;
}
Пример #10
0
static void calibration_data_post(rt_uint16_t x, rt_uint16_t y)
{
    rt_kprintf("calibration_data_post x %d y %d\n", x, y);
    
    if (calibration_ptr != RT_NULL)
    {
        switch (calibration_ptr->step)
        {
        case CALIBRATION_STEP_LEFTTOP:
            calibration_ptr->data.min_x = x;
            calibration_ptr->data.min_y = y;
            break;

        case CALIBRATION_STEP_RIGHTTOP:
            calibration_ptr->data.max_x = x;
            calibration_ptr->data.min_y = (calibration_ptr->data.min_y + y)/2;
            break;

        case CALIBRATION_STEP_LEFTBOTTOM:
            calibration_ptr->data.min_x = (calibration_ptr->data.min_x + x)/2;
            calibration_ptr->data.max_y = y;
            break;

        case CALIBRATION_STEP_RIGHTBOTTOM:
            calibration_ptr->data.max_x = (calibration_ptr->data.max_x + x)/2;
            calibration_ptr->data.max_y = (calibration_ptr->data.max_y + y)/2;
            break;

        case CALIBRATION_STEP_CENTER:
            /* calibration done */
            {
                rt_uint16_t w, h;

                struct rtgui_event_command ecmd;
                RTGUI_EVENT_COMMAND_INIT(&ecmd);
                ecmd.wid = calibration_ptr->win;                
                ecmd.command_id = TOUCH_WIN_CLOSE;

                /* calculate calibrated data */
                if (calibration_ptr->data.max_x > calibration_ptr->data.min_x)
                    w = calibration_ptr->data.max_x - calibration_ptr->data.min_x;
                else
                    w = calibration_ptr->data.min_x - calibration_ptr->data.max_x;
                w = (w/(calibration_ptr->width - 2 * CALIBRATION_WIDTH)) * CALIBRATION_WIDTH;

                if (calibration_ptr->data.max_y > calibration_ptr->data.min_y)
                    h = calibration_ptr->data.max_y - calibration_ptr->data.min_y;
                else
                    h = calibration_ptr->data.min_y - calibration_ptr->data.max_y;
                h = (h/(calibration_ptr->height - 2 * CALIBRATION_HEIGHT)) * CALIBRATION_HEIGHT;

                rt_kprintf("w: %d, h: %d\n", w, h);

                if (calibration_ptr->data.max_x > calibration_ptr->data.min_x)
                {
                    calibration_ptr->data.min_x -= w;
                    calibration_ptr->data.max_x += w;
                }
                else
                {
                    calibration_ptr->data.min_x += w;
                    calibration_ptr->data.max_x -= w;
                }

                if (calibration_ptr->data.max_y > calibration_ptr->data.min_y)
                {
                    calibration_ptr->data.min_y -= h;
                    calibration_ptr->data.max_y += h;
                }
                else
                {
                    calibration_ptr->data.min_y += h;
                    calibration_ptr->data.max_y -= h;
                }

                rt_kprintf("calibration data: (%d, %d), (%d, %d)\n",
                    calibration_ptr->data.min_x,
                    calibration_ptr->data.max_x,
                    calibration_ptr->data.min_y,
                    calibration_ptr->data.max_y);
                rtgui_send(calibration_ptr->app, &ecmd.parent, sizeof(struct rtgui_event_command));
            }
            return;
        }

        calibration_ptr->step ++;

        /* post command event */
        {
            struct rtgui_event_command ecmd;
            RTGUI_EVENT_COMMAND_INIT(&ecmd);
            ecmd.wid = calibration_ptr->win;
            ecmd.command_id = TOUCH_WIN_UPDATE;

            rtgui_send(calibration_ptr->app, &ecmd.parent, sizeof(struct rtgui_event_command));
        }
    }
}
Пример #11
0
static void calibration_data_post(rt_uint16_t x, rt_uint16_t y)
{
    if (calibration_ptr == RT_NULL)
        return;

    switch (calibration_ptr->step)
    {
    case CALIBRATION_STEP_LEFTTOP:
        cal_data->xfb[0] = CALIBRATION_WIDTH;
        cal_data->yfb[0] = CALIBRATION_HEIGHT;
        cal_data->x[0] = x;
        cal_data->y[0] = y;
        break;

    case CALIBRATION_STEP_RIGHTTOP:
        cal_data->xfb[1] = calibration_ptr->width - CALIBRATION_WIDTH;
        cal_data->yfb[1] =  CALIBRATION_HEIGHT;
        cal_data->x[1] = x;
        cal_data->y[1] = y;
        break;

    case CALIBRATION_STEP_LEFTBOTTOM:
        cal_data->xfb[3] = CALIBRATION_WIDTH;
        cal_data->yfb[3] = calibration_ptr->height - CALIBRATION_HEIGHT;
        cal_data->x[3] = x;
        cal_data->y[3] = y;
        break;

    case CALIBRATION_STEP_RIGHTBOTTOM:
        cal_data->xfb[2] = calibration_ptr->width - CALIBRATION_WIDTH;
        cal_data->yfb[2] = calibration_ptr->height - CALIBRATION_HEIGHT;
        cal_data->x[2] = x;
        cal_data->y[2] = y;
        break;

    case CALIBRATION_STEP_CENTER:
        /* calibration done */
    {
        rt_uint8_t i;
        struct rtgui_event_command ecmd;
        RTGUI_EVENT_COMMAND_INIT(&ecmd);
        ecmd.wid = calibration_ptr->win;
        ecmd.command_id = TOUCH_WIN_CLOSE;
        cal_data->xfb[4] = (calibration_ptr->width >> 1);
        cal_data->yfb[4] = (calibration_ptr->height >> 1);
        cal_data->x[4] = x;
        cal_data->y[4] = y;
        for (i = 0; i < 5; i++)
        {
            rt_kprintf("xfb[%d]:%d,yfb[%d]:%d,x[%d]:%d,y[%d]:%d\r\n", i, cal_data->xfb[i], i, cal_data->yfb[i], i, cal_data->x[i], i, cal_data->y[i]);
        }
        perform_calibration(cal_data);
        rtgui_send(calibration_ptr->app, &ecmd.parent, sizeof(struct rtgui_event_command));
    }
    calibration_ptr->step = 0;
    return;
    }

    calibration_ptr->step++;

    /* post command event */
    {
        struct rtgui_event_command ecmd;
        RTGUI_EVENT_COMMAND_INIT(&ecmd);
        ecmd.wid = calibration_ptr->win;
        ecmd.command_id = TOUCH_WIN_UPDATE;

        rtgui_send(calibration_ptr->app, &ecmd.parent, sizeof(struct rtgui_event_command));
    }
}