Skip to content

Commit 5e5937b

Browse files
committed
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.
1 parent ce38a4f commit 5e5937b

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

srcs/juloo.keyboard2/Keyboard2View.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,7 @@ void set_fake_ptr_latched(KeyboardData.Key key, KeyValue kv, boolean latched,
120120
{
121121
if (_keyboard == null || key == null)
122122
return;
123-
int flags = _pointers.getKeyFlags(key, kv);
124-
if (latched)
125-
{
126-
if (flags != -1 && !lock)
127-
return; // Don't replace an existing pointer
128-
_pointers.add_fake_pointer(kv, key, lock);
129-
}
130-
else
131-
{
132-
if ((flags & KeyValue.FLAG_FAKE_PTR) == 0)
133-
return; // Don't remove locked pointers
134-
_pointers.remove_fake_pointer(kv, key);
135-
}
123+
_pointers.set_fake_pointer_state(key, kv, latched, lock);
136124
}
137125

138126
/** Called by auto-capitalisation. */

srcs/juloo.keyboard2/Pointers.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,10 @@ public int getKeyFlags(KeyboardData.Key key, KeyValue kv)
8585
return ptr.flags;
8686
}
8787

88-
/** Fake pointers are latched and not lockable. */
89-
public void add_fake_pointer(KeyValue kv, KeyboardData.Key key, boolean locked)
88+
/** The key must not be already latched . */
89+
void add_fake_pointer(KeyboardData.Key key, KeyValue kv, boolean locked)
9090
{
91-
Pointer ptr = getLatched(key, kv);
92-
if (ptr != null)
93-
removePtr(ptr); // Already latched, replace pointer.
94-
ptr = new Pointer(-1, key, kv, 0.f, 0.f, Modifiers.EMPTY);
91+
Pointer ptr = new Pointer(-1, key, kv, 0.f, 0.f, Modifiers.EMPTY);
9592
ptr.flags &= ~(KeyValue.FLAG_LATCH | KeyValue.FLAG_LOCK);
9693
ptr.flags |= KeyValue.FLAG_FAKE_PTR;
9794
if (locked)
@@ -100,12 +97,39 @@ public void add_fake_pointer(KeyValue kv, KeyboardData.Key key, boolean locked)
10097
_handler.onPointerFlagsChanged(false);
10198
}
10299

103-
public void remove_fake_pointer(KeyValue kv, KeyboardData.Key key)
100+
/** Set whether a key is latched or locked by adding a "fake" pointer, a
101+
pointer that is not due to user interaction.
102+
This is used by auto-capitalisation.
103+
104+
When [lock] is true, [latched] control whether the modifier is locked or disabled.
105+
When [lock] is false, an existing locked pointer is not affected. */
106+
public void set_fake_pointer_state(KeyboardData.Key key, KeyValue kv,
107+
boolean latched, boolean lock)
104108
{
105109
Pointer ptr = getLatched(key, kv);
106-
if (ptr != null && (ptr.flags & KeyValue.FLAG_FAKE_PTR) != 0)
110+
if (ptr == null)
111+
{
112+
// No existing pointer, latch the key.
113+
if (latched)
114+
add_fake_pointer(key, kv, lock);
115+
}
116+
else if ((ptr.flags & KeyValue.FLAG_FAKE_PTR) != 0)
117+
{} // Key already latched but not by a fake ptr, do nothing.
118+
else if (lock)
119+
{
120+
// Acting on locked modifiers, replace the pointer each time.
107121
removePtr(ptr);
108-
_handler.onPointerFlagsChanged(false);
122+
if (latched)
123+
add_fake_pointer(key, kv, lock);
124+
}
125+
else if ((ptr.flags & KeyValue.FLAG_LOCKED) != 0)
126+
{} // Existing ptr is locked but [lock] is false, do not continue.
127+
else if (!latched)
128+
{
129+
// Key is latched by a fake ptr. Unlatch if requested.
130+
removePtr(ptr);
131+
_handler.onPointerFlagsChanged(false);
132+
}
109133
}
110134

111135
// Receiving events

0 commit comments

Comments
 (0)