/** * rtgui server thread's entry */ static void rtgui_server_entry(void *parameter) { #ifdef _WIN32_NATIVE /* set the server thread to highest */ HANDLE hCurrentThread = GetCurrentThread(); SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST); #endif /* create rtgui server application */ rtgui_server_application = rtgui_app_create("rtgui"); if (rtgui_server_application == RT_NULL) return; rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_application), rtgui_server_event_handler); /* init mouse and show */ rtgui_mouse_init(); #ifdef RTGUI_USING_MOUSE_CURSOR rtgui_mouse_show_cursor(); #endif rtgui_app_run(rtgui_server_application); rtgui_app_destroy(rtgui_server_application); rtgui_server_application = RT_NULL; }
static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc) { rtgui_widget_t* owner; if (dc == RT_NULL || dc->type != RTGUI_DC_CLIENT) return RT_FALSE; /* get owner */ owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type); if (RTGUI_IS_WINTITLE(owner->toplevel)) { /* update title extent */ rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing --; if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner)) { #ifdef __WIN32__ #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_release(&cursor_mutex); /* show cursor */ rtgui_mouse_show_cursor(); rt_kprintf("show cursor\n"); #endif /* update screen */ rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #else #ifdef RTGUI_USING_MOUSE_CURSOR /* show cursor */ rtgui_mouse_show_cursor(); #endif /* update screen */ rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #endif } } else if (RTGUI_IS_WORKBENCH(owner->toplevel) || RTGUI_IS_WIN(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing --; if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner)) { #ifdef __WIN32__ #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_release(&cursor_mutex); /* show cursor */ rtgui_mouse_show_cursor(); rt_kprintf("show cursor\n"); #endif /* update screen */ rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #else /* send to server to end drawing */ struct rtgui_event_update_end eupdate; RTGUI_EVENT_UPDATE_END_INIT(&(eupdate)); eupdate.rect = owner->extent; rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate)); #endif } } return RT_TRUE; }
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; }
static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc) { rtgui_widget_t* owner; struct rtgui_dc_hw* self; if (dc == RT_NULL || dc->type != RTGUI_DC_HW) return RT_FALSE; self = (struct rtgui_dc_hw*)dc; /* get owner */ owner = self->owner; if (RTGUI_IS_WINTITLE(owner->toplevel)) { /* update title extent */ rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing --; if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner)) { #ifdef _WIN32 #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_release(&cursor_mutex); /* show cursor */ rtgui_mouse_show_cursor(); rt_kprintf("show cursor\n"); #endif /* update screen */ rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent)); #else #ifdef RTGUI_USING_MOUSE_CURSOR /* show cursor */ rtgui_mouse_show_cursor(); #endif /* update screen */ rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent)); #endif } } else if (RTGUI_IS_APPLICATION(owner->toplevel) || RTGUI_IS_WIN(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing --; if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner)) { #ifdef _WIN32 #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_release(&cursor_mutex); /* show cursor */ rtgui_mouse_show_cursor(); rt_kprintf("show cursor\n"); #endif /* update screen */ rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent)); #else /* send to server to end drawing */ struct rtgui_event_update_end eupdate; RTGUI_EVENT_UPDATE_END_INIT(&(eupdate)); eupdate.rect = owner->extent; rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate)); #endif } } /* release hardware dc */ rtgui_free(self); return RT_TRUE; }