mirror of
https://codeberg.org/vyivel/dulcepan/
synced 2025-12-18 16:15:13 +02:00
Switch back to Cairo for drawing selection
This commit is contained in:
45
src/output.c
45
src/output.c
@@ -208,8 +208,9 @@ static void output_handle_done(void *data, struct wl_output *wl_output) {
|
||||
buffer->wl_buffer =
|
||||
dp_buffer_create(state, output->transformed_width, output->transformed_height,
|
||||
stride, WL_SHM_FORMAT_ARGB8888, &buffer->data, &buffer->size);
|
||||
buffer->image = pixman_image_create_bits(PIXMAN_a8r8g8b8, output->transformed_width,
|
||||
output->transformed_height, buffer->data, stride);
|
||||
buffer->cairo_surface = cairo_image_surface_create_for_data(buffer->data,
|
||||
CAIRO_FORMAT_ARGB32, output->transformed_width, output->transformed_height, stride);
|
||||
buffer->cairo = cairo_create(buffer->cairo_surface);
|
||||
|
||||
wl_buffer_add_listener(buffer->wl_buffer, &buffer_listener, buffer);
|
||||
}
|
||||
@@ -242,6 +243,10 @@ static const struct wl_callback_listener redraw_callback_listener = {
|
||||
.done = redraw_callback_handle_done,
|
||||
};
|
||||
|
||||
static inline void set_cairo_color(cairo_t *cairo, float color[static 4]) {
|
||||
cairo_set_source_rgba(cairo, color[0], color[1], color[2], color[3]);
|
||||
}
|
||||
|
||||
static void redraw(struct dp_output *output) {
|
||||
assert(output->redraw_callback == NULL);
|
||||
|
||||
@@ -260,30 +265,29 @@ static void redraw(struct dp_output *output) {
|
||||
buffer->used = true;
|
||||
|
||||
struct dp_state *state = output->state;
|
||||
struct dp_config *config = &state->config;
|
||||
|
||||
pixman_image_composite32(PIXMAN_OP_SRC, state->unselected_fill_image, NULL, buffer->image, 0, 0,
|
||||
0, 0, 0, 0, output->transformed_width, output->transformed_height);
|
||||
cairo_set_operator(buffer->cairo, CAIRO_OPERATOR_SOURCE);
|
||||
|
||||
set_cairo_color(buffer->cairo, config->unselected_color);
|
||||
cairo_paint(buffer->cairo);
|
||||
|
||||
struct dp_selection *selection = &state->selection;
|
||||
if (output == selection->output) {
|
||||
int border_size = state->config.border_size;
|
||||
int border_size = config->border_size;
|
||||
if (border_size != 0) {
|
||||
pixman_image_composite32(PIXMAN_OP_SRC, state->border_fill_image, NULL, buffer->image,
|
||||
0, 0, 0, 0, selection->x - border_size, selection->y - border_size,
|
||||
selection->width + border_size * 2, border_size);
|
||||
pixman_image_composite32(PIXMAN_OP_SRC, state->border_fill_image, NULL, buffer->image,
|
||||
0, 0, 0, 0, selection->x - border_size, selection->y + selection->height,
|
||||
selection->width + border_size * 2, border_size);
|
||||
pixman_image_composite32(PIXMAN_OP_SRC, state->border_fill_image, NULL, buffer->image,
|
||||
0, 0, 0, 0, selection->x - border_size, selection->y, border_size,
|
||||
selection->height);
|
||||
pixman_image_composite32(PIXMAN_OP_SRC, state->border_fill_image, NULL, buffer->image,
|
||||
0, 0, 0, 0, selection->x + selection->width, selection->y, border_size,
|
||||
selection->height);
|
||||
cairo_set_line_width(buffer->cairo, border_size);
|
||||
double off = border_size / 2.0;
|
||||
cairo_rectangle(buffer->cairo, selection->x - off, selection->y - off,
|
||||
selection->width + border_size, selection->height + border_size);
|
||||
set_cairo_color(buffer->cairo, config->border_color);
|
||||
cairo_stroke(buffer->cairo);
|
||||
}
|
||||
|
||||
pixman_image_composite32(PIXMAN_OP_SRC, state->selected_fill_image, NULL, buffer->image, 0,
|
||||
0, 0, 0, selection->x, selection->y, selection->width, selection->height);
|
||||
cairo_rectangle(
|
||||
buffer->cairo, selection->x, selection->y, selection->width, selection->height);
|
||||
set_cairo_color(buffer->cairo, config->selected_color);
|
||||
cairo_fill(buffer->cairo);
|
||||
}
|
||||
|
||||
wl_surface_attach(output->select_surface, buffer->wl_buffer, 0, 0);
|
||||
@@ -335,7 +339,8 @@ void dp_output_destroy(struct dp_output *output) {
|
||||
for (size_t i = 0; i < DP_SWAPCHAIN_LEN; i++) {
|
||||
struct dp_buffer *buffer = &output->swapchain[i];
|
||||
wl_buffer_destroy(buffer->wl_buffer);
|
||||
pixman_image_unref(buffer->image);
|
||||
cairo_destroy(buffer->cairo);
|
||||
cairo_surface_destroy(buffer->cairo_surface);
|
||||
munmap(buffer->data, buffer->size);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user