From 5be8f190264de2d6c0eeaee9b00374bb38840b47 Mon Sep 17 00:00:00 2001 From: mallum Date: Thu, 20 Oct 2005 23:07:03 +0000 Subject: [PATCH] 2005-10-21 Matthew Allum * configure.ac: * src/Makefile.am: * src/matchbox-keyboard-ui-cairo-backend.c: * src/matchbox-keyboard-ui-cairo-backend.h: * src/matchbox-keyboard-ui-xft-backend.c: * src/matchbox-keyboard-ui-xft-backend.h: * src/matchbox-keyboard-ui.c: (mb_kbd_ui_resources_create): * src/matchbox-keyboard.h: Break out rendering backend and add optional initial cairo based rendering backend ( based on patch from Tuukka Pasanen ) * layouts/Makefile.am: * layouts/keyboard-fi.xml: Add finish layout via Tuukka Pasanen git-svn-id: https://svn.o-hand.com/repos/matchbox/trunk/matchbox-keyboard@1265 b067294f-1dea-0310-9683-c47a78595994 --- ChangeLog | 17 + configure.ac | 33 +- layouts/Makefile.am | 2 +- layouts/keyboard-fi.xml | 376 +++++++++++++++++++++++ src/Makefile.am | 19 +- src/matchbox-keyboard-ui-cairo-backend.c | 296 ++++++++++++++++++ src/matchbox-keyboard-ui-cairo-backend.h | 14 + src/matchbox-keyboard-ui-xft-backend.c | 329 ++++++++++++++++++++ src/matchbox-keyboard-ui-xft-backend.h | 12 + src/matchbox-keyboard-ui.c | 341 ++++++-------------- src/matchbox-keyboard.h | 49 ++- 11 files changed, 1237 insertions(+), 251 deletions(-) create mode 100644 layouts/keyboard-fi.xml create mode 100644 src/matchbox-keyboard-ui-cairo-backend.c create mode 100644 src/matchbox-keyboard-ui-cairo-backend.h create mode 100644 src/matchbox-keyboard-ui-xft-backend.c create mode 100644 src/matchbox-keyboard-ui-xft-backend.h diff --git a/ChangeLog b/ChangeLog index 4129932..9e4f9cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-10-21 Matthew Allum + + * configure.ac: + * src/Makefile.am: + * src/matchbox-keyboard-ui-cairo-backend.c: + * src/matchbox-keyboard-ui-cairo-backend.h: + * src/matchbox-keyboard-ui-xft-backend.c: + * src/matchbox-keyboard-ui-xft-backend.h: + * src/matchbox-keyboard-ui.c: (mb_kbd_ui_resources_create): + * src/matchbox-keyboard.h: + Break out rendering backend and add optional initial cairo + based rendering backend ( based on patch from Tuukka Pasanen ) + + * layouts/Makefile.am: + * layouts/keyboard-fi.xml: + Add finish layout via Tuukka Pasanen + 2005-10-10 Matthew Allum * src/matchbox-keyboard-ui.c: (mb_kbd_ui_event_loop): diff --git a/configure.ac b/configure.ac index 171068c..25a78a0 100644 --- a/configure.ac +++ b/configure.ac @@ -25,6 +25,15 @@ AC_FUNC_SELECT_ARGTYPES AC_TYPE_SIGNAL AC_FUNC_STAT +AC_ARG_ENABLE(debug, + [ --enable-debug enable debug ( verbose ) build], + enable_debug=$enableval, enable_debug=no ) + +AC_ARG_ENABLE(cairo, + [ --disable-cairo disable Cairo support [default=auto]], + enable_cairo=$enableval, + enable_cairo=yes) + AC_ARG_ENABLE(debug, [ --enable-debug enable debug ( verbose ) build], enable_debug=$enableval, enable_debug=no ) @@ -37,9 +46,20 @@ AC_ARG_WITH(expat-lib, [ --with-expat-lib=DIR Use Expat library in DIR], expat_lib=$withval, expat_lib=yes) +PKG_CHECK_MODULES(FAKEKEY, libfakekey,, + AC_MSG_ERROR([*** You need to install libfakekey from MB SVN ***])) + +if test x$enable_cairo = xyes; then + PKG_CHECK_MODULES(CAIRO, cairo,, [enable_cairo="no"]) +fi + +if test x$enable_cairo = xno; then +PKG_CHECK_MODULES(XFT, xft,, + AC_MSG_ERROR([*** Required xft Librarys not found ***])) +fi + +AM_CONDITIONAL(WANT_CAIRO, test x$enable_cairo = xyes) -PKG_CHECK_MODULES(LIBMB, xft libfakekey,, - AC_MSG_ERROR([*** Required Librarys not found ***])) dnl ------ Expat ------------------------------------------------------------ @@ -140,14 +160,17 @@ dnl ------ GCC flags -------------------------------------------------------- if test "x$GCC" = "xyes"; then GCC_WARNINGS="-g -Wall -fno-strict-aliasing" - LIBMB_CFLAGS="$GCC_WARNINGS $LIBMB_CFLAGS" + FAKEKEY_CFLAGS="$GCC_WARNINGS $FAKEKEY_CFLAGS" fi dnl ------ Substitute in found libs, clags to Makefiles etc ----------------- -AC_SUBST(LIBMB_CFLAGS) -AC_SUBST(LIBMB_LIBS) +AC_SUBST(FAKEKEY_CFLAGS) +AC_SUBST(FAKEKEY_LIBS) + +AC_SUBST(XFT_CFLAGS) +AC_SUBST(XFT_LIBS) AC_SUBST(EXPAT_LIBS) AC_SUBST(EXPAT_CFLAGS) diff --git a/layouts/Makefile.am b/layouts/Makefile.am index 8ceff11..1c3f542 100644 --- a/layouts/Makefile.am +++ b/layouts/Makefile.am @@ -1,3 +1,3 @@ keyboardsdir = $(datadir)/matchbox-keyboard keyboards_DATA = keyboard.xml keyboard-extended.xml keyboard-dvorak.xml \ - keyboard-ru.xml + keyboard-ru.xml keyboard-fi.xml diff --git a/layouts/keyboard-fi.xml b/layouts/keyboard-fi.xml new file mode 100644 index 0000000..f350fd2 --- /dev/null +++ b/layouts/keyboard-fi.xml @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Makefile.am b/src/Makefile.am index 69cb942..b9dbe65 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,11 +2,22 @@ PREFIXDIR = $(prefix) PKGDATADIR = $(datadir)/matchbox-keyboard DATADIR = $(datadir) -INCLUDES = -DDATADIR=\"$(DATADIR)\" -DPKGDATADIR=\"$(PKGDATADIR)\" -DPREFIX=\"$(PREFIXDIR)\" $(LIBMB_CFLAGS) $(EXPAT_CFLAGS) +BACEKND_C = \ + matchbox-keyboard-ui-xft-backend.c \ + matchbox-keyboard-ui-xft-backend.h + + +if WANT_CAIRO +BACKEND_C = \ + matchbox-keyboard-ui-cairo-backend.c \ + matchbox-keyboard-ui-cairo-backend.h +endif + +INCLUDES = -DDATADIR=\"$(DATADIR)\" -DPKGDATADIR=\"$(PKGDATADIR)\" -DPREFIX=\"$(PREFIXDIR)\" $(FAKEKEY_CFLAGS) $(XFT_CFLAGS) $(EXPAT_CFLAGS) $(CAIRO_CFLAGS) bin_PROGRAMS = matchbox-keyboard -matchbox_keyboard_LDADD = $(LIBMB_LIBS) $(EXPAT_LIBS) +matchbox_keyboard_LDADD = $(FAKEKEY_LIBS) $(XFT_LIBS) $(EXPAT_LIBS) $(CAIRO_LIBS) matchbox_keyboard_SOURCES = \ matchbox-keyboard.c matchbox-keyboard.h \ @@ -16,6 +27,6 @@ matchbox_keyboard_SOURCES = \ matchbox-keyboard-ui.c \ config-parser.c \ util-list.c \ - util.c - + util.c \ + $(BACKEND_C) diff --git a/src/matchbox-keyboard-ui-cairo-backend.c b/src/matchbox-keyboard-ui-cairo-backend.c new file mode 100644 index 0000000..157ecf6 --- /dev/null +++ b/src/matchbox-keyboard-ui-cairo-backend.c @@ -0,0 +1,296 @@ +#include "matchbox-keyboard.h" + +typedef struct MBKeyboardUIBackendCario +{ + MBKeyboardUIBackend backend; + + cairo_surface_t *surface; + cairo_t *cr; + + Pixmap foo_pxm; + +} MBKeyboardUIBackendCairo; + +static void +mb_kbd_ui_cairo_text_extents (MBKeyboardUI *ui, + const unsigned char *str, + int *width, + int *height) +{ + MBKeyboardUIBackendCairo *cairo_backend = NULL; + cairo_text_extents_t extents; + + cairo_backend = (MBKeyboardUIBackendCairo*)mb_kbd_ui_backend(ui); + + cairo_text_extents (cairo_backend->cr, str, &extents); + + *width = extents.width; + *height = extents.height; +} + +static int +mb_kbd_ui_cairo_load_font(MBKeyboardUI *ui) +{ + MBKeyboard *kb = NULL; + MBKeyboardUIBackendCairo *cairo_backend = NULL; + + cairo_backend = (MBKeyboardUIBackendCairo*)mb_kbd_ui_backend(ui); + kb = mb_kbd_ui_kbd(ui); + + /* FIXME: font weights from kb->font_variant */ + cairo_select_font_face (cairo_backend->cr, + kb->font_family, + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + + /* FIXME: Is this point size ? */ + cairo_set_font_size (cairo_backend->cr, kb->font_pt_size); + + return 1; +} + + +void +mb_kbd_ui_cairo_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key) +{ + MBKeyboardUIBackendCairo *cairo_backend = NULL; + XRectangle rect; + MBKeyboardKeyStateType state; + Display *xdpy; + int xscreen; + Pixmap backbuffer; + MBKeyboard *kbd; + + if (mb_kbd_key_is_blank(key)) /* spacer */ + return; + + cairo_backend = (MBKeyboardUIBackendCairo*)mb_kbd_ui_backend(ui); + + xdpy = mb_kbd_ui_x_display(ui); + xscreen = mb_kbd_ui_x_screen(ui); + backbuffer = mb_kbd_ui_backbuffer(ui); + kbd = mb_kbd_ui_kbd(ui); + + rect.x = mb_kbd_key_abs_x(key); + rect.y = mb_kbd_key_abs_y(key); + rect.width = mb_kbd_key_width(key); + rect.height = mb_kbd_key_height(key); + + + + /* clear it */ + + cairo_set_line_width (cairo_backend->cr, 0); + cairo_stroke( cairo_backend->cr ); + + cairo_set_source_rgb(cairo_backend->cr, 0.9, 0.9, 0.8); + + cairo_rectangle( cairo_backend->cr, + rect.x, rect.y, + rect.width, rect.height); + + cairo_fill( cairo_backend->cr ); + + /* border */ + + cairo_move_to(cairo_backend->cr, + rect.x + 1, + (mb_kbd_key_abs_y(key) + mb_kbd_key_height(key)) - 1); + + cairo_rel_line_to(cairo_backend->cr, + rect.width - 2, + 0); + + cairo_rel_line_to(cairo_backend->cr, + 0, + -rect.height); + + cairo_set_source_rgba(cairo_backend->cr, 0, 0, 0, 0.2); + + cairo_move_to(cairo_backend->cr, + rect.x, + rect.y + rect.height - 1); + + cairo_rel_line_to(cairo_backend->cr, + 0, + - rect.height); + + cairo_rel_line_to(cairo_backend->cr, + rect.width - 1, + 0); + + cairo_stroke ( cairo_backend->cr ); + + cairo_set_source_rgb(cairo_backend->cr, 0, 0, 0); + + cairo_set_line_width (cairo_backend->cr, 1); + + cairo_rectangle( cairo_backend->cr, + rect.x, rect.y, rect.width, rect.height); + + cairo_stroke(cairo_backend->cr); + + + + /* Handle state related painting */ + + state = mb_kbd_keys_current_state(kbd); + + if (mb_kbd_has_state(kbd, MBKeyboardStateCaps) + && mb_kbd_key_get_obey_caps(key)) + state = MBKeyboardKeyStateShifted; + + if (!mb_kdb_key_has_state(key, state)) + { + if (state == MBKeyboardKeyStateNormal) + return; /* keys should at least have a normal state */ + else + state = MBKeyboardKeyStateNormal; + } + + cairo_set_source_rgb(cairo_backend->cr, 0, 0, 0); + + + + if (mb_kbd_key_get_face_type(key, state) == MBKeyboardKeyFaceGlyph) + { + const unsigned char *face_str = mb_kbd_key_get_glyph_face(key, state); + + if (face_str) + { + int x, y, face_width, face_height; + + mb_kbd_ui_cairo_text_extents (ui, face_str, &face_width, &face_height); + + x = rect.x + (rect.width/2); + + y = rect.y + ( (rect.height - face_height) / 2 ); + + cairo_move_to(cairo_backend->cr, x, y); + cairo_show_text (cairo_backend->cr, face_str); + + } + } + + if ( mb_kbd_key_is_held(kbd, key) ) + { + cairo_set_source_rgba(cairo_backend->cr, + 0, + 0, + 0, + 0.2); + + cairo_rectangle(cairo_backend->cr, + rect.x, + rect.y, + rect.width, + rect.height ); + + cairo_fill( cairo_backend->cr ); + } + + + // cairo_show_page(cairo_backend->cr); + // cairo_destroy (cairo_backend->cr); + + + +} + +void +mb_kbd_ui_cairo_pre_redraw(MBKeyboardUI *ui) +{ + MBKeyboardUIBackendCairo *cairo_backend = NULL; + + cairo_backend = (MBKeyboardUIBackendCairo*)mb_kbd_ui_backend(ui); + + cairo_set_source_rgb (cairo_backend->cr, 1, 1, 1); + + cairo_rectangle( cairo_backend->cr, + 0, + 0, + mb_kbd_ui_x_win_width(ui), + mb_kbd_ui_x_win_height(ui)); + + cairo_fill( cairo_backend->cr ); + + // cairo_destroy( cairo_backend->cr ); +} + +static int +mb_kbd_ui_cairo_resources_create(MBKeyboardUI *ui) +{ + MBKeyboardUIBackendCairo *cairo_backend = NULL; + + cairo_backend = (MBKeyboardUIBackendCairo*)mb_kbd_ui_backend(ui); + + /* switch now to 'real' drawable */ + cairo_xlib_surface_set_drawable (cairo_backend->surface, + mb_kbd_ui_backbuffer(ui), + mb_kbd_ui_x_win_width(ui), + mb_kbd_ui_x_win_height(ui)); + + XFreePixmap(mb_kbd_ui_x_display(ui), cairo_backend->foo_pxm); + + cairo_xlib_surface_set_size (cairo_backend->surface, + mb_kbd_ui_x_win_width(ui), + mb_kbd_ui_x_win_height(ui)); +} + +static int +mb_kbd_ui_cairo_resize(MBKeyboardUI *ui, int width, int height) +{ + MBKeyboardUIBackendCairo *cairo_backend = NULL; + + cairo_backend = (MBKeyboardUIBackendCairo*)mb_kbd_ui_backend(ui); + + if (cairo_backend->cr != NULL) /* may get called before initialised */ + { + cairo_xlib_surface_set_size (cairo_get_target(cairo_backend->cr), + mb_kbd_ui_x_win_width(ui), + mb_kbd_ui_x_win_height(ui)); + + // cairo_destroy(cairo_backend->cr); + } +} + +MBKeyboardUIBackend* +mb_kbd_ui_cairo_init(MBKeyboardUI *ui) +{ + MBKeyboardUIBackendCairo *cairo_backend = NULL; + + cairo_backend = util_malloc0(sizeof(MBKeyboardUIBackendCairo)); + + cairo_backend->backend.init = mb_kbd_ui_cairo_init; + cairo_backend->backend.font_load = mb_kbd_ui_cairo_load_font; + cairo_backend->backend.text_extents = mb_kbd_ui_cairo_text_extents; + cairo_backend->backend.redraw_key = mb_kbd_ui_cairo_redraw_key; + cairo_backend->backend.pre_redraw = mb_kbd_ui_cairo_pre_redraw; + cairo_backend->backend.resources_create = mb_kbd_ui_cairo_resources_create; + cairo_backend->backend.resize = mb_kbd_ui_cairo_resize; + + /* We need to make a temp surface so we can make cairo + * cairo font calls ok with a context before ui knows + * its window and therefore backbuffer sizes etc. + */ + cairo_backend->foo_pxm = XCreatePixmap(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_win_root(ui), + 10, + 10, + DefaultDepth(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui))); + + cairo_backend->surface + = cairo_xlib_surface_create (mb_kbd_ui_x_display(ui), + cairo_backend->foo_pxm, + DefaultVisual(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui)), + 10, 10); + + cairo_backend->cr = cairo_create (cairo_backend->surface); + + cairo_reference(cairo_backend->cr); + + return cairo_backend; +} + diff --git a/src/matchbox-keyboard-ui-cairo-backend.h b/src/matchbox-keyboard-ui-cairo-backend.h new file mode 100644 index 0000000..de75704 --- /dev/null +++ b/src/matchbox-keyboard-ui-cairo-backend.h @@ -0,0 +1,14 @@ +#ifndef HAVE_MB_KEYBOARD_CAIRO_BACKEND_XFT_H +#define HAVE_MB_KEYBOARD_CAIRO_BACKEND_XFT_H + +#include "matchbox-keyboard.h" + +#include +#include + +MBKeyboardUIBackend* +mb_kbd_ui_cairo_init(MBKeyboardUI *ui); + +#define MB_KBD_UI_BACKEND_INIT_FUNC(ui) mb_kbd_ui_cairo_init((ui)) + +#endif diff --git a/src/matchbox-keyboard-ui-xft-backend.c b/src/matchbox-keyboard-ui-xft-backend.c new file mode 100644 index 0000000..f7c48f7 --- /dev/null +++ b/src/matchbox-keyboard-ui-xft-backend.c @@ -0,0 +1,329 @@ +#include "matchbox-keyboard.h" + +typedef struct MBKeyboardUIBackendXft +{ + MBKeyboardUIBackend backend; + + XftFont *font; + XftColor font_col; + XftDraw *xft_backbuffer; + GC xgc; + + /* Our theme */ + + XColor xcol_c5c5c5, xcol_d3d3d3, xcol_f0f0f0, xcol_f8f8f5, + xcol_f4f4f4, xcol_a4a4a4; + +} MBKeyboardUIBackendXft; + +static void +mb_kbd_ui_xft_text_extents (MBKeyboardUI *ui, + const unsigned char *str, + int *width, + int *height) +{ + XGlyphInfo extents; + MBKeyboardUIBackendXft *xft_backend = NULL; + + xft_backend = (MBKeyboardUIBackendXft*)mb_kbd_ui_backend(ui); + + XftTextExtentsUtf8(mb_kbd_ui_x_display(ui), + xft_backend->font, + str, + strlen(str), + &extents); + + *width = extents.width; + /* *height = extents.height; */ + *height = xft_backend->font->ascent + xft_backend->font->descent; +} + +void +alloc_color(MBKeyboardUI *ui, XColor *xcol, char *spec) +{ + int result; + + if (spec[0] != '#') + return; + + if ( sscanf (spec+1, "%x", &result)) + { + xcol->red = ((result >> 16) & 0xff) << 8; + xcol->green = ((result >> 8) & 0xff) << 8; + xcol->blue = (result & 0xff) << 8; + xcol->flags = DoRed|DoGreen|DoBlue; + + XAllocColor(mb_kbd_ui_x_display(ui), + DefaultColormap(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui)), + xcol); + } + + return; +} + +static int +mb_kbd_ui_xft_load_font(MBKeyboardUI *ui) +{ + MBKeyboard *kb = NULL; + char desc[512]; + MBKeyboardUIBackendXft *xft_backend = NULL; + + xft_backend = (MBKeyboardUIBackendXft*)mb_kbd_ui_backend(ui); + kb = mb_kbd_ui_kbd(ui); + + /* load_font */ + + snprintf(desc, 512, "%s-%i:%s", + kb->font_family, kb->font_pt_size, kb->font_variant); + + if (xft_backend->font != NULL) + XftFontClose(mb_kbd_ui_x_display(ui), xft_backend->font); + + if ((xft_backend->font = XftFontOpenName(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui), + desc)) == NULL) + return 0; + + return 1; +} + + +void +mb_kbd_ui_xft_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key) +{ + MBKeyboardUIBackendXft *xft_backend = NULL; + XRectangle rect; + MBKeyboardKeyStateType state; + int side_pad; + Display *xdpy; + int xscreen; + Pixmap backbuffer; + MBKeyboard *kbd; + + if (mb_kbd_key_is_blank(key)) /* spacer */ + return; + + xft_backend = (MBKeyboardUIBackendXft*)mb_kbd_ui_backend(ui); + xdpy = mb_kbd_ui_x_display(ui); + xscreen = mb_kbd_ui_x_screen(ui); + backbuffer = mb_kbd_ui_backbuffer(ui); + kbd = mb_kbd_ui_kbd(ui); + + + rect.x = mb_kbd_key_abs_x(key); + rect.y = mb_kbd_key_abs_y(key); + rect.width = mb_kbd_key_width(key); + rect.height = mb_kbd_key_height(key); + + /* clear it */ + + XSetForeground(xdpy, xft_backend->xgc, WhitePixel(xdpy, xscreen)); + + XFillRectangles(xdpy, backbuffer, xft_backend->xgc, &rect, 1); + + /* draw 'main border' */ + + XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_c5c5c5.pixel); + + XDrawRectangles(xdpy, backbuffer, xft_backend->xgc, &rect, 1); + + /* shaded bottom line */ + + XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f4f4f4.pixel); + XDrawLine(xdpy, backbuffer, xft_backend->xgc, + rect.x + 1, + rect.y + rect.height - 1, + rect.x + rect.width -2 , + rect.y + rect.height - 1); + + /* Corners - XXX should really use drawpoints */ + + XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f0f0f0.pixel); + + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y); + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y); + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+rect.height); + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+rect.height); + + /* soften them more */ + + XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_d3d3d3.pixel); + + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+1, rect.y); + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+1); + + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width-1, rect.y); + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+1); + + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width-1, rect.y+rect.height); + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+rect.height-1); + + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+rect.height-1); + XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+1, rect.y+rect.height); + + /* background */ + + if (mb_kbd_key_is_held(kbd, key)) + XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_a4a4a4.pixel); + else + XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f8f8f5.pixel); + + side_pad = + mb_kbd_keys_border(kbd) + + mb_kbd_keys_margin(kbd) + + mb_kbd_keys_pad(kbd); + + /* Why does below need +1's ? */ + XFillRectangle(xdpy, backbuffer, xft_backend->xgc, + rect.x + side_pad, + rect.y + side_pad, + rect.width - (side_pad * 2) + 1, + rect.height - (side_pad * 2) + 1); + + /* real code is here */ + + state = mb_kbd_keys_current_state(kbd); + + if (mb_kbd_has_state(kbd, MBKeyboardStateCaps) + && mb_kbd_key_get_obey_caps(key)) + state = MBKeyboardKeyStateShifted; + + if (!mb_kdb_key_has_state(key, state)) + { + if (state == MBKeyboardKeyStateNormal) + return; /* keys should at least have a normal state */ + else + state = MBKeyboardKeyStateNormal; + } + + if (mb_kbd_key_get_face_type(key, state) == MBKeyboardKeyFaceGlyph) + { + const unsigned char *face_str = mb_kbd_key_get_glyph_face(key, state); + int face_str_w, face_str_h; + + if (face_str) + { + int x, y; + + mb_kbd_ui_xft_text_extents(ui, face_str, &face_str_w, &face_str_h); + + x = mb_kbd_key_abs_x(key) + ((mb_kbd_key_width(key) - face_str_w)/2); + + y = mb_kbd_key_abs_y(key) + + ( (mb_kbd_key_height(key) - (xft_backend->font->ascent + xft_backend->font->descent)) + / 2 ); + + XftDrawStringUtf8(xft_backend->xft_backbuffer, + &xft_backend->font_col, + xft_backend->font, + x, + y + xft_backend->font->ascent, + face_str, + strlen(face_str)); + } + } +} + +void +mb_kbd_ui_xft_pre_redraw(MBKeyboardUI *ui) +{ + MBKeyboardUIBackendXft *xft_backend = NULL; + + xft_backend = (MBKeyboardUIBackendXft*)mb_kbd_ui_backend(ui); + + /* Background */ + XSetForeground(mb_kbd_ui_x_display(ui), + xft_backend->xgc, xft_backend->xcol_f4f4f4.pixel); + + XFillRectangle(mb_kbd_ui_x_display(ui), + mb_kbd_ui_backbuffer(ui), + xft_backend->xgc, + 0, 0, + mb_kbd_ui_x_win_width(ui), + mb_kbd_ui_x_win_height(ui)); + + XSetForeground(mb_kbd_ui_x_display(ui), + xft_backend->xgc, + BlackPixel(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui))); + + +} + +static int +mb_kbd_ui_xft_resources_create(MBKeyboardUI *ui) +{ + MBKeyboardUIBackendXft *xft_backend = NULL; + XRenderColor coltmp; + + xft_backend = (MBKeyboardUIBackendXft*)mb_kbd_ui_backend(ui); + + xft_backend->xft_backbuffer = XftDrawCreate(mb_kbd_ui_x_display(ui), + mb_kbd_ui_backbuffer(ui), + DefaultVisual(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui)), + DefaultColormap(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui))); + + + coltmp.red = coltmp.green = coltmp.blue = 0x0000; coltmp.alpha = 0xcccc; + + XftColorAllocValue(mb_kbd_ui_x_display(ui), + DefaultVisual(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui)), + DefaultColormap(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_screen(ui)), + &coltmp, + &xft_backend->font_col); + + xft_backend->xgc = XCreateGC(mb_kbd_ui_x_display(ui), + mb_kbd_ui_x_win(ui), 0, NULL); + + XSetForeground(mb_kbd_ui_x_display(ui), + xft_backend->xgc, + BlackPixel(mb_kbd_ui_x_display(ui), mb_kbd_ui_x_screen(ui))); + + XSetBackground(mb_kbd_ui_x_display(ui), + xft_backend->xgc, + WhitePixel(mb_kbd_ui_x_display(ui), mb_kbd_ui_x_screen(ui))); + + /* Crusty theme stuff */ + + alloc_color(ui, &xft_backend->xcol_c5c5c5, "#c5c5c5"); + alloc_color(ui, &xft_backend->xcol_d3d3d3, "#d3d3d3"); + alloc_color(ui, &xft_backend->xcol_f0f0f0, "#f0f0f0"); + alloc_color(ui, &xft_backend->xcol_f8f8f5, "#f8f8f5"); + alloc_color(ui, &xft_backend->xcol_f4f4f4, "#f4f4f4"); + alloc_color(ui, &xft_backend->xcol_a4a4a4, "#a4a4a4"); + +} + +static int +mb_kbd_ui_xft_resize(MBKeyboardUI *ui, int width, int height) +{ + MBKeyboardUIBackendXft *xft_backend = NULL; + + xft_backend = (MBKeyboardUIBackendXft*)mb_kbd_ui_backend(ui); + + XftDrawChange (xft_backend->xft_backbuffer, mb_kbd_ui_backbuffer(ui)); +} + +MBKeyboardUIBackend* +mb_kbd_ui_xft_init(MBKeyboardUI *ui) +{ + MBKeyboardUIBackendXft *xft_backend = NULL; + + xft_backend = util_malloc0(sizeof(MBKeyboardUIBackendXft)); + + xft_backend->backend.init = mb_kbd_ui_xft_init; + xft_backend->backend.font_load = mb_kbd_ui_xft_load_font; + xft_backend->backend.text_extents = mb_kbd_ui_xft_text_extents; + xft_backend->backend.redraw_key = mb_kbd_ui_xft_redraw_key; + xft_backend->backend.pre_redraw = mb_kbd_ui_xft_pre_redraw; + xft_backend->backend.resources_create = mb_kbd_ui_xft_resources_create; + xft_backend->backend.resize = mb_kbd_ui_xft_resize; + + return xft_backend; +} + diff --git a/src/matchbox-keyboard-ui-xft-backend.h b/src/matchbox-keyboard-ui-xft-backend.h new file mode 100644 index 0000000..0d9172e --- /dev/null +++ b/src/matchbox-keyboard-ui-xft-backend.h @@ -0,0 +1,12 @@ +#ifndef HAVE_MB_KEYBOARD_UI_BACKEND_XFT_H +#define HAVE_MB_KEYBOARD_UI_BACKEND_XFT_H + +#include "matchbox-keyboard.h" +#include + +MBKeyboardUIBackend* +mb_kbd_ui_xft_init(MBKeyboardUI *ui); + +#define MB_KBD_UI_BACKEND_INIT_FUNC(ui) mb_kbd_ui_xft_init((ui)) + +#endif diff --git a/src/matchbox-keyboard-ui.c b/src/matchbox-keyboard-ui.c index 3661378..c6f5feb 100644 --- a/src/matchbox-keyboard-ui.c +++ b/src/matchbox-keyboard-ui.c @@ -1,6 +1,6 @@ #include "matchbox-keyboard.h" -#include + #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 #define MWM_HINTS_DECORATIONS (1L << 1) @@ -16,6 +16,8 @@ typedef struct } PropMotifWmHints; + + struct MBKeyboardUI { Display *xdpy; @@ -25,20 +27,11 @@ struct MBKeyboardUI int dpy_width; int dpy_height; - XftFont *font; - XftColor font_col; - int xwin_width; int xwin_height; - XftDraw *xft_backbuffer; - Pixmap backbuffer; - GC xgc; - - /* Crusty temp theme stuff */ - XColor xcol_c5c5c5, xcol_d3d3d3, xcol_f0f0f0, xcol_f8f8f5, - xcol_f4f4f4, xcol_a4a4a4; + Pixmap backbuffer; /************************* */ @@ -47,9 +40,9 @@ struct MBKeyboardUI int base_alloc_width, base_alloc_height; int base_font_pt_size; - FakeKey *fakekey; - - MBKeyboard *kbd; + FakeKey *fakekey; + MBKeyboardUIBackend *backend; + MBKeyboard *kbd; }; static void @@ -58,45 +51,6 @@ mb_kbd_ui_resize(MBKeyboardUI *ui, int width, int height); static int mb_kbd_ui_load_font(MBKeyboardUI *ui); -static void -text_extents(MBKeyboardUI *ui, - const unsigned char *str, - int *width, - int *height) -{ - XGlyphInfo extents; - - XftTextExtentsUtf8(ui->xdpy, - ui->font, - str, - strlen(str), - &extents); - - *width = extents.width; - /* *height = extents.height; */ - *height = ui->font->ascent + ui->font->descent; -} - -void -alloc_color(MBKeyboardUI *ui, XColor *xcol, char *spec) -{ - int result; - - if (spec[0] != '#') - return; - - if ( sscanf (spec+1, "%x", &result)) - { - xcol->red = ((result >> 16) & 0xff) << 8; - xcol->green = ((result >> 8) & 0xff) << 8; - xcol->blue = (result & 0xff) << 8; - xcol->flags = DoRed|DoGreen|DoBlue; - - XAllocColor(ui->xdpy, DefaultColormap(ui->xdpy, ui->xscreen), xcol); - } - - return; -} static unsigned char* get_current_window_manager_name (MBKeyboardUI *ui) @@ -290,7 +244,7 @@ mb_kdb_ui_unit_key_size(MBKeyboardUI *ui, int *width, int *height) { int str_w =0, str_h = 0; - text_extents(ui, face_str, &str_w, &str_h); + ui->backend->text_extents(ui, face_str, &str_w, &str_h); if (str_w > *width) *width = str_w; if (str_h > *height) *height = str_h; @@ -332,7 +286,7 @@ mb_kbd_ui_min_key_size(MBKeyboardUI *ui, face_str = mb_kbd_key_get_glyph_face(key, state); - text_extents(ui, face_str, width, height); + ui->backend->text_extents(ui, face_str, width, height); if (*width < max_w) *width = max_w; if (*height < max_h) *height = max_h; @@ -527,126 +481,7 @@ mb_kbd_ui_allocate_ui_layout(MBKeyboardUI *ui, void mb_kbd_ui_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key) { - XRectangle rect; - MBKeyboardKeyStateType state; - int side_pad; - - if (mb_kbd_key_is_blank(key)) /* spacer */ - return; - - rect.x = mb_kbd_key_abs_x(key); - rect.y = mb_kbd_key_abs_y(key); - rect.width = mb_kbd_key_width(key); - rect.height = mb_kbd_key_height(key); - - /* clear it */ - - XSetForeground(ui->xdpy, ui->xgc, WhitePixel(ui->xdpy, ui->xscreen )); - - XFillRectangles(ui->xdpy, ui->backbuffer, ui->xgc, &rect, 1); - - /* draw 'main border' */ - - XSetForeground(ui->xdpy, ui->xgc, ui->xcol_c5c5c5.pixel); - - XDrawRectangles(ui->xdpy, ui->backbuffer, ui->xgc, &rect, 1); - - /* shaded bottom line */ - - XSetForeground(ui->xdpy, ui->xgc, ui->xcol_f4f4f4.pixel); - XDrawLine(ui->xdpy, ui->backbuffer, ui->xgc, - rect.x + 1, - rect.y + rect.height - 1, - rect.x + rect.width -2 , - rect.y + rect.height - 1); - - /* Corners - XXX should really use drawpoints */ - - XSetForeground(ui->xdpy, ui->xgc, ui->xcol_f0f0f0.pixel); - - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x, rect.y); - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x+rect.width, rect.y); - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x+rect.width, rect.y+rect.height); - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x, rect.y+rect.height); - - /* soften them more */ - - XSetForeground(ui->xdpy, ui->xgc, ui->xcol_d3d3d3.pixel); - - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x+1, rect.y); - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x, rect.y+1); - - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x+rect.width-1, rect.y); - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x+rect.width, rect.y+1); - - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x+rect.width-1, rect.y+rect.height); - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x+rect.width, rect.y+rect.height-1); - - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x, rect.y+rect.height-1); - XDrawPoint(ui->xdpy, ui->backbuffer, ui->xgc, rect.x+1, rect.y+rect.height); - - /* background */ - - if (mb_kbd_key_is_held(ui->kbd, key)) - XSetForeground(ui->xdpy, ui->xgc, ui->xcol_a4a4a4.pixel); - else - XSetForeground(ui->xdpy, ui->xgc, ui->xcol_f8f8f5.pixel); - - side_pad = - mb_kbd_keys_border(ui->kbd) - + mb_kbd_keys_margin(ui->kbd) - + mb_kbd_keys_pad(ui->kbd); - - /* Why does below need +1's ? */ - XFillRectangle(ui->xdpy, ui->backbuffer, ui->xgc, - rect.x + side_pad, - rect.y + side_pad, - rect.width - (side_pad * 2) + 1, - rect.height - (side_pad * 2) + 1); - - /* real code is here */ - - state = mb_kbd_keys_current_state(ui->kbd); - - if (mb_kbd_has_state(ui->kbd, MBKeyboardStateCaps) - && mb_kbd_key_get_obey_caps(key)) - state = MBKeyboardKeyStateShifted; - - if (!mb_kdb_key_has_state(key, state)) - { - if (state == MBKeyboardKeyStateNormal) - return; /* keys should at least have a normal state */ - else - state = MBKeyboardKeyStateNormal; - } - - if (mb_kbd_key_get_face_type(key, state) == MBKeyboardKeyFaceGlyph) - { - const unsigned char *face_str = mb_kbd_key_get_glyph_face(key, state); - int face_str_w, face_str_h; - - if (face_str) - { - int x, y; - - text_extents(ui, face_str, &face_str_w, &face_str_h); - - x = mb_kbd_key_abs_x(key) + ((mb_kbd_key_width(key) - face_str_w)/2); - - y = mb_kbd_key_abs_y(key) + - ( (mb_kbd_key_height(key) - (ui->font->ascent + ui->font->descent)) - / 2 ); - - XftDrawStringUtf8(ui->xft_backbuffer, - &ui->font_col, - ui->font, - x, - y + ui->font->ascent, - face_str, - strlen(face_str)); - } - } - + ui->backend->redraw_key(ui, key); } @@ -655,7 +490,7 @@ mb_kbd_ui_redraw_row(MBKeyboardUI *ui, MBKeyboardRow *row) { List *key_item; - mb_kbd_row_for_each_key(row,key_item) + mb_kbd_row_for_each_key(row, key_item) { if (!mb_kbd_is_extended(ui->kbd) && mb_kbd_key_get_extended(key_item->data)) @@ -678,11 +513,8 @@ mb_kbd_ui_redraw(MBKeyboardUI *ui) List *row_item; MBKeyboardLayout *layout; - /* Background */ - XSetForeground(ui->xdpy, ui->xgc, ui->xcol_f4f4f4.pixel); - XFillRectangle(ui->xdpy, ui->backbuffer, ui->xgc, - 0, 0, ui->xwin_width, ui->xwin_height); - XSetForeground(ui->xdpy, ui->xgc, BlackPixel(ui->xdpy, ui->xscreen )); + /* gives backend a chance to clear everything */ + ui->backend->pre_redraw(ui); layout = mb_kbd_get_selected_layout(ui->kbd); @@ -739,7 +571,7 @@ mb_kbd_ui_resources_create(MBKeyboardUI *ui) XSizeHints size_hints; XWMHints *wm_hints; XSetWindowAttributes win_attr; - XRenderColor coltmp; + unsigned char *wm_name; boolean have_matchbox_wm = False; @@ -913,38 +745,14 @@ mb_kbd_ui_resources_create(MBKeyboardUI *ui) ui->xwin_height, DefaultDepth(ui->xdpy, ui->xscreen)); - ui->xft_backbuffer = XftDrawCreate(ui->xdpy, - ui->backbuffer, - DefaultVisual(ui->xdpy, ui->xscreen), - DefaultColormap(ui->xdpy, ui->xscreen)); - - /* #636262 - for text maybe */ - coltmp.red = coltmp.green = coltmp.blue = 0x0000; coltmp.alpha = 0xcccc; + XSetWindowBackgroundPixmap(ui->xdpy, + ui->xwin, + ui->backbuffer); - XftColorAllocValue(ui->xdpy, - DefaultVisual(ui->xdpy, ui->xscreen), - DefaultColormap(ui->xdpy, ui->xscreen), - &coltmp, - &ui->font_col); + ui->backend->resources_create(ui); - ui->xgc = XCreateGC(ui->xdpy, ui->xwin, 0, NULL); - - XSetForeground(ui->xdpy, ui->xgc, BlackPixel(ui->xdpy, ui->xscreen )); - XSetBackground(ui->xdpy, ui->xgc, WhitePixel(ui->xdpy, ui->xscreen )); - - XSetWindowBackgroundPixmap(ui->xdpy, ui->xwin, ui->backbuffer); - - /* Crusty theme stuff */ - - alloc_color(ui, &ui->xcol_c5c5c5, "#c5c5c5"); - alloc_color(ui, &ui->xcol_d3d3d3, "#d3d3d3"); - alloc_color(ui, &ui->xcol_f0f0f0, "#f0f0f0"); - alloc_color(ui, &ui->xcol_f8f8f5, "#f8f8f5"); - alloc_color(ui, &ui->xcol_f4f4f4, "#f4f4f4"); - alloc_color(ui, &ui->xcol_a4a4a4, "#a4a4a4"); - /* Get root size change events for rotation */ /* XSelectInput(ui->xdpy, ui->xwin_root, StructureNotifyMask); */ @@ -1139,6 +947,10 @@ mb_kbd_ui_resize(MBKeyboardUI *ui, int width, int height) ui->xwin_width = width; ui->xwin_height = height; + + + /* */ + if (ui->backbuffer) /* may get called before initialised */ { XFreePixmap(ui->xdpy, ui->backbuffer); @@ -1148,12 +960,14 @@ mb_kbd_ui_resize(MBKeyboardUI *ui, int width, int height) ui->xwin_height, DefaultDepth(ui->xdpy, ui->xscreen)); - XftDrawChange (ui->xft_backbuffer, ui->backbuffer); + ui->backend->resize(ui, width, height); XSetWindowBackgroundPixmap(ui->xdpy, ui->xwin, ui->backbuffer); mb_kbd_ui_redraw(ui); } + + } void @@ -1264,56 +1078,78 @@ mb_kbd_ui_event_loop(MBKeyboardUI *ui) static int mb_kbd_ui_load_font(MBKeyboardUI *ui) { - MBKeyboard *kb = ui->kbd; - char desc[512]; - - snprintf(desc, 512, "%s-%i:%s", - kb->font_family, kb->font_pt_size, kb->font_variant); + return ui->backend->font_load(ui); +} - if (ui->font != NULL) - XftFontClose(ui->xdpy, ui->font); - if ((ui->font = XftFontOpenName(ui->xdpy, ui->xscreen, desc)) == NULL) - return 0; - - return 1; +int +mb_kbd_ui_display_width(MBKeyboardUI *ui) +{ + return ui->dpy_width; } int -mb_kbd_ui_init(MBKeyboard *kbd) +mb_kbd_ui_display_height(MBKeyboardUI *ui) { - MBKeyboardUI *ui = NULL; - - ui = kbd->ui = util_malloc0(sizeof(MBKeyboardUI)); - - ui->kbd = kbd; + return ui->dpy_height; +} - if ((ui->xdpy = XOpenDisplay(getenv("DISPLAY"))) == NULL) - return 0; +MBKeyboardUIBackend* +mb_kbd_ui_backend(MBKeyboardUI *ui) +{ + return ui->backend; +} - if ((ui->fakekey = fakekey_init(ui->xdpy)) == NULL) - return 0; +Display* +mb_kbd_ui_x_display(MBKeyboardUI *ui) +{ + return ui->xdpy; +} - ui->xscreen = DefaultScreen(ui->xdpy); - ui->xwin_root = RootWindow(ui->xdpy, ui->xscreen); +int +mb_kbd_ui_x_screen(MBKeyboardUI *ui) +{ + return ui->xscreen; +} - update_display_size(ui); +Window +mb_kbd_ui_x_win(MBKeyboardUI *ui) +{ + return ui->xwin; +} - return 1; +Window +mb_kbd_ui_x_win_root(MBKeyboardUI *ui) +{ + return ui->xwin_root; } int -mb_kbd_ui_display_width(MBKeyboardUI *ui) +mb_kbd_ui_x_win_height(MBKeyboardUI *ui) { - return ui->dpy_width; + return ui->xwin_height; } int -mb_kbd_ui_display_height(MBKeyboardUI *ui) +mb_kbd_ui_x_win_width(MBKeyboardUI *ui) { - return ui->dpy_height; + return ui->xwin_width; +} + + +Pixmap +mb_kbd_ui_backbuffer(MBKeyboardUI *ui) +{ + return ui->backbuffer; +} + +MBKeyboard* +mb_kbd_ui_kbd(MBKeyboardUI *ui) +{ + return ui->kbd; } + int mb_kbd_ui_realize(MBKeyboardUI *ui) { @@ -1340,3 +1176,28 @@ mb_kbd_ui_realize(MBKeyboardUI *ui) return 1; } + +int +mb_kbd_ui_init(MBKeyboard *kbd) +{ + MBKeyboardUI *ui = NULL; + + ui = kbd->ui = util_malloc0(sizeof(MBKeyboardUI)); + + ui->kbd = kbd; + + if ((ui->xdpy = XOpenDisplay(getenv("DISPLAY"))) == NULL) + return 0; + + if ((ui->fakekey = fakekey_init(ui->xdpy)) == NULL) + return 0; + + ui->xscreen = DefaultScreen(ui->xdpy); + ui->xwin_root = RootWindow(ui->xdpy, ui->xscreen); + + ui->backend = MB_KBD_UI_BACKEND_INIT_FUNC(ui); + + update_display_size(ui); + + return 1; +} diff --git a/src/matchbox-keyboard.h b/src/matchbox-keyboard.h index 1692f43..e3bf39d 100644 --- a/src/matchbox-keyboard.h +++ b/src/matchbox-keyboard.h @@ -56,6 +56,7 @@ typedef struct MBKeyboardLayout MBKeyboardLayout; typedef struct MBKeyboardRow MBKeyboardRow; typedef struct MBKeyboardKey MBKeyboardKey; typedef struct MBKeyboardUI MBKeyboardUI; +typedef struct MBKeyboardUIBackend MBKeyboardUIBackend; typedef enum { @@ -137,6 +138,20 @@ struct MBKeyboard /**** UI ***********/ +struct MBKeyboardUIBackend +{ + MBKeyboardUIBackend* (*init) (MBKeyboardUI *ui); + int (*font_load) (MBKeyboardUI *ui); + void (*redraw_key) (MBKeyboardUI *ui, MBKeyboardKey *key); + void (*pre_redraw) (MBKeyboardUI *ui); + int (*resources_create) (MBKeyboardUI *ui); + int (*resize) (MBKeyboardUI *ui, int width, int height); + void (*text_extents) (MBKeyboardUI *ui, + const unsigned char *str, + int *width, + int *height); +}; + int mb_kbd_ui_init(MBKeyboard *kbd); @@ -171,6 +186,33 @@ mb_kbd_ui_display_width(MBKeyboardUI *ui); int mb_kbd_ui_display_height(MBKeyboardUI *ui); +MBKeyboardUIBackend* +mb_kbd_ui_backend(MBKeyboardUI *ui); + +Display* +mb_kbd_ui_x_display(MBKeyboardUI *ui); + +int +mb_kbd_ui_x_screen(MBKeyboardUI *ui); + +Window +mb_kbd_ui_x_win(MBKeyboardUI *ui); + +int +mb_kbd_ui_x_win_height(MBKeyboardUI *ui); + +int +mb_kbd_ui_x_win_width(MBKeyboardUI *ui); + +Window +mb_kbd_ui_x_win_root(MBKeyboardUI *ui); + +Pixmap +mb_kbd_ui_backbuffer(MBKeyboardUI *ui); + +MBKeyboard* +mb_kbd_ui_kbd(MBKeyboardUI *ui); + void mb_kbd_ui_event_loop(MBKeyboardUI *ui); @@ -475,7 +517,12 @@ util_list_append(List *list, void *data); void util_list_foreach(List *list, ListForEachCB func, void *userdata); -/* util pixbuf */ +/* Backends */ +#if 1 +#include "matchbox-keyboard-ui-cairo-backend.h" +#else +#include "matchbox-keyboard-ui-xft-backend.h" +#endif #endif