static void redraw_handler(struct widget *widget, void *data) { struct cliptest *cliptest = data; struct geometry *g = cliptest->view.geometry; struct rectangle allocation; cairo_t *cr; cairo_surface_t *surface; GLfloat ex[8]; GLfloat ey[8]; int n; n = calculate_edges(&cliptest->view, &g->clip, &g->surf, ex, ey); widget_get_allocation(cliptest->widget, &allocation); surface = window_get_surface(cliptest->window); cr = cairo_create(surface); widget_get_allocation(cliptest->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_paint(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_line_width(cr, 1.0); cairo_move_to(cr, allocation.width / 2.0, 0.0); cairo_line_to(cr, allocation.width / 2.0, allocation.height); cairo_move_to(cr, 0.0, allocation.height / 2.0); cairo_line_to(cr, allocation.width, allocation.height / 2.0); cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 1.0); cairo_stroke(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_push_group(cr); cairo_translate(cr, allocation.width / 2.0, allocation.height / 2.0); cairo_scale(cr, 4.0, 4.0); cairo_set_line_width(cr, 0.5); cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL); cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 5.0); draw_geometry(cr, &cliptest->view, ex, ey, n); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0); cairo_select_font_face(cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(cr, 12.0); draw_coordinates(cr, 10.0, 10.0, ex, ey, n); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void locked_pointer_frame_callback(void *data, struct wl_callback *callback, uint32_t time) { struct resizor *resizor = data; struct wl_surface *surface; struct rectangle allocation; float x, y; if (resizor->pointer_locked) { widget_get_allocation(resizor->widget, &allocation); x = resizor->pointer_x + (allocation.width - allocation.x); y = resizor->pointer_y + (allocation.height - allocation.y); widget_set_locked_pointer_cursor_hint(resizor->widget, x, y); } wl_callback_destroy(callback); surface = window_get_wl_surface(resizor->window); callback = wl_surface_frame(surface); wl_callback_add_listener(callback, &locked_pointer_frame_listener, resizor); }
static void panel_launcher_redraw_handler(struct widget *widget, void *data) { struct panel_launcher *launcher = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(launcher->panel->window); cr = cairo_create(surface); widget_get_allocation(widget, &allocation); if (launcher->pressed) { allocation.x++; allocation.y++; } cairo_set_source_surface(cr, launcher->icon, allocation.x, allocation.y); cairo_paint(cr); if (launcher->focused) { cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4); cairo_mask_surface(cr, launcher->icon, allocation.x, allocation.y); } cairo_destroy(cr); }
/** * \brief CALLBACK function, Wayland requests the window to redraw. * \param widget widget to be redrawn * \param data user data associated to the window * * Draws a red rectangle as demonstration of per-window data. */ static void redraw_handler(struct widget *widget, void *data) { struct eventdemo *e = data; cairo_surface_t *surface; cairo_t *cr; struct rectangle rect; if (log_redraw) printf("redraw\n"); widget_get_allocation(e->widget, &rect); surface = window_get_surface(e->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, rect.x, rect.y, rect.width, rect.height); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_fill(cr); cairo_rectangle(cr, e->x, e->y, e->w, e->h); cairo_set_source_rgba(cr, 1.0, 0, 0, 1); cairo_fill(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void text_entry_get_cursor_rectangle(struct text_entry *entry, struct rectangle *rectangle) { struct rectangle allocation; PangoRectangle extents; PangoRectangle cursor_pos; widget_get_allocation(entry->widget, &allocation); if (entry->preedit.text && entry->preedit.cursor < 0) { rectangle->x = 0; rectangle->y = 0; rectangle->width = 0; rectangle->height = 0; return; } pango_layout_get_extents(entry->layout, &extents, NULL); pango_layout_get_cursor_pos(entry->layout, entry->cursor + entry->preedit.cursor, &cursor_pos, NULL); rectangle->x = allocation.x + (allocation.height / 2) + PANGO_PIXELS(cursor_pos.x); rectangle->y = allocation.y + 10 + PANGO_PIXELS(cursor_pos.y); rectangle->width = PANGO_PIXELS(cursor_pos.width); rectangle->height = PANGO_PIXELS(cursor_pos.height); }
static void clamp_view(struct image *image) { struct rectangle allocation; double scale = get_scale(image); double sw, sh; sw = image->width * scale; sh = image->height * scale; widget_get_allocation(image->widget, &allocation); if (sw < allocation.width) { image->matrix.x0 = (allocation.width - image->width * scale) / 2; } else { if (image->matrix.x0 > 0.0) image->matrix.x0 = 0.0; if (sw + image->matrix.x0 < allocation.width) image->matrix.x0 = allocation.width - sw; } if (sh < allocation.width) { image->matrix.y0 = (allocation.height - image->height * scale) / 2; } else { if (image->matrix.y0 > 0.0) image->matrix.y0 = 0.0; if (sh + image->matrix.y0 < allocation.height) image->matrix.y0 = allocation.height - sh; } }
static void redraw_handler(struct widget *widget, void *data) { struct editor *editor = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(editor->window); widget_get_allocation(editor->widget, &allocation); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_translate(cr, allocation.x, allocation.y); /* Draw background */ cairo_push_group(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_fill(cr); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct demoapp *app = data; cairo_t *cr; struct rectangle allocation; uint32_t time; widget_get_allocation(app->widget, &allocation); cr = widget_cairo_create(widget); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_set_source_rgba(cr, 0, 0.8, 0, 0.8); cairo_fill(cr); time = widget_get_last_time(widget); cairo_set_source_rgba(cr, 0.5, 1.0, 0.5, 1.0); draw_spinner(cr, &allocation, time); cairo_destroy(cr); DBG("%dx%d @ %d,%d, last time %u\n", allocation.width, allocation.height, allocation.x, allocation.y, time); }
static void resize_handler(struct widget *widget, int32_t width, int32_t height, void *data) { struct demoapp *app = data; struct rectangle area; int side, h; widget_get_allocation(widget, &area); side = area.width < area.height ? area.width / 2 : area.height / 2; h = area.height - side; widget_set_allocation(app->subsurface, area.x + area.width - side, area.y, side, h); if (app->triangle) { widget_set_allocation(app->triangle->widget, area.x + area.width - side, area.y + h, side, side); } DBG("green %dx%d, red %dx%d, GL %dx%d\n", area.width, area.height, side, h, side, side); }
static void redraw_handler(struct widget *widget, void *data) { struct resizor *resizor = data; cairo_surface_t *surface; cairo_t *cr; struct rectangle allocation; widget_get_allocation(resizor->widget, &allocation); surface = window_get_surface(resizor->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_fill(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct keyboard *keyboard = data; struct rectangle allocation; int32_t x, y; int row, col; unsigned int i; if (state != WL_POINTER_BUTTON_STATE_PRESSED || button != BTN_LEFT) { return; } input_get_position(input, &x, &y); widget_get_allocation(keyboard->widget, &allocation); x -= allocation.x; y -= allocation.y; row = y / key_height; col = x / key_width + row * columns; for (i = 0; i < sizeof(keys) / sizeof(*keys); ++i) { col -= keys[i].width; if (col < 0) { keyboard_handle_key(keyboard, &keys[i]); break; } } widget_schedule_redraw(widget); }
static void redraw_handler(struct widget *widget, void *data) { struct image *image = data; struct rectangle allocation; cairo_t *cr; cairo_surface_t *surface; double width, height, doc_aspect, window_aspect, scale; cairo_matrix_t matrix; cairo_matrix_t translate; surface = window_get_surface(image->window); cr = cairo_create(surface); widget_get_allocation(image->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_push_group(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_paint(cr); if (!image->initialized) { image->initialized = true; width = cairo_image_surface_get_width(image->image); height = cairo_image_surface_get_height(image->image); doc_aspect = width / height; window_aspect = (double) allocation.width / allocation.height; if (doc_aspect < window_aspect) scale = allocation.height / height; else scale = allocation.width / width; image->width = width; image->height = height; cairo_matrix_init_scale(&image->matrix, scale, scale); clamp_view(image); } matrix = image->matrix; cairo_matrix_init_translate(&translate, allocation.x, allocation.y); cairo_matrix_multiply(&matrix, &matrix, &translate); cairo_set_matrix(cr, &matrix); cairo_set_source_surface(cr, image->image, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_paint(cr); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void set_cursor_inv_offset(struct resizor *resizor, float x, float y) { struct rectangle allocation; widget_get_allocation(resizor->widget, &allocation); resizor->pointer_x = x - (allocation.width - allocation.x); resizor->pointer_y = y - (allocation.height - allocation.y); }
static void text_entry_redraw_handler(struct widget *widget, void *data) { struct text_entry *entry = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(entry->window); widget_get_allocation(entry->widget, &allocation); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_push_group(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_fill(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); if (entry->active) { cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_set_line_width (cr, 3); cairo_set_source_rgba(cr, 0, 0, 1, 1.0); cairo_stroke(cr); } cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_translate(cr, text_offset_left, allocation.height / 2); if (!entry->layout) entry->layout = pango_cairo_create_layout(cr); else pango_cairo_update_layout(cr, entry->layout); text_entry_update_layout(entry); pango_cairo_show_layout(cr, entry->layout); text_entry_draw_cursor(entry, cr); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct view *view = data; struct rectangle allocation; cairo_surface_t *surface; cairo_t *cr; PopplerPage *page; double width, height, doc_aspect, window_aspect, scale; widget_get_allocation(view->widget, &allocation); surface = window_get_surface(view->window); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); if(!view->document) { cairo_destroy(cr); cairo_surface_destroy(surface); window_flush(view->window); return; } page = poppler_document_get_page(view->document, view->page); poppler_page_get_size(page, &width, &height); doc_aspect = width / height; window_aspect = (double) allocation.width / allocation.height; if (doc_aspect < window_aspect) scale = allocation.height / height; else scale = allocation.width / width; cairo_translate(cr, allocation.x, allocation.y); cairo_scale(cr, scale, scale); cairo_translate(cr, (allocation.width - width * scale) / 2 / scale, (allocation.height - height * scale) / 2 / scale); cairo_rectangle(cr, 0, 0, width, height); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgb(cr, 1, 1, 1); cairo_fill(cr); poppler_page_render(page, cr); cairo_destroy(cr); cairo_surface_destroy(surface); g_object_unref(G_OBJECT(page)); }
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; }
static void resize_handler(struct widget *widget, int32_t width, int32_t height, void *data) { struct editor *editor = data; struct rectangle allocation; widget_get_allocation(editor->widget, &allocation); text_entry_allocate(editor->entry, allocation.x + 20, allocation.y + 20, width - 40, height / 2 - 40); text_entry_allocate(editor->editor, allocation.x + 20, allocation.y + height / 2 + 20, width - 40, height / 2 - 40); }
static int text_entry_motion_handler(struct widget *widget, struct input *input, uint32_t time, float x, float y, void *data) { struct text_entry *entry = data; struct rectangle allocation; widget_get_allocation(entry->widget, &allocation); text_entry_set_cursor_position(entry, x - allocation.x - text_offset_left, y - allocation.y - text_offset_left); return CURSOR_IBEAM; }
static int enter_handler(struct widget *widget, struct input *input, float x, float y, void *data) { struct image *image = data; struct rectangle allocation; widget_get_allocation(image->widget, &allocation); x -= allocation.x; y -= allocation.y; image->pointer.x = x; image->pointer.y = y; return 1; }
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); if (button == BTN_LEFT) { entry->button_pressed = (state == WL_POINTER_BUTTON_STATE_PRESSED); if (state == WL_POINTER_BUTTON_STATE_PRESSED) input_grab(input, entry->widget, button); else input_ungrab(input); } if (text_entry_has_preedit(entry)) { result = text_entry_try_invoke_preedit_action(entry, x, y, button, state); if (result) return; } 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_cursor_position(entry, x, y, true); } }
static void redraw_handler(struct widget *widget, void *data) { struct keyboard *keyboard = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; unsigned int i; unsigned int row = 0, col = 0; const struct layout *layout; layout = get_current_layout(keyboard->keyboard); surface = window_get_surface(keyboard->window); widget_get_allocation(keyboard->widget, &allocation); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_select_font_face(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 16); cairo_translate(cr, allocation.x, allocation.y); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 1, 1, 1, 0.75); cairo_rectangle(cr, 0, 0, layout->columns * key_width, layout->rows * key_height); cairo_paint(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); for (i = 0; i < layout->count; ++i) { cairo_set_source_rgb(cr, 0, 0, 0); draw_key(keyboard, &layout->keys[i], cr, row, col); col += layout->keys[i].width; if (col >= layout->columns) { row += 1; col = 0; } } cairo_destroy(cr); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct ModeInfo *mi = data; struct wscreensaver *wscr = mi->priv; struct rectangle drawarea; struct rectangle winarea; struct wl_callback *callback; int bottom; mi->swap_buffers = 0; widget_get_allocation(mi->widget, &drawarea); window_get_allocation(mi->window, &winarea); if (display_acquire_window_surface(wscr->display, mi->window, mi->eglctx) < 0) { fprintf(stderr, "%s: unable to acquire window surface", progname); return; } bottom = winarea.height - (drawarea.height + drawarea.y); glViewport(drawarea.x, bottom, drawarea.width, drawarea.height); glScissor(drawarea.x, bottom, drawarea.width, drawarea.height); glEnable(GL_SCISSOR_TEST); if (mi->width != drawarea.width || mi->height != drawarea.height) { mi->width = drawarea.width; mi->height = drawarea.height; wscr->plugin->reshape(mi, mi->width, mi->height); } wscr->plugin->draw(mi); if (mi->swap_buffers == 0) fprintf(stderr, "%s: swapBuffers not called\n", progname); display_release_window_surface(wscr->display, mi->window); callback = wl_surface_frame(window_get_wl_surface(mi->window)); wl_callback_add_listener(callback, &listener, mi); }
static int motion_handler(struct widget *widget, struct input *input, uint32_t time, float x, float y, void *data) { struct image *image = data; struct rectangle allocation; widget_get_allocation(image->widget, &allocation); x -= allocation.x; y -= allocation.y; if (image->button_pressed) move_viewport(image, image->pointer.x - x, image->pointer.y - y); image->pointer.x = x; image->pointer.y = y; return image->button_pressed ? CURSOR_DRAGGING : CURSOR_LEFT_PTR; }
static void sub_redraw_handler(struct widget *widget, void *data) { struct demoapp *app = data; cairo_t *cr; struct rectangle allocation; uint32_t time; widget_get_allocation(app->subsurface, &allocation); cr = widget_cairo_create(widget); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); /* debug: paint whole surface magenta; no magenta should show */ cairo_set_source_rgba(cr, 0.9, 0.0, 0.9, 1.0); cairo_paint(cr); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_source_rgba(cr, 0.8, 0, 0, 0.8); cairo_paint(cr); time = widget_get_last_time(widget); cairo_set_source_rgba(cr, 1.0, 0.5, 0.5, 1.0); draw_spinner(cr, &allocation, time); cairo_destroy(cr); if (app->animate) widget_schedule_redraw(app->subsurface); DBG("%dx%d @ %d,%d, last time %u\n", allocation.width, allocation.height, allocation.x, allocation.y, time); }
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; widget_get_allocation(entry->widget, &allocation); input_get_position(input, &x, &y); editor = window_get_user_data(entry->window); if (button != BTN_LEFT) { return; } text_entry_set_cursor_position(entry, x - allocation.x - text_offset_left, y - allocation.y - text_offset_left); 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 - allocation.x - text_offset_left, y - allocation.y - text_offset_left); widget_set_motion_handler(entry->widget, text_entry_motion_handler); } else { widget_set_motion_handler(entry->widget, NULL); } }
static void redraw_handler(struct widget *widget, void *data) { static const double r = 10.0; struct clickdot *clickdot = data; cairo_surface_t *surface; cairo_t *cr; struct rectangle allocation; widget_get_allocation(clickdot->widget, &allocation); surface = window_get_surface(clickdot->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_fill(cr); draw_line(clickdot, cr, &allocation); cairo_translate(cr, clickdot->dot.x + 0.5, clickdot->dot.y + 0.5); cairo_set_line_width(cr, 1.0); cairo_set_source_rgb(cr, 0.1, 0.9, 0.9); cairo_move_to(cr, 0.0, -r); cairo_line_to(cr, 0.0, r); cairo_move_to(cr, -r, 0.0); cairo_line_to(cr, r, 0.0); cairo_arc(cr, 0.0, 0.0, r, 0.0, 2.0 * M_PI); cairo_stroke(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct transformed *transformed = data; struct rectangle allocation; cairo_surface_t *surface; cairo_t *cr; surface = window_get_surface(transformed->window); if (surface == NULL || cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "failed to create cairo egl surface\n"); return; } widget_get_allocation(transformed->widget, &allocation); cr = widget_cairo_create(widget); draw_stuff(cr, allocation.width, allocation.height); cairo_surface_destroy(surface); }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct editor *editor = data; struct rectangle allocation; int32_t x, y; struct wl_seat *seat; if (state != WL_POINTER_BUTTON_STATE_PRESSED || button != BTN_LEFT) { return; } input_get_position(input, &x, &y); widget_get_allocation(editor->widget, &allocation); x -= allocation.x; y -= allocation.y; int32_t activate_entry = rectangle_contains(&editor->entry->allocation, x, y); int32_t activate_editor = rectangle_contains(&editor->editor->allocation, x, y); assert(!(activate_entry && activate_editor)); seat = input_get_seat(input); if (activate_entry) { text_entry_activate(editor->entry, seat); } else if (activate_editor) { text_entry_activate(editor->editor, seat); } else { text_entry_deactivate(editor->entry, seat); text_entry_deactivate(editor->editor, seat); } widget_schedule_redraw(widget); }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct keyboard *keyboard = data; struct rectangle allocation; int32_t x, y; int row, col; unsigned int i; const struct layout *layout; layout = get_current_layout(keyboard->keyboard); if (button != BTN_LEFT) { return; } input_get_position(input, &x, &y); widget_get_allocation(keyboard->widget, &allocation); x -= allocation.x; y -= allocation.y; row = y / key_height; col = x / key_width + row * layout->columns; for (i = 0; i < layout->count; ++i) { col -= layout->keys[i].width; if (col < 0) { keyboard_handle_key(keyboard, time, &layout->keys[i], input, state); break; } } widget_schedule_redraw(widget); }
static void panel_tag_redraw_handler(struct widget *widget, void *data) { static char* tag_names[] = {"a", "s", "d", "f", "g", "h", "j", "k", "l", ";"}; struct panel_tag *tag = data; cairo_text_extents_t extents; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(tag->panel->window); cr = cairo_create(surface); widget_get_allocation(widget, &allocation); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_select_font_face(cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, tag->font_size); //cairo_text_extents(cr, "1", &extents); int x = 0; int y = 0; cairo_move_to(cr, allocation.x, 26); if (tag->focused) cairo_set_source_rgba(cr, 0.8, 1, 1, 1); else if (tag->pressed) cairo_set_source_rgba(cr, 1, 0, 0, 1); else cairo_set_source_rgba(cr, 0, 0.7, 1, 1); cairo_show_text(cr, tag_names[tag->no]); //cairo_set_source_surface(cr, launcher->icon, allocation.x, allocation.y); //cairo_paint(cr); cairo_destroy(cr); }