mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-20 17:57:52 +02:00
Refactor: Simplify double tap for capslock
This doesn't fix a bug but remove some tricky code. The shift key is no longer different when the "double tap for capslock" option is on. The handling of the option is moved to Pointer instead and becomes simpler.
This commit is contained in:
parent
f64a0be6fa
commit
42c23d3864
@ -101,8 +101,8 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
|
||||
// Behavior flags.
|
||||
public static final int FLAG_LATCH = (1 << FLAGS_OFFSET << 0);
|
||||
// Key can be locked by typing twice
|
||||
public static final int FLAG_LOCK = (1 << FLAGS_OFFSET << 1);
|
||||
// Key can be locked by typing twice when enabled in settings
|
||||
public static final int FLAG_DOUBLE_TAP_LOCK = (1 << FLAGS_OFFSET << 1);
|
||||
// Special keys are not repeated and don't clear latched modifiers.
|
||||
public static final int FLAG_SPECIAL = (1 << FLAGS_OFFSET << 2);
|
||||
// Whether the symbol should be greyed out. For example, keys that are not
|
||||
@ -118,8 +118,8 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
|
||||
// Ranges for the different components
|
||||
private static final int FLAGS_BITS =
|
||||
FLAG_LATCH | FLAG_LOCK | FLAG_SPECIAL | FLAG_GREYED | FLAG_KEY_FONT |
|
||||
FLAG_SMALLER_FONT | FLAG_SECONDARY;
|
||||
FLAG_LATCH | FLAG_DOUBLE_TAP_LOCK | FLAG_SPECIAL | FLAG_GREYED |
|
||||
FLAG_KEY_FONT | FLAG_SMALLER_FONT | FLAG_SECONDARY;
|
||||
private static final int KIND_BITS = (0b1111 << KIND_OFFSET); // 4 bits wide
|
||||
private static final int VALUE_BITS = ~(FLAGS_BITS | KIND_BITS); // 20 bits wide
|
||||
|
||||
@ -500,7 +500,7 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
case "\\\\": return makeStringKey("\\");
|
||||
|
||||
/* Modifiers and dead-keys */
|
||||
case "shift": return modifierKey(0xE00A, Modifier.SHIFT, 0);
|
||||
case "shift": return modifierKey(0xE00A, Modifier.SHIFT, FLAG_DOUBLE_TAP_LOCK);
|
||||
case "ctrl": return modifierKey("Ctrl", Modifier.CTRL, 0);
|
||||
case "alt": return modifierKey("Alt", Modifier.ALT, 0);
|
||||
case "accent_aigu": return diacritic(0xE050, Modifier.AIGU);
|
||||
|
@ -104,11 +104,6 @@ public class Keyboard2View extends View
|
||||
_keyboard = kw;
|
||||
_shift_kv = KeyValue.getKeyByName("shift");
|
||||
_shift_key = _keyboard.findKeyWithValue(_shift_kv);
|
||||
if (_shift_key == null)
|
||||
{
|
||||
_shift_kv = _shift_kv.withFlags(_shift_kv.getFlags() | KeyValue.FLAG_LOCK);
|
||||
_shift_key = _keyboard.findKeyWithValue(_shift_kv);
|
||||
}
|
||||
_compose_kv = KeyValue.getKeyByName("compose");
|
||||
_compose_key = _keyboard.findKeyWithValue(_compose_kv);
|
||||
KeyModifier.set_modmap(_keyboard.modmap);
|
||||
|
@ -175,15 +175,6 @@ public final class LayoutModifier
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Modifier:
|
||||
switch (orig.getModifier())
|
||||
{
|
||||
case SHIFT:
|
||||
if (globalConfig.double_tap_lock_shift)
|
||||
return orig.withFlags(orig.getFlags() | KeyValue.FLAG_LOCK);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return orig;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public final class Pointers implements Handler.Callback
|
||||
public static final int FLAG_P_LATCHABLE = 1;
|
||||
public static final int FLAG_P_LATCHED = (1 << 1);
|
||||
public static final int FLAG_P_FAKE = (1 << 2);
|
||||
public static final int FLAG_P_LOCKABLE = (1 << 3);
|
||||
public static final int FLAG_P_DOUBLE_TAP_LOCK = (1 << 3);
|
||||
public static final int FLAG_P_LOCKED = (1 << 4);
|
||||
public static final int FLAG_P_SLIDING = (1 << 5);
|
||||
/** Clear latched (only if also FLAG_P_LATCHABLE set). */
|
||||
@ -86,10 +86,10 @@ public final class Pointers implements Handler.Callback
|
||||
/** The key must not be already latched . */
|
||||
void add_fake_pointer(KeyboardData.Key key, KeyValue kv, boolean locked)
|
||||
{
|
||||
Pointer ptr = new Pointer(-1, key, kv, 0.f, 0.f, Modifiers.EMPTY);
|
||||
ptr.flags = FLAG_P_FAKE | FLAG_P_LATCHED;
|
||||
int flags = pointer_flags_of_kv(kv) | FLAG_P_FAKE | FLAG_P_LATCHED;
|
||||
if (locked)
|
||||
ptr.flags |= FLAG_P_LOCKED;
|
||||
flags |= FLAG_P_LOCKED;
|
||||
Pointer ptr = new Pointer(-1, key, kv, 0.f, 0.f, Modifiers.EMPTY, flags);
|
||||
_ptrs.add(ptr);
|
||||
_handler.onPointerFlagsChanged(false);
|
||||
}
|
||||
@ -153,7 +153,7 @@ public final class Pointers implements Handler.Callback
|
||||
if (latched != null) // Already latched
|
||||
{
|
||||
removePtr(ptr); // Remove dupplicate
|
||||
if ((latched.flags & FLAG_P_LOCKABLE) != 0) // Toggle lockable key
|
||||
if ((latched.flags & FLAG_P_DOUBLE_TAP_LOCK) != 0) // Toggle lockable key
|
||||
lockPointer(latched, false);
|
||||
else // Otherwise, unlatch
|
||||
{
|
||||
@ -204,7 +204,7 @@ public final class Pointers implements Handler.Callback
|
||||
// The other key already "own" the latched modifiers and will clear them.
|
||||
Modifiers mods = getModifiers(isOtherPointerDown());
|
||||
KeyValue value = _handler.modifyKey(key.keys[0], mods);
|
||||
Pointer ptr = new Pointer(pointerId, key, value, x, y, mods);
|
||||
Pointer ptr = make_pointer(pointerId, key, value, x, y, mods);
|
||||
_ptrs.add(ptr);
|
||||
startLongPress(ptr);
|
||||
_handler.onPointerDown(value, false);
|
||||
@ -368,7 +368,7 @@ public final class Pointers implements Handler.Callback
|
||||
/** Make a pointer into the locked state. */
|
||||
private void lockPointer(Pointer ptr, boolean shouldVibrate)
|
||||
{
|
||||
ptr.flags = (ptr.flags & ~FLAG_P_LOCKABLE) | FLAG_P_LOCKED;
|
||||
ptr.flags = (ptr.flags & ~FLAG_P_DOUBLE_TAP_LOCK) | FLAG_P_LOCKED;
|
||||
_handler.onPointerFlagsChanged(shouldVibrate);
|
||||
}
|
||||
|
||||
@ -460,7 +460,7 @@ public final class Pointers implements Handler.Callback
|
||||
}
|
||||
|
||||
/** Return the [FLAG_P_*] flags that correspond to pressing [kv]. */
|
||||
static int pointer_flags_of_kv(KeyValue kv)
|
||||
int pointer_flags_of_kv(KeyValue kv)
|
||||
{
|
||||
int flags = 0;
|
||||
if (kv.hasFlagsAny(KeyValue.FLAG_LATCH))
|
||||
@ -470,8 +470,9 @@ public final class Pointers implements Handler.Callback
|
||||
flags |= FLAG_P_CLEAR_LATCHED | FLAG_P_CANT_LOCK;
|
||||
flags |= FLAG_P_LATCHABLE;
|
||||
}
|
||||
if (kv.hasFlagsAny(KeyValue.FLAG_LOCK))
|
||||
flags |= FLAG_P_LOCKABLE;
|
||||
if (_config.double_tap_lock_shift &&
|
||||
kv.hasFlagsAny(KeyValue.FLAG_DOUBLE_TAP_LOCK))
|
||||
flags |= FLAG_P_DOUBLE_TAP_LOCK;
|
||||
return flags;
|
||||
}
|
||||
|
||||
@ -512,6 +513,13 @@ public final class Pointers implements Handler.Callback
|
||||
|
||||
// Pointers
|
||||
|
||||
Pointer make_pointer(int p, KeyboardData.Key k, KeyValue v, float x, float y,
|
||||
Modifiers m)
|
||||
{
|
||||
int flags = (v == null) ? 0 : pointer_flags_of_kv(v);
|
||||
return new Pointer(p, k, v, x, y, m, flags);
|
||||
}
|
||||
|
||||
private static final class Pointer
|
||||
{
|
||||
/** -1 when latched. */
|
||||
@ -533,7 +541,7 @@ public final class Pointers implements Handler.Callback
|
||||
/** [null] when not in sliding mode. */
|
||||
public Sliding sliding;
|
||||
|
||||
public Pointer(int p, KeyboardData.Key k, KeyValue v, float x, float y, Modifiers m)
|
||||
public Pointer(int p, KeyboardData.Key k, KeyValue v, float x, float y, Modifiers m, int f)
|
||||
{
|
||||
pointerId = p;
|
||||
key = k;
|
||||
@ -542,7 +550,7 @@ public final class Pointers implements Handler.Callback
|
||||
downX = x;
|
||||
downY = y;
|
||||
modifiers = m;
|
||||
flags = (v == null) ? 0 : pointer_flags_of_kv(v);
|
||||
flags = f;
|
||||
timeoutWhat = -1;
|
||||
sliding = null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user