static struct cliptest * cliptest_create(struct display *display) { struct cliptest *cliptest; cliptest = xzalloc(sizeof *cliptest); cliptest->view.geometry = &cliptest->geometry; cliptest->view.transform.enabled = 0; geometry_init(&cliptest->geometry); geometry_init(&cliptest->ui.geometry); cliptest->window = window_create(display); cliptest->widget = window_frame_create(cliptest->window, cliptest); window_set_title(cliptest->window, "cliptest"); cliptest->display = display; window_set_user_data(cliptest->window, cliptest); widget_set_redraw_handler(cliptest->widget, redraw_handler); widget_set_button_handler(cliptest->widget, button_handler); widget_set_motion_handler(cliptest->widget, motion_handler); widget_set_axis_handler(cliptest->widget, axis_handler); window_set_keyboard_focus_handler(cliptest->window, keyboard_focus_handler); window_set_key_handler(cliptest->window, key_handler); window_set_fullscreen_handler(cliptest->window, fullscreen_handler); /* set minimum size */ widget_schedule_resize(cliptest->widget, 200, 100); /* set current size */ widget_schedule_resize(cliptest->widget, 500, 400); return cliptest; }
static struct clickdot * clickdot_create(struct display *display) { struct clickdot *clickdot; clickdot = xzalloc(sizeof *clickdot); clickdot->window = window_create(display); clickdot->widget = frame_create(clickdot->window, clickdot); window_set_title(clickdot->window, "Wayland ClickDot"); clickdot->display = display; clickdot->buffer = NULL; window_set_key_handler(clickdot->window, key_handler); window_set_user_data(clickdot->window, clickdot); window_set_keyboard_focus_handler(clickdot->window, keyboard_focus_handler); widget_set_redraw_handler(clickdot->widget, redraw_handler); widget_set_button_handler(clickdot->widget, button_handler); widget_set_motion_handler(clickdot->widget, motion_handler); widget_set_resize_handler(clickdot->widget, resize_handler); widget_set_leave_handler(clickdot->widget, leave_handler); widget_schedule_resize(clickdot->widget, 500, 400); clickdot->dot.x = 250; clickdot->dot.y = 200; clickdot->line.x = -1; clickdot->line.y = -1; clickdot->line.old_x = -1; clickdot->line.old_y = -1; clickdot->reset = 0; return clickdot; }
static void text_entry_button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct text_entry *entry = data; struct rectangle allocation; struct editor *editor; int32_t x, y; uint32_t result; widget_get_allocation(entry->widget, &allocation); input_get_position(input, &x, &y); x -= allocation.x + text_offset_left; y -= allocation.y + text_offset_left; editor = window_get_user_data(entry->window); result = text_entry_try_invoke_preedit_action(entry, x, y, button, state); if (result) return; if (button != BTN_LEFT) { return; } text_entry_set_cursor_position(entry, x, y); if (state == WL_POINTER_BUTTON_STATE_PRESSED) { struct wl_seat *seat = input_get_seat(input); text_entry_activate(entry, seat); editor->active_entry = entry; text_entry_set_anchor_position(entry, x, y); widget_set_motion_handler(entry->widget, text_entry_motion_handler); } else { widget_set_motion_handler(entry->widget, NULL); } }
static struct image * image_create(struct display *display, const char *filename, int *image_counter) { struct image *image; char *b, *copy, title[512];; image = malloc(sizeof *image); if (image == NULL) return image; memset(image, 0, sizeof *image); copy = strdup(filename); b = basename(copy); snprintf(title, sizeof title, "Wayland Image - %s", b); free(copy); image->filename = strdup(filename); image->image = load_cairo_surface(filename); if (!image->image) { fprintf(stderr, "could not find the image %s!\n", b); free(image); return NULL; } image->window = window_create(display); image->widget = frame_create(image->window, image); window_set_title(image->window, title); image->display = display; image->image_counter = image_counter; *image_counter += 1; image->initialized = false; window_set_user_data(image->window, image); widget_set_redraw_handler(image->widget, redraw_handler); widget_set_resize_handler(image->widget, resize_handler); window_set_keyboard_focus_handler(image->window, keyboard_focus_handler); window_set_fullscreen_handler(image->window, fullscreen_handler); window_set_close_handler(image->window, close_handler); widget_set_enter_handler(image->widget, enter_handler); widget_set_motion_handler(image->widget, motion_handler); widget_set_button_handler(image->widget, button_handler); widget_set_axis_handler(image->widget, axis_handler); window_set_key_handler(image->window, key_handler); widget_schedule_resize(image->widget, 500, 400); return image; }
int main(int argc, char *argv[]) { struct timespec ts; struct smoke smoke; struct display *d; int size; d = display_create(&argc, argv); if (d == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } smoke.width = 200; smoke.height = 200; smoke.display = d; smoke.window = window_create(d); smoke.widget = window_add_widget(smoke.window, &smoke); window_set_title(smoke.window, "smoke"); window_set_buffer_type(smoke.window, WINDOW_BUFFER_TYPE_SHM); clock_gettime(CLOCK_MONOTONIC, &ts); srandom(ts.tv_nsec); smoke.current = 0; size = smoke.height * smoke.width; smoke.b[0].d = calloc(size, sizeof(float)); smoke.b[0].u = calloc(size, sizeof(float)); smoke.b[0].v = calloc(size, sizeof(float)); smoke.b[1].d = calloc(size, sizeof(float)); smoke.b[1].u = calloc(size, sizeof(float)); smoke.b[1].v = calloc(size, sizeof(float)); widget_set_motion_handler(smoke.widget, mouse_motion_handler); widget_set_touch_motion_handler(smoke.widget, touch_motion_handler); widget_set_resize_handler(smoke.widget, resize_handler); widget_set_redraw_handler(smoke.widget, redraw_handler); window_set_user_data(smoke.window, &smoke); widget_schedule_resize(smoke.widget, smoke.width, smoke.height); display_run(d); widget_destroy(smoke.widget); window_destroy(smoke.window); display_destroy(d); return 0; }
static struct clickdot * clickdot_create(struct display *display) { struct clickdot *clickdot; clickdot = xzalloc(sizeof *clickdot); clickdot->window = window_create(display); clickdot->widget = window_frame_create(clickdot->window, clickdot); window_set_title(clickdot->window, "Wayland ClickDot"); clickdot->display = display; clickdot->buffer = NULL; window_set_key_handler(clickdot->window, key_handler); window_set_user_data(clickdot->window, clickdot); window_set_keyboard_focus_handler(clickdot->window, keyboard_focus_handler); widget_set_redraw_handler(clickdot->widget, redraw_handler); widget_set_button_handler(clickdot->widget, button_handler); widget_set_motion_handler(clickdot->widget, motion_handler); widget_set_resize_handler(clickdot->widget, resize_handler); widget_set_leave_handler(clickdot->widget, leave_handler); widget_schedule_resize(clickdot->widget, 500, 400); clickdot->dot.x = 250; clickdot->dot.y = 200; clickdot->line.x = -1; clickdot->line.y = -1; clickdot->line.old_x = -1; clickdot->line.old_y = -1; clickdot->reset = 0; clickdot->cursor_timeout_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); clickdot->cursor_timeout_task.run = cursor_timeout_func; display_watch_fd(window_get_display(clickdot->window), clickdot->cursor_timeout_fd, EPOLLIN, &clickdot->cursor_timeout_task); return clickdot; }
static struct text_entry* text_entry_create(struct editor *editor, const char *text) { struct text_entry *entry; entry = xmalloc(sizeof *entry); memset(entry, 0, sizeof *entry); entry->widget = widget_add_widget(editor->widget, entry); entry->window = editor->window; entry->text = strdup(text); entry->active = 0; entry->cursor = strlen(text); entry->anchor = entry->cursor; entry->text_input = wl_text_input_manager_create_text_input(editor->text_input_manager); wl_text_input_add_listener(entry->text_input, &text_input_listener, entry); widget_set_redraw_handler(entry->widget, text_entry_redraw_handler); widget_set_button_handler(entry->widget, text_entry_button_handler); widget_set_motion_handler(entry->widget, text_entry_motion_handler); return entry; }
static struct resizor * resizor_create(struct display *display) { struct resizor *resizor; resizor = xzalloc(sizeof *resizor); resizor->window = window_create(display); resizor->widget = window_frame_create(resizor->window, resizor); window_set_title(resizor->window, "Wayland Resizor"); resizor->display = display; window_set_key_handler(resizor->window, key_handler); window_set_user_data(resizor->window, resizor); widget_set_redraw_handler(resizor->widget, redraw_handler); window_set_keyboard_focus_handler(resizor->window, keyboard_focus_handler); widget_set_enter_handler(resizor->widget, enter_handler); widget_set_motion_handler(resizor->widget, motion_handler); window_set_locked_pointer_motion_handler( resizor->window, locked_pointer_handle_motion); widget_set_button_handler(resizor->widget, button_handler); resizor->height.previous = 400; resizor->height.current = 400; resizor->height.target = 400; resizor->width.previous = 400; resizor->width.current = 400; resizor->width.target = 400; widget_schedule_resize(resizor->widget, 400, 400); return resizor; }
static struct gears * gears_create(struct display *display) { const int width = 450, height = 500; struct gears *gears; struct timeval tv; int i; gears = zalloc(sizeof *gears); gears->d = display; gears->window = window_create(display); gears->widget = window_frame_create(gears->window, gears); window_set_title(gears->window, "Wayland Gears"); gears->display = display_get_egl_display(gears->d); if (gears->display == NULL) die("failed to create egl display\n"); eglBindAPI(EGL_OPENGL_API); gears->config = display_get_argb_egl_config(gears->d); gears->context = eglCreateContext(gears->display, gears->config, EGL_NO_CONTEXT, NULL); if (gears->context == NULL) die("failed to create context\n"); if (!eglMakeCurrent(gears->display, NULL, NULL, gears->context)) die("failed to make context current\n"); for (i = 0; i < 3; i++) { gears->gear_list[i] = glGenLists(1); glNewList(gears->gear_list[i], GL_COMPILE); make_gear(&gear_templates[i]); glEndList(); } gears->button_down = 0; gears->last_x = 0; gears->last_y = 0; gears->view.rotx = 20.0; gears->view.roty = 30.0; gettimeofday(&tv, NULL); gears->last_fps = tv.tv_sec * 1000 + tv.tv_usec / 1000; printf("Warning: FPS count is limited by the wayland compositor or monitor refresh rate\n"); glEnable(GL_NORMALIZE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 200.0); glMatrixMode(GL_MODELVIEW); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glClearColor(0, 0, 0, 0.92); window_set_user_data(gears->window, gears); widget_set_resize_handler(gears->widget, resize_handler); widget_set_redraw_handler(gears->widget, redraw_handler); widget_set_button_handler(gears->widget, button_handler); widget_set_motion_handler(gears->widget, motion_handler); window_set_keyboard_focus_handler(gears->window, keyboard_focus_handler); window_set_fullscreen_handler(gears->window, fullscreen_handler); window_schedule_resize(gears->window, width, height); return gears; }
/** * \brief Create and initialise a new eventdemo window. * The returned eventdemo instance should be destroyed using \c eventdemo_destroy(). * \param d associated display */ static struct eventdemo * eventdemo_create(struct display *d) { struct eventdemo *e; e = zalloc(sizeof (struct eventdemo)); if (e == NULL) return NULL; e->window = window_create(d); if (noborder) { /* Demonstrate how to create a borderless window. * Move windows with META + left mouse button. */ e->widget = window_add_widget(e->window, e); } else { e->widget = window_frame_create(e->window, e); window_set_title(e->window, title); } e->display = d; /* The eventdemo window draws a red rectangle as a demonstration * of per-window data. The dimensions of that rectangle are set * here. */ e->x = width * 1.0 / 4.0; e->w = width * 2.0 / 4.0; e->y = height * 1.0 / 4.0; e->h = height * 2.0 / 4.0; /* Connect the user data to the window */ window_set_user_data(e->window, e); /* Set the callback redraw handler for the window */ widget_set_redraw_handler(e->widget, redraw_handler); /* Set the callback resize handler for the window */ widget_set_resize_handler(e->widget, resize_handler); /* Set the callback focus handler for the window */ window_set_keyboard_focus_handler(e->window, keyboard_focus_handler); /* Set the callback key handler for the window */ window_set_key_handler(e->window, key_handler); /* Set the callback button handler for the window */ widget_set_button_handler(e->widget, button_handler); /* Set the callback motion handler for the window */ widget_set_motion_handler(e->widget, motion_handler); /* Set the callback pointer frame handler for the window */ widget_set_pointer_frame_handler(e->widget, pointer_frame_handler); /* Set the callback axis handler for the window */ widget_set_axis_handlers(e->widget, axis_handler, axis_source_handler, axis_stop_handler, axis_discrete_handler); /* Initial drawing of the window */ window_schedule_resize(e->window, width, height); return e; }
int main(int argc, char *argv[]) { struct fullscreen fullscreen; struct display *d; int i; fullscreen.width = 640; fullscreen.height = 480; fullscreen.fullscreen = 0; fullscreen.present_method = _WL_FULLSCREEN_SHELL_PRESENT_METHOD_DEFAULT; wl_list_init(&fullscreen.output_list); fullscreen.current_output = NULL; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-w") == 0) { if (++i >= argc) usage(EXIT_FAILURE); fullscreen.width = atol(argv[i]); } else if (strcmp(argv[i], "-h") == 0) { if (++i >= argc) usage(EXIT_FAILURE); fullscreen.height = atol(argv[i]); } else if (strcmp(argv[i], "--help") == 0) usage(EXIT_SUCCESS); else usage(EXIT_FAILURE); } d = display_create(&argc, argv); if (d == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } fullscreen.display = d; fullscreen.fshell = NULL; display_set_user_data(fullscreen.display, &fullscreen); display_set_global_handler(fullscreen.display, global_handler); display_set_output_configure_handler(fullscreen.display, output_handler); if (fullscreen.fshell) { fullscreen.window = window_create_custom(d); _wl_fullscreen_shell_present_surface(fullscreen.fshell, window_get_wl_surface(fullscreen.window), fullscreen.present_method, NULL); /* If we get the CURSOR_PLANE capability, we'll change this */ fullscreen.draw_cursor = 1; } else { fullscreen.window = window_create(d); fullscreen.draw_cursor = 0; } fullscreen.widget = window_add_widget(fullscreen.window, &fullscreen); window_set_title(fullscreen.window, "Fullscreen"); widget_set_transparent(fullscreen.widget, 0); widget_set_default_cursor(fullscreen.widget, CURSOR_LEFT_PTR); widget_set_redraw_handler(fullscreen.widget, redraw_handler); widget_set_button_handler(fullscreen.widget, button_handler); widget_set_motion_handler(fullscreen.widget, motion_handler); widget_set_enter_handler(fullscreen.widget, enter_handler); widget_set_touch_down_handler(fullscreen.widget, touch_handler); window_set_key_handler(fullscreen.window, key_handler); window_set_fullscreen_handler(fullscreen.window, fullscreen_handler); window_set_user_data(fullscreen.window, &fullscreen); /* Hack to set minimum allocation so we can shrink later */ window_schedule_resize(fullscreen.window, 1, 1); window_schedule_resize(fullscreen.window, fullscreen.width, fullscreen.height); display_run(d); return 0; }