diff options
| author | Jari Vetoniemi <mailroxas@gmail.com> | 2015-01-16 02:08:18 +0200 | 
|---|---|---|
| committer | Jari Vetoniemi <mailroxas@gmail.com> | 2015-01-16 02:08:18 +0200 | 
| commit | a54bcf694ad152ba0a5c1c3f2de6bc9c82bba02f (patch) | |
| tree | 035ff1c1db386e48135705b5c663060248b3fa66 /lib | |
| parent | 20189fb8d26e422bf17dda4264e84ed7b1b2a340 (diff) | |
| parent | ada6edc175eb89d318e55204368e2ba5dad07b1b (diff) | |
| download | bemenu-a54bcf694ad152ba0a5c1c3f2de6bc9c82bba02f.tar.gz bemenu-a54bcf694ad152ba0a5c1c3f2de6bc9c82bba02f.tar.bz2 bemenu-a54bcf694ad152ba0a5c1c3f2de6bc9c82bba02f.zip  | |
Merge branch 'pango-wip'
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bemenu.h | 53 | ||||
| -rw-r--r-- | lib/internal.h | 30 | ||||
| -rw-r--r-- | lib/menu.c | 71 | ||||
| -rw-r--r-- | lib/renderers/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | lib/renderers/cairo.h | 171 | ||||
| -rw-r--r-- | lib/renderers/wayland/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | lib/renderers/wayland/wayland.c | 7 | ||||
| -rw-r--r-- | lib/renderers/wayland/wayland.h | 4 | ||||
| -rw-r--r-- | lib/renderers/wayland/window.c | 44 | ||||
| -rw-r--r-- | lib/renderers/x11/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | lib/renderers/x11/window.c | 224 | ||||
| -rw-r--r-- | lib/renderers/x11/x11.c | 235 | ||||
| -rw-r--r-- | lib/renderers/x11/x11.h | 56 | ||||
| -rw-r--r-- | lib/renderers/x11/xkb_unicode.c | 857 | ||||
| -rw-r--r-- | lib/renderers/x11/xkb_unicode.h | 8 | 
15 files changed, 1693 insertions, 86 deletions
diff --git a/lib/bemenu.h b/lib/bemenu.h index 33ff20c..e968d26 100644 --- a/lib/bemenu.h +++ b/lib/bemenu.h @@ -389,6 +389,57 @@ bool bm_menu_set_color(struct bm_menu *menu, enum bm_color color, const char *he   */  const char* bm_menu_get_color(const struct bm_menu *menu, enum bm_color color); +/** + * Display menu at bottom of the screen. + * This may be no-op on some renderers (curses, wayland) + * + * @param menu bm_menu instance to set bottom mode for. + * @param bottom true for bottom mode, false for top mode. + */ +void bm_menu_set_bottom(struct bm_menu *menu, bool bottom); + +/** + * Is menu being displayed at bottom of the screen? + * + * @param menu bm_menu instance where to get bottom mode from. + * @return true if bottom mode, false otherwise. + */ +bool bm_menu_get_bottom(struct bm_menu *menu); + +/** + * Display menu at monitor index. + * Indices start from 1, pass 0 for active monitor (default). + * If index is more than amount of monitors, the monitor with highest index will be selected. + * + * @param menu bm_menu instance to set monitor for. + * @param monitor Monitor index starting from 1. + */ +void bm_menu_set_monitor(struct bm_menu *menu, uint32_t monitor); + +/** + * Return index for current monitor. + * + * @param menu bm_menu instance where to get current monitor from. + * @return Monitor index starting from 1. + */ +uint32_t bm_menu_get_monitor(struct bm_menu *menu); + +/** + * Tell renderer to grab keyboard. + * This only works with x11 renderer. + * + * @param menu bm_menu instance to set grab for. + * @param grab true for grab, false for ungrab. + */ +void bm_menu_grab_keyboard(struct bm_menu *menu, bool grab); + +/** + * Is keyboard grabbed for bm_menu? + * + * @param menu bm_menu instance where to check grab status from. + * @return true if grabbed, false if not. + */ +bool bm_menu_is_keyboard_grabbed(struct bm_menu *menu);  /**  @} Properties */ @@ -531,6 +582,8 @@ struct bm_item** bm_menu_get_filtered_items(const struct bm_menu *menu, uint32_t  /**   * Render bm_menu instance using chosen renderer.   * + * This function may block on **wayland** and **x11** renderer. + *   * @param menu bm_menu instance to be rendered.   */  void bm_menu_render(const struct bm_menu *menu); diff --git a/lib/internal.h b/lib/internal.h index e22c546..290a2f7 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -72,6 +72,21 @@ struct render_api {      void (*render)(const struct bm_menu *menu);      /** +     * Set menu to appear from bottom of the screen. +     */ +    void (*set_bottom)(const struct bm_menu *menu, bool bottom); + +    /** +     * Set monitor indeax where menu will appear +     */ +    void (*set_monitor)(const struct bm_menu *menu, uint32_t monitor); + +    /** +     * Grab/Ungrab keyboard +     */ +    void (*grab_keyboard)(const struct bm_menu *menu, bool grab); + +    /**       * Version of the plugin.       * Should match BM_PLUGIN_VERSION or failure.       */ @@ -254,6 +269,11 @@ struct bm_menu {      uint32_t lines;      /** +     * Current monitor. +     */ +    uint32_t monitor; + +    /**       * Current filtering method in menu instance.       */      enum bm_filter_mode filter_mode; @@ -262,6 +282,16 @@ struct bm_menu {       * Should selection be wrapped?       */      bool wrap; + +    /** +     * Is menu shown from bottom? +     */ +    bool bottom; + +    /** +     * Is menu grabbed? +     */ +    bool grabbed;  };  /* library.c */ @@ -248,14 +248,16 @@ bm_menu_set_font(struct bm_menu *menu, const char *font, uint32_t size)      return true;  } -const char* bm_menu_get_font(const struct bm_menu *menu, uint32_t *out_size) +const char* +bm_menu_get_font(const struct bm_menu *menu, uint32_t *out_size)  {      assert(menu);      if (out_size) *out_size = menu->font.size;      return menu->font.name;  } -bool bm_menu_set_color(struct bm_menu *menu, enum bm_color color, const char *hex) +bool +bm_menu_set_color(struct bm_menu *menu, enum bm_color color, const char *hex)  {      assert(menu); @@ -277,12 +279,75 @@ bool bm_menu_set_color(struct bm_menu *menu, enum bm_color color, const char *he      return true;  } -const char* bm_menu_get_color(const struct bm_menu *menu, enum bm_color color) +const +char* bm_menu_get_color(const struct bm_menu *menu, enum bm_color color)  {      assert(menu);      return menu->colors[color].hex;  } +void +bm_menu_set_bottom(struct bm_menu *menu, bool bottom) +{ +    assert(menu); + +    if (menu->bottom == bottom) +        return; + +    menu->bottom = bottom; + +    if (menu->renderer->api.set_bottom) +        menu->renderer->api.set_bottom(menu, bottom); +} + +bool +bm_menu_get_bottom(struct bm_menu *menu) +{ +    assert(menu); +    return menu->bottom; +} + +void +bm_menu_set_monitor(struct bm_menu *menu, uint32_t monitor) +{ +    assert(menu); + +    if (menu->monitor == monitor) +        return; + +    menu->monitor = monitor; + +    if (menu->renderer->api.set_monitor) +        menu->renderer->api.set_monitor(menu, monitor); +} + +uint32_t +bm_menu_get_monitor(struct bm_menu *menu) +{ +    assert(menu); +    return menu->monitor; +} + +void +bm_menu_grab_keyboard(struct bm_menu *menu, bool grab) +{ +    assert(menu); + +    if (menu->grabbed == grab) +        return; + +    menu->grabbed = grab; + +    if (menu->renderer->api.grab_keyboard) +        menu->renderer->api.grab_keyboard(menu, grab); +} + +bool +bm_menu_is_keyboard_grabbed(struct bm_menu *menu) +{ +    return menu->grabbed; +} +  bool  bm_menu_add_items_at(struct bm_menu *menu, struct bm_item *item, uint32_t index)  { diff --git a/lib/renderers/CMakeLists.txt b/lib/renderers/CMakeLists.txt index 35a0edd..ef85317 100644 --- a/lib/renderers/CMakeLists.txt +++ b/lib/renderers/CMakeLists.txt @@ -1,8 +1,11 @@  SET(RENDERERS      "curses"      "wayland" +    "x11"  ) +ADD_DEFINITIONS(-DPANGO_DISABLE_DEPRECATED) +  SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/renderers)  INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index d9ba093..3fc1c90 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -4,19 +4,14 @@  #include "internal.h"  #include <string.h>  #include <assert.h> +#include <math.h>  #include <cairo/cairo.h> - -#ifndef MAX -#  define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - -#ifndef MIN -#  define MIN(a,b) (((a)<(b))?(a):(b)) -#endif +#include <pango/pangocairo.h>  struct cairo {      cairo_t *cr;      cairo_surface_t *surface; +    PangoContext *pango;  };  struct cairo_color { @@ -26,7 +21,7 @@ struct cairo_color {  struct cairo_paint {      struct cairo_color fg;      struct cairo_color bg; -    cairo_font_extents_t fe; +    const char *font;      struct box {          int32_t lx, rx; // left/right offset (pos.x - lx, box.w + rx) @@ -40,25 +35,62 @@ struct cairo_paint {  };  struct cairo_result { -    cairo_text_extents_t te; +    uint32_t x_advance; +    uint32_t height; +}; + +struct cairo_paint_result { +    uint32_t displayed; +    uint32_t height;  };  static size_t blen = 0;  static char *buffer = NULL; +__attribute__((unused)) static bool +bm_cairo_create_for_surface(struct cairo *cairo, cairo_surface_t *surface) +{ +    assert(cairo && surface); +    if (!(cairo->cr = cairo_create(surface))) +        goto fail; + +    if (!(cairo->pango = pango_cairo_create_context(cairo->cr))) +        goto fail; + +    cairo->surface = surface; +    return true; + +fail: +    if (cairo->cr) +      cairo_destroy(cairo->cr); +    return false; +} +  __attribute__((unused)) static void -bm_cairo_get_font_extents(struct cairo *cairo, const struct bm_font *font, cairo_font_extents_t *fe) +bm_cairo_destroy(struct cairo *cairo)  { -    assert(cairo && font && fe); -    cairo_select_font_face(cairo->cr, font->name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); -    cairo_set_font_size(cairo->cr, font->size); -    cairo_font_extents(cairo->cr, fe); +    if (cairo->cr) +        cairo_destroy(cairo->cr); +    if (cairo->surface) +        cairo_surface_destroy(cairo->surface);  } -__attribute__((unused)) BM_LOG_ATTR(3, 4) static bool -bm_cairo_get_text_extents(struct cairo *cairo, struct cairo_result *result, const char *fmt, ...) +__attribute__((unused)) static PangoLayout* +bm_pango_get_layout(struct cairo *cairo, struct cairo_paint *paint, const char *buffer)  { -    assert(cairo && result && fmt); +    PangoLayout *layout = pango_cairo_create_layout(cairo->cr); +    pango_layout_set_text(layout, buffer, -1); +    PangoFontDescription *desc = pango_font_description_from_string(paint->font); +    pango_layout_set_font_description(layout, desc); +    pango_layout_set_single_paragraph_mode(layout, 1); +    pango_font_description_free(desc); +    return layout; +} + +__attribute__((unused)) BM_LOG_ATTR(4, 5) static bool +bm_pango_get_text_extents(struct cairo *cairo, struct cairo_paint *paint, struct cairo_result *result, const char *fmt, ...) +{ +    assert(cairo && paint && result && fmt);      memset(result, 0, sizeof(struct cairo_result));      va_list args; @@ -69,7 +101,13 @@ bm_cairo_get_text_extents(struct cairo *cairo, struct cairo_result *result, cons      if (!ret)          return false; -    cairo_text_extents(cairo->cr, buffer, &result->te); +    PangoRectangle rect; +    PangoLayout *layout = bm_pango_get_layout(cairo, paint, buffer); +    pango_layout_get_pixel_extents(layout, &rect, NULL); +    g_object_unref(layout); + +    result->x_advance = rect.x + rect.width; +    result->height = rect.height;      return true;  } @@ -87,22 +125,29 @@ bm_cairo_draw_line(struct cairo *cairo, struct cairo_paint *paint, struct cairo_      if (!ret)          return false; -    cairo_text_extents_t te; -    cairo_text_extents(cairo->cr, buffer, &te); +    PangoLayout *layout = bm_pango_get_layout(cairo, paint, buffer); +    pango_cairo_update_layout(cairo->cr, layout); + +    int width, height; +    pango_layout_get_pixel_size(layout, &width, &height); +    int base =  pango_layout_get_baseline(layout) / PANGO_SCALE; +    int yoff = height - base;      cairo_set_source_rgba(cairo->cr, paint->bg.r, paint->bg.b, paint->bg.g, paint->bg.a);      cairo_rectangle(cairo->cr,              paint->pos.x - paint->box.lx, paint->pos.y - paint->box.ty, -            (paint->box.w > 0 ? paint->box.w : te.width) + paint->box.rx + paint->box.lx, -            (paint->box.h > 0 ? paint->box.h : paint->fe.height) + paint->box.by + paint->box.ty); +            (paint->box.w > 0 ? paint->box.w : width) + paint->box.rx + paint->box.lx, +            (paint->box.h > 0 ? paint->box.h : height) + paint->box.by + paint->box.ty);      cairo_fill(cairo->cr);      cairo_set_source_rgba(cairo->cr, paint->fg.r, paint->fg.b, paint->fg.g, paint->fg.a); -    cairo_move_to(cairo->cr, paint->box.lx + paint->pos.x, paint->pos.y + paint->fe.descent + paint->fe.height * 0.5 + paint->box.ty); -    cairo_show_text(cairo->cr, buffer); +    cairo_move_to(cairo->cr, paint->box.lx + paint->pos.x, paint->pos.y - yoff + paint->box.ty); +    pango_cairo_show_layout(cairo->cr, layout); -    te.x_advance += paint->box.rx; -    memcpy(&result->te, &te, sizeof(te)); +    g_object_unref(layout); + +    result->x_advance = width + paint->box.rx; +    result->height = height + paint->box.by;      return true;  } @@ -116,10 +161,16 @@ bm_cairo_color_from_menu_color(const struct bm_menu *menu, enum bm_color color,      c->a = 1.0f;  } -__attribute__((unused)) static uint32_t -bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struct bm_menu *menu) +__attribute__((unused)) static void +bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t max_height, const struct bm_menu *menu, struct cairo_paint_result *out_result)  { -    assert(cairo && menu); +    assert(cairo && menu && out_result); + +    memset(out_result, 0, sizeof(struct cairo_paint_result)); +    out_result->displayed = 1; + +    char font[128]; +    snprintf(font, sizeof(font), "%s %d", menu->font.name, menu->font.size);      struct cairo_color c;      bm_cairo_color_from_menu_color(menu, BM_COLOR_BG, &c); @@ -129,37 +180,50 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struc      struct cairo_paint paint;      memset(&paint, 0, sizeof(paint)); -    bm_cairo_get_font_extents(cairo, &menu->font, &paint.fe); +    paint.font = font;      struct cairo_result result;      memset(&result, 0, sizeof(result)); +    uint32_t title_x = 0;      if (menu->title) {          bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_FG, &paint.fg);          bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_BG, &paint.bg); -        paint.pos = (struct pos){ result.te.x_advance, 2 }; +        paint.pos = (struct pos){ result.x_advance, 2 };          paint.box = (struct box){ 4, 8, 2, 2, 0, 0 };          bm_cairo_draw_line(cairo, &paint, &result, "%s", menu->title); +        title_x = result.x_advance;      }      bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_FG, &paint.fg);      bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg); -    paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.te.x_advance, 2 }; +    paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.x_advance, 2 };      paint.box = (struct box){ (menu->title ? 2 : 4), 0, 2, 2, width - paint.pos.x, 0 };      bm_cairo_draw_line(cairo, &paint, &result, "%s", (menu->filter ? menu->filter : "")); +    out_result->height = result.height; + +    uint32_t count; +    struct bm_item **items = bm_menu_get_filtered_items(menu, &count); +    uint32_t lines = (menu->lines > 0 ? menu->lines : 1); -    uint32_t displayed = 1; -    uint32_t lines = MAX(height / (paint.fe.height + 4), 1);      if (lines > 1) { +        /* vertical mode */ + +        uint32_t spacing = 0; // 0 == variable width spacing +        if (lines > max_height / result.height) { +            /* there is more lines than screen can fit, enter fixed spacing mode */ +            lines = max_height / result.height - 1; +            spacing = result.height; +        } +          uint32_t start_x = 0;          if (menu->prefix) { -            bm_cairo_get_text_extents(cairo, &result, "%s ", menu->prefix); -            start_x = result.te.x_advance; +            bm_pango_get_text_extents(cairo, &paint, &result, "%s ", menu->prefix); +            start_x = result.x_advance;          } -        uint32_t count, cl = 1; -        struct bm_item **items = bm_menu_get_filtered_items(menu, &count); -        for (uint32_t i = (menu->index / (lines - 1)) * (lines - 1); i < count && cl < lines; ++i) { +        uint32_t posy = out_result->height; +        for (uint32_t l = 0, i = (menu->index / lines) * lines; l < lines && i < count && posy < max_height; ++i, ++l) {              bool highlighted = (items[i] == bm_menu_get_highlighted_item(menu));              if (highlighted) { @@ -174,27 +238,29 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struc              }              if (menu->prefix && highlighted) { -                paint.pos = (struct pos){ 0, 2 + (paint.fe.height + 4) * cl++ }; +                paint.pos = (struct pos){ 0, 2 + posy };                  paint.box = (struct box){ 4, 0, 2, 2, width - paint.pos.x, 0 };                  bm_cairo_draw_line(cairo, &paint, &result, "%s %s", menu->prefix, (items[i]->text ? items[i]->text : ""));              } else { -                paint.pos = (struct pos){ 0, 2 + (paint.fe.height + 4) * cl++ }; +                paint.pos = (struct pos){ 0, 2 + posy };                  paint.box = (struct box){ 4 + start_x, 0, 2, 2, width - paint.pos.x, 0 };                  bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : ""));              } -            ++displayed; +            posy += (spacing ? spacing : result.height); +            out_result->height = posy + 2; +            out_result->displayed++;          }      } else { -        uint32_t count; -        struct bm_item **items = bm_menu_get_filtered_items(menu, &count); +        /* single-line mode */ +        bm_pango_get_text_extents(cairo, &paint, &result, "lorem ipsum lorem ipsum lorem ipsum lorem"); +        uint32_t cl = fmin(title_x + result.x_advance, width / 4); -        uint32_t cl = width / 4;          if (menu->wrap || menu->index > 0) {              paint.pos = (struct pos){ cl, 2 };              paint.box = (struct box){ 1, 2, 2, 2, 0, 0 };              bm_cairo_draw_line(cairo, &paint, &result, "<"); -            cl += result.te.x_advance + 1; +            cl += result.x_advance + 1;          }          for (uint32_t i = menu->index; i < count && cl < width; ++i) { @@ -214,21 +280,20 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struc              paint.pos = (struct pos){ cl, 2 };              paint.box = (struct box){ 2, 4, 2, 2, 0, 0 };              bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : "")); -            cl += result.te.x_advance + 2; -            displayed += (cl < width); +            cl += result.x_advance + 2; +            out_result->displayed += (cl < width); +            out_result->height = fmax(out_result->height, result.height);          }          if (menu->wrap || menu->index + 1 < count) {              bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_FG, &paint.fg);              bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg); -            bm_cairo_get_text_extents(cairo, &result, ">"); -            paint.pos = (struct pos){ width - result.te.x_advance - 2, 2 }; +            bm_pango_get_text_extents(cairo, &paint, &result, ">"); +            paint.pos = (struct pos){ width - result.x_advance - 2, 2 };              paint.box = (struct box){ 1, 2, 2, 2, 0, 0 };              bm_cairo_draw_line(cairo, &paint, &result, ">");          }      } - -    return displayed;  }  #endif /* _BM_CAIRO_H */ diff --git a/lib/renderers/wayland/CMakeLists.txt b/lib/renderers/wayland/CMakeLists.txt index 4f93d18..19672da 100644 --- a/lib/renderers/wayland/CMakeLists.txt +++ b/lib/renderers/wayland/CMakeLists.txt @@ -2,12 +2,13 @@ FIND_PACKAGE(Wayland)  if (WAYLAND_FOUND)      FIND_PACKAGE(Cairo REQUIRED) +    FIND_PACKAGE(Pango REQUIRED)      FIND_PACKAGE(XKBCommon REQUIRED)      INCLUDE(Wayland)      WAYLAND_ADD_PROTOCOL_CLIENT(proto-xdg-shell "xdg-shell.xml" xdg-shell) -    INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${WAYLAND_CLIENT_INCLUDE_DIR} ${XKBCOMMON_INCLUDE_DIR} ${CAIRO_INCLUDE_DIRECTORIES}) +    INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${WAYLAND_CLIENT_INCLUDE_DIR} ${XKBCOMMON_INCLUDE_DIR} ${CAIRO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS})      ADD_LIBRARY(bemenu-renderer-wayland SHARED wayland.c registry.c window.c ${proto-xdg-shell})      SET_TARGET_PROPERTIES(bemenu-renderer-wayland PROPERTIES PREFIX "") -    TARGET_LINK_LIBRARIES(bemenu-renderer-wayland ${WAYLAND_CLIENT_LIBRARIES} ${XKBCOMMON_LIBRARIES} ${CAIRO_LIBRARIES}) +    TARGET_LINK_LIBRARIES(bemenu-renderer-wayland ${WAYLAND_CLIENT_LIBRARIES} ${XKBCOMMON_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES})      INSTALL(TARGETS bemenu-renderer-wayland DESTINATION lib/bemenu)  endif () diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index 3852a6d..5d85479 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -39,10 +39,7 @@ render(const struct bm_menu *menu)      }      if (wayland->input.code != wayland->input.last_code) { -        uint32_t count; -        bm_menu_get_filtered_items(menu, &count); -        uint32_t lines = (count < menu->lines ? count : menu->lines) + 1; -        bm_wl_window_render(&wayland->window, menu, lines); +        bm_wl_window_render(&wayland->window, menu);          wayland->input.last_code = wayland->input.code;      }  } @@ -187,7 +184,7 @@ constructor(struct bm_menu *menu)          goto fail;      wayland->window.width = 800; -    wayland->window.height = 14; +    wayland->window.height = 1;      if (!(wayland->display = wl_display_connect(NULL)))          goto fail; diff --git a/lib/renderers/wayland/wayland.h b/lib/renderers/wayland/wayland.h index 886a0fd..dff6aba 100644 --- a/lib/renderers/wayland/wayland.h +++ b/lib/renderers/wayland/wayland.h @@ -85,7 +85,7 @@ struct window {      uint32_t displayed;      struct { -        uint32_t (*render)(struct cairo *cairo, uint32_t width, uint32_t height, const struct bm_menu *menu); +        void (*render)(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t max_height, const struct bm_menu *menu, struct cairo_paint_result *result);      } notify;  }; @@ -111,7 +111,7 @@ struct wayland {  void bm_wl_repeat(struct wayland *wayland);  bool bm_wl_registry_register(struct wayland *wayland);  void bm_wl_registry_destroy(struct wayland *wayland); -void bm_wl_window_render(struct window *window, const struct bm_menu *menu, uint32_t lines); +void bm_wl_window_render(struct window *window, const struct bm_menu *menu);  bool bm_wl_window_create(struct window *window, struct wl_shm *shm, struct wl_shell *shell, struct xdg_shell *xdg_shell, struct wl_surface *surface);  void bm_wl_window_destroy(struct window *window); diff --git a/lib/renderers/wayland/window.c b/lib/renderers/wayland/window.c index 58d2e2b..bfff232 100644 --- a/lib/renderers/wayland/window.c +++ b/lib/renderers/wayland/window.c @@ -105,11 +105,7 @@ destroy_buffer(struct buffer *buffer)  {      if (buffer->buffer)          wl_buffer_destroy(buffer->buffer); -    if (buffer->cairo.cr) -        cairo_destroy(buffer->cairo.cr); -    if (buffer->cairo.surface) -        cairo_surface_destroy(buffer->cairo.surface); - +    bm_cairo_destroy(&buffer->cairo);      memset(buffer, 0, sizeof(struct buffer));  } @@ -149,11 +145,14 @@ create_buffer(struct wl_shm *shm, struct buffer *buffer, int32_t width, int32_t      wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer); -    if (!(buffer->cairo.surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride))) +    cairo_surface_t *surf; +    if (!(surf = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride)))          goto fail; -    if (!(buffer->cairo.cr = cairo_create(buffer->cairo.surface))) +    if (!bm_cairo_create_for_surface(&buffer->cairo, surf)) { +        cairo_surface_destroy(surf);          goto fail; +    }      buffer->width = width;      buffer->height = height; @@ -251,7 +250,7 @@ static const struct wl_callback_listener listener = {  };  void -bm_wl_window_render(struct window *window, const struct bm_menu *menu, uint32_t lines) +bm_wl_window_render(struct window *window, const struct bm_menu *menu)  {      assert(window && menu); @@ -259,22 +258,25 @@ bm_wl_window_render(struct window *window, const struct bm_menu *menu, uint32_t          return;      struct buffer *buffer; -    if (!(buffer = next_buffer(window))) { -        fprintf(stderr, "could not get next buffer"); -        exit(EXIT_FAILURE); -    } +    for (int tries = 0; tries < 2; ++tries) { +        if (!(buffer = next_buffer(window))) { +            fprintf(stderr, "could not get next buffer"); +            exit(EXIT_FAILURE); +        } -    cairo_font_extents_t fe; -    bm_cairo_get_font_extents(&buffer->cairo, &menu->font, &fe); -    window->height = MIN(lines * (fe.height + 4), window->max_height); +        if (!window->notify.render) +            break; -    if (window->height != buffer->height && !(buffer = next_buffer(window))) { -        fprintf(stderr, "could not get next buffer"); -        exit(EXIT_FAILURE); -    } +        struct cairo_paint_result result; +        window->notify.render(&buffer->cairo, buffer->width, fmin(buffer->height, window->max_height), window->max_height, menu, &result); +        window->displayed = result.displayed; -    if (window->notify.render) -        window->displayed = window->notify.render(&buffer->cairo, buffer->width, buffer->height, menu); +        if (window->height == result.height) +            break; + +        window->height = result.height; +        destroy_buffer(buffer); +    }      window->frame_cb = wl_surface_frame(window->surface);      wl_callback_add_listener(window->frame_cb, &listener, window); diff --git a/lib/renderers/x11/CMakeLists.txt b/lib/renderers/x11/CMakeLists.txt new file mode 100644 index 0000000..50a9cae --- /dev/null +++ b/lib/renderers/x11/CMakeLists.txt @@ -0,0 +1,11 @@ +FIND_PACKAGE(X11) + +if (X11_FOUND) +    FIND_PACKAGE(Cairo REQUIRED) +    FIND_PACKAGE(Pango REQUIRED) +    INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${X11_INCLUDE_DIR} ${X11_Xinerama_INCLUDE_PATH} ${CAIRO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS}) +    ADD_LIBRARY(bemenu-renderer-x11 SHARED x11.c window.c xkb_unicode.c) +    SET_TARGET_PROPERTIES(bemenu-renderer-x11 PROPERTIES PREFIX "") +    TARGET_LINK_LIBRARIES(bemenu-renderer-x11 ${X11_LIBRARIES} ${X11_Xinerama_LIB} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES}) +    INSTALL(TARGETS bemenu-renderer-x11 DESTINATION lib/bemenu) +endif () diff --git a/lib/renderers/x11/window.c b/lib/renderers/x11/window.c new file mode 100644 index 0000000..0b4c94a --- /dev/null +++ b/lib/renderers/x11/window.c @@ -0,0 +1,224 @@ +#include "x11.h" + +#include <stdlib.h> +#include <cairo-xlib.h> +#include <X11/extensions/Xinerama.h> + +static void +destroy_buffer(struct buffer *buffer) +{ +    bm_cairo_destroy(&buffer->cairo); +    memset(buffer, 0, sizeof(struct buffer)); +} + +static bool +create_buffer(struct window *window, struct buffer *buffer, int32_t width, int32_t height) +{ +    cairo_surface_t *surf; +    if (!(surf = cairo_xlib_surface_create(window->display, window->drawable, DefaultVisual(window->display, window->screen), width, height))) +        goto fail; + +    cairo_xlib_surface_set_size(surf, width, height); + +    if (!bm_cairo_create_for_surface(&buffer->cairo, surf)) { +        cairo_surface_destroy(surf); +        goto fail; +    } + +    buffer->width = width; +    buffer->height = height; +    buffer->created = true; +    return true; + +fail: +    destroy_buffer(buffer); +    return false; +} + +static struct buffer* +next_buffer(struct window *window) +{ +    assert(window); + +    struct buffer *buffer = &window->buffer; + +    if (!buffer) +        return NULL; + +    if (window->width != buffer->width || window->height != buffer->height) +        destroy_buffer(buffer); + +    if (!buffer->created && !create_buffer(window, buffer, window->width, window->height)) +        return NULL; + +    return buffer; +} + +void +bm_x11_window_render(struct window *window, const struct bm_menu *menu) +{ +    assert(window && menu); +    uint32_t oldw = window->width, oldh = window->height; + +    struct buffer *buffer; +    for (int32_t tries = 0; tries < 2; ++tries) { +        if (!(buffer = next_buffer(window))) { +            fprintf(stderr, "could not get next buffer"); +            exit(EXIT_FAILURE); +        } + +        if (!window->notify.render) +            break; + +        cairo_push_group(buffer->cairo.cr); +        struct cairo_paint_result result; +        window->notify.render(&buffer->cairo, buffer->width, buffer->height, window->max_height, menu, &result); +        window->displayed = result.displayed; +        cairo_pop_group_to_source(buffer->cairo.cr); + +        if (window->height == result.height) +            break; + +        window->height = result.height; +        destroy_buffer(buffer); +    } + +    if (oldw != window->width || oldh != window->height) { +        if (window->bottom) { +            XMoveResizeWindow(window->display, window->drawable, window->x, window->max_height - window->height, window->width, window->height); +        } else { +            XResizeWindow(window->display, window->drawable, window->width, window->height); +        } +    } + +    if (buffer->created) { +        cairo_paint(buffer->cairo.cr); +        cairo_surface_flush(buffer->cairo.surface); +    } +} + +void +bm_x11_window_key_press(struct window *window, XKeyEvent *ev) +{ +    KeySym keysym = NoSymbol; +    XmbLookupString(window->xic, ev, NULL, 0, &keysym, NULL); +    window->mods = 0; +    if (ev->state & ControlMask) window->mods |= MOD_CTRL; +    if (ev->state & ShiftMask) window->mods |= MOD_SHIFT; +    window->keysym = keysym; +} + +void +bm_x11_window_destroy(struct window *window) +{ +    assert(window); +    destroy_buffer(&window->buffer); + +    if (window->display && window->drawable) +        XDestroyWindow(window->display, window->drawable); +} + +void +bm_x11_window_set_monitor(struct window *window, uint32_t monitor) +{ +    if (window->monitor == monitor) +        return; + +    Window root = DefaultRootWindow(window->display); + +    { +        /* xinerama logic straight from dmenu */ +#define INTERSECT(x,y,w,h,r)  (fmax(0, fmin((x)+(w),(r).x_org+(r).width) - fmax((x),(r).x_org)) * fmax(0, fmin((y)+(h),(r).y_org+(r).height) - fmax((y),(r).y_org))) + +        int32_t n; +        XineramaScreenInfo *info; +        if ((info = XineramaQueryScreens(window->display, &n))) { +            int32_t x, y, a, j, di, i = 0, area = 0; +            uint32_t du; +            Window w, pw, dw, *dws; +            XWindowAttributes wa; + +            XGetInputFocus(window->display, &w, &di); +            if (monitor > 0) +                i = ((int32_t)monitor > n ? n : (int32_t)monitor) - 1; + +            if (monitor == 0 && w != root && w != PointerRoot && w != None) { +                /* find top-level window containing current input focus */ +                do { +                    if (XQueryTree(window->display, (pw = w), &dw, &w, &dws, &du) && dws) +                        XFree(dws); +                } while(w != root && w != pw); + +                /* find xinerama screen with which the window intersects most */ +                if (XGetWindowAttributes(window->display, pw, &wa)) { +                    for (j = 0; j < n; j++) +                        if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { +                            area = a; +                            i = j; +                        } +                } +            } + +            /* no focused window is on screen, so use pointer location instead */ +            if (monitor == 0 && !area && XQueryPointer(window->display, root, &dw, &dw, &x, &y, &di, &di, &du)) { +                for (i = 0; i < n; i++) { +                    if (INTERSECT(x, y, 1, 1, info[i])) +                        break; +                } +            } + +            window->x = info[i].x_org; +            window->y = info[i].y_org + (window->bottom ? info[i].height - window->height : 0); +            window->width = info[i].width; +            window->max_height = info[i].height; +            XFree(info); +        } else { +            window->max_height = DisplayHeight(window->display, window->screen); +            window->x = 0; +            window->y = (window->bottom ? window->max_height - window->height : 0); +            window->width = DisplayWidth(window->display, window->screen); +        } + +#undef INTERSECT +    } + +    window->monitor = monitor; +    XMoveResizeWindow(window->display, window->drawable, window->x, window->y, window->width, window->height); +    XFlush(window->display); +} + +void +bm_x11_window_set_bottom(struct window *window, bool bottom) +{ +    if (window->bottom == bottom) +        return; + +    window->bottom = bottom; +    bm_x11_window_set_monitor(window, window->monitor); +} + +bool +bm_x11_window_create(struct window *window, Display *display) +{ +    assert(window); + +    window->display = display; +    window->screen = DefaultScreen(display); +    window->width = window->height = 1; +    window->monitor = -1; + +    XSetWindowAttributes wa = { +        .override_redirect = True, +        .event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask +    }; + +    window->drawable = XCreateWindow(display, DefaultRootWindow(display), 0, 0, window->width, window->height, 0, DefaultDepth(display, window->screen), CopyFromParent, DefaultVisual(display, window->screen), CWOverrideRedirect | CWBackPixel | CWEventMask, &wa); + +    XSelectInput(display, window->drawable, ButtonPressMask | KeyPressMask); +    XMapRaised(display, window->drawable); +    window->xim = XOpenIM(display, NULL, NULL, NULL); +    window->xic = XCreateIC(window->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, window->drawable, XNFocusWindow, window->drawable, NULL); +    return true; +} + +/* vim: set ts=8 sw=4 tw=0 :*/ diff --git a/lib/renderers/x11/x11.c b/lib/renderers/x11/x11.c new file mode 100644 index 0000000..3e9ced9 --- /dev/null +++ b/lib/renderers/x11/x11.c @@ -0,0 +1,235 @@ +#define _DEFAULT_SOURCE +#include "internal.h" +#include "version.h" +#include "x11.h" +#include "xkb_unicode.h" + +#include <stdlib.h> +#include <unistd.h> + +static void +render(const struct bm_menu *menu) +{ +    struct x11 *x11 = menu->renderer->internal; + +    bm_x11_window_render(&x11->window, menu); +    XFlush(x11->display); + +    XEvent ev; +    if (XNextEvent(x11->display, &ev) || XFilterEvent(&ev, x11->window.drawable)) +        return; + +    switch (ev.type) { +        case KeyPress: +            bm_x11_window_key_press(&x11->window, &ev.xkey); +            break; +        case SelectionNotify: +            // paste here +            break; +        case VisibilityNotify: +            if (ev.xvisibility.state != VisibilityUnobscured) { +                XRaiseWindow(x11->display, x11->window.drawable); +                XFlush(x11->display); +            } +            break; +    } +} + +static enum bm_key +poll_key(const struct bm_menu *menu, unsigned int *unicode) +{ +    struct x11 *x11 = menu->renderer->internal; +    assert(x11 && unicode); + +    if (x11->window.keysym == NoSymbol) +        return BM_KEY_UNICODE; + +    KeySym sym = x11->window.keysym; +    uint32_t mods = x11->window.mods; +    *unicode = bm_x11_key_sym2unicode(sym); + +    x11->window.keysym = NoSymbol; + +    switch (sym) { +        case XK_Up: +            return BM_KEY_UP; + +        case XK_Down: +            return BM_KEY_DOWN; + +        case XK_Left: +            return BM_KEY_LEFT; + +        case XK_Right: +            return BM_KEY_RIGHT; + +        case XK_Home: +            return BM_KEY_HOME; + +        case XK_End: +            return BM_KEY_END; + +        case XK_Page_Up: +            return (mods & MOD_SHIFT ? BM_KEY_SHIFT_PAGE_UP : BM_KEY_PAGE_UP); + +        case XK_Page_Down: +            return (mods & MOD_SHIFT ? BM_KEY_SHIFT_PAGE_DOWN : BM_KEY_PAGE_DOWN); + +        case XK_BackSpace: +            return BM_KEY_BACKSPACE; + +        case XK_Delete: +            return (mods & MOD_SHIFT ? BM_KEY_LINE_DELETE_LEFT : BM_KEY_DELETE); + +        case XK_Tab: +            return (mods & MOD_SHIFT ? BM_KEY_SHIFT_TAB : BM_KEY_TAB); + +        case XK_ISO_Left_Tab: +            return BM_KEY_SHIFT_TAB; + +        case XK_Insert: +            return BM_KEY_SHIFT_RETURN; + +        case XK_Return: +            return (mods & MOD_CTRL ? BM_KEY_CONTROL_RETURN : (mods & MOD_SHIFT ? BM_KEY_SHIFT_RETURN : BM_KEY_RETURN)); + +        case XK_Escape: +            return BM_KEY_ESCAPE; + +        case XK_p: +            return (mods & MOD_CTRL ? BM_KEY_UP : BM_KEY_UNICODE); + +        case XK_n: +            return (mods & MOD_CTRL ? BM_KEY_DOWN : BM_KEY_UNICODE); + +        case XK_l: +            return (mods & MOD_CTRL ? BM_KEY_LEFT : BM_KEY_UNICODE); + +        case XK_f: +            return (mods & MOD_CTRL ? BM_KEY_RIGHT : BM_KEY_UNICODE); + +        case XK_a: +            return (mods & MOD_CTRL ? BM_KEY_HOME : BM_KEY_UNICODE); + +        case XK_e: +            return (mods & MOD_CTRL ? BM_KEY_END : BM_KEY_UNICODE); + +        case XK_h: +            return (mods & MOD_CTRL ? BM_KEY_BACKSPACE : BM_KEY_UNICODE); + +        case XK_u: +            return (mods & MOD_CTRL ? BM_KEY_LINE_DELETE_LEFT : BM_KEY_UNICODE); + +        case XK_k: +            return (mods & MOD_CTRL ? BM_KEY_LINE_DELETE_RIGHT : BM_KEY_UNICODE); + +        case XK_w: +            return (mods & MOD_CTRL ? BM_KEY_WORD_DELETE : BM_KEY_UNICODE); + +        default: break; +    } + +    return BM_KEY_UNICODE; +} + +static uint32_t +get_displayed_count(const struct bm_menu *menu) +{ +    struct x11 *x11 = menu->renderer->internal; +    assert(x11); +    return x11->window.displayed; +} + +static void +set_bottom(const struct bm_menu *menu, bool bottom) +{ +    struct x11 *x11 = menu->renderer->internal; +    assert(x11); +    bm_x11_window_set_bottom(&x11->window, bottom); +} + +static void +set_monitor(const struct bm_menu *menu, uint32_t monitor) +{ +    struct x11 *x11 = menu->renderer->internal; +    assert(x11); +    bm_x11_window_set_monitor(&x11->window, monitor); +} + +static void +grab_keyboard(const struct bm_menu *menu, bool grab) +{ +    struct x11 *x11 = menu->renderer->internal; +    assert(x11); + +    if (grab) { +        for (uint32_t i = 0; i < 1000; ++i) { +            if (XGrabKeyboard(x11->display, DefaultRootWindow(x11->display), True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) +                return; +            usleep(1000); +        } + +        fprintf(stderr, "x11: cannot grab keyboard\n"); +    } else { +        XUngrabKeyboard(x11->display, CurrentTime); +    } +} + +static void +destructor(struct bm_menu *menu) +{ +    struct x11 *x11 = menu->renderer->internal; + +    if (!x11) +        return; + +    bm_x11_window_destroy(&x11->window); + +    if (x11->display) +        XCloseDisplay(x11->display); + +    free(x11); +    menu->renderer->internal = NULL; +} + +static bool +constructor(struct bm_menu *menu) +{ +    struct x11 *x11; +    if (!(menu->renderer->internal = x11 = calloc(1, sizeof(struct x11)))) +        goto fail; + +    if (!(x11->display = XOpenDisplay(NULL))) +        goto fail; + +    if (!bm_x11_window_create(&x11->window, x11->display)) +        goto fail; + +    x11->window.bottom = menu->bottom; +    bm_x11_window_set_monitor(&x11->window, menu->monitor); + +    x11->window.notify.render = bm_cairo_paint; +    return true; + +fail: +    destructor(menu); +    return false; +} + +extern const char* +register_renderer(struct render_api *api) +{ +    api->constructor = constructor; +    api->destructor = destructor; +    api->get_displayed_count = get_displayed_count; +    api->poll_key = poll_key; +    api->render = render; +    api->set_bottom = set_bottom; +    api->set_monitor = set_monitor; +    api->grab_keyboard = grab_keyboard; +    api->prioritory = BM_PRIO_GUI; +    api->version = BM_PLUGIN_VERSION; +    return "x11"; +} + +/* vim: set ts=8 sw=4 tw=0 :*/ diff --git a/lib/renderers/x11/x11.h b/lib/renderers/x11/x11.h new file mode 100644 index 0000000..e930cb2 --- /dev/null +++ b/lib/renderers/x11/x11.h @@ -0,0 +1,56 @@ +#ifndef _BM_X11_H_ +#define _BM_X11_H_ + +#include <X11/Xlib.h> +#include <X11/keysym.h> + +#include "renderers/cairo.h" + +enum mod_bit { +    MOD_SHIFT = 1<<0, +    MOD_CTRL = 1<<1, +}; + +struct buffer { +    struct cairo cairo; +    uint32_t width, height; +    bool created; +}; + +struct window { +    Display *display; +    int32_t screen; +    Drawable drawable; +    XIM xim; +    XIC xic; + +    KeySym keysym; +    uint32_t mods; + +    struct buffer buffer; +    uint32_t x, y, width, height, max_height; +    uint32_t displayed; + +    uint32_t monitor; +    bool bottom; + +    struct { +        void (*render)(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t max_height, const struct bm_menu *menu, struct cairo_paint_result *result); +    } notify; +}; + +struct x11 { +    Display *display; +    struct window window; +}; + +void bm_x11_window_render(struct window *window, const struct bm_menu *menu); +void bm_x11_window_key_press(struct window *window, XKeyEvent *ev); +void bm_x11_window_set_monitor(struct window *window, uint32_t monitor); +void bm_x11_window_set_bottom(struct window *window, bool bottom); +bool bm_x11_window_create(struct window *window, Display *display); +void bm_x11_window_destroy(struct window *window); + +#endif /* _BM_WAYLAND_H_ */ + +/* vim: set ts=8 sw=4 tw=0 :*/ diff --git a/lib/renderers/x11/xkb_unicode.c b/lib/renderers/x11/xkb_unicode.c new file mode 100644 index 0000000..982b670 --- /dev/null +++ b/lib/renderers/x11/xkb_unicode.c @@ -0,0 +1,857 @@ +/** + * From GLFW + */ + +/* + * Marcus: This code was originally written by Markus G. Kuhn. + * I have made some slight changes (trimmed it down a bit from >60 KB to + * 20 KB), but the functionality is the same. + */ + +/* + * This module converts keysym values into the corresponding ISO 10646 + * (UCS, Unicode) values. + * + * The array keysymtab[] contains pairs of X11 keysym values for graphical + * characters and the corresponding Unicode value. The function + * _glfwKeySym2Unicode() maps a keysym onto a Unicode value using a binary + * search, therefore keysymtab[] must remain SORTED by keysym value. + * + * We allow to represent any UCS character in the range U-00000000 to + * U-00FFFFFF by a keysym value in the range 0x01000000 to 0x01ffffff. + * This admittedly does not cover the entire 31-bit space of UCS, but + * it does cover all of the characters up to U-10FFFF, which can be + * represented by UTF-16, and more, and it is very unlikely that higher + * UCS codes will ever be assigned by ISO. So to get Unicode character + * U+ABCD you can directly use keysym 0x0100abcd. + * + * Original author: Markus G. Kuhn <mkuhn@acm.org>, University of + *                  Cambridge, April 2001 + * + * Special thanks to Richard Verhoeven <river@win.tue.nl> for preparing + * an initial draft of the mapping table. + * + */ + + +//************************************************************************ +//****                KeySym to Unicode mapping table                 **** +//************************************************************************ + +#include "xkb_unicode.h" +#include "x11.h" + +static const struct codepair { +  unsigned short keysym; +  unsigned short ucs; +} keysymtab[] = { +  { 0x01a1, 0x0104 }, +  { 0x01a2, 0x02d8 }, +  { 0x01a3, 0x0141 }, +  { 0x01a5, 0x013d }, +  { 0x01a6, 0x015a }, +  { 0x01a9, 0x0160 }, +  { 0x01aa, 0x015e }, +  { 0x01ab, 0x0164 }, +  { 0x01ac, 0x0179 }, +  { 0x01ae, 0x017d }, +  { 0x01af, 0x017b }, +  { 0x01b1, 0x0105 }, +  { 0x01b2, 0x02db }, +  { 0x01b3, 0x0142 }, +  { 0x01b5, 0x013e }, +  { 0x01b6, 0x015b }, +  { 0x01b7, 0x02c7 }, +  { 0x01b9, 0x0161 }, +  { 0x01ba, 0x015f }, +  { 0x01bb, 0x0165 }, +  { 0x01bc, 0x017a }, +  { 0x01bd, 0x02dd }, +  { 0x01be, 0x017e }, +  { 0x01bf, 0x017c }, +  { 0x01c0, 0x0154 }, +  { 0x01c3, 0x0102 }, +  { 0x01c5, 0x0139 }, +  { 0x01c6, 0x0106 }, +  { 0x01c8, 0x010c }, +  { 0x01ca, 0x0118 }, +  { 0x01cc, 0x011a }, +  { 0x01cf, 0x010e }, +  { 0x01d0, 0x0110 }, +  { 0x01d1, 0x0143 }, +  { 0x01d2, 0x0147 }, +  { 0x01d5, 0x0150 }, +  { 0x01d8, 0x0158 }, +  { 0x01d9, 0x016e }, +  { 0x01db, 0x0170 }, +  { 0x01de, 0x0162 }, +  { 0x01e0, 0x0155 }, +  { 0x01e3, 0x0103 }, +  { 0x01e5, 0x013a }, +  { 0x01e6, 0x0107 }, +  { 0x01e8, 0x010d }, +  { 0x01ea, 0x0119 }, +  { 0x01ec, 0x011b }, +  { 0x01ef, 0x010f }, +  { 0x01f0, 0x0111 }, +  { 0x01f1, 0x0144 }, +  { 0x01f2, 0x0148 }, +  { 0x01f5, 0x0151 }, +  { 0x01f8, 0x0159 }, +  { 0x01f9, 0x016f }, +  { 0x01fb, 0x0171 }, +  { 0x01fe, 0x0163 }, +  { 0x01ff, 0x02d9 }, +  { 0x02a1, 0x0126 }, +  { 0x02a6, 0x0124 }, +  { 0x02a9, 0x0130 }, +  { 0x02ab, 0x011e }, +  { 0x02ac, 0x0134 }, +  { 0x02b1, 0x0127 }, +  { 0x02b6, 0x0125 }, +  { 0x02b9, 0x0131 }, +  { 0x02bb, 0x011f }, +  { 0x02bc, 0x0135 }, +  { 0x02c5, 0x010a }, +  { 0x02c6, 0x0108 }, +  { 0x02d5, 0x0120 }, +  { 0x02d8, 0x011c }, +  { 0x02dd, 0x016c }, +  { 0x02de, 0x015c }, +  { 0x02e5, 0x010b }, +  { 0x02e6, 0x0109 }, +  { 0x02f5, 0x0121 }, +  { 0x02f8, 0x011d }, +  { 0x02fd, 0x016d }, +  { 0x02fe, 0x015d }, +  { 0x03a2, 0x0138 }, +  { 0x03a3, 0x0156 }, +  { 0x03a5, 0x0128 }, +  { 0x03a6, 0x013b }, +  { 0x03aa, 0x0112 }, +  { 0x03ab, 0x0122 }, +  { 0x03ac, 0x0166 }, +  { 0x03b3, 0x0157 }, +  { 0x03b5, 0x0129 }, +  { 0x03b6, 0x013c }, +  { 0x03ba, 0x0113 }, +  { 0x03bb, 0x0123 }, +  { 0x03bc, 0x0167 }, +  { 0x03bd, 0x014a }, +  { 0x03bf, 0x014b }, +  { 0x03c0, 0x0100 }, +  { 0x03c7, 0x012e }, +  { 0x03cc, 0x0116 }, +  { 0x03cf, 0x012a }, +  { 0x03d1, 0x0145 }, +  { 0x03d2, 0x014c }, +  { 0x03d3, 0x0136 }, +  { 0x03d9, 0x0172 }, +  { 0x03dd, 0x0168 }, +  { 0x03de, 0x016a }, +  { 0x03e0, 0x0101 }, +  { 0x03e7, 0x012f }, +  { 0x03ec, 0x0117 }, +  { 0x03ef, 0x012b }, +  { 0x03f1, 0x0146 }, +  { 0x03f2, 0x014d }, +  { 0x03f3, 0x0137 }, +  { 0x03f9, 0x0173 }, +  { 0x03fd, 0x0169 }, +  { 0x03fe, 0x016b }, +  { 0x047e, 0x203e }, +  { 0x04a1, 0x3002 }, +  { 0x04a2, 0x300c }, +  { 0x04a3, 0x300d }, +  { 0x04a4, 0x3001 }, +  { 0x04a5, 0x30fb }, +  { 0x04a6, 0x30f2 }, +  { 0x04a7, 0x30a1 }, +  { 0x04a8, 0x30a3 }, +  { 0x04a9, 0x30a5 }, +  { 0x04aa, 0x30a7 }, +  { 0x04ab, 0x30a9 }, +  { 0x04ac, 0x30e3 }, +  { 0x04ad, 0x30e5 }, +  { 0x04ae, 0x30e7 }, +  { 0x04af, 0x30c3 }, +  { 0x04b0, 0x30fc }, +  { 0x04b1, 0x30a2 }, +  { 0x04b2, 0x30a4 }, +  { 0x04b3, 0x30a6 }, +  { 0x04b4, 0x30a8 }, +  { 0x04b5, 0x30aa }, +  { 0x04b6, 0x30ab }, +  { 0x04b7, 0x30ad }, +  { 0x04b8, 0x30af }, +  { 0x04b9, 0x30b1 }, +  { 0x04ba, 0x30b3 }, +  { 0x04bb, 0x30b5 }, +  { 0x04bc, 0x30b7 }, +  { 0x04bd, 0x30b9 }, +  { 0x04be, 0x30bb }, +  { 0x04bf, 0x30bd }, +  { 0x04c0, 0x30bf }, +  { 0x04c1, 0x30c1 }, +  { 0x04c2, 0x30c4 }, +  { 0x04c3, 0x30c6 }, +  { 0x04c4, 0x30c8 }, +  { 0x04c5, 0x30ca }, +  { 0x04c6, 0x30cb }, +  { 0x04c7, 0x30cc }, +  { 0x04c8, 0x30cd }, +  { 0x04c9, 0x30ce }, +  { 0x04ca, 0x30cf }, +  { 0x04cb, 0x30d2 }, +  { 0x04cc, 0x30d5 }, +  { 0x04cd, 0x30d8 }, +  { 0x04ce, 0x30db }, +  { 0x04cf, 0x30de }, +  { 0x04d0, 0x30df }, +  { 0x04d1, 0x30e0 }, +  { 0x04d2, 0x30e1 }, +  { 0x04d3, 0x30e2 }, +  { 0x04d4, 0x30e4 }, +  { 0x04d5, 0x30e6 }, +  { 0x04d6, 0x30e8 }, +  { 0x04d7, 0x30e9 }, +  { 0x04d8, 0x30ea }, +  { 0x04d9, 0x30eb }, +  { 0x04da, 0x30ec }, +  { 0x04db, 0x30ed }, +  { 0x04dc, 0x30ef }, +  { 0x04dd, 0x30f3 }, +  { 0x04de, 0x309b }, +  { 0x04df, 0x309c }, +  { 0x05ac, 0x060c }, +  { 0x05bb, 0x061b }, +  { 0x05bf, 0x061f }, +  { 0x05c1, 0x0621 }, +  { 0x05c2, 0x0622 }, +  { 0x05c3, 0x0623 }, +  { 0x05c4, 0x0624 }, +  { 0x05c5, 0x0625 }, +  { 0x05c6, 0x0626 }, +  { 0x05c7, 0x0627 }, +  { 0x05c8, 0x0628 }, +  { 0x05c9, 0x0629 }, +  { 0x05ca, 0x062a }, +  { 0x05cb, 0x062b }, +  { 0x05cc, 0x062c }, +  { 0x05cd, 0x062d }, +  { 0x05ce, 0x062e }, +  { 0x05cf, 0x062f }, +  { 0x05d0, 0x0630 }, +  { 0x05d1, 0x0631 }, +  { 0x05d2, 0x0632 }, +  { 0x05d3, 0x0633 }, +  { 0x05d4, 0x0634 }, +  { 0x05d5, 0x0635 }, +  { 0x05d6, 0x0636 }, +  { 0x05d7, 0x0637 }, +  { 0x05d8, 0x0638 }, +  { 0x05d9, 0x0639 }, +  { 0x05da, 0x063a }, +  { 0x05e0, 0x0640 }, +  { 0x05e1, 0x0641 }, +  { 0x05e2, 0x0642 }, +  { 0x05e3, 0x0643 }, +  { 0x05e4, 0x0644 }, +  { 0x05e5, 0x0645 }, +  { 0x05e6, 0x0646 }, +  { 0x05e7, 0x0647 }, +  { 0x05e8, 0x0648 }, +  { 0x05e9, 0x0649 }, +  { 0x05ea, 0x064a }, +  { 0x05eb, 0x064b }, +  { 0x05ec, 0x064c }, +  { 0x05ed, 0x064d }, +  { 0x05ee, 0x064e }, +  { 0x05ef, 0x064f }, +  { 0x05f0, 0x0650 }, +  { 0x05f1, 0x0651 }, +  { 0x05f2, 0x0652 }, +  { 0x06a1, 0x0452 }, +  { 0x06a2, 0x0453 }, +  { 0x06a3, 0x0451 }, +  { 0x06a4, 0x0454 }, +  { 0x06a5, 0x0455 }, +  { 0x06a6, 0x0456 }, +  { 0x06a7, 0x0457 }, +  { 0x06a8, 0x0458 }, +  { 0x06a9, 0x0459 }, +  { 0x06aa, 0x045a }, +  { 0x06ab, 0x045b }, +  { 0x06ac, 0x045c }, +  { 0x06ae, 0x045e }, +  { 0x06af, 0x045f }, +  { 0x06b0, 0x2116 }, +  { 0x06b1, 0x0402 }, +  { 0x06b2, 0x0403 }, +  { 0x06b3, 0x0401 }, +  { 0x06b4, 0x0404 }, +  { 0x06b5, 0x0405 }, +  { 0x06b6, 0x0406 }, +  { 0x06b7, 0x0407 }, +  { 0x06b8, 0x0408 }, +  { 0x06b9, 0x0409 }, +  { 0x06ba, 0x040a }, +  { 0x06bb, 0x040b }, +  { 0x06bc, 0x040c }, +  { 0x06be, 0x040e }, +  { 0x06bf, 0x040f }, +  { 0x06c0, 0x044e }, +  { 0x06c1, 0x0430 }, +  { 0x06c2, 0x0431 }, +  { 0x06c3, 0x0446 }, +  { 0x06c4, 0x0434 }, +  { 0x06c5, 0x0435 }, +  { 0x06c6, 0x0444 }, +  { 0x06c7, 0x0433 }, +  { 0x06c8, 0x0445 }, +  { 0x06c9, 0x0438 }, +  { 0x06ca, 0x0439 }, +  { 0x06cb, 0x043a }, +  { 0x06cc, 0x043b }, +  { 0x06cd, 0x043c }, +  { 0x06ce, 0x043d }, +  { 0x06cf, 0x043e }, +  { 0x06d0, 0x043f }, +  { 0x06d1, 0x044f }, +  { 0x06d2, 0x0440 }, +  { 0x06d3, 0x0441 }, +  { 0x06d4, 0x0442 }, +  { 0x06d5, 0x0443 }, +  { 0x06d6, 0x0436 }, +  { 0x06d7, 0x0432 }, +  { 0x06d8, 0x044c }, +  { 0x06d9, 0x044b }, +  { 0x06da, 0x0437 }, +  { 0x06db, 0x0448 }, +  { 0x06dc, 0x044d }, +  { 0x06dd, 0x0449 }, +  { 0x06de, 0x0447 }, +  { 0x06df, 0x044a }, +  { 0x06e0, 0x042e }, +  { 0x06e1, 0x0410 }, +  { 0x06e2, 0x0411 }, +  { 0x06e3, 0x0426 }, +  { 0x06e4, 0x0414 }, +  { 0x06e5, 0x0415 }, +  { 0x06e6, 0x0424 }, +  { 0x06e7, 0x0413 }, +  { 0x06e8, 0x0425 }, +  { 0x06e9, 0x0418 }, +  { 0x06ea, 0x0419 }, +  { 0x06eb, 0x041a }, +  { 0x06ec, 0x041b }, +  { 0x06ed, 0x041c }, +  { 0x06ee, 0x041d }, +  { 0x06ef, 0x041e }, +  { 0x06f0, 0x041f }, +  { 0x06f1, 0x042f }, +  { 0x06f2, 0x0420 }, +  { 0x06f3, 0x0421 }, +  { 0x06f4, 0x0422 }, +  { 0x06f5, 0x0423 }, +  { 0x06f6, 0x0416 }, +  { 0x06f7, 0x0412 }, +  { 0x06f8, 0x042c }, +  { 0x06f9, 0x042b }, +  { 0x06fa, 0x0417 }, +  { 0x06fb, 0x0428 }, +  { 0x06fc, 0x042d }, +  { 0x06fd, 0x0429 }, +  { 0x06fe, 0x0427 }, +  { 0x06ff, 0x042a }, +  { 0x07a1, 0x0386 }, +  { 0x07a2, 0x0388 }, +  { 0x07a3, 0x0389 }, +  { 0x07a4, 0x038a }, +  { 0x07a5, 0x03aa }, +  { 0x07a7, 0x038c }, +  { 0x07a8, 0x038e }, +  { 0x07a9, 0x03ab }, +  { 0x07ab, 0x038f }, +  { 0x07ae, 0x0385 }, +  { 0x07af, 0x2015 }, +  { 0x07b1, 0x03ac }, +  { 0x07b2, 0x03ad }, +  { 0x07b3, 0x03ae }, +  { 0x07b4, 0x03af }, +  { 0x07b5, 0x03ca }, +  { 0x07b6, 0x0390 }, +  { 0x07b7, 0x03cc }, +  { 0x07b8, 0x03cd }, +  { 0x07b9, 0x03cb }, +  { 0x07ba, 0x03b0 }, +  { 0x07bb, 0x03ce }, +  { 0x07c1, 0x0391 }, +  { 0x07c2, 0x0392 }, +  { 0x07c3, 0x0393 }, +  { 0x07c4, 0x0394 }, +  { 0x07c5, 0x0395 }, +  { 0x07c6, 0x0396 }, +  { 0x07c7, 0x0397 }, +  { 0x07c8, 0x0398 }, +  { 0x07c9, 0x0399 }, +  { 0x07ca, 0x039a }, +  { 0x07cb, 0x039b }, +  { 0x07cc, 0x039c }, +  { 0x07cd, 0x039d }, +  { 0x07ce, 0x039e }, +  { 0x07cf, 0x039f }, +  { 0x07d0, 0x03a0 }, +  { 0x07d1, 0x03a1 }, +  { 0x07d2, 0x03a3 }, +  { 0x07d4, 0x03a4 }, +  { 0x07d5, 0x03a5 }, +  { 0x07d6, 0x03a6 }, +  { 0x07d7, 0x03a7 }, +  { 0x07d8, 0x03a8 }, +  { 0x07d9, 0x03a9 }, +  { 0x07e1, 0x03b1 }, +  { 0x07e2, 0x03b2 }, +  { 0x07e3, 0x03b3 }, +  { 0x07e4, 0x03b4 }, +  { 0x07e5, 0x03b5 }, +  { 0x07e6, 0x03b6 }, +  { 0x07e7, 0x03b7 }, +  { 0x07e8, 0x03b8 }, +  { 0x07e9, 0x03b9 }, +  { 0x07ea, 0x03ba }, +  { 0x07eb, 0x03bb }, +  { 0x07ec, 0x03bc }, +  { 0x07ed, 0x03bd }, +  { 0x07ee, 0x03be }, +  { 0x07ef, 0x03bf }, +  { 0x07f0, 0x03c0 }, +  { 0x07f1, 0x03c1 }, +  { 0x07f2, 0x03c3 }, +  { 0x07f3, 0x03c2 }, +  { 0x07f4, 0x03c4 }, +  { 0x07f5, 0x03c5 }, +  { 0x07f6, 0x03c6 }, +  { 0x07f7, 0x03c7 }, +  { 0x07f8, 0x03c8 }, +  { 0x07f9, 0x03c9 }, +  { 0x08a1, 0x23b7 }, +  { 0x08a2, 0x250c }, +  { 0x08a3, 0x2500 }, +  { 0x08a4, 0x2320 }, +  { 0x08a5, 0x2321 }, +  { 0x08a6, 0x2502 }, +  { 0x08a7, 0x23a1 }, +  { 0x08a8, 0x23a3 }, +  { 0x08a9, 0x23a4 }, +  { 0x08aa, 0x23a6 }, +  { 0x08ab, 0x239b }, +  { 0x08ac, 0x239d }, +  { 0x08ad, 0x239e }, +  { 0x08ae, 0x23a0 }, +  { 0x08af, 0x23a8 }, +  { 0x08b0, 0x23ac }, +  { 0x08bc, 0x2264 }, +  { 0x08bd, 0x2260 }, +  { 0x08be, 0x2265 }, +  { 0x08bf, 0x222b }, +  { 0x08c0, 0x2234 }, +  { 0x08c1, 0x221d }, +  { 0x08c2, 0x221e }, +  { 0x08c5, 0x2207 }, +  { 0x08c8, 0x223c }, +  { 0x08c9, 0x2243 }, +  { 0x08cd, 0x21d4 }, +  { 0x08ce, 0x21d2 }, +  { 0x08cf, 0x2261 }, +  { 0x08d6, 0x221a }, +  { 0x08da, 0x2282 }, +  { 0x08db, 0x2283 }, +  { 0x08dc, 0x2229 }, +  { 0x08dd, 0x222a }, +  { 0x08de, 0x2227 }, +  { 0x08df, 0x2228 }, +  { 0x08ef, 0x2202 }, +  { 0x08f6, 0x0192 }, +  { 0x08fb, 0x2190 }, +  { 0x08fc, 0x2191 }, +  { 0x08fd, 0x2192 }, +  { 0x08fe, 0x2193 }, +  { 0x09e0, 0x25c6 }, +  { 0x09e1, 0x2592 }, +  { 0x09e2, 0x2409 }, +  { 0x09e3, 0x240c }, +  { 0x09e4, 0x240d }, +  { 0x09e5, 0x240a }, +  { 0x09e8, 0x2424 }, +  { 0x09e9, 0x240b }, +  { 0x09ea, 0x2518 }, +  { 0x09eb, 0x2510 }, +  { 0x09ec, 0x250c }, +  { 0x09ed, 0x2514 }, +  { 0x09ee, 0x253c }, +  { 0x09ef, 0x23ba }, +  { 0x09f0, 0x23bb }, +  { 0x09f1, 0x2500 }, +  { 0x09f2, 0x23bc }, +  { 0x09f3, 0x23bd }, +  { 0x09f4, 0x251c }, +  { 0x09f5, 0x2524 }, +  { 0x09f6, 0x2534 }, +  { 0x09f7, 0x252c }, +  { 0x09f8, 0x2502 }, +  { 0x0aa1, 0x2003 }, +  { 0x0aa2, 0x2002 }, +  { 0x0aa3, 0x2004 }, +  { 0x0aa4, 0x2005 }, +  { 0x0aa5, 0x2007 }, +  { 0x0aa6, 0x2008 }, +  { 0x0aa7, 0x2009 }, +  { 0x0aa8, 0x200a }, +  { 0x0aa9, 0x2014 }, +  { 0x0aaa, 0x2013 }, +  { 0x0aae, 0x2026 }, +  { 0x0aaf, 0x2025 }, +  { 0x0ab0, 0x2153 }, +  { 0x0ab1, 0x2154 }, +  { 0x0ab2, 0x2155 }, +  { 0x0ab3, 0x2156 }, +  { 0x0ab4, 0x2157 }, +  { 0x0ab5, 0x2158 }, +  { 0x0ab6, 0x2159 }, +  { 0x0ab7, 0x215a }, +  { 0x0ab8, 0x2105 }, +  { 0x0abb, 0x2012 }, +  { 0x0abc, 0x2329 }, +  { 0x0abe, 0x232a }, +  { 0x0ac3, 0x215b }, +  { 0x0ac4, 0x215c }, +  { 0x0ac5, 0x215d }, +  { 0x0ac6, 0x215e }, +  { 0x0ac9, 0x2122 }, +  { 0x0aca, 0x2613 }, +  { 0x0acc, 0x25c1 }, +  { 0x0acd, 0x25b7 }, +  { 0x0ace, 0x25cb }, +  { 0x0acf, 0x25af }, +  { 0x0ad0, 0x2018 }, +  { 0x0ad1, 0x2019 }, +  { 0x0ad2, 0x201c }, +  { 0x0ad3, 0x201d }, +  { 0x0ad4, 0x211e }, +  { 0x0ad6, 0x2032 }, +  { 0x0ad7, 0x2033 }, +  { 0x0ad9, 0x271d }, +  { 0x0adb, 0x25ac }, +  { 0x0adc, 0x25c0 }, +  { 0x0add, 0x25b6 }, +  { 0x0ade, 0x25cf }, +  { 0x0adf, 0x25ae }, +  { 0x0ae0, 0x25e6 }, +  { 0x0ae1, 0x25ab }, +  { 0x0ae2, 0x25ad }, +  { 0x0ae3, 0x25b3 }, +  { 0x0ae4, 0x25bd }, +  { 0x0ae5, 0x2606 }, +  { 0x0ae6, 0x2022 }, +  { 0x0ae7, 0x25aa }, +  { 0x0ae8, 0x25b2 }, +  { 0x0ae9, 0x25bc }, +  { 0x0aea, 0x261c }, +  { 0x0aeb, 0x261e }, +  { 0x0aec, 0x2663 }, +  { 0x0aed, 0x2666 }, +  { 0x0aee, 0x2665 }, +  { 0x0af0, 0x2720 }, +  { 0x0af1, 0x2020 }, +  { 0x0af2, 0x2021 }, +  { 0x0af3, 0x2713 }, +  { 0x0af4, 0x2717 }, +  { 0x0af5, 0x266f }, +  { 0x0af6, 0x266d }, +  { 0x0af7, 0x2642 }, +  { 0x0af8, 0x2640 }, +  { 0x0af9, 0x260e }, +  { 0x0afa, 0x2315 }, +  { 0x0afb, 0x2117 }, +  { 0x0afc, 0x2038 }, +  { 0x0afd, 0x201a }, +  { 0x0afe, 0x201e }, +  { 0x0ba3, 0x003c }, +  { 0x0ba6, 0x003e }, +  { 0x0ba8, 0x2228 }, +  { 0x0ba9, 0x2227 }, +  { 0x0bc0, 0x00af }, +  { 0x0bc2, 0x22a5 }, +  { 0x0bc3, 0x2229 }, +  { 0x0bc4, 0x230a }, +  { 0x0bc6, 0x005f }, +  { 0x0bca, 0x2218 }, +  { 0x0bcc, 0x2395 }, +  { 0x0bce, 0x22a4 }, +  { 0x0bcf, 0x25cb }, +  { 0x0bd3, 0x2308 }, +  { 0x0bd6, 0x222a }, +  { 0x0bd8, 0x2283 }, +  { 0x0bda, 0x2282 }, +  { 0x0bdc, 0x22a2 }, +  { 0x0bfc, 0x22a3 }, +  { 0x0cdf, 0x2017 }, +  { 0x0ce0, 0x05d0 }, +  { 0x0ce1, 0x05d1 }, +  { 0x0ce2, 0x05d2 }, +  { 0x0ce3, 0x05d3 }, +  { 0x0ce4, 0x05d4 }, +  { 0x0ce5, 0x05d5 }, +  { 0x0ce6, 0x05d6 }, +  { 0x0ce7, 0x05d7 }, +  { 0x0ce8, 0x05d8 }, +  { 0x0ce9, 0x05d9 }, +  { 0x0cea, 0x05da }, +  { 0x0ceb, 0x05db }, +  { 0x0cec, 0x05dc }, +  { 0x0ced, 0x05dd }, +  { 0x0cee, 0x05de }, +  { 0x0cef, 0x05df }, +  { 0x0cf0, 0x05e0 }, +  { 0x0cf1, 0x05e1 }, +  { 0x0cf2, 0x05e2 }, +  { 0x0cf3, 0x05e3 }, +  { 0x0cf4, 0x05e4 }, +  { 0x0cf5, 0x05e5 }, +  { 0x0cf6, 0x05e6 }, +  { 0x0cf7, 0x05e7 }, +  { 0x0cf8, 0x05e8 }, +  { 0x0cf9, 0x05e9 }, +  { 0x0cfa, 0x05ea }, +  { 0x0da1, 0x0e01 }, +  { 0x0da2, 0x0e02 }, +  { 0x0da3, 0x0e03 }, +  { 0x0da4, 0x0e04 }, +  { 0x0da5, 0x0e05 }, +  { 0x0da6, 0x0e06 }, +  { 0x0da7, 0x0e07 }, +  { 0x0da8, 0x0e08 }, +  { 0x0da9, 0x0e09 }, +  { 0x0daa, 0x0e0a }, +  { 0x0dab, 0x0e0b }, +  { 0x0dac, 0x0e0c }, +  { 0x0dad, 0x0e0d }, +  { 0x0dae, 0x0e0e }, +  { 0x0daf, 0x0e0f }, +  { 0x0db0, 0x0e10 }, +  { 0x0db1, 0x0e11 }, +  { 0x0db2, 0x0e12 }, +  { 0x0db3, 0x0e13 }, +  { 0x0db4, 0x0e14 }, +  { 0x0db5, 0x0e15 }, +  { 0x0db6, 0x0e16 }, +  { 0x0db7, 0x0e17 }, +  { 0x0db8, 0x0e18 }, +  { 0x0db9, 0x0e19 }, +  { 0x0dba, 0x0e1a }, +  { 0x0dbb, 0x0e1b }, +  { 0x0dbc, 0x0e1c }, +  { 0x0dbd, 0x0e1d }, +  { 0x0dbe, 0x0e1e }, +  { 0x0dbf, 0x0e1f }, +  { 0x0dc0, 0x0e20 }, +  { 0x0dc1, 0x0e21 }, +  { 0x0dc2, 0x0e22 }, +  { 0x0dc3, 0x0e23 }, +  { 0x0dc4, 0x0e24 }, +  { 0x0dc5, 0x0e25 }, +  { 0x0dc6, 0x0e26 }, +  { 0x0dc7, 0x0e27 }, +  { 0x0dc8, 0x0e28 }, +  { 0x0dc9, 0x0e29 }, +  { 0x0dca, 0x0e2a }, +  { 0x0dcb, 0x0e2b }, +  { 0x0dcc, 0x0e2c }, +  { 0x0dcd, 0x0e2d }, +  { 0x0dce, 0x0e2e }, +  { 0x0dcf, 0x0e2f }, +  { 0x0dd0, 0x0e30 }, +  { 0x0dd1, 0x0e31 }, +  { 0x0dd2, 0x0e32 }, +  { 0x0dd3, 0x0e33 }, +  { 0x0dd4, 0x0e34 }, +  { 0x0dd5, 0x0e35 }, +  { 0x0dd6, 0x0e36 }, +  { 0x0dd7, 0x0e37 }, +  { 0x0dd8, 0x0e38 }, +  { 0x0dd9, 0x0e39 }, +  { 0x0dda, 0x0e3a }, +  { 0x0ddf, 0x0e3f }, +  { 0x0de0, 0x0e40 }, +  { 0x0de1, 0x0e41 }, +  { 0x0de2, 0x0e42 }, +  { 0x0de3, 0x0e43 }, +  { 0x0de4, 0x0e44 }, +  { 0x0de5, 0x0e45 }, +  { 0x0de6, 0x0e46 }, +  { 0x0de7, 0x0e47 }, +  { 0x0de8, 0x0e48 }, +  { 0x0de9, 0x0e49 }, +  { 0x0dea, 0x0e4a }, +  { 0x0deb, 0x0e4b }, +  { 0x0dec, 0x0e4c }, +  { 0x0ded, 0x0e4d }, +  { 0x0df0, 0x0e50 }, +  { 0x0df1, 0x0e51 }, +  { 0x0df2, 0x0e52 }, +  { 0x0df3, 0x0e53 }, +  { 0x0df4, 0x0e54 }, +  { 0x0df5, 0x0e55 }, +  { 0x0df6, 0x0e56 }, +  { 0x0df7, 0x0e57 }, +  { 0x0df8, 0x0e58 }, +  { 0x0df9, 0x0e59 }, +  { 0x0ea1, 0x3131 }, +  { 0x0ea2, 0x3132 }, +  { 0x0ea3, 0x3133 }, +  { 0x0ea4, 0x3134 }, +  { 0x0ea5, 0x3135 }, +  { 0x0ea6, 0x3136 }, +  { 0x0ea7, 0x3137 }, +  { 0x0ea8, 0x3138 }, +  { 0x0ea9, 0x3139 }, +  { 0x0eaa, 0x313a }, +  { 0x0eab, 0x313b }, +  { 0x0eac, 0x313c }, +  { 0x0ead, 0x313d }, +  { 0x0eae, 0x313e }, +  { 0x0eaf, 0x313f }, +  { 0x0eb0, 0x3140 }, +  { 0x0eb1, 0x3141 }, +  { 0x0eb2, 0x3142 }, +  { 0x0eb3, 0x3143 }, +  { 0x0eb4, 0x3144 }, +  { 0x0eb5, 0x3145 }, +  { 0x0eb6, 0x3146 }, +  { 0x0eb7, 0x3147 }, +  { 0x0eb8, 0x3148 }, +  { 0x0eb9, 0x3149 }, +  { 0x0eba, 0x314a }, +  { 0x0ebb, 0x314b }, +  { 0x0ebc, 0x314c }, +  { 0x0ebd, 0x314d }, +  { 0x0ebe, 0x314e }, +  { 0x0ebf, 0x314f }, +  { 0x0ec0, 0x3150 }, +  { 0x0ec1, 0x3151 }, +  { 0x0ec2, 0x3152 }, +  { 0x0ec3, 0x3153 }, +  { 0x0ec4, 0x3154 }, +  { 0x0ec5, 0x3155 }, +  { 0x0ec6, 0x3156 }, +  { 0x0ec7, 0x3157 }, +  { 0x0ec8, 0x3158 }, +  { 0x0ec9, 0x3159 }, +  { 0x0eca, 0x315a }, +  { 0x0ecb, 0x315b }, +  { 0x0ecc, 0x315c }, +  { 0x0ecd, 0x315d }, +  { 0x0ece, 0x315e }, +  { 0x0ecf, 0x315f }, +  { 0x0ed0, 0x3160 }, +  { 0x0ed1, 0x3161 }, +  { 0x0ed2, 0x3162 }, +  { 0x0ed3, 0x3163 }, +  { 0x0ed4, 0x11a8 }, +  { 0x0ed5, 0x11a9 }, +  { 0x0ed6, 0x11aa }, +  { 0x0ed7, 0x11ab }, +  { 0x0ed8, 0x11ac }, +  { 0x0ed9, 0x11ad }, +  { 0x0eda, 0x11ae }, +  { 0x0edb, 0x11af }, +  { 0x0edc, 0x11b0 }, +  { 0x0edd, 0x11b1 }, +  { 0x0ede, 0x11b2 }, +  { 0x0edf, 0x11b3 }, +  { 0x0ee0, 0x11b4 }, +  { 0x0ee1, 0x11b5 }, +  { 0x0ee2, 0x11b6 }, +  { 0x0ee3, 0x11b7 }, +  { 0x0ee4, 0x11b8 }, +  { 0x0ee5, 0x11b9 }, +  { 0x0ee6, 0x11ba }, +  { 0x0ee7, 0x11bb }, +  { 0x0ee8, 0x11bc }, +  { 0x0ee9, 0x11bd }, +  { 0x0eea, 0x11be }, +  { 0x0eeb, 0x11bf }, +  { 0x0eec, 0x11c0 }, +  { 0x0eed, 0x11c1 }, +  { 0x0eee, 0x11c2 }, +  { 0x0eef, 0x316d }, +  { 0x0ef0, 0x3171 }, +  { 0x0ef1, 0x3178 }, +  { 0x0ef2, 0x317f }, +  { 0x0ef3, 0x3181 }, +  { 0x0ef4, 0x3184 }, +  { 0x0ef5, 0x3186 }, +  { 0x0ef6, 0x318d }, +  { 0x0ef7, 0x318e }, +  { 0x0ef8, 0x11eb }, +  { 0x0ef9, 0x11f0 }, +  { 0x0efa, 0x11f9 }, +  { 0x0eff, 0x20a9 }, +  { 0x13a4, 0x20ac }, +  { 0x13bc, 0x0152 }, +  { 0x13bd, 0x0153 }, +  { 0x13be, 0x0178 }, +  { 0x20ac, 0x20ac }, +  // Numeric keypad with numlock on +  { XK_KP_Space, ' ' }, +  { XK_KP_Equal, '=' }, +  { XK_KP_Multiply, '*' }, +  { XK_KP_Add, '+' }, +  { XK_KP_Separator, ',' }, +  { XK_KP_Subtract, '-' }, +  { XK_KP_Decimal, '.' }, +  { XK_KP_Divide, '/' }, +  { XK_KP_0, 0x0030 }, +  { XK_KP_1, 0x0031 }, +  { XK_KP_2, 0x0032 }, +  { XK_KP_3, 0x0033 }, +  { XK_KP_4, 0x0034 }, +  { XK_KP_5, 0x0035 }, +  { XK_KP_6, 0x0036 }, +  { XK_KP_7, 0x0037 }, +  { XK_KP_8, 0x0038 }, +  { XK_KP_9, 0x0039 } +}; + + +/** + * Convert X11 KeySym to Unicode + */ +uint32_t +bm_x11_key_sym2unicode(uint32_t keysym) +{ +    uint32_t min = 0, max = sizeof(keysymtab) / sizeof(struct codepair) - 1, mid; + +    // First check for Latin-1 characters (1:1 mapping) +    if ((keysym >= 0x0020 && keysym <= 0x007e) || (keysym >= 0x00a0 && keysym <= 0x00ff)) +        return keysym; + +    // Also check for directly encoded 24-bit UCS characters +    if ((keysym & 0xff000000) == 0x01000000) +        return keysym & 0x00ffffff; + +    // Binary search in table +    while (max >= min) { +        mid = (min + max) / 2; +        if (keysymtab[mid].keysym < keysym) +            min = mid + 1; +        else if (keysymtab[mid].keysym > keysym) +            max = mid - 1; +        else +            return keysymtab[mid].ucs; +    } + +    // No matching Unicode value found +    return 0; +} diff --git a/lib/renderers/x11/xkb_unicode.h b/lib/renderers/x11/xkb_unicode.h new file mode 100644 index 0000000..23e8b30 --- /dev/null +++ b/lib/renderers/x11/xkb_unicode.h @@ -0,0 +1,8 @@ +#ifndef _BM_XKB_UNICODE_H_ +#define _BM_XKB_UNICODE_H_ + +#include <stdint.h> + +uint32_t bm_x11_key_sym2unicode(uint32_t keysym); + +#endif // _BM_XKB_UNICODE_H_  | 
