int main (int argc, char ** argv) { yutani_t * yctx; yutani_window_t * wina; gfx_context_t * ctx; int should_exit = 0; int blur = 0; int stopped = 0; int left = 30; int top = 30; int width = 500; int height = 500; yctx = yutani_init(); wina = yutani_window_create(yctx, width, height); yutani_window_move(yctx, wina, left, top); ctx = init_graphics_yutani_double_buffer(wina); draw_fill(ctx, rgb(0,0,0)); yutani_window_update_shape(yctx, wina, YUTANI_SHAPE_THRESHOLD_HALF); yutani_window_advertise_icon(yctx, wina, "Mesa Gears", "gears"); OSMesaContext gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL); if (resize(ctx, gl_ctx)) { fprintf(stderr, "%s: Something bad happened.\n", argv[0]); goto finish; } init(); while (!should_exit) { yutani_msg_t * m = yutani_poll_async(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) { switch (ke->event.keycode) { case 'q': should_exit = 1; free(m); goto finish; case 'b': blur = (1-blur); break; case 's': stopped = (1-stopped); break; case KEY_ARROW_LEFT: view_roty += 5.0; break; case KEY_ARROW_RIGHT: view_roty -= 5.0; break; case KEY_ARROW_UP: view_rotx += 5.0; break; case KEY_ARROW_DOWN: view_rotx -= 5.0; break; default: break; } } } break; case YUTANI_MSG_WINDOW_MOUSE_EVENT: { struct yutani_msg_window_mouse_event * me = (void*)m->data; if (me->command == YUTANI_MOUSE_EVENT_DOWN && me->buttons & YUTANI_MOUSE_BUTTON_LEFT) { yutani_window_drag_start(yctx, wina); } } break; case YUTANI_MSG_SESSION_END: should_exit = 1; break; case YUTANI_MSG_RESIZE_OFFER: { struct yutani_msg_window_resize * wr = (void*)m->data; yutani_window_resize_accept(yctx, wina, wr->width, wr->height); reinit_graphics_yutani(ctx, wina); resize(ctx, gl_ctx); draw(); yutani_window_resize_done(yctx, wina); flip(ctx); yutani_flip(yctx, wina); yutani_window_update_shape(yctx, wina, 1); /* Reset statistics */ frames = 0; start_time = 0; } default: break; } free(m); } fps(); if (!stopped) { angle += 0.2; } draw(); if (blur) { blur_context_box(ctx, 20); } flip(ctx); yutani_flip(yctx, wina); syscall_yield(); } finish: OSMesaDestroyContext(gl_ctx); yutani_close(yctx, wina); return 0; }
int main(int argc, char * argv[]) { static struct option long_opts[] = { {"help", no_argument, 0, '?'}, {0,0,0,0} }; if (argc > 1) { /* Read some arguments */ int index, c; while ((c = getopt_long(argc, argv, "h", long_opts, &index)) != -1) { if (!c) { if (long_opts[index].flag == 0) { c = long_opts[index].val; } } switch (c) { case 'h': usage(argv); exit(0); break; default: break; } } } yctx = yutani_init(); if (!yctx) { fprintf(stderr, "%s: failed to connect to compositor\n", argv[0]); return 1; } init_decorations(); struct decor_bounds bounds; decor_get_bounds(NULL, &bounds); decor_left_width = bounds.left_width; decor_top_height = bounds.top_height; decor_right_width = bounds.right_width; decor_bottom_height = bounds.bottom_height; decor_width = bounds.width; decor_height = bounds.height; if (strstr(argv[optind],".jpg")) { load_sprite_jpg(&img, argv[optind]); } else { load_sprite(&img, argv[optind]); } if (!img.width) { fprintf(stderr, "%s: failed to open image %s\n", argv[0], argv[optind]); return 1; } img.alpha = ALPHA_EMBEDDED; width = img.width; height = img.height; window = yutani_window_create(yctx, width + decor_width, height + decor_height); yutani_window_move(yctx, window, left, top); yutani_window_advertise_icon(yctx, window, APPLICATION_TITLE, "imgviewer"); ctx = init_graphics_yutani_double_buffer(window); redraw(); yutani_flip(yctx, window); int playing = 1; while (playing) { yutani_msg_t * m = yutani_poll(yctx); while (m) { if (menu_process_event(yctx, m)) { /* just decorations should be fine */ decors(); flip(ctx); yutani_flip(yctx, window); } 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') { playing = 0; } } 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 == window) { win->focused = wf->focused; decors(); flip(ctx); yutani_flip(yctx, window); } } break; case YUTANI_MSG_RESIZE_OFFER: { struct yutani_msg_window_resize * wr = (void*)m->data; resize_finish(wr->width, wr->height); } break; case YUTANI_MSG_WINDOW_MOUSE_EVENT: { struct yutani_msg_window_mouse_event * me = (void*)m->data; int result = decor_handle_event(yctx, m); switch (result) { case DECOR_CLOSE: playing = 0; break; case DECOR_RIGHT: /* right click in decoration, show appropriate menu */ decor_show_default_menu(window, window->x + me->new_x, window->y + me->new_y); break; default: /* Other actions */ break; } } break; case YUTANI_MSG_WINDOW_CLOSE: case YUTANI_MSG_SESSION_END: playing = 0; break; default: break; } free(m); m = yutani_poll_async(yctx); } } yutani_close(yctx, window); return 0; }