11 Commits

Author SHA1 Message Date
927918ccc5 version bump 2023-11-04 14:33:44 +01:00
9f8e73b315 fixup: re-add flip_landscape() to wl_surface_enter (needed for landscape detection) 2023-11-04 14:33:30 +01:00
0e17680041 do not refresh on wl_surface_enter
there is no need to do so, because this event is followed by layer_surface_configure.
sway-HEAD(020a572) complains "A configure is scheduled for an uninitialized xdg_surface",
but it works anyway.

fix #50
2023-11-04 14:32:04 +01:00
3cccdab2e8 version bump 2023-11-03 20:53:14 +01:00
2d01b8963b fix hyprland crashes when creating a surface multiple times 2023-11-03 20:47:29 +01:00
c457d697aa optimize output iteration 2023-11-03 20:47:29 +01:00
5471e2ea0e resize keyboard only when entered to different output
the keyboard layout is saved even when hide/show (if output is same).
this is old behavior.
2023-11-03 20:47:29 +01:00
a126945401 handle screen resize and redraw in layer_surface_configure 2023-11-03 20:47:29 +01:00
aa9e8ab7ab avoid using "wl_output" literal 2023-10-29 16:42:19 +01:00
d6439afcb9 Make font selection scheme specific
Add the members font and font_descriptor to struct clr_scheme, so that
it is possible to specify a font for each scheme.

During initialization create the font descriptors for each scheme.

Instead of initially setting the font descriptor when setting up the
buffer, set the font descriptor when drawing the text.

Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2023-10-29 13:07:57 +01:00
6e52be343d Add support for multiple schemes
Allow to use more than two color schemes.

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2023-10-13 21:20:18 +02:00
7 changed files with 77 additions and 51 deletions

View File

@ -1,24 +1,28 @@
#ifndef config_def_h_INCLUDED
#define config_def_h_INCLUDED
static const char *default_font = "Sans 14";
#define DEFAULT_FONT "Sans 14"
static const int transparency = 255;
struct clr_scheme scheme = {
struct clr_scheme schemes[] = {
{
/* colors */
.bg = {.bgra = {15, 15, 15, transparency}},
.fg = {.bgra = {45, 45, 45, transparency}},
.high = {.bgra = {100, 100, 100, transparency}},
.swipe = {.bgra = {100, 255, 100, 64}},
.text = {.color = UINT32_MAX},
};
struct clr_scheme scheme1 = {
.font = DEFAULT_FONT,
},
{
/* colors */
.bg = {.bgra = {15, 15, 15, transparency}},
.fg = {.bgra = {32, 32, 32, transparency}},
.high = {.bgra = {100, 100, 100, transparency}},
.swipe = {.bgra = {100, 255, 100, 64}},
.text = {.color = UINT32_MAX},
.font = DEFAULT_FONT,
}
};
/* layers is an ordered list of layouts, used to cycle through */

View File

@ -1,4 +1,4 @@
VERSION = 0.14.1
VERSION = 0.14.3
CFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=700
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man

7
drw.c
View File

@ -30,11 +30,14 @@ drwsurf_flip(struct drwsurf *ds)
void
drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
uint32_t w, uint32_t h, uint32_t b, const char *label)
uint32_t w, uint32_t h, uint32_t b, const char *label,
PangoFontDescription *font_description)
{
cairo_save(d->cairo);
pango_layout_set_font_description(d->layout, font_description);
cairo_set_source_rgba(
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
@ -134,8 +137,6 @@ setup_buffer(struct drwsurf *drwsurf)
cairo_scale(drwsurf->cairo, drwsurf->scale, drwsurf->scale);
cairo_set_antialias(drwsurf->cairo, CAIRO_ANTIALIAS_NONE);
drwsurf->layout = pango_cairo_create_layout(drwsurf->cairo);
pango_layout_set_font_description(drwsurf->layout,
drwsurf->ctx->font_description);
pango_layout_set_auto_dir(drwsurf->layout, false);
cairo_save(drwsurf->cairo);

4
drw.h
View File

@ -6,7 +6,6 @@
struct drw {
struct wl_shm *shm;
PangoFontDescription *font_description;
};
struct drwsurf {
uint32_t width, height, size;
@ -41,7 +40,8 @@ void drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
void drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
uint32_t w, uint32_t h, uint32_t b, const char *label);
uint32_t w, uint32_t h, uint32_t b, const char *label,
PangoFontDescription *font_description);
uint32_t setup_buffer(struct drwsurf *drwsurf);

View File

@ -555,8 +555,7 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
if (kb->debug)
fprintf(stderr, "Draw key +%d+%d %dx%d -> %s\n", k->x, k->y, k->w, k->h,
label);
struct clr_scheme *scheme =
(k->scheme == 0) ? &(kb->scheme) : &(kb->scheme1);
struct clr_scheme *scheme = &kb->schemes[k->scheme];
switch (type) {
case None:
@ -575,7 +574,7 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
}
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
KBD_KEY_BORDER, label);
KBD_KEY_BORDER, label, scheme->font_description);
wl_surface_damage(kb->surf->surf, k->x, k->y, k->w, k->h);
if (type == Press || type == Unpress) {
@ -586,12 +585,13 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
kb->last_popup_w = k->w;
kb->last_popup_h = k->h;
drw_fill_rectangle(kb->popup_surf, kb->scheme.bg, k->x,
drw_fill_rectangle(kb->popup_surf, scheme->bg, k->x,
kb->last_popup_y, k->w, k->h);
draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h,
KBD_KEY_BORDER, scheme->high);
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y,
k->w, k->h, KBD_KEY_BORDER, label);
k->w, k->h, KBD_KEY_BORDER, label,
scheme->font_description);
wl_surface_damage(kb->popup_surf->surf, k->x, kb->last_popup_y, k->w,
k->h);
}
@ -605,7 +605,7 @@ kbd_draw_layout(struct kbd *kb)
if (kb->debug)
fprintf(stderr, "Draw layout\n");
drw_fill_rectangle(d, kb->scheme.bg, 0, 0, kb->w, kb->h);
drw_fill_rectangle(d, kb->schemes[0].bg, 0, 0, kb->w, kb->h);
while (next_key->type != Last) {
if ((next_key->type == Pad) || (next_key->type == EndRow)) {

View File

@ -54,6 +54,8 @@ struct clr_scheme {
Color high;
Color swipe;
Color text;
char *font;
PangoFontDescription *font_description;
};
struct key {
@ -90,8 +92,7 @@ struct kbd {
bool debug;
struct layout *layout;
struct clr_scheme scheme;
struct clr_scheme scheme1;
struct clr_scheme *schemes;
bool print;
bool print_intersect;

86
main.c
View File

@ -24,6 +24,9 @@
fprintf(stderr, __VA_ARGS__); \
exit(1)
/* array size */
#define countof(x) (sizeof(x) / sizeof(*x))
/* client state */
static const char *namespace = "wlroots";
static struct wl_display *display;
@ -339,15 +342,18 @@ void
wl_surface_enter(void *data, struct wl_surface *wl_surface,
struct wl_output *wl_output)
{
for (int i = 0; i < WL_OUTPUTS_LIMIT; i += 1) {
struct Output *old_output = current_output;
for (int i = 0; i < wl_outputs_size; i += 1) {
if (wl_outputs[i].data == wl_output) {
current_output = &wl_outputs[i];
break;
}
}
if (current_output == old_output) {
return;
}
keyboard.preferred_scale = current_output->scale;
flip_landscape();
}
@ -421,7 +427,7 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name,
wl_registry_bind(registry, name, &wl_compositor_interface, 3);
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
draw_ctx.shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
} else if (strcmp(interface, "wl_output") == 0) {
} else if (strcmp(interface, wl_output_interface.name) == 0) {
if (wl_outputs_size < WL_OUTPUTS_LIMIT) {
struct Output *output = &wl_outputs[wl_outputs_size];
output->data =
@ -457,10 +463,10 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name,
void
handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
{
for (int i = 0; i < WL_OUTPUTS_LIMIT; i += 1) {
for (int i = 0; i < wl_outputs_size; i += 1) {
if (wl_outputs[i].name == name) {
wl_output_destroy(wl_outputs[i].data);
for (; i < WL_OUTPUTS_LIMIT - 1; i += 1) {
for (; i < wl_outputs_size - 1; i += 1) {
wl_outputs[i] = wl_outputs[i + 1];
}
wl_outputs_size -= 1;
@ -485,9 +491,6 @@ static void
xdg_popup_configure(void *data, struct xdg_popup *xdg_popup, int32_t x,
int32_t y, int32_t width, int32_t height)
{
kbd_resize(&keyboard, layouts, NumLayouts);
drwsurf_flip(&draw_surf);
}
static void
@ -599,9 +602,13 @@ layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
}
wl_surface_commit(popup_draw_surf.surf);
}
zwlr_layer_surface_v1_ack_configure(surface, serial);
zwlr_layer_surface_v1_ack_configure(surface, serial);
kbd_resize(&keyboard, layouts, NumLayouts);
drwsurf_flip(&draw_surf);
} else {
zwlr_layer_surface_v1_ack_configure(surface, serial);
}
}
void
@ -669,6 +676,15 @@ hide()
return;
}
if(wfs_draw_surf) {
wp_fractional_scale_v1_destroy(wfs_draw_surf);
wfs_draw_surf = NULL;
}
if(draw_surf_viewport) {
wp_viewport_destroy(draw_surf_viewport);
draw_surf_viewport = NULL;
}
zwlr_layer_surface_v1_destroy(layer_surface);
wl_surface_destroy(draw_surf.surf);
layer_surface = NULL;
@ -747,7 +763,7 @@ main(int argc, char **argv)
{
/* parse command line arguments */
char *layer_names_list = NULL, *landscape_layer_names_list = NULL;
const char *fc_font_pattern = NULL;
char *fc_font_pattern = NULL;
height = normal_height = KBD_PIXEL_HEIGHT;
landscape_height = KBD_PIXEL_LANDSCAPE_HEIGHT;
@ -764,9 +780,8 @@ main(int argc, char **argv)
/* keyboard settings */
keyboard.layers = (enum layout_id *)&layers;
keyboard.landscape_layers = (enum layout_id *)&landscape_layers;
keyboard.scheme = scheme;
keyboard.schemes = schemes;
keyboard.layer_index = 0;
keyboard.scheme1 = scheme1;
keyboard.preferred_scale = 1;
keyboard.preferred_fractional_scale = 0;
@ -803,7 +818,7 @@ main(int argc, char **argv)
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme.bg.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[0].bg.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-alpha")) ||
(!strcmp(argv[i], "--alpha"))) {
if (i >= argc - 1) {
@ -817,56 +832,56 @@ main(int argc, char **argv)
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme.fg.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[0].fg.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-fg-sp")) ||
(!strcmp(argv[i], "--fg-sp"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme1.fg.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[1].fg.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-press")) ||
(!strcmp(argv[i], "--press"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme.high.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[0].high.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-press-sp")) ||
(!strcmp(argv[i], "--press-sp"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme1.high.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[1].high.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-swipe")) ||
(!strcmp(argv[i], "--swipe"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme.swipe.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[0].swipe.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-swipe-sp")) ||
(!strcmp(argv[i], "--swipe-sp"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme1.swipe.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[1].swipe.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-text")) ||
(!strcmp(argv[i], "--text"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme.text.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[0].text.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-text-sp")) ||
(!strcmp(argv[i], "--text-sp"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.scheme1.text.bgra, argv[++i]);
set_kbd_colors(keyboard.schemes[1].text.bgra, argv[++i]);
} else if (!strcmp(argv[i], "-H")) {
if (i >= argc - 1) {
usage(argv[0]);
@ -906,16 +921,17 @@ main(int argc, char **argv)
}
if (alpha_defined) {
keyboard.scheme.bg.bgra[3] = alpha;
keyboard.scheme.fg.bgra[3] = alpha;
keyboard.scheme.high.bgra[3] = alpha;
keyboard.scheme1.bg.bgra[3] = alpha;
keyboard.scheme1.fg.bgra[3] = alpha;
keyboard.scheme1.high.bgra[3] = alpha;
keyboard.schemes[0].bg.bgra[3] = alpha;
keyboard.schemes[0].fg.bgra[3] = alpha;
keyboard.schemes[0].high.bgra[3] = alpha;
keyboard.schemes[1].bg.bgra[3] = alpha;
keyboard.schemes[1].fg.bgra[3] = alpha;
keyboard.schemes[1].high.bgra[3] = alpha;
}
if (!fc_font_pattern) {
fc_font_pattern = default_font;
if (fc_font_pattern) {
for (i = 0; i < countof(schemes); i++)
schemes[i].font = fc_font_pattern;
}
display = wl_display_connect(NULL);
@ -960,8 +976,10 @@ main(int argc, char **argv)
kbd_init(&keyboard, (struct layout *)&layouts, layer_names_list,
landscape_layer_names_list);
draw_ctx.font_description =
pango_font_description_from_string(fc_font_pattern);
for (i = 0; i < countof(schemes); i++) {
schemes[i].font_description =
pango_font_description_from_string(schemes[i].font);
}
if (!hidden)
show();
@ -1015,8 +1033,10 @@ main(int argc, char **argv)
}
}
if (fc_font_pattern != default_font) {
if (fc_font_pattern) {
free((void *)fc_font_pattern);
for (i = 0; i < countof(schemes); i++)
schemes[i].font = NULL;
}
return 0;