ttk_window_t * ttk_window_new(char * title, uint16_t width, uint16_t height) { ttk_window_t * new_win = malloc(sizeof(ttk_window_t)); new_win->title = strdup(title); new_win->width = width; new_win->height = height; new_win->off_x = decor_left_width; new_win->off_y = decor_top_height; new_win->core_window = yutani_window_create(yctx, new_win->width + decor_width(), new_win->height + decor_height()); yutani_window_move(yctx, new_win->core_window, TTK_DEFAULT_X, TTK_DEFAULT_Y); assert(new_win->core_window && "Oh dear, I've failed to allocate a new window from the server. This is terrible."); /* XXX icon; also need to do this if we change the title later */ yutani_window_advertise(yctx, new_win->core_window, new_win->title); new_win->core_context = init_graphics_yutani_double_buffer(new_win->core_window); draw_fill(new_win->core_context, rgb(TTK_BACKGROUND_DEFAULT)); ttk_window_draw(new_win); hashmap_set(ttk_wids_to_windows, (void*)new_win->core_window->wid, new_win); }
int main (int argc, char ** argv) { yctx = yutani_init(); win_width = 100; win_height = 100; init_decorations(); off_x = decor_left_width; off_y = decor_top_height; /* Do something with a window */ wina = yutani_window_create(yctx, win_width + decor_width(), win_height + decor_height()); yutani_window_move(yctx, wina, 300, 300); ctx = init_graphics_yutani_double_buffer(wina); draw_fill(ctx, rgb(0,0,0)); redraw_borders(); flip(ctx); yutani_flip(yctx, wina); yutani_window_advertise(yctx, wina, "Graphics Test"); pthread_t thread; pthread_create(&thread, NULL, draw_thread, NULL); while (!should_exit) { yutani_msg_t * m = yutani_poll(yctx); if (m) { switch (m->type) { case YUTANI_MSG_KEY_EVENT: { struct yutani_msg_key_event * ke = (void*)m->data; if (ke->event.action == KEY_ACTION_DOWN && ke->event.keycode == 'q') { should_exit = 1; } } break; case YUTANI_MSG_WINDOW_FOCUS_CHANGE: { struct yutani_msg_window_focus_change * wf = (void*)m->data; yutani_window_t * win = hashmap_get(yctx->windows, (void*)wf->wid); if (win) { win->focused = wf->focused; } } break; case YUTANI_MSG_SESSION_END: should_exit = 1; break; case YUTANI_MSG_RESIZE_OFFER: { struct yutani_msg_window_resize * wr = (void*)m->data; spin_lock(&draw_lock); resize_finish(wr->width, wr->height); spin_unlock(&draw_lock); } break; case YUTANI_MSG_WINDOW_MOUSE_EVENT: if (decor_handle_event(yctx, m) == DECOR_CLOSE) { should_exit = 1; } break; default: break; } free(m); } } yutani_close(yctx, wina); return 0; }