mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 09:51:29 +00:00
Initial setup of window border rendering
Please don't complain to me about the performance of this
This commit is contained in:
parent
c3a5e00b6e
commit
4611bba3db
7
include/render.h
Normal file
7
include/render.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef _SWAY_RENDER_H
|
||||
#define _SWAY_RENDER_H
|
||||
#include <wlc/wlc.h>
|
||||
|
||||
void render_view_borders(wlc_handle view);
|
||||
|
||||
#endif
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <ctype.h>
|
||||
|
||||
#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);
|
||||
|
|
35
sway/render.c
Normal file
35
sway/render.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "render.h"
|
||||
#include <cairo.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in a new issue