From 4611bba3dbf63a5ef67bf90d5ebd192eeb07742e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 28 Jan 2016 08:39:51 -0500 Subject: [PATCH] Initial setup of window border rendering Please don't complain to me about the performance of this --- include/render.h | 7 +++++++ sway/CMakeLists.txt | 5 +++++ sway/handlers.c | 6 ++++++ sway/render.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 include/render.h create mode 100644 sway/render.c diff --git a/include/render.h b/include/render.h new file mode 100644 index 000000000..19d3a52e7 --- /dev/null +++ b/include/render.h @@ -0,0 +1,7 @@ +#ifndef _SWAY_RENDER_H +#define _SWAY_RENDER_H +#include + +void render_view_borders(wlc_handle view); + +#endif diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt index 5b6104f3a..6c62d6763 100644 --- a/sway/CMakeLists.txt +++ b/sway/CMakeLists.txt @@ -5,6 +5,8 @@ include_directories( ${JSONC_INCLUDE_DIRS} ${XKBCOMMON_INCLUDE_DIRS} ${LIBINPUT_INCLUDE_DIRS} + ${CAIRO_INCLUDE_DIRS} + ${PANGO_INCLUDE_DIRS} ) add_executable(sway @@ -24,6 +26,7 @@ add_executable(sway output.c resize.c workspace.c + render.c ) add_definitions( @@ -39,6 +42,8 @@ target_link_libraries(sway ${JSONC_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${LIBINPUT_LIBRARIES} + ${PANGO_LIBRARIES} + ${JSONC_LIBRARIES} m ) diff --git a/sway/handlers.c b/sway/handlers.c index 7d4ea263f..dff682f5b 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -9,6 +9,7 @@ #include #include "handlers.h" +#include "render.h" #include "log.h" #include "layout.h" #include "config.h" @@ -150,6 +151,10 @@ static void handle_output_post_render(wlc_handle output) { ipc_get_pixels(output); } +static void handle_view_pre_render(wlc_handle view) { + render_view_borders(view); +} + static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h); swayc_t *c = swayc_by_handle(output); @@ -716,6 +721,7 @@ void register_wlc_handlers() { wlc_set_view_created_cb(handle_view_created); wlc_set_view_destroyed_cb(handle_view_destroyed); wlc_set_view_focus_cb(handle_view_focus); + wlc_set_view_render_pre_cb(handle_view_pre_render); wlc_set_view_request_geometry_cb(handle_view_geometry_request); wlc_set_view_request_state_cb(handle_view_state_request); wlc_set_keyboard_key_cb(handle_key); diff --git a/sway/render.c b/sway/render.c new file mode 100644 index 000000000..66d2e5f01 --- /dev/null +++ b/sway/render.c @@ -0,0 +1,35 @@ +#include "render.h" +#include +#include + +cairo_t *create_cairo_context(int width, int height, int channels, + cairo_surface_t **surf, unsigned char **buf) { + cairo_t *cr; + *buf = calloc(channels * width * height, sizeof(unsigned char)); + if (!*buf) { + return NULL; + } + *surf = cairo_image_surface_create_for_data(*buf, CAIRO_FORMAT_ARGB32, + width, height, channels * width); + if (cairo_surface_status(*surf) != CAIRO_STATUS_SUCCESS) { + free(*buf); + return NULL; + } + cr = cairo_create(*surf); + if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) { + free(*buf); + return NULL; + } + return cr; +} + +void render_view_borders(wlc_handle view) { + unsigned char *surf_data; + cairo_surface_t *surf; + int texture_id; + const struct wlc_geometry *geo = wlc_view_get_geometry(view); + cairo_t *cr = create_cairo_context(geo->size.w, geo->size.h, 4, &surf, &surf_data); + // TODO + cairo_destroy(cr); + free(surf_data); +}