static void key_handler(struct window *window, struct input *input, uint32_t time, uint32_t key, uint32_t sym, enum wl_keyboard_key_state state, void *data) { struct demoapp *app = data; struct rectangle winrect; if (state == WL_KEYBOARD_KEY_STATE_RELEASED) return; switch (sym) { case XKB_KEY_space: app->animate = !app->animate; window_schedule_redraw(window); break; case XKB_KEY_Up: window_get_allocation(window, &winrect); winrect.height -= 100; if (winrect.height < 150) winrect.height = 150; window_schedule_resize(window, winrect.width, winrect.height); break; case XKB_KEY_Down: window_get_allocation(window, &winrect); winrect.height += 100; if (winrect.height > 600) winrect.height = 600; window_schedule_resize(window, winrect.width, winrect.height); break; case XKB_KEY_Escape: display_exit(app->display); break; } }
static void keyboard_create(struct output *output, struct virtual_keyboard *virtual_keyboard) { struct keyboard *keyboard; keyboard = malloc(sizeof *keyboard); memset(keyboard, 0, sizeof *keyboard); keyboard->keyboard = virtual_keyboard; keyboard->window = window_create_custom(virtual_keyboard->display); keyboard->widget = window_add_widget(keyboard->window, keyboard); window_set_title(keyboard->window, "Virtual keyboard"); window_set_user_data(keyboard->window, keyboard); widget_set_redraw_handler(keyboard->widget, redraw_handler); widget_set_resize_handler(keyboard->widget, resize_handler); widget_set_button_handler(keyboard->widget, button_handler); window_schedule_resize(keyboard->window, columns * key_width, rows * key_height); input_panel_set_surface(virtual_keyboard->input_panel, window_get_wl_surface(keyboard->window), output_get_wl_output(output)); }
static void keyboard_create(struct output *output, struct virtual_keyboard *virtual_keyboard) { struct keyboard *keyboard; const struct layout *layout; struct wl_input_panel_surface *ips; layout = get_current_layout(virtual_keyboard); keyboard = xzalloc(sizeof *keyboard); keyboard->keyboard = virtual_keyboard; keyboard->window = window_create_custom(virtual_keyboard->display); keyboard->widget = window_add_widget(keyboard->window, keyboard); virtual_keyboard->keyboard = keyboard; window_set_title(keyboard->window, "Virtual keyboard"); window_set_user_data(keyboard->window, keyboard); widget_set_redraw_handler(keyboard->widget, redraw_handler); widget_set_resize_handler(keyboard->widget, resize_handler); widget_set_button_handler(keyboard->widget, button_handler); window_schedule_resize(keyboard->window, layout->columns * key_width, layout->rows * key_height); ips = wl_input_panel_get_input_panel_surface(virtual_keyboard->input_panel, window_get_wl_surface(keyboard->window)); wl_input_panel_surface_set_toplevel(ips, output_get_wl_output(output), WL_INPUT_PANEL_SURFACE_POSITION_CENTER_BOTTOM); }
int main(int argc, char *argv[]) { struct editor editor; editor.display = display_create(argc, argv); if (editor.display == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } wl_display_add_global_listener(display_get_display(editor.display), global_handler, &editor); editor.window = window_create(editor.display); editor.widget = frame_create(editor.window, &editor); editor.entry = text_entry_create(&editor, "Entry"); editor.editor = text_entry_create(&editor, "Editor"); window_set_title(editor.window, "Text Editor"); widget_set_redraw_handler(editor.widget, redraw_handler); widget_set_resize_handler(editor.widget, resize_handler); widget_set_button_handler(editor.widget, button_handler); window_schedule_resize(editor.window, 500, 400); display_run(editor.display); text_entry_destroy(editor.entry); text_entry_destroy(editor.editor); return 0; }
int main(int argc, char *argv[]) { struct flower flower; struct display *d; struct timeval tv; d = display_create(&argc, argv); if (d == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } gettimeofday(&tv, NULL); srandom(tv.tv_usec); flower.width = 200; flower.height = 200; flower.display = d; flower.window = window_create(d); flower.widget = window_add_widget(flower.window, &flower); window_set_title(flower.window, "Flower"); widget_set_resize_handler(flower.widget, resize_handler); widget_set_redraw_handler(flower.widget, redraw_handler); widget_set_button_handler(flower.widget, button_handler); widget_set_default_cursor(flower.widget, CURSOR_HAND1); widget_set_touch_down_handler(flower.widget, touch_down_handler); window_schedule_resize(flower.window, flower.width, flower.height); display_run(d); return 0; }
static struct view * view_create(struct display *display, uint32_t key, const char *filename, int fullscreen, int *view_counter) { struct view *view; gchar *basename; gchar *title; GFile *file = NULL; GError *error = NULL; view = malloc(sizeof *view); if (view == NULL) return view; memset(view, 0, sizeof *view); file = g_file_new_for_commandline_arg(filename); basename = g_file_get_basename(file); if(!basename) { title = g_strdup("Wayland View"); } else { title = g_strdup_printf("Wayland View - %s", basename); g_free(basename); } view->document = poppler_document_new_from_file(g_file_get_uri(file), NULL, &error); if(error) { title = g_strdup("File not found"); } view->window = window_create(display); view->widget = frame_create(view->window, view); window_set_title(view->window, title); g_free(title); view->display = display; window_set_user_data(view->window, view); window_set_key_handler(view->window, key_handler); window_set_keyboard_focus_handler(view->window, keyboard_focus_handler); window_set_fullscreen_handler(view->window, fullscreen_handler); window_set_close_handler(view->window, close_handler); widget_set_button_handler(view->widget, button_handler); widget_set_resize_handler(view->widget, resize_handler); widget_set_redraw_handler(view->widget, redraw_handler); view->page = 0; view->fullscreen = fullscreen; window_set_fullscreen(view->window, view->fullscreen); window_schedule_resize(view->window, 500, 400); view->view_counter = view_counter; *view_counter += 1; return view; }
static void input_method_activate(void *data, struct wl_input_method *input_method, struct wl_input_method_context *context) { struct virtual_keyboard *keyboard = data; struct wl_array modifiers_map; const struct layout *layout; keyboard->keyboard->state = keyboardstate_default; if (keyboard->context) wl_input_method_context_destroy(keyboard->context); if (keyboard->preedit_string) free(keyboard->preedit_string); keyboard->preedit_string = strdup(""); keyboard->content_hint = 0; keyboard->content_purpose = 0; free(keyboard->preferred_language); keyboard->preferred_language = NULL; free(keyboard->surrounding_text); keyboard->surrounding_text = NULL; keyboard->serial = 0; keyboard->context = context; wl_input_method_context_add_listener(context, &input_method_context_listener, keyboard); wl_array_init(&modifiers_map); keysym_modifiers_add(&modifiers_map, "Shift"); keysym_modifiers_add(&modifiers_map, "Control"); keysym_modifiers_add(&modifiers_map, "Mod1"); wl_input_method_context_modifiers_map(context, &modifiers_map); keyboard->keysym.shift_mask = keysym_modifiers_get_mask(&modifiers_map, "Shift"); wl_array_release(&modifiers_map); layout = get_current_layout(keyboard); window_schedule_resize(keyboard->keyboard->window, layout->columns * key_width, layout->rows * key_height); wl_input_method_context_language(context, keyboard->serial, layout->language); wl_input_method_context_text_direction(context, keyboard->serial, layout->text_direction); widget_schedule_redraw(keyboard->keyboard->widget); }
static struct ModeInfo * create_wscreensaver_instance(struct wscreensaver *screensaver, struct wl_output *output, int width, int height) { static int instance; struct ModeInfo *mi; struct rectangle drawarea; mi = calloc(1, sizeof *mi); if (!mi) return NULL; if (demo_mode) mi->window = window_create(screensaver->display); else mi->window = window_create_custom(screensaver->display); if (!mi->window) { fprintf(stderr, "%s: creating a window failed.\n", progname); free(mi); return NULL; } window_set_title(mi->window, progname); if (screensaver->interface && !demo_mode) { mi->widget = window_add_widget(mi->window, mi); screensaver_set_surface(screensaver->interface, window_get_wl_surface(mi->window), output); } else { mi->widget = frame_create(mi->window, mi); } widget_set_redraw_handler(mi->widget, redraw_handler); mi->priv = screensaver; mi->eglctx = EGL_NO_CONTEXT; mi->instance_number = instance++; /* XXX */ widget_get_allocation(mi->widget, &drawarea); mi->width = drawarea.width; mi->height = drawarea.height; screensaver->plugin->init(mi); window_schedule_resize(mi->window, width, height); return mi; }
int main(int argc, char *argv[]) { struct editor editor; memset(&editor, 0, sizeof editor); editor.display = display_create(argc, argv); if (editor.display == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } display_set_user_data(editor.display, &editor); display_set_global_handler(editor.display, global_handler); editor.window = window_create(editor.display); editor.widget = frame_create(editor.window, &editor); editor.entry = text_entry_create(&editor, "Entry"); editor.editor = text_entry_create(&editor, "Editor"); window_set_title(editor.window, "Text Editor"); window_set_key_handler(editor.window, key_handler); window_set_user_data(editor.window, &editor); widget_set_redraw_handler(editor.widget, redraw_handler); widget_set_resize_handler(editor.widget, resize_handler); widget_set_button_handler(editor.widget, editor_button_handler); window_schedule_resize(editor.window, 500, 400); display_run(editor.display); text_entry_destroy(editor.entry); text_entry_destroy(editor.editor); return 0; }
/* Iff parent_window is set, the new window will be transient. */ static struct window * new_window(struct stacking *stacking, struct window *parent_window) { struct window *new_window; struct widget *new_widget; new_window = window_create(stacking->display); window_set_parent(new_window, parent_window); new_widget = window_frame_create(new_window, new_window); window_set_title(new_window, "Stacking Test"); window_set_key_handler(new_window, key_handler); window_set_keyboard_focus_handler(new_window, keyboard_focus_handler); window_set_fullscreen_handler(new_window, fullscreen_handler); widget_set_button_handler(new_widget, button_handler); widget_set_redraw_handler(new_widget, redraw_handler); window_set_user_data(new_window, stacking); window_schedule_resize(new_window, 300, 300); return new_window; }
static void handle_commit_state(void *data, struct wl_input_method_context *context, uint32_t serial) { struct virtual_keyboard *keyboard = data; const struct layout *layout; keyboard->serial = serial; layout = get_current_layout(keyboard); if (keyboard->surrounding_text) fprintf(stderr, "Surrounding text updated: %s\n", keyboard->surrounding_text); window_schedule_resize(keyboard->keyboard->window, layout->columns * key_width, layout->rows * key_height); wl_input_method_context_language(context, keyboard->serial, layout->language); wl_input_method_context_text_direction(context, keyboard->serial, layout->text_direction); widget_schedule_redraw(keyboard->keyboard->widget); }
static void key_handler(struct window *window, struct input *input, uint32_t time, uint32_t key, uint32_t sym, enum wl_keyboard_key_state state, void *data) { struct fullscreen *fullscreen = data; int transform, scale; static int current_size = 0; struct fs_output *fsout; struct wl_output *wl_output; int widths[] = { 640, 320, 800, 400 }; int heights[] = { 480, 240, 600, 300 }; if (state == WL_KEYBOARD_KEY_STATE_RELEASED) return; switch (sym) { case XKB_KEY_t: transform = window_get_buffer_transform (window); transform = (transform + 1) % 8; window_set_buffer_transform(window, transform); window_schedule_redraw(window); break; case XKB_KEY_s: scale = window_get_buffer_scale (window); if (scale == 1) scale = 2; else scale = 1; window_set_buffer_scale(window, scale); window_schedule_redraw(window); break; case XKB_KEY_z: current_size = (current_size + 1) % 4; fullscreen->width = widths[current_size]; fullscreen->height = heights[current_size]; window_schedule_resize(fullscreen->window, fullscreen->width, fullscreen->height); break; case XKB_KEY_m: if (!fullscreen->fshell) break; wl_output = NULL; if (fullscreen->current_output) wl_output = output_get_wl_output(fullscreen->current_output->output); fullscreen->present_method = (fullscreen->present_method + 1) % 5; _wl_fullscreen_shell_present_surface(fullscreen->fshell, window_get_wl_surface(fullscreen->window), fullscreen->present_method, wl_output); window_schedule_redraw(window); break; case XKB_KEY_o: if (!fullscreen->fshell) break; fsout = fullscreen->current_output; wl_output = fsout ? output_get_wl_output(fsout->output) : NULL; /* Clear the current presentation */ _wl_fullscreen_shell_present_surface(fullscreen->fshell, NULL, 0, wl_output); if (fullscreen->current_output) { if (fullscreen->current_output->link.next == &fullscreen->output_list) fsout = NULL; else fsout = wl_container_of(fullscreen->current_output->link.next, fsout, link); } else { fsout = wl_container_of(fullscreen->output_list.next, fsout, link); } fullscreen->current_output = fsout; wl_output = fsout ? output_get_wl_output(fsout->output) : NULL; _wl_fullscreen_shell_present_surface(fullscreen->fshell, window_get_wl_surface(fullscreen->window), fullscreen->present_method, wl_output); window_schedule_redraw(window); break; case XKB_KEY_w: if (!fullscreen->fshell || !fullscreen->current_output) break; wl_output = NULL; if (fullscreen->current_output) wl_output = output_get_wl_output(fullscreen->current_output->output); _wl_fullscreen_shell_mode_feedback_destroy( _wl_fullscreen_shell_present_surface_for_mode(fullscreen->fshell, window_get_wl_surface(fullscreen->window), wl_output, 0)); window_schedule_redraw(window); break; case XKB_KEY_f: if (fullscreen->fshell) break; fullscreen->fullscreen ^= 1; window_set_fullscreen(window, fullscreen->fullscreen); break; case XKB_KEY_q: exit (0); break; } }
/** * \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 editor editor; int i; uint32_t click_to_show = 0; const char *preferred_language = NULL; for (i = 1; i < argc; i++) { if (strcmp("--click-to-show", argv[i]) == 0) click_to_show = 1; else if (strcmp("--preferred-language", argv[i]) == 0) { if (i + 1 < argc) { preferred_language = argv[i + 1]; i++; } } } memset(&editor, 0, sizeof editor); #ifdef HAVE_PANGO g_type_init(); #endif editor.display = display_create(&argc, argv); if (editor.display == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } display_set_user_data(editor.display, &editor); display_set_global_handler(editor.display, global_handler); editor.window = window_create(editor.display); editor.widget = frame_create(editor.window, &editor); editor.entry = text_entry_create(&editor, "Entry"); editor.entry->click_to_show = click_to_show; if (preferred_language) editor.entry->preferred_language = strdup(preferred_language); editor.editor = text_entry_create(&editor, "Numeric"); editor.editor->content_purpose = WL_TEXT_INPUT_CONTENT_PURPOSE_NUMBER; editor.editor->click_to_show = click_to_show; window_set_title(editor.window, "Text Editor"); window_set_key_handler(editor.window, key_handler); window_set_user_data(editor.window, &editor); widget_set_redraw_handler(editor.widget, redraw_handler); widget_set_resize_handler(editor.widget, resize_handler); widget_set_button_handler(editor.widget, editor_button_handler); window_schedule_resize(editor.window, 500, 400); display_run(editor.display); text_entry_destroy(editor.entry); text_entry_destroy(editor.editor); return 0; }
int main(int argc, char *argv[]) { struct transformed transformed; struct display *d; int i; transformed.width = 500; transformed.height = 250; transformed.fullscreen = 0; transformed.fullscreen_method = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-d") == 0) { transformed.fullscreen_method = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER; } else if (strcmp(argv[i], "-w") == 0) { if (++i >= argc) usage(EXIT_FAILURE); transformed.width = atol(argv[i]); } else if (strcmp(argv[i], "-h") == 0) { if (++i >= argc) usage(EXIT_FAILURE); transformed.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; } transformed.display = d; transformed.window = window_create(d); transformed.widget = window_add_widget(transformed.window, &transformed); window_set_title(transformed.window, "Transformed"); window_set_fullscreen_method(transformed.window, transformed.fullscreen_method); widget_set_transparent(transformed.widget, 0); widget_set_default_cursor(transformed.widget, CURSOR_BLANK); widget_set_resize_handler(transformed.widget, resize_handler); widget_set_redraw_handler(transformed.widget, redraw_handler); widget_set_button_handler(transformed.widget, button_handler); widget_set_touch_down_handler(transformed.widget, touch_handler); window_set_key_handler(transformed.window, key_handler); window_set_fullscreen_handler(transformed.window, fullscreen_handler); window_set_output_handler(transformed.window, output_handler); window_set_user_data(transformed.window, &transformed); window_schedule_resize(transformed.window, transformed.width, transformed.height); display_run(d); return 0; }
int main(int argc, char *argv[]) { struct box box; struct display *d; struct timeval tv; int i; d = display_create(&argc, argv); if (d == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } box.mode = MODE_SRC_DST; for (i = 1; i < argc; i++) { if (strcmp("-s", argv[i]) == 0) box.mode = MODE_SRC_ONLY; else if (strcmp("-d", argv[i]) == 0) box.mode = MODE_DST_ONLY; else if (strcmp("-b", argv[i]) == 0) box.mode = MODE_SRC_DST; else if (strcmp("-n", argv[i]) == 0) box.mode = MODE_NO_VIEWPORT; else { usage(argv[0]); exit(1); } } gettimeofday(&tv, NULL); srandom(tv.tv_usec); box.width = BUFFER_WIDTH / BUFFER_SCALE; box.height = BUFFER_HEIGHT / BUFFER_SCALE; box.display = d; box.window = window_create(d); box.widget = window_add_widget(box.window, &box); window_set_title(box.window, "Scaler Test Box"); window_set_buffer_scale(box.window, BUFFER_SCALE); widget_set_resize_handler(box.widget, resize_handler); widget_set_redraw_handler(box.widget, redraw_handler); widget_set_button_handler(box.widget, button_handler); widget_set_default_cursor(box.widget, CURSOR_HAND1); widget_set_touch_down_handler(box.widget, touch_down_handler); window_schedule_resize(box.window, box.width, box.height); display_set_user_data(box.display, &box); display_set_global_handler(box.display, global_handler); display_run(d); widget_destroy(box.widget); window_destroy(box.window); display_destroy(d); return 0; }
static struct gears * gears_create(struct display *display) { const int width = 450, height = 500; struct gears *gears; int i; gears = malloc(sizeof *gears); memset(gears, 0, sizeof *gears); gears->d = display; gears->window = window_create(display); gears->widget = 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(); } 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); window_set_keyboard_focus_handler(gears->window, keyboard_focus_handler); window_schedule_resize(gears->window, width, height); return gears; }
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; }
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; }