forked from extern/Unexpected-Keyboard
Fix auto-capitalisation disabling locked shift
Shift locked via the "caps lock" key use the "fake pointer" mechanism that is also used by auto-capitalisation. Make sure that unlatching a fake pointer do not disabled a locked modifier. The implementation is moved into the Pointers class for a safer API and easier implementation.
This commit is contained in:
parent
ce38a4f151
commit
5e5937b0f4
@ -120,19 +120,7 @@ public class Keyboard2View extends View
|
||||
{
|
||||
if (_keyboard == null || key == null)
|
||||
return;
|
||||
int flags = _pointers.getKeyFlags(key, kv);
|
||||
if (latched)
|
||||
{
|
||||
if (flags != -1 && !lock)
|
||||
return; // Don't replace an existing pointer
|
||||
_pointers.add_fake_pointer(kv, key, lock);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((flags & KeyValue.FLAG_FAKE_PTR) == 0)
|
||||
return; // Don't remove locked pointers
|
||||
_pointers.remove_fake_pointer(kv, key);
|
||||
}
|
||||
_pointers.set_fake_pointer_state(key, kv, latched, lock);
|
||||
}
|
||||
|
||||
/** Called by auto-capitalisation. */
|
||||
|
@ -85,13 +85,10 @@ public final class Pointers implements Handler.Callback
|
||||
return ptr.flags;
|
||||
}
|
||||
|
||||
/** Fake pointers are latched and not lockable. */
|
||||
public void add_fake_pointer(KeyValue kv, KeyboardData.Key key, boolean locked)
|
||||
/** The key must not be already latched . */
|
||||
void add_fake_pointer(KeyboardData.Key key, KeyValue kv, boolean locked)
|
||||
{
|
||||
Pointer ptr = getLatched(key, kv);
|
||||
if (ptr != null)
|
||||
removePtr(ptr); // Already latched, replace pointer.
|
||||
ptr = new Pointer(-1, key, kv, 0.f, 0.f, Modifiers.EMPTY);
|
||||
Pointer ptr = new Pointer(-1, key, kv, 0.f, 0.f, Modifiers.EMPTY);
|
||||
ptr.flags &= ~(KeyValue.FLAG_LATCH | KeyValue.FLAG_LOCK);
|
||||
ptr.flags |= KeyValue.FLAG_FAKE_PTR;
|
||||
if (locked)
|
||||
@ -100,13 +97,40 @@ public final class Pointers implements Handler.Callback
|
||||
_handler.onPointerFlagsChanged(false);
|
||||
}
|
||||
|
||||
public void remove_fake_pointer(KeyValue kv, KeyboardData.Key key)
|
||||
/** Set whether a key is latched or locked by adding a "fake" pointer, a
|
||||
pointer that is not due to user interaction.
|
||||
This is used by auto-capitalisation.
|
||||
|
||||
When [lock] is true, [latched] control whether the modifier is locked or disabled.
|
||||
When [lock] is false, an existing locked pointer is not affected. */
|
||||
public void set_fake_pointer_state(KeyboardData.Key key, KeyValue kv,
|
||||
boolean latched, boolean lock)
|
||||
{
|
||||
Pointer ptr = getLatched(key, kv);
|
||||
if (ptr != null && (ptr.flags & KeyValue.FLAG_FAKE_PTR) != 0)
|
||||
if (ptr == null)
|
||||
{
|
||||
// No existing pointer, latch the key.
|
||||
if (latched)
|
||||
add_fake_pointer(key, kv, lock);
|
||||
}
|
||||
else if ((ptr.flags & KeyValue.FLAG_FAKE_PTR) != 0)
|
||||
{} // Key already latched but not by a fake ptr, do nothing.
|
||||
else if (lock)
|
||||
{
|
||||
// Acting on locked modifiers, replace the pointer each time.
|
||||
removePtr(ptr);
|
||||
if (latched)
|
||||
add_fake_pointer(key, kv, lock);
|
||||
}
|
||||
else if ((ptr.flags & KeyValue.FLAG_LOCKED) != 0)
|
||||
{} // Existing ptr is locked but [lock] is false, do not continue.
|
||||
else if (!latched)
|
||||
{
|
||||
// Key is latched by a fake ptr. Unlatch if requested.
|
||||
removePtr(ptr);
|
||||
_handler.onPointerFlagsChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Receiving events
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user