diff options
Diffstat (limited to 'components/rtgui/server')
| -rw-r--r-- | components/rtgui/server/driver.c | 37 | ||||
| -rw-r--r-- | components/rtgui/server/mouse.c | 15 | ||||
| -rw-r--r-- | components/rtgui/server/mouse.h | 2 | ||||
| -rw-r--r-- | components/rtgui/server/server.c | 73 | ||||
| -rw-r--r-- | components/rtgui/server/topwin.c | 20 |
5 files changed, 106 insertions, 41 deletions
diff --git a/components/rtgui/server/driver.c b/components/rtgui/server/driver.c index 2fe19347b5..dd441afb88 100644 --- a/components/rtgui/server/driver.c +++ b/components/rtgui/server/driver.c @@ -41,6 +41,7 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device) { rt_err_t result; struct rt_device_graphic_info info; + struct rtgui_graphic_ext_ops *ext_ops; /* get framebuffer address */ result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info); @@ -59,6 +60,13 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device) _driver.pitch = _driver.width * _driver.bits_per_pixel / 8; _driver.framebuffer = info.framebuffer; + /* get graphic extension operations */ + result = rt_device_control(device, RTGRAPHIC_CTRL_GET_EXT, &ext_ops); + if (result == RT_EOK) + { + _driver.ext_ops = ext_ops; + } + if (info.framebuffer != RT_NULL) { /* is a frame buffer device */ @@ -70,6 +78,11 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device) _driver.ops = rtgui_pixel_device_get_ops(_driver.pixel_format); } +#ifdef RTGUI_USING_HW_CURSOR + /* set default cursor image */ + rtgui_cursor_set_image(RTGUI_CURSOR_ARROW); +#endif + return RT_EOK; } RTM_EXPORT(rtgui_graphic_set_device); @@ -100,3 +113,27 @@ rt_uint8_t *rtgui_graphic_driver_get_default_framebuffer(void) } RTM_EXPORT(rtgui_graphic_driver_get_default_framebuffer); +#ifdef RTGUI_USING_HW_CURSOR +void rtgui_cursor_set_position(rt_uint16_t x, rt_uint16_t y) +{ + rt_uint32_t value; + + if (_driver.device != RT_NULL) + { + value = (x << 16 | y); + rt_device_control(_driver.device, RT_DEVICE_CTRL_CURSOR_SET_POSITION, &value); + } +} + +void rtgui_cursor_set_image(enum rtgui_cursor_type type) +{ + rt_uint32_t value; + + if (_driver.device != RT_NULL) + { + value = type; + rt_device_control(_driver.device, RT_DEVICE_CTRL_CURSOR_SET_TYPE, &value); + } +}; +#endif + diff --git a/components/rtgui/server/mouse.c b/components/rtgui/server/mouse.c index 27972af2b2..0fff8f101c 100644 --- a/components/rtgui/server/mouse.c +++ b/components/rtgui/server/mouse.c @@ -255,6 +255,10 @@ void rtgui_mouse_moveto(int x, int y) rtgui_mouse_show_cursor(); #endif } + +#ifdef RTGUI_USING_HW_CURSOR + rtgui_cursor_set_position(_rtgui_cursor->cx, _rtgui_cursor->cy); +#endif } #ifdef RTGUI_USING_MOUSE_CURSOR @@ -262,6 +266,17 @@ void rtgui_mouse_moveto(int x, int y) #endif } +void rtgui_mouse_set_position(int x, int y) +{ + /* move current cursor */ + _rtgui_cursor->cx = x; + _rtgui_cursor->cy = y; + +#ifdef RTGUI_USING_HW_CURSOR + rtgui_cursor_set_position(_rtgui_cursor->cx, _rtgui_cursor->cy); +#endif +} + #ifdef RTGUI_USING_MOUSE_CURSOR void rtgui_mouse_set_cursor_enable(rt_bool_t enable) { diff --git a/components/rtgui/server/mouse.h b/components/rtgui/server/mouse.h index 7b8c4f5990..dd62596efe 100644 --- a/components/rtgui/server/mouse.h +++ b/components/rtgui/server/mouse.h @@ -31,6 +31,8 @@ typedef struct rtgui_mouse_monitor rtgui_mouse_monitor_t; void rtgui_mouse_init(void); void rtgui_mouse_fini(void); void rtgui_mouse_moveto(int x, int y); +/* set cursor position */ +void rtgui_mouse_set_position(int x, int y); void rtgui_mouse_set_cursor_enable(rt_bool_t enable); void rtgui_mouse_set_cursor(rtgui_image_t *cursor); diff --git a/components/rtgui/server/server.c b/components/rtgui/server/server.c index ea0fbc44c8..8728a5ed44 100644 --- a/components/rtgui/server/server.c +++ b/components/rtgui/server/server.c @@ -22,9 +22,7 @@ #include "mouse.h" #include "topwin.h" -static struct rt_thread *rtgui_server_tid; - -static struct rtgui_app *rtgui_server_application = RT_NULL; +static struct rtgui_app *rtgui_server_app = RT_NULL; static struct rtgui_app *rtgui_wm_application = RT_NULL; void rtgui_server_handle_update(struct rtgui_event_update_end *event) @@ -57,6 +55,9 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event) /* 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)) @@ -87,7 +88,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event) } /* send to client thread */ - rtgui_send(topwin->tid, &(ewin.parent), sizeof(ewin)); + rtgui_send(topwin->app, &(ewin.parent), sizeof(ewin)); return; } @@ -100,9 +101,10 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event) { event->wid = wnd->wid; - if (rtgui_topwin_get_focus() != wnd) + /* only raise window if the button is pressed down */ + if (event->button & RTGUI_MOUSE_BUTTON_DOWN + && rtgui_topwin_get_focus() != wnd) { - /* raise this window */ rtgui_topwin_activate_topwin(wnd); } @@ -114,7 +116,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event) else { /* send mouse event to thread */ - rtgui_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_mouse)); + rtgui_send(wnd->app, (struct rtgui_event *)event, sizeof(struct rtgui_event_mouse)); } return ; } @@ -146,7 +148,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse *event) { event->wid = last_monitor_topwin->wid; /* send mouse motion event */ - rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + rtgui_send(last_monitor_topwin->app, &(event->parent), sizeof(struct rtgui_event_mouse)); } if (last_monitor_topwin != win) @@ -157,7 +159,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse *event) event->wid = last_monitor_topwin->wid; /* send mouse motion event */ - rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + rtgui_send(last_monitor_topwin->app, &(event->parent), sizeof(struct rtgui_event_mouse)); } } @@ -183,7 +185,7 @@ void rtgui_server_handle_kbd(struct rtgui_event_kbd *event) event->wid = wnd->wid; /* send keyboard event to thread */ - rtgui_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_kbd)); + rtgui_send(wnd->app, (struct rtgui_event *)event, sizeof(struct rtgui_event_kbd)); return; } @@ -207,7 +209,7 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object, if (rtgui_wm_application != RT_NULL) { /* forward event to wm application */ - rtgui_send(rtgui_wm_application->tid, event, sizeof(struct rtgui_event_application)); + rtgui_send(rtgui_wm_application, event, sizeof(struct rtgui_event_application)); } else { @@ -349,12 +351,12 @@ static void rtgui_server_entry(void *parameter) #endif /* create rtgui server application */ - rtgui_server_application = rtgui_app_create(rtgui_server_tid, - "rtgui"); - if (rtgui_server_application == RT_NULL) + rtgui_server_app = rtgui_app_create("rtgui"); + rt_kprintf("RTGUI: create server: %p", rtgui_server_app); + if (rtgui_server_app == RT_NULL) return; - rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_application), + rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_app), rtgui_server_event_handler); /* init mouse and show */ rtgui_mouse_init(); @@ -362,24 +364,24 @@ static void rtgui_server_entry(void *parameter) rtgui_mouse_show_cursor(); #endif - rtgui_app_run(rtgui_server_application); + rtgui_app_run(rtgui_server_app); - rtgui_app_destroy(rtgui_server_application); - rtgui_server_application = RT_NULL; + rtgui_app_destroy(rtgui_server_app); + rtgui_server_app = RT_NULL; } 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); + if (rtgui_server_app != RT_NULL) + rtgui_send(rtgui_server_app, event, size); else rt_kprintf("post when server is not running\n"); } rt_err_t rtgui_server_post_event_sync(struct rtgui_event *event, rt_size_t size) { - if (rtgui_server_tid != RT_NULL) - return rtgui_send_sync(rtgui_server_tid, event, size); + if (rtgui_server_app != RT_NULL) + return rtgui_send_sync(rtgui_server_app, event, size); else { rt_kprintf("post when server is not running\n"); @@ -387,18 +389,27 @@ rt_err_t rtgui_server_post_event_sync(struct rtgui_event *event, rt_size_t size) } } +struct rtgui_app* rtgui_get_server(void) +{ + rt_thread_t tid = rt_thread_find("rtgui"); + + if (tid == RT_NULL) + return RT_NULL; + return (struct rtgui_app*)tid->user_data; +} +RTM_EXPORT(rtgui_get_server); + void rtgui_server_init(void) { - if (rtgui_server_tid != RT_NULL) - return; + rt_thread_t tid; - rtgui_server_tid = rt_thread_create("rtgui", - rtgui_server_entry, RT_NULL, - RTGUI_SVR_THREAD_STACK_SIZE, - RTGUI_SVR_THREAD_PRIORITY, - RTGUI_SVR_THREAD_TIMESLICE); + tid = rt_thread_create("rtgui", + rtgui_server_entry, RT_NULL, + RTGUI_SVR_THREAD_STACK_SIZE, + RTGUI_SVR_THREAD_PRIORITY, + RTGUI_SVR_THREAD_TIMESLICE); /* start rtgui server thread */ - if (rtgui_server_tid != RT_NULL) - rt_thread_startup(rtgui_server_tid); + if (tid != RT_NULL) + rt_thread_startup(tid); } diff --git a/components/rtgui/server/topwin.c b/components/rtgui/server/topwin.c index abb69d717d..d052e00071 100644 --- a/components/rtgui/server/topwin.c +++ b/components/rtgui/server/topwin.c @@ -102,7 +102,7 @@ rt_err_t rtgui_topwin_add(struct rtgui_event_win_create *event) #else topwin->extent = event->extent; #endif - topwin->tid = event->parent.sender; + topwin->app = event->parent.sender; if (event->parent_window == RT_NULL) { @@ -337,7 +337,7 @@ static void _rtgui_topwin_only_activate(struct rtgui_topwin *topwin) topwin->flag |= WINTITLE_ACTIVATE; event.wid = topwin->wid; - rtgui_send(topwin->tid, &(event.parent), sizeof(struct rtgui_event_win)); + rtgui_send(topwin->app, &(event.parent), sizeof(struct rtgui_event_win)); /* redraw title */ if (topwin->title != RT_NULL) @@ -366,11 +366,11 @@ static void _rtgui_topwin_deactivate(struct rtgui_topwin *topwin) struct rtgui_event_win event; RT_ASSERT(topwin != RT_NULL); - RT_ASSERT(topwin->tid != RT_NULL); + RT_ASSERT(topwin->app != RT_NULL); RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); event.wid = topwin->wid; - rtgui_send(topwin->tid, + rtgui_send(topwin->app, &event.parent, sizeof(struct rtgui_event_win)); topwin->flag &= ~WINTITLE_ACTIVATE; @@ -495,7 +495,7 @@ static void _rtgui_topwin_draw_tree(struct rtgui_topwin *topwin, struct rtgui_ev } epaint->wid = topwin->wid; - rtgui_send(topwin->tid, &(epaint->parent), sizeof(struct rtgui_event_paint)); + rtgui_send(topwin->app, &(epaint->parent), sizeof(struct rtgui_event_paint)); rtgui_dlist_foreach(node, &topwin->child_list, prev) { @@ -748,7 +748,7 @@ rt_err_t rtgui_topwin_move(struct rtgui_event_win_move *event) struct rtgui_event_paint epaint; RTGUI_EVENT_PAINT_INIT(&epaint); epaint.wid = topwin->wid; - rtgui_send(topwin->tid, &(epaint.parent), sizeof(epaint)); + rtgui_send(topwin->app, &(epaint.parent), sizeof(epaint)); } return RT_EOK; @@ -945,7 +945,7 @@ static void rtgui_topwin_update_clip(void) /* send clip event to destination window */ eclip.wid = top->wid; - rtgui_send(top->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); + rtgui_send(top->app, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); /* move to next sibling tree */ if (top->parent == RT_NULL) @@ -991,7 +991,7 @@ static void _rtgui_topwin_redraw_tree(struct rtgui_dlist_node *list, if (rtgui_rect_is_intersect(rect, &(topwin->extent)) == RT_EOK) { epaint->wid = topwin->wid; - rtgui_send(topwin->tid, &(epaint->parent), sizeof(*epaint)); + rtgui_send(topwin->app, &(epaint->parent), sizeof(*epaint)); /* draw title */ if (topwin->title != RT_NULL) @@ -1059,7 +1059,7 @@ void rtgui_topwin_title_onmouse(struct rtgui_topwin *win, struct rtgui_event_mou if (rtgui_rect_contains_point(&win->extent, event->x, event->y) == RT_EOK) { /* send mouse event to thread */ - rtgui_send(win->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + rtgui_send(win->app, &(event->parent), sizeof(struct rtgui_event_mouse)); return; } @@ -1098,7 +1098,7 @@ void rtgui_topwin_title_onmouse(struct rtgui_topwin *win, struct rtgui_event_mou /* send close event to window */ RTGUI_EVENT_WIN_CLOSE_INIT(&event); event.wid = win->wid; - rtgui_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); + rtgui_send(win->app, &(event.parent), sizeof(struct rtgui_event_win)); } } } |
