aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AUTHORS2
-rw-r--r--ChangeLog51
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac32
-rw-r--r--examples/Makefile.am8
-rw-r--r--examples/matchbox-keyboard-embbed.c153
-rw-r--r--src/Makefile.am13
-rw-r--r--src/config-parser.c26
-rw-r--r--src/matchbox-keyboard-key.c35
-rw-r--r--src/matchbox-keyboard-layout.c19
-rw-r--r--src/matchbox-keyboard-row.c19
-rw-r--r--src/matchbox-keyboard-ui-cairo-backend.c108
-rw-r--r--src/matchbox-keyboard-ui-cairo-backend.h19
-rw-r--r--src/matchbox-keyboard-ui-xft-backend.c34
-rw-r--r--src/matchbox-keyboard-ui-xft-backend.h19
-rw-r--r--src/matchbox-keyboard-ui.c263
-rw-r--r--src/matchbox-keyboard-xembed.c172
-rw-r--r--src/matchbox-keyboard.c34
-rw-r--r--src/matchbox-keyboard.h70
-rw-r--r--src/util.c32
20 files changed, 926 insertions, 187 deletions
diff --git a/AUTHORS b/AUTHORS
index e69de29..d73e0c6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Matthew Allum <mallum@o-hand.com> ( Most stuff )
+Tuukka Pasanen <tuukka.pasanen@ilmi.fi> ( Cairo work, initial -xid work )
diff --git a/ChangeLog b/ChangeLog
index 9e4f9cc..94cdf89 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,54 @@
+2005-10-26 Matthew Allum <mallum@openedhand.com>
+
+ * AUTHORS:
+ Populate.
+ * Makefile.am:
+ * configure.ac:
+ * src/Makefile.am:
+ Fix cairo build issues,
+
+ * src/matchbox-keyboard-xembed.c:
+ Add XEMBED support for embedding keyboard in other apps.
+
+ * examples/Makefile.am:
+ * examples/matchbox-keyboard-embbed.c:
+ Add example embedding app
+
+ * src/config-parser.c: (config_str_to_keysym),
+ (config_str_to_modtype), (config_xml_start_cb):
+ * src/matchbox-keyboard-key.c: (mb_kbd_key_get_extended),
+ (mb_kbd_key_set_row), (mb_kdb_key_has_state),
+ (mb_kbd_key_set_glyph_face), (mb_kbd_key_get_glyph_face),
+ (mb_kbd_key_set_image_face), (mb_kbd_key_set_char_action),
+ (mb_kbd_key_press):
+ * src/matchbox-keyboard-layout.c:
+ * src/matchbox-keyboard-row.c:
+ * src/matchbox-keyboard-ui-cairo-backend.c:
+ (mb_kbd_ui_cairo_text_extents), (mb_kbd_ui_cairo_load_font),
+ (mb_kbd_ui_cairo_redraw_key), (mb_kbd_ui_cairo_pre_redraw),
+ (mb_kbd_ui_cairo_resources_create), (mb_kbd_ui_cairo_resize),
+ (mb_kbd_ui_cairo_init):
+ * src/matchbox-keyboard-ui-cairo-backend.h:
+ * src/matchbox-keyboard-ui-xft-backend.c:
+ (mb_kbd_ui_xft_text_extents), (mb_kbd_ui_xft_redraw_key),
+ (mb_kbd_ui_xft_resources_create), (mb_kbd_ui_xft_resize),
+ (mb_kbd_ui_xft_init):
+ * src/matchbox-keyboard-ui-xft-backend.h:
+ * src/matchbox-keyboard-ui.c: (get_current_window_manager_name),
+ (get_desktop_area), (get_xevent_timed),
+ (mb_kbd_ui_send_keysym_press), (mb_kbd_ui_send_release),
+ (mb_kdb_ui_unit_key_size), (mb_kbd_ui_min_key_size),
+ (mb_kbd_ui_redraw_row), (mb_kbd_ui_swap_buffers),
+ (mb_kbd_ui_redraw), (mb_kbd_ui_resources_create),
+ (mb_kbd_ui_resize), (mb_kbd_ui_event_loop), (mb_kbd_ui_realize),
+ (mb_kbd_ui_init):
+ * src/matchbox-keyboard.c: (mb_kbd_new):
+ * src/matchbox-keyboard.h:
+ * src/util.c: (util_utf8_char_cnt), (util_file_readable):
+ Fix GCC 4 Warnings.
+ Add License to all files.
+ Improve buggy cairo backend and add gradient keys
+
2005-10-21 Matthew Allum <mallum@openedhand.com>
* configure.ac:
diff --git a/Makefile.am b/Makefile.am
index ce262f1..145939c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,9 @@
SUBDIRS = src layouts
+if WANT_EXAMPLES
+SUBDIRS += examples
+endif
+
EXTRA_DIST = matchbox-keyboard.desktop matchbox-keyboard.png
desktopdir = $(datadir)/applications/inputmethods
diff --git a/configure.ac b/configure.ac
index 25a78a0..e18d1d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,15 +25,16 @@ 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]],
+ [ --disable-cairo disable Cairo support [default=auto]],
enable_cairo=$enableval,
enable_cairo=yes)
+AC_ARG_ENABLE(examples,
+ [ --enable-examples Build embedding examples ( requires GTK ) [default=no]],
+ enable_examples=$enableval,
+ enable_examples=no)
+
AC_ARG_ENABLE(debug,
[ --enable-debug enable debug ( verbose ) build],
enable_debug=$enableval, enable_debug=no )
@@ -60,6 +61,15 @@ fi
AM_CONDITIONAL(WANT_CAIRO, test x$enable_cairo = xyes)
+if test x$enable_cairo = xyes; then
+ AC_DEFINE_UNQUOTED(WANT_CAIRO, 1, [Use Cairo to paint libs])
+fi
+
+if test x$enable_examples = xyes; then
+ PKG_CHECK_MODULES(GTK2, gtk+-2.0,, [enable_examples="no"])
+fi
+
+AM_CONDITIONAL(WANT_EXAMPLES, test x$enable_examples = xyes)
dnl ------ Expat ------------------------------------------------------------
@@ -175,11 +185,11 @@ AC_SUBST(XFT_LIBS)
AC_SUBST(EXPAT_LIBS)
AC_SUBST(EXPAT_CFLAGS)
-
AC_OUTPUT([
Makefile
src/Makefile
layouts/Makefile
+examples/Makefile
])
dnl ==========================================================================
@@ -187,9 +197,11 @@ echo "
Matchbox-keyboard $VERSION
=========================
- prefix: ${prefix}
- source code location: ${srcdir}
- compiler: ${CC}
+ prefix: ${prefix}
+ source code location: ${srcdir}
+ compiler: ${CC}
- Building with Debug: ${enable_debug}
+ Building with Debug: ${enable_debug}
+ Building with Cairo: ${enable_cairo}
+ Building Examples: ${enable_examples}
" \ No newline at end of file
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..a6e040e
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,8 @@
+PREFIXDIR = $(prefix)
+
+INCLUDES = -DAPPDIR=\"$(top_builddir)/src\" $(GTK2_CFLAGS)
+
+noinst_PROGRAMS = matchbox-keyboard-gtk-embed
+
+matchbox_keyboard_gtk_embed_SOURCES=matchbox-keyboard-embbed.c
+matchbox_keyboard_gtk_embed_LDADD=$(GTK2_LIBS) \ No newline at end of file
diff --git a/examples/matchbox-keyboard-embbed.c b/examples/matchbox-keyboard-embbed.c
new file mode 100644
index 0000000..cbebe09
--- /dev/null
+++ b/examples/matchbox-keyboard-embbed.c
@@ -0,0 +1,153 @@
+#include <gtk/gtk.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+GtkWidget *m_layout;
+static const char *m_kbd_path = "/usr/local/bin/matchbox-keyboard";
+static const char *m_kbd_str;
+static guint m_kbd_xid;
+static guint m_kbd_pid;
+
+void
+cleanup_children(int s)
+{
+ kill(-getpid(), 15); /* kill every one in our process group */
+ exit(0);
+}
+
+void
+install_signal_handlers(void)
+{
+ signal (SIGCHLD, SIG_IGN); /* kernel can deal with zombies */
+ signal (SIGINT, cleanup_children);
+ signal (SIGQUIT, cleanup_children);
+ signal (SIGTERM, cleanup_children);
+}
+
+unsigned long
+launch_keyboard(void)
+{
+ int i = 0, fd[2];
+ int stdout_pipe[2];
+ int stdin_pipe[2];
+ char buf[256], c;
+ size_t n;
+
+ unsigned long result;
+
+ printf("Launching keyboard from: %s\r\n",m_kbd_path);
+
+ pipe (stdout_pipe);
+ pipe (stdin_pipe);
+
+ switch (fork ())
+ {
+ case 0:
+ {
+ /* Close the Child process' STDOUT */
+ close(1);
+ dup(stdout_pipe[1]);
+ close(stdout_pipe[0]);
+ close(stdout_pipe[1]);
+
+ execlp ("/bin/sh", "sh", "-c", "matchbox-keyboard --xid", NULL);
+ }
+ case -1:
+ perror ("### Failed to launch 'matchbox-keyboard --xid', is it installed? ### ");
+ exit(1);
+ }
+
+ /* Parent */
+
+ /* Close the write end of STDOUT */
+ close(stdout_pipe[1]);
+
+ /* FIXME: This could be a little safer... */
+ do
+ {
+ n = read(stdout_pipe[0], &c, 1);
+ if (n == 0 || c == '\n')
+ break;
+ buf[i++] = c;
+ }
+ while (i < 256);
+
+ buf[i] = '\0';
+ result = atol (buf);
+
+ close(stdout_pipe[0]);
+
+ return result;
+}
+
+
+void widget_destroy( GtkWidget *widget,
+ gpointer data )
+{
+ gtk_widget_destroy(widget);
+ gtk_widget_destroy(m_layout);
+ gtk_main_quit ();
+}
+
+
+int main(int argc, char **argv)
+{
+ GtkWidget *window, *button, *textview, *vbox;
+ GtkWidget *socket, *plug, *socket_box;
+
+ unsigned long kb_xid;
+
+ gtk_init (&argc, &argv);
+
+ install_signal_handlers();
+
+ kb_xid = launch_keyboard();
+
+ if (!kb_xid)
+ {
+ perror ("### 'matchbox-keyboard --xid', failed to return valid window ID. ### ");
+ exit(-1);
+ }
+
+ /* Window */
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 10);
+
+ g_signal_connect (G_OBJECT (window), "destroy",
+ G_CALLBACK (widget_destroy), NULL);
+
+ /* Container and textview */
+
+ vbox = gtk_vbox_new(FALSE, 5);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ textview = gtk_text_view_new();
+ gtk_box_pack_start (GTK_BOX(vbox), textview, TRUE, TRUE, 2);
+
+ /* Socket ( XEMBED ) stuff */
+
+ socket_box = gtk_event_box_new ();
+ gtk_widget_show (socket_box);
+
+ socket = gtk_socket_new ();
+
+ gtk_container_add (GTK_CONTAINER (socket_box), socket);
+ gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET(socket_box), TRUE, TRUE, 0);
+ gtk_socket_add_id(GTK_SOCKET(socket), kb_xid);
+
+ /* FIXME: handle "plug-added" & "plug-removed" signals for socket */
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+
+ return 0;
+}
+
diff --git a/src/Makefile.am b/src/Makefile.am
index b9dbe65..9774264 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,15 +2,15 @@ PREFIXDIR = $(prefix)
PKGDATADIR = $(datadir)/matchbox-keyboard
DATADIR = $(datadir)
-BACEKND_C = \
- matchbox-keyboard-ui-xft-backend.c \
- matchbox-keyboard-ui-xft-backend.h
-
if WANT_CAIRO
-BACKEND_C = \
+CAIRO_BACKEND_C = \
matchbox-keyboard-ui-cairo-backend.c \
matchbox-keyboard-ui-cairo-backend.h
+else
+XFT_BACKEND_C = \
+ matchbox-keyboard-ui-xft-backend.c \
+ matchbox-keyboard-ui-xft-backend.h
endif
INCLUDES = -DDATADIR=\"$(DATADIR)\" -DPKGDATADIR=\"$(PKGDATADIR)\" -DPREFIX=\"$(PREFIXDIR)\" $(FAKEKEY_CFLAGS) $(XFT_CFLAGS) $(EXPAT_CFLAGS) $(CAIRO_CFLAGS)
@@ -25,8 +25,9 @@ matchbox_keyboard_SOURCES = \
matchbox-keyboard-row.c \
matchbox-keyboard-key.c \
matchbox-keyboard-ui.c \
+ matchbox-keyboard-xembed.c \
config-parser.c \
util-list.c \
util.c \
- $(BACKEND_C)
+ $(XFT_BACKEND_C) $(CAIRO_BACKEND_C)
diff --git a/src/config-parser.c b/src/config-parser.c
index fa1a9eb..1b4d877 100644
--- a/src/config-parser.c
+++ b/src/config-parser.c
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#include "matchbox-keyboard.h"
/*
@@ -140,13 +159,12 @@ config_str_to_modtype(const char* str)
}
-static unsigned char*
+static char*
config_load_file(MBKeyboard *kbd, char *variant_in)
{
struct stat stat_info;
FILE* fp;
- unsigned char* result;
-
+ char *result;
char *country = NULL;
char *variant = NULL;
char *lang = NULL;
@@ -508,7 +526,7 @@ config_xml_start_cb(void *data, const char *tag, const char **attr)
int
mb_kbd_config_load(MBKeyboard *kbd, char *variant)
{
- unsigned char *data;
+ char *data;
XML_Parser p;
MBKeyboardConfigState *state;
diff --git a/src/matchbox-keyboard-key.c b/src/matchbox-keyboard-key.c
index 5f92251..efdda94 100644
--- a/src/matchbox-keyboard-key.c
+++ b/src/matchbox-keyboard-key.c
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#include "matchbox-keyboard.h"
#define MBKB_N_KEY_STATES 5
@@ -8,8 +27,8 @@ typedef struct MBKeyboardKeyFace
union
{
- void *image;
- unsigned char *str;
+ void *image;
+ char *str;
} u;
}
MBKeyboardKeyFace;
@@ -19,7 +38,7 @@ typedef struct MBKeyboardKeyAction
MBKeyboardKeyActionType type;
union
{
- unsigned char *glyph;
+ char *glyph;
KeySym keysym;
MBKeyboardKeyModType type;
} u;
@@ -243,7 +262,7 @@ mb_kdb_key_has_state(MBKeyboardKey *key,
void
mb_kbd_key_set_glyph_face(MBKeyboardKey *key,
MBKeyboardKeyStateType state,
- const unsigned char *glyph)
+ const char *glyph)
{
if (key->states[state] == NULL)
_mb_kbd_key_init_state(key, state);
@@ -252,7 +271,7 @@ mb_kbd_key_set_glyph_face(MBKeyboardKey *key,
key->states[state]->face.u.str = strdup(glyph);
}
-const unsigned char*
+const char*
mb_kbd_key_get_glyph_face(MBKeyboardKey *key,
MBKeyboardKeyStateType state)
{
@@ -280,7 +299,7 @@ mb_kbd_key_set_image_face(MBKeyboardKey *key,
void
mb_kbd_key_set_char_action(MBKeyboardKey *key,
MBKeyboardKeyStateType state,
- const unsigned char *glyphs)
+ const char *glyphs)
{
if (key->states[state] == NULL)
_mb_kbd_key_init_state(key, state);
@@ -289,7 +308,7 @@ mb_kbd_key_set_char_action(MBKeyboardKey *key,
key->states[state]->action.u.glyph = strdup(glyphs);
}
-const unsigned char*
+const char*
mb_kbd_key_get_char_action(MBKeyboardKey *key,
MBKeyboardKeyStateType state)
{
@@ -410,7 +429,7 @@ mb_kbd_key_press(MBKeyboardKey *key)
{
case MBKeyboardKeyActionGlyph:
{
- const unsigned char *key_char;
+ const char *key_char;
if ((key_char = mb_kbd_key_get_char_action(key, state)) != NULL)
{
diff --git a/src/matchbox-keyboard-layout.c b/src/matchbox-keyboard-layout.c
index 1cc8b36..b8d4fa8 100644
--- a/src/matchbox-keyboard-layout.c
+++ b/src/matchbox-keyboard-layout.c
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#include "matchbox-keyboard.h"
struct MBKeyboardLayout
diff --git a/src/matchbox-keyboard-row.c b/src/matchbox-keyboard-row.c
index bc9e31e..01123b7 100644
--- a/src/matchbox-keyboard-row.c
+++ b/src/matchbox-keyboard-row.c
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#include "matchbox-keyboard.h"
struct MBKeyboardRow
diff --git a/src/matchbox-keyboard-ui-cairo-backend.c b/src/matchbox-keyboard-ui-cairo-backend.c
index 157ecf6..a49b8f0 100644
--- a/src/matchbox-keyboard-ui-cairo-backend.c
+++ b/src/matchbox-keyboard-ui-cairo-backend.c
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#include "matchbox-keyboard.h"
typedef struct MBKeyboardUIBackendCario
@@ -12,10 +31,10 @@ typedef struct MBKeyboardUIBackendCario
} MBKeyboardUIBackendCairo;
static void
-mb_kbd_ui_cairo_text_extents (MBKeyboardUI *ui,
- const unsigned char *str,
- int *width,
- int *height)
+mb_kbd_ui_cairo_text_extents (MBKeyboardUI *ui,
+ const char *str,
+ int *width,
+ int *height)
{
MBKeyboardUIBackendCairo *cairo_backend = NULL;
cairo_text_extents_t extents;
@@ -33,6 +52,7 @@ mb_kbd_ui_cairo_load_font(MBKeyboardUI *ui)
{
MBKeyboard *kb = NULL;
MBKeyboardUIBackendCairo *cairo_backend = NULL;
+ double mm_per_pixel, pixel_size;
cairo_backend = (MBKeyboardUIBackendCairo*)mb_kbd_ui_backend(ui);
kb = mb_kbd_ui_kbd(ui);
@@ -43,8 +63,18 @@ mb_kbd_ui_cairo_load_font(MBKeyboardUI *ui)
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
- /* FIXME: Is this point size ? */
- cairo_set_font_size (cairo_backend->cr, kb->font_pt_size);
+ mm_per_pixel = (double)DisplayHeightMM(mb_kbd_ui_x_display(ui),
+ mb_kbd_ui_x_screen(ui))
+ / DisplayHeight(mb_kbd_ui_x_display(ui),
+ mb_kbd_ui_x_screen(ui));
+
+ /* 1 millimeter = 0.0393700787 inches */
+
+ /* 1 inch = 72 PostScript points */
+
+ pixel_size = (double)kb->font_pt_size / ( (double)mm_per_pixel * 0.03 * 72 );
+
+ cairo_set_font_size (cairo_backend->cr, pixel_size);
return 1;
}
@@ -54,12 +84,14 @@ 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;
+ cairo_pattern_t *pat;
if (mb_kbd_key_is_blank(key)) /* spacer */
return;
@@ -77,19 +109,28 @@ mb_kbd_ui_cairo_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key)
rect.height = mb_kbd_key_height(key);
-
/* clear it */
- cairo_set_line_width (cairo_backend->cr, 0);
+ cairo_set_line_width (cairo_backend->cr, 0.04);
+ cairo_set_source_rgb(cairo_backend->cr, 0.9, 0.9, 0.8);
+
cairo_stroke( cairo_backend->cr );
- cairo_set_source_rgb(cairo_backend->cr, 0.9, 0.9, 0.8);
+ pat = cairo_pattern_create_linear (0, rect.y, 0, rect.y + rect.height);
+
+ cairo_pattern_add_color_stop_rgb (pat, 1, 0.2, 0.2, 0.2 );
+ cairo_pattern_add_color_stop_rgb (pat, 0, 0.7, 0.7, 0.7 );
+
+ cairo_set_source (cairo_backend->cr, pat);
cairo_rectangle( cairo_backend->cr,
rect.x, rect.y,
rect.width, rect.height);
- cairo_fill( cairo_backend->cr );
+ cairo_fill (cairo_backend->cr);
+
+ cairo_pattern_destroy (pat);
+
/* border */
@@ -130,8 +171,6 @@ mb_kbd_ui_cairo_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key)
cairo_stroke(cairo_backend->cr);
-
-
/* Handle state related painting */
state = mb_kbd_keys_current_state(kbd);
@@ -150,21 +189,30 @@ mb_kbd_ui_cairo_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key)
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);
+ const char *face_str = mb_kbd_key_get_glyph_face(key, state);
if (face_str)
{
- int x, y, face_width, face_height;
+ double x, y;
+ int face_width, face_height;
+ cairo_font_extents_t font_extents;
+ /* FIXME: Below is borked */
mb_kbd_ui_cairo_text_extents (ui, face_str, &face_width, &face_height);
- x = rect.x + (rect.width/2);
+ cairo_font_extents (cairo_backend->cr, &font_extents);
+
+ DBG(" %i - %i = %i",
+ rect.width, face_width,
+ (rect.width - face_width) );
- y = rect.y + ( (rect.height - face_height) / 2 );
+ x = rect.x + ( (rect.width - face_width) / 2.0);
+
+ y = rect.y + ( (rect.height - (font_extents.ascent + font_extents.descent)) / 2.0 ) + font_extents.ascent;
+
+ /* DBG("draw text to %d,%d", __func__, x, y); */
cairo_move_to(cairo_backend->cr, x, y);
cairo_show_text (cairo_backend->cr, face_str);
@@ -189,22 +237,20 @@ mb_kbd_ui_cairo_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key)
cairo_fill( cairo_backend->cr );
}
-
// cairo_show_page(cairo_backend->cr);
// cairo_destroy (cairo_backend->cr);
-
-
}
-void
+
+void /* FIXME: rename to clear backbuffer ? */
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_set_source_rgb (cairo_backend->cr, 0.95, 0.95, 0.95);
cairo_rectangle( cairo_backend->cr,
0,
@@ -235,6 +281,8 @@ mb_kbd_ui_cairo_resources_create(MBKeyboardUI *ui)
cairo_xlib_surface_set_size (cairo_backend->surface,
mb_kbd_ui_x_win_width(ui),
mb_kbd_ui_x_win_height(ui));
+
+ return True;
}
static int
@@ -250,8 +298,18 @@ mb_kbd_ui_cairo_resize(MBKeyboardUI *ui, int width, int height)
mb_kbd_ui_x_win_width(ui),
mb_kbd_ui_x_win_height(ui));
- // cairo_destroy(cairo_backend->cr);
+ 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));
+ /*
+ cairo_scale (cairo_get_target(cairo_backend->cr),
+ mb_kbd_ui_x_win_width(ui),
+ mb_kbd_ui_x_win_height(ui));
+ */
}
+
+ return True;
}
MBKeyboardUIBackend*
@@ -291,6 +349,6 @@ mb_kbd_ui_cairo_init(MBKeyboardUI *ui)
cairo_reference(cairo_backend->cr);
- return cairo_backend;
+ return (MBKeyboardUIBackend*)cairo_backend;
}
diff --git a/src/matchbox-keyboard-ui-cairo-backend.h b/src/matchbox-keyboard-ui-cairo-backend.h
index de75704..07042c4 100644
--- a/src/matchbox-keyboard-ui-cairo-backend.h
+++ b/src/matchbox-keyboard-ui-cairo-backend.h
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#ifndef HAVE_MB_KEYBOARD_CAIRO_BACKEND_XFT_H
#define HAVE_MB_KEYBOARD_CAIRO_BACKEND_XFT_H
diff --git a/src/matchbox-keyboard-ui-xft-backend.c b/src/matchbox-keyboard-ui-xft-backend.c
index f7c48f7..c13d472 100644
--- a/src/matchbox-keyboard-ui-xft-backend.c
+++ b/src/matchbox-keyboard-ui-xft-backend.c
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#include "matchbox-keyboard.h"
typedef struct MBKeyboardUIBackendXft
@@ -18,7 +37,7 @@ typedef struct MBKeyboardUIBackendXft
static void
mb_kbd_ui_xft_text_extents (MBKeyboardUI *ui,
- const unsigned char *str,
+ const char *str,
int *width,
int *height)
{
@@ -29,7 +48,7 @@ mb_kbd_ui_xft_text_extents (MBKeyboardUI *ui,
XftTextExtentsUtf8(mb_kbd_ui_x_display(ui),
xft_backend->font,
- str,
+ (unsigned char*)str,
strlen(str),
&extents);
@@ -199,8 +218,8 @@ mb_kbd_ui_xft_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key)
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;
+ const char *face_str = mb_kbd_key_get_glyph_face(key, state);
+ int face_str_w, face_str_h;
if (face_str)
{
@@ -219,7 +238,7 @@ mb_kbd_ui_xft_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key)
xft_backend->font,
x,
y + xft_backend->font->ascent,
- face_str,
+ (unsigned char*)face_str,
strlen(face_str));
}
}
@@ -297,6 +316,7 @@ mb_kbd_ui_xft_resources_create(MBKeyboardUI *ui)
alloc_color(ui, &xft_backend->xcol_f4f4f4, "#f4f4f4");
alloc_color(ui, &xft_backend->xcol_a4a4a4, "#a4a4a4");
+ return True;
}
static int
@@ -307,6 +327,8 @@ mb_kbd_ui_xft_resize(MBKeyboardUI *ui, int width, int height)
xft_backend = (MBKeyboardUIBackendXft*)mb_kbd_ui_backend(ui);
XftDrawChange (xft_backend->xft_backbuffer, mb_kbd_ui_backbuffer(ui));
+
+ return True;
}
MBKeyboardUIBackend*
@@ -324,6 +346,6 @@ mb_kbd_ui_xft_init(MBKeyboardUI *ui)
xft_backend->backend.resources_create = mb_kbd_ui_xft_resources_create;
xft_backend->backend.resize = mb_kbd_ui_xft_resize;
- return xft_backend;
+ return (MBKeyboardUIBackend*)xft_backend;
}
diff --git a/src/matchbox-keyboard-ui-xft-backend.h b/src/matchbox-keyboard-ui-xft-backend.h
index 0d9172e..65cc291 100644
--- a/src/matchbox-keyboard-ui-xft-backend.h
+++ b/src/matchbox-keyboard-ui-xft-backend.h
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#ifndef HAVE_MB_KEYBOARD_UI_BACKEND_XFT_H
#define HAVE_MB_KEYBOARD_UI_BACKEND_XFT_H
diff --git a/src/matchbox-keyboard-ui.c b/src/matchbox-keyboard-ui.c
index c6f5feb..3096621 100644
--- a/src/matchbox-keyboard-ui.c
+++ b/src/matchbox-keyboard-ui.c
@@ -1,6 +1,23 @@
-#include "matchbox-keyboard.h"
-
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include "matchbox-keyboard.h"
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5
#define MWM_HINTS_DECORATIONS (1L << 1)
@@ -20,25 +37,20 @@ PropMotifWmHints;
struct MBKeyboardUI
{
- Display *xdpy;
- int xscreen;
- Window xwin_root, xwin;
+ Display *xdpy;
+ int xscreen;
+ Window xwin_root, xwin;
+ Pixmap backbuffer;
- int dpy_width;
- int dpy_height;
+ int dpy_width, dpy_height;
+ int xwin_width, xwin_height;
- int xwin_width;
- int xwin_height;
+ int key_uwidth, key_uheight;
+ int base_alloc_width, base_alloc_height;
+ int base_font_pt_size;
- Pixmap backbuffer;
-
- /************************* */
-
- int key_uwidth, key_uheight;
-
- int base_alloc_width, base_alloc_height;
- int base_font_pt_size;
+ Bool want_embedding;
FakeKey *fakekey;
MBKeyboardUIBackend *backend;
@@ -52,13 +64,13 @@ static int
mb_kbd_ui_load_font(MBKeyboardUI *ui);
-static unsigned char*
+static char*
get_current_window_manager_name (MBKeyboardUI *ui)
{
Atom atom_utf8_string, atom_wm_name, atom_check, type;
int result, format;
- unsigned char *val, *retval;
- long nitems, bytes_after;
+ char *val, *retval;
+ unsigned long nitems, bytes_after;
Window *support_xwin = NULL;
atom_check = XInternAtom (ui->xdpy, "_NET_SUPPORTING_WM_CHECK", False);
@@ -100,7 +112,7 @@ get_desktop_area(MBKeyboardUI *ui, int *x, int *y, int *width, int *height)
{
Atom atom_area, type;
int result, format;
- long nitems, bytes_after;
+ unsigned long nitems, bytes_after;
int *geometry = NULL;
atom_area = XInternAtom (ui->xdpy, "_NET_WORKAREA", False);
@@ -190,11 +202,11 @@ get_xevent_timed(Display *dpy,
void
mb_kbd_ui_send_press(MBKeyboardUI *ui,
- const unsigned char *utf8_char_in,
+ const char *utf8_char_in,
int modifiers)
{
DBG("Sending '%s'", utf8_char_in);
- fakekey_press(ui->fakekey, utf8_char_in, -1, modifiers);
+ fakekey_press(ui->fakekey, (unsigned char*)utf8_char_in, -1, modifiers);
}
void
@@ -217,7 +229,7 @@ mb_kdb_ui_unit_key_size(MBKeyboardUI *ui, int *width, int *height)
MBKeyboardLayout *layout;
List *row_item, *key_item;
MBKeyboardKeyStateType state;
- const unsigned char *face_str;
+ const char *face_str;
*width = 0; *height = 0;
@@ -266,8 +278,8 @@ mb_kbd_ui_min_key_size(MBKeyboardUI *ui,
int *width,
int *height)
{
- const unsigned char *face_str = NULL;
- int max_w = 0, max_h = 0, state;
+ const char *face_str = NULL;
+ int max_w = 0, max_h = 0, state;
if (mb_kbd_key_get_req_uwidth(key) || mb_kbd_key_is_blank(key))
{
@@ -513,6 +525,8 @@ mb_kbd_ui_redraw(MBKeyboardUI *ui)
List *row_item;
MBKeyboardLayout *layout;
+ MARK();
+
/* gives backend a chance to clear everything */
ui->backend->pre_redraw(ui);
@@ -532,7 +546,7 @@ mb_kbd_ui_redraw(MBKeyboardUI *ui)
mb_kbd_ui_swap_buffers(ui);
}
-static void
+void
mb_kbd_ui_show(MBKeyboardUI *ui)
{
XMapWindow(ui->xdpy, ui->xwin);
@@ -573,7 +587,7 @@ mb_kbd_ui_resources_create(MBKeyboardUI *ui)
XSetWindowAttributes win_attr;
- unsigned char *wm_name;
+ char *wm_name;
boolean have_matchbox_wm = False;
boolean have_ewmh_wm = False;
@@ -653,89 +667,92 @@ mb_kbd_ui_resources_create(MBKeyboardUI *ui)
XSetStandardProperties(ui->xdpy, ui->xwin, "Keyboard",
NULL, 0, NULL, 0, &size_hints);
- mwm_hints = util_malloc0(sizeof(PropMotifWmHints));
-
- if (mwm_hints)
- {
- mwm_hints->flags = MWM_HINTS_DECORATIONS;
- mwm_hints->decorations = 0;
-
- XChangeProperty(ui->xdpy, ui->xwin, atom_MOTIF_WM_HINTS,
- XA_ATOM, 32, PropModeReplace,
- (unsigned char *)mwm_hints,
- PROP_MOTIF_WM_HINTS_ELEMENTS);
-
- free(mwm_hints);
- }
-
- if (have_ewmh_wm)
+ if (!ui->want_embedding)
{
- /* XXX Fix this for display size */
- int wm_struct_vals[] = { 0, /* left */
- 0, /* right */
- 0, /* top */
- 0, /* bottom */
- 0, /* left_start_y */
- 0, /* left_end_y */
- 0, /* right_start_y */
- 0, /* right_end_y */
- 0, /* top_start_x */
- 0, /* top_end_x */
- 0, /* bottom_start_x */
- 1399 }; /* bottom_end_x */
-
- Atom states[] = { atom_NET_WM_STATE_SKIP_TASKBAR, atom_NET_WM_STATE_SKIP_PAGER };
- int desk_width = 0, desk_height = 0, desk_y = 0;
-
- XChangeProperty(ui->xdpy, ui->xwin,
- atom_NET_WM_STATE, XA_ATOM, 32,
- PropModeReplace,
- (unsigned char *)states, 2);
-
- if (get_desktop_area(ui, NULL, &desk_y, &desk_width, &desk_height))
- {
- /* Assuming we take up all available display width
- * ( at least true with matchbox wm ). we resize
- * the base ui width to this ( and height as a factor )
- * to avoid the case of mapping and then the wm resizing
- * us, causing an ugly repaint.
- */
- if (desk_width > ui->xwin_width)
- {
- mb_kbd_ui_resize(ui,
- desk_width,
- ( desk_width * ui->xwin_height ) / ui->xwin_width);
- }
-
- wm_struct_vals[2] = desk_y + desk_height - ui->xwin_height;
- wm_struct_vals[11] = desk_width;
-
- XChangeProperty(ui->xdpy, ui->xwin,
- atom_NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32,
- PropModeReplace,
- (unsigned char *)wm_struct_vals , 12);
-
- DBG("desk width: %i, desk height: %i xwin_height :%i",
- desk_width, desk_height, ui->xwin_height);
-
- }
-
- if (have_matchbox_wm)
+ mwm_hints = util_malloc0(sizeof(PropMotifWmHints));
+
+ if (mwm_hints)
{
- XChangeProperty(ui->xdpy, ui->xwin,
- atom_NET_WM_WINDOW_TYPE, XA_ATOM, 32,
- PropModeReplace,
- (unsigned char *) &atom_NET_WM_WINDOW_TYPE_TOOLBAR, 1);
+ mwm_hints->flags = MWM_HINTS_DECORATIONS;
+ mwm_hints->decorations = 0;
+
+ XChangeProperty(ui->xdpy, ui->xwin, atom_MOTIF_WM_HINTS,
+ XA_ATOM, 32, PropModeReplace,
+ (unsigned char *)mwm_hints,
+ PROP_MOTIF_WM_HINTS_ELEMENTS);
+
+ free(mwm_hints);
}
- else
+
+ if (have_ewmh_wm)
{
- /*
+ /* XXX Fix this for display size */
+ int wm_struct_vals[] = { 0, /* left */
+ 0, /* right */
+ 0, /* top */
+ 0, /* bottom */
+ 0, /* left_start_y */
+ 0, /* left_end_y */
+ 0, /* right_start_y */
+ 0, /* right_end_y */
+ 0, /* top_start_x */
+ 0, /* top_end_x */
+ 0, /* bottom_start_x */
+ 1399 }; /* bottom_end_x */
+
+ Atom states[] = { atom_NET_WM_STATE_SKIP_TASKBAR, atom_NET_WM_STATE_SKIP_PAGER };
+ int desk_width = 0, desk_height = 0, desk_y = 0;
+
XChangeProperty(ui->xdpy, ui->xwin,
- atom_NET_WM_WINDOW_TYPE, XA_ATOM, 32,
+ atom_NET_WM_STATE, XA_ATOM, 32,
PropModeReplace,
- (unsigned char *) &atom_NET_WM_WINDOW_TYPE_DOCK, 1);
- */
-
+ (unsigned char *)states, 2);
+
+ if (get_desktop_area(ui, NULL, &desk_y, &desk_width, &desk_height))
+ {
+ /* Assuming we take up all available display width
+ * ( at least true with matchbox wm ). we resize
+ * the base ui width to this ( and height as a factor )
+ * to avoid the case of mapping and then the wm resizing
+ * us, causing an ugly repaint.
+ */
+ if (desk_width > ui->xwin_width)
+ {
+ mb_kbd_ui_resize(ui,
+ desk_width,
+ ( desk_width * ui->xwin_height ) / ui->xwin_width);
+ }
+
+ wm_struct_vals[2] = desk_y + desk_height - ui->xwin_height;
+ wm_struct_vals[11] = desk_width;
+
+ XChangeProperty(ui->xdpy, ui->xwin,
+ atom_NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32,
+ PropModeReplace,
+ (unsigned char *)wm_struct_vals , 12);
+
+ DBG("desk width: %i, desk height: %i xwin_height :%i",
+ desk_width, desk_height, ui->xwin_height);
+
+ }
+
+ if (have_matchbox_wm)
+ {
+ XChangeProperty(ui->xdpy, ui->xwin,
+ atom_NET_WM_WINDOW_TYPE, XA_ATOM, 32,
+ PropModeReplace,
+ (unsigned char *) &atom_NET_WM_WINDOW_TYPE_TOOLBAR, 1);
+ }
+ else
+ {
+ /*
+ XChangeProperty(ui->xdpy, ui->xwin,
+ atom_NET_WM_WINDOW_TYPE, XA_ATOM, 32,
+ PropModeReplace,
+ (unsigned char *) &atom_NET_WM_WINDOW_TYPE_DOCK, 1);
+ */
+
+ }
}
}
@@ -948,9 +965,6 @@ mb_kbd_ui_resize(MBKeyboardUI *ui, int width, int height)
ui->xwin_height = height;
-
- /* */
-
if (ui->backbuffer) /* may get called before initialised */
{
XFreePixmap(ui->xdpy, ui->backbuffer);
@@ -1062,6 +1076,8 @@ mb_kbd_ui_event_loop(MBKeyboardUI *ui)
default:
break;
}
+ if (ui->want_embedding)
+ mb_kbd_xembed_process_xevents (ui, &xev);
}
else
{
@@ -1170,9 +1186,13 @@ mb_kbd_ui_realize(MBKeyboardUI *ui)
mb_kbd_ui_resources_create(ui);
- mb_kbd_ui_redraw(ui);
-
- mb_kbd_ui_show(ui);
+ unless (mb_kbd_ui_embeded(ui))
+ {
+ mb_kbd_ui_show(ui);
+ mb_kbd_ui_redraw(ui);
+ }
+ else
+ mb_kbd_xembed_init (ui);
return 1;
}
@@ -1201,3 +1221,24 @@ mb_kbd_ui_init(MBKeyboard *kbd)
return 1;
}
+
+/* Embedding */
+
+void
+mb_kbd_ui_set_embeded (MBKeyboardUI *ui, int embed)
+{
+ ui->want_embedding = embed;
+}
+
+int
+mb_kbd_ui_embeded (MBKeyboardUI *ui)
+{
+ return ui->want_embedding;
+}
+
+void
+mb_kbd_ui_print_window (MBKeyboardUI *ui)
+{
+ fprintf(stdout, "%li\n", mb_kbd_ui_x_win(ui));
+ fflush(stdout);
+}
diff --git a/src/matchbox-keyboard-xembed.c b/src/matchbox-keyboard-xembed.c
new file mode 100644
index 0000000..11d3f31
--- /dev/null
+++ b/src/matchbox-keyboard-xembed.c
@@ -0,0 +1,172 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include "matchbox-keyboard.h"
+
+#define MAX_SUPPORTED_XEMBED_VERSION 1
+
+#define XEMBED_MAPPED (1 << 0)
+
+/* XEMBED messages */
+#define XEMBED_EMBEDDED_NOTIFY 0
+#define XEMBED_WINDOW_ACTIVATE 1
+#define XEMBED_WINDOW_DEACTIVATE 2
+#define XEMBED_REQUEST_FOCUS 3
+#define XEMBED_FOCUS_IN 4
+#define XEMBED_FOCUS_OUT 5
+#define XEMBED_FOCUS_NEXT 6
+#define XEMBED_FOCUS_PREV 7
+/* 8-9 were used for XEMBED_GRAB_KEY/XEMBED_UNGRAB_KEY */
+#define XEMBED_MODALITY_ON 10
+#define XEMBED_MODALITY_OFF 11
+#define XEMBED_REGISTER_ACCELERATOR 12
+#define XEMBED_UNREGISTER_ACCELERATOR 13
+#define XEMBED_ACTIVATE_ACCELERATOR 14
+
+static Atom Atom_XEMBED; /* FIXME: put array of atoms in UI struct */
+static Window ParentEmbedderWin = None;
+
+static void
+mb_kbd_xembed_set_win_info (MBKeyboardUI *ui, int flags)
+{
+ CARD32 list[2];
+
+ Atom atom_ATOM_XEMBED_INFO;
+
+ atom_ATOM_XEMBED_INFO
+ = XInternAtom(mb_kbd_ui_x_display(ui), "_XEMBED_INFO", False);
+
+
+ list[0] = MAX_SUPPORTED_XEMBED_VERSION;
+ list[1] = flags;
+ XChangeProperty (mb_kbd_ui_x_display(ui),
+ mb_kbd_ui_x_win(ui),
+ atom_ATOM_XEMBED_INFO,
+ atom_ATOM_XEMBED_INFO, 32,
+ PropModeReplace, (unsigned char *) list, 2);
+}
+
+static Bool
+mb_kbd_xembed_send_message (MBKeyboardUI *ui,
+ Window w,
+ long message,
+ long detail,
+ long data1,
+ long data2)
+{
+ XEvent ev;
+
+ memset(&ev, 0, sizeof(ev));
+
+ ev.xclient.type = ClientMessage;
+ ev.xclient.window = w;
+ ev.xclient.message_type = Atom_XEMBED;
+ ev.xclient.format = 32;
+ ev.xclient.data.l[0] = CurrentTime; /* FIXME: Is this correct */
+ ev.xclient.data.l[1] = message;
+ ev.xclient.data.l[2] = detail;
+ ev.xclient.data.l[3] = data1;
+ ev.xclient.data.l[4] = data2;
+
+ util_trap_x_errors();
+
+ XSendEvent(mb_kbd_ui_x_display(ui), w, False, NoEventMask, &ev);
+ XSync(mb_kbd_ui_x_display(ui), False);
+
+ if (util_untrap_x_errors())
+ return False;
+
+ return True;
+}
+
+void
+mb_kbd_xembed_init (MBKeyboardUI *ui)
+{
+ /* FIXME: Urg global */
+ Atom_XEMBED = XInternAtom(mb_kbd_ui_x_display(ui), "_XEMBED", False);
+
+ mb_kbd_xembed_set_win_info (ui, 0);
+}
+
+void
+mb_kbd_xembed_process_xevents (MBKeyboardUI *ui, XEvent *xevent)
+{
+
+ switch (xevent->type)
+ {
+ case MapNotify:
+ DBG("### got Mapped ###");
+ break;
+ case ClientMessage:
+ if (xevent->xclient.message_type == Atom_XEMBED)
+ {
+ switch (xevent->xclient.data.l[1])
+ {
+ case XEMBED_EMBEDDED_NOTIFY:
+ /* We are now reparented. Call the repaint.
+ * note, 'data1' ( see spec ) is is embedders window
+ */
+ DBG("### got XEMBED_EMBEDDED_NOTIFY ###");
+ ParentEmbedderWin = xevent->xclient.data.l[3];
+
+ /* FIXME: we really want to know what our final
+ * size will be before mapping as this can
+ * look ugly when window is mapped then a
+ * load of resizes.
+ * Maybe fixible in GTK calling code ?
+ */
+
+ mb_kbd_ui_redraw(ui);
+
+ XSync(mb_kbd_ui_x_display(ui), False);
+
+ /* And please Map us */
+
+
+
+ mb_kbd_xembed_set_win_info (ui, XEMBED_MAPPED);
+
+ break;
+ case XEMBED_WINDOW_ACTIVATE:
+ /* FIXME: What to do here */
+ DBG("### got XEMBED_WINDOW_ACTIVATE ###");
+ break;
+ case XEMBED_WINDOW_DEACTIVATE:
+ /* FIXME: What to do here ? unmap or exit */
+ DBG("### got XEMBED_WINDOW_DEACTIVATE ###");
+ break;
+ case XEMBED_FOCUS_IN:
+ DBG("### got XEMBED_FOCUS_IN ###");
+ /*
+ * Please never give us key focus...
+ */
+ if (ParentEmbedderWin)
+ mb_kbd_xembed_send_message (ui,
+ ParentEmbedderWin,
+ XEMBED_FOCUS_NEXT,
+ 0, 0, 0);
+ break
+; /* TODO: Modility + rest of spec ? */
+ }
+ }
+ }
+
+ /* FIXME: Handle case of Embedder dieing ( Xfixes call ) ? */
+
+}
diff --git a/src/matchbox-keyboard.c b/src/matchbox-keyboard.c
index a07f6fa..5d43a6f 100644
--- a/src/matchbox-keyboard.c
+++ b/src/matchbox-keyboard.c
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#include "matchbox-keyboard.h"
MBKeyboard*
@@ -5,6 +24,7 @@ mb_kbd_new(int argc, char **argv)
{
MBKeyboard *kb = NULL;
char *variant = NULL;
+ Bool want_embedding = False;
kb = util_malloc0(sizeof(MBKeyboard));
@@ -21,7 +41,13 @@ mb_kbd_new(int argc, char **argv)
if (argc > 1)
{
- variant = argv[1];
+ /* FIXME: varient should always be last argv[1] */
+ if (streq(argv[1], "-xid") || streq(argv[1], "--xid"))
+ {
+ want_embedding = True;
+ }
+ else
+ variant = argv[1];
DBG("varient is %s\n", variant);
}
else variant = getenv("MB_KBD_VARIANT");
@@ -44,9 +70,15 @@ mb_kbd_new(int argc, char **argv)
kb->selected_layout
= (MBKeyboardLayout *)util_list_get_nth_data(kb->layouts, 0);
+ if (want_embedding)
+ mb_kbd_ui_set_embeded( kb->ui, True );
+
if (!mb_kbd_ui_realize(kb->ui))
return NULL;
+ if (want_embedding)
+ mb_kbd_ui_print_window( kb->ui );
+
return kb;
}
diff --git a/src/matchbox-keyboard.h b/src/matchbox-keyboard.h
index e3bf39d..a69004a 100644
--- a/src/matchbox-keyboard.h
+++ b/src/matchbox-keyboard.h
@@ -1,3 +1,22 @@
+/*
+ * Matchbox Keyboard - A lightweight software keyboard.
+ *
+ * Authored By Matthew Allum <mallum@o-hand.com>
+ *
+ * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
#ifndef HAVE_MB_KEYBOARD_H
#define HAVE_MB_KEYBOARD_H
@@ -118,11 +137,11 @@ MBKeyboardStateType;
struct MBKeyboard
{
MBKeyboardUI *ui;
- unsigned char *font_family;
+ char *font_family;
int font_pt_size;
- unsigned char *font_variant;
+ char *font_variant;
- unsigned char *config_file;
+ char *config_file;
List *layouts;
MBKeyboardLayout *selected_layout;
@@ -146,10 +165,10 @@ struct MBKeyboardUIBackend
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);
+ void (*text_extents) (MBKeyboardUI *ui,
+ const char *str,
+ int *width,
+ int *height);
};
int
@@ -159,6 +178,9 @@ int
mb_kbd_ui_realize(MBKeyboardUI *ui);
void
+mb_kbd_ui_show(MBKeyboardUI *ui);
+
+void
mb_kbd_ui_redraw_key(MBKeyboardUI *ui, MBKeyboardKey *key);
void
@@ -169,7 +191,7 @@ mb_kbd_ui_swap_buffers(MBKeyboardUI *ui);
void
mb_kbd_ui_send_press(MBKeyboardUI *ui,
- const unsigned char *utf8_char_in,
+ const char *utf8_char_in,
int modifiers);
void
@@ -216,6 +238,22 @@ mb_kbd_ui_kbd(MBKeyboardUI *ui);
void
mb_kbd_ui_event_loop(MBKeyboardUI *ui);
+void
+mb_kbd_ui_set_embeded (MBKeyboardUI *ui, int embed);
+
+int
+mb_kbd_ui_embeded (MBKeyboardUI *ui);
+
+void
+mb_kbd_ui_print_window (MBKeyboardUI *ui);
+
+/*** XEmbed ***/
+
+void
+mb_kbd_xembed_init (MBKeyboardUI *ui);
+
+void
+mb_kbd_xembed_process_xevents (MBKeyboardUI *ui, XEvent *xevent);
/**** Keyboard ****/
@@ -412,9 +450,9 @@ mb_kdb_key_has_state(MBKeyboardKey *key,
void
mb_kbd_key_set_glyph_face(MBKeyboardKey *key,
MBKeyboardKeyStateType state,
- const unsigned char *glyph);
+ const char *glyph);
-const unsigned char*
+const char*
mb_kbd_key_get_glyph_face(MBKeyboardKey *key,
MBKeyboardKeyStateType state);
@@ -430,7 +468,7 @@ mb_kbd_key_get_face_type(MBKeyboardKey *key,
void
mb_kbd_key_set_char_action(MBKeyboardKey *key,
MBKeyboardKeyStateType state,
- const unsigned char *glyphs);
+ const char *glyphs);
void
mb_kbd_key_set_keysym_action(MBKeyboardKey *key,
@@ -479,6 +517,12 @@ mb_kbd_config_load(MBKeyboard *kbd, char *varient);
#define unless(x) if (!(x))
#define util_abs(x) ((x) > 0) ? (x) : -1*(x)
+void
+util_trap_x_errors(void);
+
+int
+util_untrap_x_errors(void);
+
void*
util_malloc0(int size);
@@ -486,7 +530,7 @@ void
util_fatal_error(char *msg);
int
-util_utf8_char_cnt(const unsigned char *str);
+util_utf8_char_cnt(const char *str);
boolean
util_file_readable(char *path);
@@ -519,7 +563,7 @@ util_list_foreach(List *list, ListForEachCB func, void *userdata);
/* Backends */
-#if 1
+#if WANT_CAIRO
#include "matchbox-keyboard-ui-cairo-backend.h"
#else
#include "matchbox-keyboard-ui-xft-backend.h"
diff --git a/src/util.c b/src/util.c
index 1b2e437..ed5ef80 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,5 +1,30 @@
#include "matchbox-keyboard.h"
+static int TrappedErrorCode = 0;
+static int (*old_error_handler) (Display *, XErrorEvent *);
+
+static int
+error_handler(Display *xdpy,
+ XErrorEvent *error)
+{
+ TrappedErrorCode = error->error_code;
+ return 0;
+}
+
+void
+util_trap_x_errors(void)
+{
+ TrappedErrorCode = 0;
+ old_error_handler = XSetErrorHandler(error_handler);
+}
+
+int
+util_untrap_x_errors(void)
+{
+ XSetErrorHandler(old_error_handler);
+ return TrappedErrorCode;
+}
+
void*
util_malloc0(int size)
{
@@ -56,10 +81,10 @@ util_fatal_error(char *msg)
int
-util_utf8_char_cnt(const unsigned char *str)
+util_utf8_char_cnt(const char *str)
{
- const unsigned char *p = str;
- int mask, len, result = 0;
+ const unsigned char *p = (unsigned char *)str;
+ int mask, len, result = 0;
/* XXX Should validate too */
@@ -83,3 +108,4 @@ util_file_readable(char *path)
return True;
}
+