From aba242301d12eae30ae249cd78e40030086e8754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Thu, 4 Jul 2019 15:50:46 +0200 Subject: [PATCH 1/2] Use a gresource to store the css This makes build / test faster since one can skip install. It's also more obvious which file is being used. --- data/meson.build | 5 --- eek/eek-theme.c | 53 ++++++++++++++++++++++-- src/meson.build | 10 ++++- src/server-context-service.c | 6 +-- src/squeekboard.gresources.xml | 6 +++ data/themes/default.css => src/style.css | 0 6 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/squeekboard.gresources.xml rename data/themes/default.css => src/style.css (100%) diff --git a/data/meson.build b/data/meson.build index 2aa9afa6..4def2b8c 100644 --- a/data/meson.build +++ b/data/meson.build @@ -1,9 +1,4 @@ -install_data( - 'themes/default.css', - install_dir: pkgdatadir + '/themes', -) - install_data( 'keyboards/keyboards.xml', install_dir: pkgdatadir + '/keyboards/', diff --git a/eek/eek-theme.c b/eek/eek-theme.c index a80d0433..ad9fd134 100644 --- a/eek/eek-theme.c +++ b/eek/eek-theme.c @@ -43,6 +43,7 @@ * Copyright (C) 2003-2004 Dodji Seketeli. All Rights Reserved. */ +#define G_LOG_DOMAIN "eek-theme" #include #include @@ -256,13 +257,59 @@ parse_stylesheet (const char *filename, { enum CRStatus status; CRStyleSheet *stylesheet; + g_autoptr (GFileInputStream) stream = NULL; + g_autoptr (GFileInfo) info = NULL; + g_autoptr (GFile) file = NULL; + g_autofree guchar* contents = NULL; + goffset size; + gsize out = 0; + GError *err = NULL; if (filename == NULL) return NULL; - status = cr_om_parser_simply_parse_file ((const guchar *) filename, - CR_UTF_8, - &stylesheet); + g_debug ("Parsing %s", filename); + if (g_strcmp0 (filename, "resource://") > 0) { + file = g_file_new_for_uri (filename); + stream = g_file_read (file, NULL, &err); + if (!stream) { + g_warning ("Failed to open %s: %s", filename, err->message); + g_clear_error (&err); + return NULL; + } + + info = g_file_input_stream_query_info (stream, + G_FILE_ATTRIBUTE_STANDARD_SIZE, + NULL, + &err); + + if (!info) { + g_warning ("Failed to stat %s: %s", filename, err->message); + g_clear_error (&err); + return NULL; + } + + size = g_file_info_get_size (info); + contents = g_malloc0 (size); + if (!g_input_stream_read_all (G_INPUT_STREAM (stream), + contents, + size, + &out, + NULL, + &err)) { + g_warning ("Failed to read %s: %s", filename, err->message); + g_clear_error (&err); + return NULL; + } + status = cr_om_parser_simply_parse_buf (contents, + size, + CR_UTF_8, + &stylesheet); + } else { + status = cr_om_parser_simply_parse_file ((const guchar *) filename, + CR_UTF_8, + &stylesheet); + } if (status != CR_OK) { diff --git a/src/meson.build b/src/meson.build index 5f849ec8..1b304308 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,6 +4,13 @@ dbus_src = gnome.gdbus_codegen( join_paths(dbusdir, 'sm.puri.OSK0.xml') ) +squeekboard_resources = gnome.compile_resources( + 'squeekboard-resources', + 'squeekboard.gresources.xml', + + c_name: 'squeekboard', +) + sources = [ 'imservice.c', 'server-context-service.c', @@ -40,7 +47,8 @@ sources = [ '../eekboard/eekboard-context-service.c', '../eekboard/eekboard-context.c', '../eekboard/eekboard-service.c', -# '../eekboard/eekboard-xklutil.c', + # '../eekboard/eekboard-xklutil.c', + squeekboard_resources, wl_proto_sources, ] diff --git a/src/server-context-service.c b/src/server-context-service.c index 32e3b078..90371257 100644 --- a/src/server-context-service.c +++ b/src/server-context-service.c @@ -338,9 +338,9 @@ update_widget (ServerContextService *context) context->widget = NULL; } - theme_path = g_build_filename (THEMESDIR, "default.css", NULL); - - theme = eek_theme_new (theme_path, NULL, NULL); + theme = eek_theme_new ("resource:///sm/puri/squeekboard/style.css", + NULL, + NULL); g_free (theme_path); keyboard = eekboard_context_service_get_keyboard (EEKBOARD_CONTEXT_SERVICE(context)); diff --git a/src/squeekboard.gresources.xml b/src/squeekboard.gresources.xml new file mode 100644 index 00000000..3f17a884 --- /dev/null +++ b/src/squeekboard.gresources.xml @@ -0,0 +1,6 @@ + + + + style.css + + diff --git a/data/themes/default.css b/src/style.css similarity index 100% rename from data/themes/default.css rename to src/style.css From abf8f4daa85ddb774d1e00e5518554aa8a232cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Thu, 4 Jul 2019 16:20:36 +0200 Subject: [PATCH 2/2] eek-theme: Remove code for old croko versions These versions aren't even in Debian's oldstable release. --- eek/eek-theme.c | 85 ------------------------------------------------- 1 file changed, 85 deletions(-) diff --git a/eek/eek-theme.c b/eek/eek-theme.c index ad9fd134..91d91783 100644 --- a/eek/eek-theme.c +++ b/eek/eek-theme.c @@ -167,90 +167,6 @@ eek_theme_class_init (EekThemeClass *klass) } -/* This is a workaround for a bug in libcroco < 0.6.2 where - * function starting with 'r' (and 'u') are misparsed. We work - * around this by exploiting the fact that libcroco is incomformant - * with the CSS-spec and case sensitive and pre-convert all - * occurrences of rgba to RGBA. Then we make our own parsing - * code check for RGBA as well. - */ -#if LIBCROCO_VERSION_NUMBER < 602 -static gboolean -is_identifier_character (char c) -{ - /* Actual CSS rules allow for unicode > 0x00a1 and escaped - * characters, but we'll assume we won't do that in our stylesheets - * or at least not next to the string 'rgba'. - */ - return g_ascii_isalnum(c) || c == '-' || c == '_'; -} - -static void -convert_rgba_RGBA (char *buf) -{ - char *p; - - p = strstr (buf, "rgba"); - while (p) - { - /* Check if this looks like a complete token; this is to - * avoiding mangling, say, a selector '.rgba-entry' */ - if (!((p > buf && is_identifier_character (*(p - 1))) || - (is_identifier_character (*(p + 4))))) - memcpy(p, "RGBA", 4); - p += 4; - p = strstr (p, "rgba"); - } -} - -static CRStyleSheet * -parse_stylesheet (const char *filename, - GError **error) -{ - enum CRStatus status; - char *contents; - gsize length; - CRStyleSheet *stylesheet = NULL; - - if (filename == NULL) - return NULL; - - if (!g_file_get_contents (filename, &contents, &length, error)) - return NULL; - - convert_rgba_RGBA (contents); - - status = cr_om_parser_simply_parse_buf ((const guchar *) contents, - length, - CR_UTF_8, - &stylesheet); - g_free (contents); - - if (status != CR_OK) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Error parsing stylesheet '%s'; errcode:%d", filename, status); - return NULL; - } - - return stylesheet; -} - -CRDeclaration * -_eek_theme_parse_declaration_list (const char *str) -{ - char *copy = g_strdup (str); - CRDeclaration *result; - - convert_rgba_RGBA (copy); - - result = cr_declaration_parse_list_from_buf ((const guchar *)copy, - CR_UTF_8); - g_free (copy); - - return result; -} -#else /* LIBCROCO_VERSION_NUMBER >= 602 */ static CRStyleSheet * parse_stylesheet (const char *filename, GError **error) @@ -327,7 +243,6 @@ _eek_theme_parse_declaration_list (const char *str) return cr_declaration_parse_list_from_buf ((const guchar *)str, CR_UTF_8); } -#endif /* LIBCROCO_VERSION_NUMBER < 602 */ /* Just g_warning for now until we have something nicer to do */ static CRStyleSheet *