From 9b7cfb7c8d8d337554ad7c5995ce75fac52c7d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= Date: Sun, 17 Sep 2017 19:28:31 +0200 Subject: Move utf8_locale to its own file So that we can easily use it from tests. --- src/Makefile.am | 4 +++- src/data.h | 1 - src/editor.h | 7 ++++--- src/globals.c | 4 ++-- src/main.c | 4 ++-- src/manage.c | 4 ++-- src/ratpoison.h | 1 + src/utf8.c | 3 +++ src/utf8.h | 6 ++++++ 9 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 src/utf8.c create mode 100644 src/utf8.h diff --git a/src/Makefile.am b/src/Makefile.am index 7f4a673..beb2278 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,6 +69,8 @@ ratpoison_SOURCES = actions.c \ screen.c \ split.c \ split.h \ + utf8.c \ + utf8.h \ window.c \ window.h @@ -83,6 +85,6 @@ check_PROGRAMS = format_test format_test_SOURCES = actions.c bar.c completions.c editor.c events.c format.c \ frame.c globals.c group.c history.c hook.c input.c \ linkedlist.c manage.c number.c sbuf.c screen.c split.c \ - window.c xrandr.c + window.c xrandr.c utf8.c utf8.h format_test_CPPFLAGS = $(AM_CPPFLAGS) -DRUN_FORMAT_TEST format_test_LDADD = $(ratpoison_LDADD) diff --git a/src/data.h b/src/data.h index 6816422..f959ab9 100644 --- a/src/data.h +++ b/src/data.h @@ -262,7 +262,6 @@ struct rp_defaults XFontSet font; char *font_string; - int utf8_locale; char *fgcolor_string; char *bgcolor_string; diff --git a/src/editor.h b/src/editor.h index 445cd82..be79b6c 100644 --- a/src/editor.h +++ b/src/editor.h @@ -21,6 +21,7 @@ #ifndef _RATPOISON_EDITOR_H #define _RATPOISON_EDITOR_H 1 +#include "utf8.h" typedef enum edit_status { @@ -34,9 +35,9 @@ typedef enum edit_status } edit_status; /* UTF-8 handling macros */ -#define RP_IS_UTF8_CHAR(c) (defaults.utf8_locale && (c) & 0xC0) -#define RP_IS_UTF8_START(c) (defaults.utf8_locale && ((c) & 0xC0) == 0xC0) -#define RP_IS_UTF8_CONT(c) (defaults.utf8_locale && ((c) & 0xC0) == 0x80) +#define RP_IS_UTF8_CHAR(c) (utf8_locale && (c) & 0xC0) +#define RP_IS_UTF8_START(c) (utf8_locale && ((c) & 0xC0) == 0xC0) +#define RP_IS_UTF8_CONT(c) (utf8_locale && ((c) & 0xC0) == 0x80) /* Input line functions */ rp_input_line *input_line_new (char *prompt, char *preinput, int history_id, enum completion_styles style, completion_fn fn); diff --git a/src/globals.c b/src/globals.c index 69f86bd..5f4350d 100644 --- a/src/globals.c +++ b/src/globals.c @@ -316,7 +316,7 @@ rp_draw_string (rp_screen *s, Drawable d, int style, int x, int y, return; } - if (defaults.utf8_locale) + if (utf8_locale) { XftDrawStringUtf8 (draw, style == STYLE_NORMAL ? &s->xft_fg_color : &s->xft_bg_color, s->xft_font, x, y, @@ -349,7 +349,7 @@ rp_text_width (rp_screen *s, char *string, int count) if (s->xft_font) { XGlyphInfo extents; - if (defaults.utf8_locale) + if (utf8_locale) XftTextExtentsUtf8 (dpy, s->xft_font, (FcChar8*) string, count, &extents); else XftTextExtents8 (dpy, s->xft_font, (FcChar8*) string, count, &extents); diff --git a/src/main.c b/src/main.c index a287258..e1875fa 100644 --- a/src/main.c +++ b/src/main.c @@ -268,10 +268,10 @@ init_defaults (void) #endif #ifdef HAVE_LANGINFO_CODESET - defaults.utf8_locale = !strcmp (nl_langinfo (CODESET), "UTF-8"); + utf8_locale = !strcmp (nl_langinfo (CODESET), "UTF-8"); #endif PRINT_DEBUG (("UTF-8 locale detected: %s\n", - defaults.utf8_locale ? "yes" : "no")); + utf8_locale ? "yes" : "no")); defaults.fgcolor_string = xstrdup ("black"); defaults.bgcolor_string = xstrdup ("white"); diff --git a/src/manage.c b/src/manage.c index 073235f..1440fab 100644 --- a/src/manage.c +++ b/src/manage.c @@ -184,7 +184,7 @@ get_wmname (Window w) /* If current encoding is UTF-8, try to use the window's _NET_WM_NAME ewmh property */ - if (defaults.utf8_locale) + if (utf8_locale) { Atom type = None; unsigned long nitems, bytes_after; @@ -231,7 +231,7 @@ get_wmname (Window w) _NET_WM_NAME don't bother making their WM_NAME available as UTF8_STRING (but only as either STRING or COMPOUND_TEXT). Let's try anyway. */ - if (defaults.utf8_locale && text_prop.encoding == xa_utf8_string) + if (utf8_locale && text_prop.encoding == xa_utf8_string) { ret = Xutf8TextPropertyToTextList (dpy, &text_prop, &cl, &n); PRINT_DEBUG (("Xutf8TextPropertyToTextList: %s\n", diff --git a/src/ratpoison.h b/src/ratpoison.h index 06cdfce..fc12d7d 100644 --- a/src/ratpoison.h +++ b/src/ratpoison.h @@ -91,6 +91,7 @@ do { \ #include "hook.h" #include "xrandr.h" #include "format.h" +#include "utf8.h" void set_extents_of_fontset (XFontSet font); XFontSet load_query_font_set (Display *disp, const char *fontset_name); diff --git a/src/utf8.c b/src/utf8.c new file mode 100644 index 0000000..bb53d57 --- /dev/null +++ b/src/utf8.c @@ -0,0 +1,3 @@ +#include "utf8.h" + +int utf8_locale; diff --git a/src/utf8.h b/src/utf8.h new file mode 100644 index 0000000..10cec7f --- /dev/null +++ b/src/utf8.h @@ -0,0 +1,6 @@ +#ifndef UTF8_H +#define UTF8_H + +extern int utf8_locale; + +#endif -- cgit v1.2.3