/* Draws a border with a specified line width */
void draw_cairo_border(cairo_t *cairo, struct wlr_fbox fbox, double line_width);
-struct lab_data_buffer;
+/* Converts X11 color name to ARGB32 (with alpha = 255) */
+bool lookup_named_color(const char *name, uint32_t *argb);
#endif /* LABWC_GRAPHIC_HELPERS_H */
#!/usr/bin/perl -w
-# Generates xpm-color-table.h from X11's rgb.txt
+# Generates xcolor-table.h from X11's rgb.txt
# Adapted from gdk-pixbuf (LGPL-2.0-or-later)
if (@ARGV != 1) {
- die "Usage: gen-color-table.pl rgb.txt > xpm-color-table.h\n";
+ die "Usage: gen-color-table.pl rgb.txt > xcolor-table.h\n";
}
open IN, '<', $ARGV[0] or die "Cannot open $ARGV[0]: $!\n";
print <<EOT;
/* SPDX-License-Identifier: LGPL-2.0-or-later */
-/* xpm-color-table.h: Generated by gen-color-table.pl from rgb.txt
+/* xcolor-table.h: Generated by gen-color-table.pl from rgb.txt
*
* Date: $date
*
// SPDX-License-Identifier: GPL-2.0-only
#include <cairo.h>
+#include <glib.h> /* g_ascii_strcasecmp */
#include <wlr/types/wlr_scene.h>
#include "common/graphic-helpers.h"
+#include "common/macros.h"
+#include "xcolor-table.h"
/* Draws a border with a specified line width */
void
cairo_set_source_rgba(cairo, c[0] / alpha, c[1] / alpha,
c[2] / alpha, alpha);
}
+
+static int
+compare_xcolor_entry(const void *a, const void *b)
+{
+ /* using ASCII version to avoid locale-dependent ordering */
+ return g_ascii_strcasecmp((const char *)a,
+ color_names + ((const struct xcolor_entry *)b)->name_offset);
+}
+
+bool
+lookup_named_color(const char *name, uint32_t *argb)
+{
+ struct xcolor_entry *found = bsearch(name, xcolors, ARRAY_SIZE(xcolors),
+ sizeof(struct xcolor_entry), compare_xcolor_entry);
+ if (!found) {
+ return false;
+ }
+
+ *argb = 0xFF000000u | ((uint32_t)found->red << 16)
+ | ((uint32_t)found->green << 8) | found->blue;
+ return true;
+}
/* SPDX-License-Identifier: LGPL-2.0-or-later */
-/* xpm-color-table.h: Generated by gen-color-table.pl from rgb.txt
+/* xcolor-table.h: Generated by gen-color-table.pl from rgb.txt
*
- * Date: Mon Sep 30 09:04:01 2024
+ * Date: Tue Apr 22 14:56:18 2025
*
* Do not edit.
*/
#include "buffer.h"
#include "common/buf.h"
-#include "common/macros.h"
+#include "common/graphic-helpers.h"
#include "common/mem.h"
#include "img/img-xpm.h"
-#include "xpm-color-table.h"
-
enum buf_op { op_header, op_cmap, op_body };
struct xpm_color {
return ((uint32_t)a << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
}
-static int
-compare_xcolor_entries(const void *a, const void *b)
-{
- return g_ascii_strcasecmp((const char *)a,
- color_names + ((const struct xcolor_entry *)b)->name_offset);
-}
-
-static bool
-lookup_named_color(const char *name, uint32_t *argb)
-{
- struct xcolor_entry *found = bsearch(name, xcolors, ARRAY_SIZE(xcolors),
- sizeof(struct xcolor_entry), compare_xcolor_entries);
- if (!found) {
- return false;
- }
-
- *argb = make_argb(0xFF, found->red, found->green, found->blue);
- return true;
-}
-
static bool
parse_color(const char *spec, uint32_t *argb)
{