@@ -85,13 +85,10 @@ public int getKeyFlags(KeyboardData.Key key, KeyValue kv)
85
85
return ptr .flags ;
86
86
}
87
87
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 )
90
90
{
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 );
95
92
ptr .flags &= ~(KeyValue .FLAG_LATCH | KeyValue .FLAG_LOCK );
96
93
ptr .flags |= KeyValue .FLAG_FAKE_PTR ;
97
94
if (locked )
@@ -100,12 +97,39 @@ public void add_fake_pointer(KeyValue kv, KeyboardData.Key key, boolean locked)
100
97
_handler .onPointerFlagsChanged (false );
101
98
}
102
99
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 )
104
108
{
105
109
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.
107
121
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
+ }
109
133
}
110
134
111
135
// Receiving events
0 commit comments