# HG changeset patch
# Parent ff9e137c388d090f183ac62efd0ad10a1cc2ef6d
Fix bugs in dead key support.

diff --git a/src/org/connectbot/TerminalView.java b/src/org/connectbot/TerminalView.java
--- a/src/org/connectbot/TerminalView.java
+++ b/src/org/connectbot/TerminalView.java
@@ -30,6 +30,7 @@
 import android.graphics.Path;
 import android.graphics.PixelXorXfermode;
 import android.graphics.RectF;
+import android.graphics.Typeface;
 import android.view.KeyEvent;
 import android.view.View;
 import android.view.ViewGroup.LayoutParams;
@@ -80,6 +81,10 @@
 		cursorPaint.setXfermode(new PixelXorXfermode(bridge.color[bridge.defaultBg]));
 		cursorPaint.setAntiAlias(true);
 
+		// Set dead key cursor font.
+		cursorPaint.setTypeface(Typeface.MONOSPACE);
+		cursorPaint.setFakeBoldText(true); // more readable?
+
 		cursorStrokePaint = new Paint(cursorPaint);
 		cursorStrokePaint.setStrokeWidth(0.1f);
 		cursorStrokePaint.setStyle(Paint.Style.STROKE);
@@ -134,6 +139,9 @@
 	}
 
 	private void scaleCursors() {
+		// Set dead key cursor font size.
+		cursorPaint.setTextSize(bridge.fontSize);
+
 		// Create a scale matrix to scale our 1x1 representation of the cursor
 		tempDst.set(0.0f, 0.0f, bridge.charWidth, bridge.charHeight);
 		scaleMatrix.setRectToRect(tempSrc, tempDst, scaleType);
@@ -181,7 +189,8 @@
 
 				final int deadKey = bridge.getKeyHandler().getDeadKey();
 				if (deadKey != 0) {
-					canvas.drawText(new char[] { (char)deadKey }, 0, 1, 0, 0, cursorStrokePaint);
+					canvas.drawText(new char[] { (char)deadKey }, 0, 1,
+							0, -bridge.charTop, cursorPaint);
 				}
 
 				// Make sure we scale our decorations to the correct size.
diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -102,9 +102,9 @@
 
 	public int charWidth = -1;
 	public int charHeight = -1;
-	private int charTop = -1;
+	public int charTop = -1;
 
-	private float fontSize = -1;
+	public float fontSize = -1;
 
 	private final List<FontSizeChangedListener> fontSizeChangedListeners;
 
diff --git a/src/org/connectbot/service/TerminalKeyListener.java b/src/org/connectbot/service/TerminalKeyListener.java
--- a/src/org/connectbot/service/TerminalKeyListener.java
+++ b/src/org/connectbot/service/TerminalKeyListener.java
@@ -51,6 +51,7 @@
 	public final static int META_SHIFT_LOCK = 0x20;
 	public final static int META_SLASH = 0x40;
 	public final static int META_TAB = 0x80;
+	public final static int META_DEAD_KEY = 0x100;
 
 	// The bit mask of momentary and lock states for each
 	public final static int META_CTRL_MASK = META_CTRL_ON | META_CTRL_LOCK;
@@ -59,20 +60,18 @@
 
 	// All the transient key codes
 	public final static int META_TRANSIENT = META_CTRL_ON | META_ALT_ON
-			| META_SHIFT_ON;
+			| META_SHIFT_ON | META_DEAD_KEY;
 
 	private final TerminalManager manager;
 	private final TerminalBridge bridge;
 	private final VDUBuffer buffer;
 
-	protected KeyCharacterMap keymap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
-
 	private String keymode = null;
 	private boolean hardKeyboard = false;
 
 	private int metaState = 0;
 
-	private int mDeadKey = 0;
+	private int mDeadKey;
 
 	private ClipboardManager clipboard = null;
 	private final SelectionArea selectionArea;
@@ -183,25 +182,28 @@
 			int key = event.getUnicodeChar(curMetaState);
 
 			if ((key & KeyCharacterMap.COMBINING_ACCENT) != 0) {
+				metaState &= ~META_TRANSIENT;
+				metaState |= META_DEAD_KEY;
 				mDeadKey = key & KeyCharacterMap.COMBINING_ACCENT_MASK;
+				bridge.redraw();
 				return true;
 			}
 
-			if (mDeadKey != 0) {
-				key = KeyCharacterMap.getDeadChar(mDeadKey, keyCode);
-				mDeadKey = 0;
+			if ((metaState & META_DEAD_KEY) != 0 && key != 0) {
+				// Combine printable key with accent, combination may not be printable.
+				key = KeyCharacterMap.getDeadChar(mDeadKey, key);
 			}
 
-			final boolean printing = (key != 0);
+			final boolean printing = (keyCode != KeyEvent.KEYCODE_ENTER && key != 0);
 
 			// otherwise pass through to existing session
 			// print normal keys
 			if (printing) {
 				metaState &= ~(META_SLASH | META_TAB);
 
-				// Remove shift and alt modifiers
+				// Remove shift, alt, & dead key modifiers
 				final int lastMetaState = metaState;
-				metaState &= ~(META_SHIFT_ON | META_ALT_ON);
+				metaState &= ~(META_SHIFT_ON | META_ALT_ON | META_DEAD_KEY);
 				if (metaState != lastMetaState) {
 					bridge.redraw();
 				}
@@ -507,7 +509,7 @@
 	}
 
 	public int getDeadKey() {
-		return mDeadKey;
+		return (metaState & META_DEAD_KEY) != 0 ? mDeadKey : 0;
 	}
 
 	public void setClipboardManager(ClipboardManager clipboard) {
