mirror of
https://github.com/labwc/labwc.git
synced 2026-02-27 01:40:30 -05:00
Prepare to move from wlr_texture to lab_data_buffer
This commit is contained in:
parent
7ea733761b
commit
044388a5cd
13 changed files with 148 additions and 122 deletions
|
|
@ -36,9 +36,15 @@ struct lab_data_buffer {
|
||||||
void *data;
|
void *data;
|
||||||
uint32_t format;
|
uint32_t format;
|
||||||
size_t stride;
|
size_t stride;
|
||||||
|
bool free_on_destroy;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lab_data_buffer *buffer_create(uint32_t width, uint32_t height,
|
/* Create a buffer which creates a new cairo CAIRO_FORMAT_ARGB32 surface */
|
||||||
float scale);
|
struct lab_data_buffer *buffer_create_cairo(uint32_t width, uint32_t height,
|
||||||
|
float scale, bool free_on_destroy);
|
||||||
|
|
||||||
|
/* Create a buffer which wraps a given DRM_FORMAT_ARGB8888 pointer */
|
||||||
|
struct lab_data_buffer *buffer_create_wrap(void *pixel_data, uint32_t width,
|
||||||
|
uint32_t height, uint32_t stride, bool free_on_destroy);
|
||||||
|
|
||||||
#endif /* __LABWC_BUFFER_H */
|
#endif /* __LABWC_BUFFER_H */
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
#ifndef __LABWC_FONT_H
|
#ifndef __LABWC_FONT_H
|
||||||
#define __LABWC_FONT_H
|
#define __LABWC_FONT_H
|
||||||
|
|
||||||
struct server;
|
struct lab_data_buffer;
|
||||||
struct wlr_texture;
|
|
||||||
struct wlr_box;
|
|
||||||
|
|
||||||
struct font {
|
struct font {
|
||||||
char *name;
|
char *name;
|
||||||
|
|
@ -18,16 +16,23 @@ struct font {
|
||||||
int font_height(struct font *font);
|
int font_height(struct font *font);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* texture_create - Create ARGB8888 texture using pango
|
* font_buffer_create - Create ARGB8888 lab_data_buffer using pango
|
||||||
* @server: context (for wlr_renderer)
|
* @buffer: buffer pointer
|
||||||
* @texture: texture pointer; existing pointer will be freed
|
|
||||||
* @max_width: max allowable width; will be ellipsized if longer
|
* @max_width: max allowable width; will be ellipsized if longer
|
||||||
* @text: text to be generated as texture
|
* @text: text to be generated as texture
|
||||||
* @font: font description
|
* @font: font description
|
||||||
* @color: foreground color in rgba format
|
* @color: foreground color in rgba format
|
||||||
*/
|
*/
|
||||||
void font_texture_create(struct server *server, struct wlr_texture **texture,
|
void font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
||||||
int max_width, const char *text, struct font *font, float *color);
|
const char *text, struct font *font, float *color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* font_buffer_update - Wrapper around font_buffer_create
|
||||||
|
* Only difference is that if given buffer pointer is != NULL
|
||||||
|
* wlr_buffer_drop() will be called on the buffer.
|
||||||
|
*/
|
||||||
|
void font_buffer_update(struct lab_data_buffer **buffer, int max_width,
|
||||||
|
const char *text, struct font *font, float *color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* font_finish - free some font related resources
|
* font_finish - free some font related resources
|
||||||
|
|
|
||||||
|
|
@ -54,20 +54,20 @@ struct theme {
|
||||||
float osd_label_text_color[4];
|
float osd_label_text_color[4];
|
||||||
|
|
||||||
/* textures */
|
/* textures */
|
||||||
struct wlr_texture *xbm_close_active_unpressed;
|
struct lab_data_buffer *xbm_close_active_unpressed;
|
||||||
struct wlr_texture *xbm_maximize_active_unpressed;
|
struct lab_data_buffer *xbm_maximize_active_unpressed;
|
||||||
struct wlr_texture *xbm_iconify_active_unpressed;
|
struct lab_data_buffer *xbm_iconify_active_unpressed;
|
||||||
struct wlr_texture *xbm_menu_active_unpressed;
|
struct lab_data_buffer *xbm_menu_active_unpressed;
|
||||||
|
|
||||||
struct wlr_texture *xbm_close_inactive_unpressed;
|
struct lab_data_buffer *xbm_close_inactive_unpressed;
|
||||||
struct wlr_texture *xbm_maximize_inactive_unpressed;
|
struct lab_data_buffer *xbm_maximize_inactive_unpressed;
|
||||||
struct wlr_texture *xbm_iconify_inactive_unpressed;
|
struct lab_data_buffer *xbm_iconify_inactive_unpressed;
|
||||||
struct wlr_texture *xbm_menu_inactive_unpressed;
|
struct lab_data_buffer *xbm_menu_inactive_unpressed;
|
||||||
|
|
||||||
struct wlr_texture *corner_top_left_active_normal;
|
struct lab_data_buffer *corner_top_left_active_normal;
|
||||||
struct wlr_texture *corner_top_right_active_normal;
|
struct lab_data_buffer *corner_top_right_active_normal;
|
||||||
struct wlr_texture *corner_top_left_inactive_normal;
|
struct lab_data_buffer *corner_top_left_inactive_normal;
|
||||||
struct wlr_texture *corner_top_right_inactive_normal;
|
struct lab_data_buffer *corner_top_right_inactive_normal;
|
||||||
|
|
||||||
/* not set in rc.xml/themerc, but derived from font & padding_height */
|
/* not set in rc.xml/themerc, but derived from font & padding_height */
|
||||||
int title_height;
|
int title_height;
|
||||||
|
|
@ -76,12 +76,10 @@ struct theme {
|
||||||
/**
|
/**
|
||||||
* theme_init - read openbox theme and generate button textures
|
* theme_init - read openbox theme and generate button textures
|
||||||
* @theme: theme data
|
* @theme: theme data
|
||||||
* @renderer: wlr_renderer for creating button textures
|
|
||||||
* @theme_name: theme-name in <theme-dir>/<theme-name>/openbox-3/themerc
|
* @theme_name: theme-name in <theme-dir>/<theme-name>/openbox-3/themerc
|
||||||
* Note <theme-dir> is obtained in theme-dir.c
|
* Note <theme-dir> is obtained in theme-dir.c
|
||||||
*/
|
*/
|
||||||
void theme_init(struct theme *theme, struct wlr_renderer *renderer,
|
void theme_init(struct theme *theme, const char *theme_name);
|
||||||
const char *theme_name);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* theme_finish - free button textures
|
* theme_finish - free button textures
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@
|
||||||
/**
|
/**
|
||||||
* xbm_load - load theme xbm files into global theme struct
|
* xbm_load - load theme xbm files into global theme struct
|
||||||
*/
|
*/
|
||||||
void xbm_load(struct theme *theme, struct wlr_renderer *renderer);
|
void xbm_load(struct theme *theme);
|
||||||
|
|
||||||
#endif /* __LABWC_XBM_H */
|
#endif /* __LABWC_XBM_H */
|
||||||
|
|
|
||||||
27
src/buffer.c
27
src/buffer.c
|
|
@ -42,10 +42,17 @@ static void
|
||||||
data_buffer_destroy(struct wlr_buffer *wlr_buffer)
|
data_buffer_destroy(struct wlr_buffer *wlr_buffer)
|
||||||
{
|
{
|
||||||
struct lab_data_buffer *buffer = data_buffer_from_buffer(wlr_buffer);
|
struct lab_data_buffer *buffer = data_buffer_from_buffer(wlr_buffer);
|
||||||
|
if (!buffer->free_on_destroy) {
|
||||||
|
free(buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (buffer->cairo) {
|
if (buffer->cairo) {
|
||||||
cairo_surface_t *surf = cairo_get_target(buffer->cairo);
|
cairo_surface_t *surf = cairo_get_target(buffer->cairo);
|
||||||
cairo_destroy(buffer->cairo);
|
cairo_destroy(buffer->cairo);
|
||||||
cairo_surface_destroy(surf);
|
cairo_surface_destroy(surf);
|
||||||
|
} else if (buffer->data) {
|
||||||
|
free(buffer->data);
|
||||||
|
buffer->data = NULL;
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +83,8 @@ static const struct wlr_buffer_impl data_buffer_impl = {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lab_data_buffer *
|
struct lab_data_buffer *
|
||||||
buffer_create(uint32_t width, uint32_t height, float scale)
|
buffer_create_cairo(uint32_t width, uint32_t height, float scale,
|
||||||
|
bool free_on_destroy)
|
||||||
{
|
{
|
||||||
struct lab_data_buffer *buffer = calloc(1, sizeof(*buffer));
|
struct lab_data_buffer *buffer = calloc(1, sizeof(*buffer));
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
|
|
@ -92,6 +100,7 @@ buffer_create(uint32_t width, uint32_t height, float scale)
|
||||||
buffer->data = cairo_image_surface_get_data(surf);
|
buffer->data = cairo_image_surface_get_data(surf);
|
||||||
buffer->format = DRM_FORMAT_ARGB8888;
|
buffer->format = DRM_FORMAT_ARGB8888;
|
||||||
buffer->stride = cairo_image_surface_get_stride(surf);
|
buffer->stride = cairo_image_surface_get_stride(surf);
|
||||||
|
buffer->free_on_destroy = free_on_destroy;
|
||||||
|
|
||||||
if (!buffer->data) {
|
if (!buffer->data) {
|
||||||
cairo_destroy(buffer->cairo);
|
cairo_destroy(buffer->cairo);
|
||||||
|
|
@ -101,3 +110,19 @@ buffer_create(uint32_t width, uint32_t height, float scale)
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct lab_data_buffer *
|
||||||
|
buffer_create_wrap(void *pixel_data, uint32_t width, uint32_t height,
|
||||||
|
uint32_t stride, bool free_on_destroy)
|
||||||
|
{
|
||||||
|
struct lab_data_buffer *buffer = calloc(1, sizeof(*buffer));
|
||||||
|
if (!buffer) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
wlr_buffer_init(&buffer->base, &data_buffer_impl, width, height);
|
||||||
|
buffer->data = pixel_data;
|
||||||
|
buffer->format = DRM_FORMAT_ARGB8888;
|
||||||
|
buffer->stride = stride;
|
||||||
|
buffer->free_on_destroy = free_on_destroy;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
static PangoRectangle
|
static PangoRectangle
|
||||||
font_extents(struct font *font, const char *string)
|
font_extents(struct font *font, const char *string)
|
||||||
|
|
@ -49,25 +50,33 @@ font_height(struct font *font)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
font_texture_create(struct server *server, struct wlr_texture **texture,
|
font_buffer_update(struct lab_data_buffer **buffer, int max_width,
|
||||||
int max_width, const char *text, struct font *font, float *color)
|
const char *text, struct font *font, float *color)
|
||||||
|
{
|
||||||
|
if (*buffer) {
|
||||||
|
wlr_buffer_drop(&(*buffer)->base);
|
||||||
|
*buffer = NULL;
|
||||||
|
}
|
||||||
|
font_buffer_create(buffer, max_width, text, font, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
||||||
|
const char *text, struct font *font, float *color)
|
||||||
{
|
{
|
||||||
if (!text || !*text) {
|
if (!text || !*text) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (*texture) {
|
|
||||||
wlr_texture_destroy(*texture);
|
|
||||||
*texture = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
PangoRectangle rect = font_extents(font, text);
|
PangoRectangle rect = font_extents(font, text);
|
||||||
if (max_width && rect.width > max_width) {
|
if (max_width && rect.width > max_width) {
|
||||||
rect.width = max_width;
|
rect.width = max_width;
|
||||||
}
|
}
|
||||||
|
/* TODO: scale */
|
||||||
|
*buffer = buffer_create_cairo(rect.width, rect.height, 1, true);
|
||||||
|
|
||||||
cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
cairo_t *cairo = (*buffer)->cairo;
|
||||||
rect.width, rect.height);
|
cairo_surface_t *surf = cairo_get_target(cairo);
|
||||||
cairo_t *cairo = cairo_create(surf);
|
|
||||||
|
|
||||||
cairo_set_source_rgba(cairo, color[0], color[1], color[2], color[3]);
|
cairo_set_source_rgba(cairo, color[0], color[1], color[2], color[3]);
|
||||||
cairo_move_to(cairo, 0, 0);
|
cairo_move_to(cairo, 0, 0);
|
||||||
|
|
@ -88,13 +97,6 @@ font_texture_create(struct server *server, struct wlr_texture **texture,
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
|
|
||||||
cairo_surface_flush(surf);
|
cairo_surface_flush(surf);
|
||||||
unsigned char *data = cairo_image_surface_get_data(surf);
|
|
||||||
*texture = wlr_texture_from_pixels(server->renderer, DRM_FORMAT_ARGB8888,
|
|
||||||
cairo_image_surface_get_stride(surf), rect.width,
|
|
||||||
rect.height, data);
|
|
||||||
|
|
||||||
cairo_destroy(cairo);
|
|
||||||
cairo_surface_destroy(surf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ main(int argc, char *argv[])
|
||||||
server_start(&server);
|
server_start(&server);
|
||||||
|
|
||||||
struct theme theme = { 0 };
|
struct theme theme = { 0 };
|
||||||
theme_init(&theme, server.renderer, rc.theme_name);
|
theme_init(&theme, rc.theme_name);
|
||||||
server.theme = &theme;
|
server.theme = &theme;
|
||||||
|
|
||||||
menu_init_rootmenu(&server);
|
menu_init_rootmenu(&server);
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,11 @@ item_create(struct menu *menu, const char *text)
|
||||||
if (!menuitem) {
|
if (!menuitem) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* FIXME */
|
||||||
|
#if 0
|
||||||
struct server *server = menu->server;
|
struct server *server = menu->server;
|
||||||
struct theme *theme = server->theme;
|
struct theme *theme = server->theme;
|
||||||
|
#endif
|
||||||
struct font font = {
|
struct font font = {
|
||||||
.name = rc.font_name_menuitem,
|
.name = rc.font_name_menuitem,
|
||||||
.size = rc.font_size_menuitem,
|
.size = rc.font_size_menuitem,
|
||||||
|
|
@ -84,6 +87,8 @@ item_create(struct menu *menu, const char *text)
|
||||||
menuitem->box.width = MENUWIDTH;
|
menuitem->box.width = MENUWIDTH;
|
||||||
menuitem->box.height = font_height(&font) + 2 * MENU_ITEM_PADDING_Y;
|
menuitem->box.height = font_height(&font) + 2 * MENU_ITEM_PADDING_Y;
|
||||||
|
|
||||||
|
/* FIXME */
|
||||||
|
#if 0
|
||||||
int item_max_width = MENUWIDTH - 2 * MENU_ITEM_PADDING_X;
|
int item_max_width = MENUWIDTH - 2 * MENU_ITEM_PADDING_X;
|
||||||
font_texture_create(server, &menuitem->texture.active, item_max_width,
|
font_texture_create(server, &menuitem->texture.active, item_max_width,
|
||||||
text, &font, theme->menu_items_active_text_color);
|
text, &font, theme->menu_items_active_text_color);
|
||||||
|
|
@ -94,6 +99,7 @@ item_create(struct menu *menu, const char *text)
|
||||||
menuitem->texture.offset_y =
|
menuitem->texture.offset_y =
|
||||||
(menuitem->box.height - menuitem->texture.active->height) / 2;
|
(menuitem->box.height - menuitem->texture.active->height) / 2;
|
||||||
menuitem->texture.offset_x = MENU_ITEM_PADDING_X;
|
menuitem->texture.offset_x = MENU_ITEM_PADDING_X;
|
||||||
|
#endif
|
||||||
|
|
||||||
wl_list_insert(&menu->menuitems, &menuitem->link);
|
wl_list_insert(&menu->menuitems, &menuitem->link);
|
||||||
wl_list_init(&menuitem->actions);
|
wl_list_init(&menuitem->actions);
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ osd_update(struct server *server)
|
||||||
if (output->osd_buffer) {
|
if (output->osd_buffer) {
|
||||||
wlr_buffer_drop(&output->osd_buffer->base);
|
wlr_buffer_drop(&output->osd_buffer->base);
|
||||||
}
|
}
|
||||||
output->osd_buffer = buffer_create(w, h, scale);
|
output->osd_buffer = buffer_create_cairo(w, h, scale, true);
|
||||||
|
|
||||||
cairo_t *cairo = output->osd_buffer->cairo;
|
cairo_t *cairo = output->osd_buffer->cairo;
|
||||||
cairo_surface_t *surf = cairo_get_target(cairo);
|
cairo_surface_t *surf = cairo_get_target(cairo);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ reload_config_and_theme(void)
|
||||||
rcxml_finish();
|
rcxml_finish();
|
||||||
rcxml_read(NULL);
|
rcxml_read(NULL);
|
||||||
theme_finish(g_server->theme);
|
theme_finish(g_server->theme);
|
||||||
theme_init(g_server->theme, g_server->renderer, rc.theme_name);
|
theme_init(g_server->theme, rc.theme_name);
|
||||||
|
|
||||||
struct view *view;
|
struct view *view;
|
||||||
wl_list_for_each (view, &g_server->views, link) {
|
wl_list_for_each (view, &g_server->views, link) {
|
||||||
|
|
|
||||||
13
src/ssd.c
13
src/ssd.c
|
|
@ -322,12 +322,16 @@ add_part(struct view *view, enum ssd_part_type type)
|
||||||
void
|
void
|
||||||
ssd_update_title(struct view *view)
|
ssd_update_title(struct view *view)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* FIXME */
|
||||||
|
#if 0
|
||||||
struct theme *theme = view->server->theme;
|
struct theme *theme = view->server->theme;
|
||||||
|
|
||||||
struct font font = {
|
struct font font = {
|
||||||
.name = rc.font_name_activewindow,
|
.name = rc.font_name_activewindow,
|
||||||
.size = rc.font_size_activewindow,
|
.size = rc.font_size_activewindow,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct ssd_part *part;
|
struct ssd_part *part;
|
||||||
wl_list_for_each(part, &view->ssd.parts, link) {
|
wl_list_for_each(part, &view->ssd.parts, link) {
|
||||||
|
|
@ -340,6 +344,8 @@ ssd_update_title(struct view *view)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* FIXME */
|
||||||
|
#if 0
|
||||||
int max_width = part->box.width > 0 ? part->box.width : 1000;
|
int max_width = part->box.width > 0 ? part->box.width : 1000;
|
||||||
|
|
||||||
font_texture_create(view->server, &view->title.active, max_width,
|
font_texture_create(view->server, &view->title.active, max_width,
|
||||||
|
|
@ -349,6 +355,7 @@ ssd_update_title(struct view *view)
|
||||||
font_texture_create(view->server, &view->title.inactive, max_width,
|
font_texture_create(view->server, &view->title.inactive, max_width,
|
||||||
view_get_string_prop(view, "title"),
|
view_get_string_prop(view, "title"),
|
||||||
&font, theme->window_inactive_label_text_color);
|
&font, theme->window_inactive_label_text_color);
|
||||||
|
#endif
|
||||||
|
|
||||||
part->box = ssd_visible_box(view, part->type);
|
part->box = ssd_visible_box(view, part->type);
|
||||||
}
|
}
|
||||||
|
|
@ -387,14 +394,20 @@ ssd_create(struct view *view)
|
||||||
/* titlebar top-left corner */
|
/* titlebar top-left corner */
|
||||||
part = add_part(view, LAB_SSD_PART_CORNER_TOP_LEFT);
|
part = add_part(view, LAB_SSD_PART_CORNER_TOP_LEFT);
|
||||||
part->box = ssd_visible_box(view, part->type);
|
part->box = ssd_visible_box(view, part->type);
|
||||||
|
/* FIXME */
|
||||||
|
#if 0
|
||||||
part->texture.active = &theme->corner_top_left_active_normal;
|
part->texture.active = &theme->corner_top_left_active_normal;
|
||||||
part->texture.inactive = &theme->corner_top_left_inactive_normal;
|
part->texture.inactive = &theme->corner_top_left_inactive_normal;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* titlebar top-right corner */
|
/* titlebar top-right corner */
|
||||||
part = add_part(view, LAB_SSD_PART_CORNER_TOP_RIGHT);
|
part = add_part(view, LAB_SSD_PART_CORNER_TOP_RIGHT);
|
||||||
part->box = ssd_visible_box(view, part->type);
|
part->box = ssd_visible_box(view, part->type);
|
||||||
|
/* FIXME */
|
||||||
|
#if 0
|
||||||
part->texture.active = &theme->corner_top_right_active_normal;
|
part->texture.active = &theme->corner_top_right_active_normal;
|
||||||
part->texture.inactive = &theme->corner_top_right_inactive_normal;
|
part->texture.inactive = &theme->corner_top_right_inactive_normal;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* title text */
|
/* title text */
|
||||||
part = add_part(view, LAB_SSD_PART_TITLE);
|
part = add_part(view, LAB_SSD_PART_TITLE);
|
||||||
|
|
|
||||||
41
src/theme.c
41
src/theme.c
|
|
@ -25,6 +25,7 @@
|
||||||
#include "config/rcxml.h"
|
#include "config/rcxml.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "xbm/xbm.h"
|
#include "xbm/xbm.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
hex_to_dec(char c)
|
hex_to_dec(char c)
|
||||||
|
|
@ -336,8 +337,8 @@ set_source(cairo_t *cairo, float *c)
|
||||||
cairo_set_source_rgba(cairo, c[0], c[1], c[2], c[3]);
|
cairo_set_source_rgba(cairo, c[0], c[1], c[2], c[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_texture *
|
static struct lab_data_buffer *
|
||||||
rounded_rect(struct wlr_renderer *renderer, struct rounded_corner_ctx *ctx)
|
rounded_rect(struct rounded_corner_ctx *ctx)
|
||||||
{
|
{
|
||||||
/* 1 degree in radians (=2π/360) */
|
/* 1 degree in radians (=2π/360) */
|
||||||
double deg = 0.017453292519943295;
|
double deg = 0.017453292519943295;
|
||||||
|
|
@ -350,9 +351,12 @@ rounded_rect(struct wlr_renderer *renderer, struct rounded_corner_ctx *ctx)
|
||||||
double h = ctx->box->height;
|
double h = ctx->box->height;
|
||||||
double r = ctx->radius;
|
double r = ctx->radius;
|
||||||
|
|
||||||
cairo_surface_t *surf =
|
struct lab_data_buffer *buffer;
|
||||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
|
/* TODO: scale */
|
||||||
cairo_t *cairo = cairo_create(surf);
|
buffer = buffer_create_cairo(w, h, 1, true);
|
||||||
|
|
||||||
|
cairo_t *cairo = buffer->cairo;
|
||||||
|
cairo_surface_t *surf = cairo_get_target(cairo);
|
||||||
|
|
||||||
/* set transparent background */
|
/* set transparent background */
|
||||||
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
|
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
|
||||||
|
|
@ -405,21 +409,13 @@ rounded_rect(struct wlr_renderer *renderer, struct rounded_corner_ctx *ctx)
|
||||||
wlr_log(WLR_ERROR, "unknown corner type");
|
wlr_log(WLR_ERROR, "unknown corner type");
|
||||||
}
|
}
|
||||||
cairo_stroke(cairo);
|
cairo_stroke(cairo);
|
||||||
|
|
||||||
/* convert to wlr_texture */
|
|
||||||
cairo_surface_flush(surf);
|
cairo_surface_flush(surf);
|
||||||
unsigned char *data = cairo_image_surface_get_data(surf);
|
|
||||||
struct wlr_texture *texture = wlr_texture_from_pixels(renderer,
|
|
||||||
DRM_FORMAT_ARGB8888, cairo_image_surface_get_stride(surf),
|
|
||||||
w, h, data);
|
|
||||||
|
|
||||||
cairo_destroy(cairo);
|
return buffer;
|
||||||
cairo_surface_destroy(surf);
|
|
||||||
return texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
create_corners(struct theme *theme, struct wlr_renderer *renderer)
|
create_corners(struct theme *theme)
|
||||||
{
|
{
|
||||||
int corner_square = theme->title_height + theme->border_width;
|
int corner_square = theme->title_height + theme->border_width;
|
||||||
struct wlr_box box = {
|
struct wlr_box box = {
|
||||||
|
|
@ -437,20 +433,20 @@ create_corners(struct theme *theme, struct wlr_renderer *renderer)
|
||||||
.border_color = theme->window_active_border_color,
|
.border_color = theme->window_active_border_color,
|
||||||
.corner = LAB_CORNER_TOP_LEFT,
|
.corner = LAB_CORNER_TOP_LEFT,
|
||||||
};
|
};
|
||||||
theme->corner_top_left_active_normal = rounded_rect(renderer, &ctx);
|
theme->corner_top_left_active_normal = rounded_rect(&ctx);
|
||||||
|
|
||||||
ctx.fill_color = theme->window_inactive_title_bg_color,
|
ctx.fill_color = theme->window_inactive_title_bg_color,
|
||||||
ctx.border_color = theme->window_inactive_border_color,
|
ctx.border_color = theme->window_inactive_border_color,
|
||||||
theme->corner_top_left_inactive_normal = rounded_rect(renderer, &ctx);
|
theme->corner_top_left_inactive_normal = rounded_rect(&ctx);
|
||||||
|
|
||||||
ctx.corner = LAB_CORNER_TOP_RIGHT;
|
ctx.corner = LAB_CORNER_TOP_RIGHT;
|
||||||
ctx.fill_color = theme->window_active_title_bg_color,
|
ctx.fill_color = theme->window_active_title_bg_color,
|
||||||
ctx.border_color = theme->window_active_border_color,
|
ctx.border_color = theme->window_active_border_color,
|
||||||
theme->corner_top_right_active_normal = rounded_rect(renderer, &ctx);
|
theme->corner_top_right_active_normal = rounded_rect(&ctx);
|
||||||
|
|
||||||
ctx.fill_color = theme->window_inactive_title_bg_color,
|
ctx.fill_color = theme->window_inactive_title_bg_color,
|
||||||
ctx.border_color = theme->window_inactive_border_color,
|
ctx.border_color = theme->window_inactive_border_color,
|
||||||
theme->corner_top_right_inactive_normal = rounded_rect(renderer, &ctx);
|
theme->corner_top_right_inactive_normal = rounded_rect(&ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -480,8 +476,7 @@ post_processing(struct theme *theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
theme_init(struct theme *theme, struct wlr_renderer *renderer,
|
theme_init(struct theme *theme, const char *theme_name)
|
||||||
const char *theme_name)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Set some default values. This is particularly important on
|
* Set some default values. This is particularly important on
|
||||||
|
|
@ -491,8 +486,8 @@ theme_init(struct theme *theme, struct wlr_renderer *renderer,
|
||||||
|
|
||||||
theme_read(theme, theme_name);
|
theme_read(theme, theme_name);
|
||||||
post_processing(theme);
|
post_processing(theme);
|
||||||
create_corners(theme, renderer);
|
create_corners(theme);
|
||||||
xbm_load(theme, renderer);
|
xbm_load(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "xbm/parse.h"
|
#include "xbm/parse.h"
|
||||||
#include "xbm/xbm.h"
|
#include "xbm/xbm.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
/* built-in 6x6 buttons */
|
/* built-in 6x6 buttons */
|
||||||
char menu_button_normal[] = { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 };
|
char menu_button_normal[] = { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 };
|
||||||
|
|
@ -23,28 +24,6 @@ char max_button_normal[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
|
||||||
char max_button_toggled[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f };
|
char max_button_toggled[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f };
|
||||||
char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
|
char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
|
||||||
|
|
||||||
static struct wlr_texture *
|
|
||||||
texture_from_pixmap(struct wlr_renderer *renderer, struct pixmap *pixmap)
|
|
||||||
{
|
|
||||||
if (!pixmap) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return wlr_texture_from_pixels(renderer, DRM_FORMAT_ARGB8888,
|
|
||||||
pixmap->width * 4, pixmap->width,
|
|
||||||
pixmap->height, pixmap->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_texture *
|
|
||||||
texture_from_builtin(struct wlr_renderer *renderer, const char *button)
|
|
||||||
{
|
|
||||||
struct pixmap pixmap = parse_xbm_builtin(button, 6);
|
|
||||||
struct wlr_texture *texture = texture_from_pixmap(renderer, &pixmap);
|
|
||||||
if (pixmap.data) {
|
|
||||||
free(pixmap.data);
|
|
||||||
}
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
xbm_path(const char *button)
|
xbm_path(const char *button)
|
||||||
{
|
{
|
||||||
|
|
@ -55,62 +34,59 @@ xbm_path(const char *button)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_button(struct wlr_renderer *renderer, const char *filename,
|
load_button(const char *filename, struct lab_data_buffer **buffer, char *button)
|
||||||
struct wlr_texture **texture, char *button)
|
|
||||||
{
|
{
|
||||||
if (*texture) {
|
struct pixmap pixmap = {0};
|
||||||
wlr_texture_destroy(*texture);
|
if (*buffer) {
|
||||||
*texture = NULL;
|
wlr_buffer_drop(&(*buffer)->base);
|
||||||
|
*buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read file into memory as it's easier to tokenzie that way */
|
/* Read file into memory as it's easier to tokenzie that way */
|
||||||
char *buffer = grab_file(xbm_path(filename));
|
char *token_buffer = grab_file(xbm_path(filename));
|
||||||
if (!buffer) {
|
if (token_buffer) {
|
||||||
goto out;
|
struct token *tokens = tokenize_xbm(token_buffer);
|
||||||
|
free(token_buffer);
|
||||||
|
pixmap = parse_xbm_tokens(tokens);
|
||||||
|
if (tokens) {
|
||||||
|
free(tokens);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!pixmap.data) {
|
||||||
|
pixmap = parse_xbm_builtin(button, 6);
|
||||||
}
|
}
|
||||||
struct token *tokens = tokenize_xbm(buffer);
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
struct pixmap pixmap = parse_xbm_tokens(tokens);
|
/* Create buffer with free_on_destroy being true */
|
||||||
*texture = texture_from_pixmap(renderer, &pixmap);
|
*buffer = buffer_create_wrap(pixmap.data, pixmap.width, pixmap.height,
|
||||||
if (tokens) {
|
pixmap.width * 4, true);
|
||||||
free(tokens);
|
|
||||||
}
|
|
||||||
if (pixmap.data) {
|
|
||||||
free(pixmap.data);
|
|
||||||
}
|
|
||||||
out:
|
|
||||||
if (!(*texture)) {
|
|
||||||
*texture = texture_from_builtin(renderer, button);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xbm_load(struct theme *theme, struct wlr_renderer *r)
|
xbm_load(struct theme *theme)
|
||||||
{
|
{
|
||||||
parse_set_color(theme->window_active_button_menu_unpressed_image_color);
|
parse_set_color(theme->window_active_button_menu_unpressed_image_color);
|
||||||
load_button(r, "menu.xbm", &theme->xbm_menu_active_unpressed,
|
load_button("menu.xbm", &theme->xbm_menu_active_unpressed,
|
||||||
menu_button_normal);
|
menu_button_normal);
|
||||||
parse_set_color(theme->window_active_button_iconify_unpressed_image_color);
|
parse_set_color(theme->window_active_button_iconify_unpressed_image_color);
|
||||||
load_button(r, "iconify.xbm", &theme->xbm_iconify_active_unpressed,
|
load_button("iconify.xbm", &theme->xbm_iconify_active_unpressed,
|
||||||
iconify_button_normal);
|
iconify_button_normal);
|
||||||
parse_set_color(theme->window_active_button_max_unpressed_image_color);
|
parse_set_color(theme->window_active_button_max_unpressed_image_color);
|
||||||
load_button(r, "max.xbm", &theme->xbm_maximize_active_unpressed,
|
load_button("max.xbm", &theme->xbm_maximize_active_unpressed,
|
||||||
max_button_normal);
|
max_button_normal);
|
||||||
parse_set_color(theme->window_active_button_close_unpressed_image_color);
|
parse_set_color(theme->window_active_button_close_unpressed_image_color);
|
||||||
load_button(r, "close.xbm", &theme->xbm_close_active_unpressed,
|
load_button("close.xbm", &theme->xbm_close_active_unpressed,
|
||||||
close_button_normal);
|
close_button_normal);
|
||||||
|
|
||||||
parse_set_color(theme->window_inactive_button_menu_unpressed_image_color);
|
parse_set_color(theme->window_inactive_button_menu_unpressed_image_color);
|
||||||
load_button(r, "menu.xbm", &theme->xbm_menu_inactive_unpressed,
|
load_button("menu.xbm", &theme->xbm_menu_inactive_unpressed,
|
||||||
menu_button_normal);
|
menu_button_normal);
|
||||||
parse_set_color(theme->window_inactive_button_iconify_unpressed_image_color);
|
parse_set_color(theme->window_inactive_button_iconify_unpressed_image_color);
|
||||||
load_button(r, "iconify.xbm", &theme->xbm_iconify_inactive_unpressed,
|
load_button("iconify.xbm", &theme->xbm_iconify_inactive_unpressed,
|
||||||
iconify_button_normal);
|
iconify_button_normal);
|
||||||
parse_set_color(theme->window_inactive_button_max_unpressed_image_color);
|
parse_set_color(theme->window_inactive_button_max_unpressed_image_color);
|
||||||
load_button(r, "max.xbm", &theme->xbm_maximize_inactive_unpressed,
|
load_button("max.xbm", &theme->xbm_maximize_inactive_unpressed,
|
||||||
max_button_normal);
|
max_button_normal);
|
||||||
parse_set_color(theme->window_inactive_button_close_unpressed_image_color);
|
parse_set_color(theme->window_inactive_button_close_unpressed_image_color);
|
||||||
load_button(r, "close.xbm", &theme->xbm_close_inactive_unpressed,
|
load_button("close.xbm", &theme->xbm_close_inactive_unpressed,
|
||||||
close_button_normal);
|
close_button_normal);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue