diff --git a/include/render.h b/include/render.h new file mode 100644 index 00000000..19d3a52e --- /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 5b6104f3..6c62d676 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 7d4ea263..dff682f5 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 00000000..66d2e5f0 --- /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); +}