abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2
diff options
context:
space:
mode:
authorJules Aguillon2022-10-23 21:34:05 +0200
committerJules Aguillon2022-10-23 21:37:04 +0200
commit36e10a792ffd034ffb56e48e2e2282f6ae16cc8d (patch)
treeaf8b28705250fd8a1a685d0bc79c759cd5b66059 /srcs/juloo.keyboard2
parent55cece796588ad58646d9ea877912510af06e24e (diff)
downloadunexpected-keyboard-36e10a792ffd034ffb56e48e2e2282f6ae16cc8d.tar.gz
unexpected-keyboard-36e10a792ffd034ffb56e48e2e2282f6ae16cc8d.zip
Add the capslock key
The key enable caps lock immediately. It does nothing if caps lock is already enabled. It is not present on the keyboard by default but a place is defined on every layout, top-right of the shift key. It can be enabled in the settings. The icon is from materialdesignicons.com.
Diffstat (limited to 'srcs/juloo.keyboard2')
-rw-r--r--srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java1
-rw-r--r--srcs/juloo.keyboard2/KeyEventHandler.java2
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java4
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java9
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java4
-rw-r--r--srcs/juloo.keyboard2/Pointers.java11
6 files changed, 21 insertions, 10 deletions
diff --git a/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java b/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java
index d0734b9..e66c2cc 100644
--- a/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java
+++ b/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java
@@ -33,6 +33,7 @@ public class ExtraKeyCheckBoxPreference extends CheckBoxPreference
"ß",
"£",
"switch_greekmath",
+ "capslock",
};
public static boolean default_checked(String name)
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java
index 57f15f6..4623dec 100644
--- a/srcs/juloo.keyboard2/KeyEventHandler.java
+++ b/srcs/juloo.keyboard2/KeyEventHandler.java
@@ -35,6 +35,7 @@ class KeyEventHandler implements Config.IKeyEventHandler
case ACTION: _recv.performAction(); break;
case SWITCH_PROGRAMMING: _recv.switchProgramming(); break;
case SWITCH_GREEKMATH: _recv.switchGreekmath(); break;
+ case CAPS_LOCK: _recv.enableCapsLock(); break;
}
break;
case Keyevent:
@@ -102,6 +103,7 @@ class KeyEventHandler implements Config.IKeyEventHandler
public void setPane_normal();
public void showKeyboardConfig();
public void performAction();
+ public void enableCapsLock();
public void switchMain();
public void switchNumeric();
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java
index 9b89101..9c88b4a 100644
--- a/srcs/juloo.keyboard2/KeyValue.java
+++ b/srcs/juloo.keyboard2/KeyValue.java
@@ -16,7 +16,8 @@ final class KeyValue
CHANGE_METHOD,
ACTION,
SWITCH_PROGRAMMING,
- SWITCH_GREEKMATH
+ SWITCH_GREEKMATH,
+ CAPS_LOCK,
}
// Must be evaluated in the reverse order of their values.
@@ -287,6 +288,7 @@ final class KeyValue
addEventKey("switch_greekmath", "πλ∇¬", Event.SWITCH_GREEKMATH, FLAG_SMALLER_FONT);
addEventKey("change_method", "\u0009", Event.CHANGE_METHOD, FLAG_KEY_FONT | FLAG_SMALLER_FONT);
addEventKey("action", "Action", Event.ACTION, FLAG_SMALLER_FONT); // Will always be replaced
+ addEventKey("capslock", "\u0012", Event.CAPS_LOCK, FLAG_KEY_FONT);
addKeyeventKey("esc", "Esc", KeyEvent.KEYCODE_ESCAPE, FLAG_SMALLER_FONT);
addKeyeventKey("enter", "\u000E", KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT);
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index 12ee196..35d5b26 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -63,9 +63,9 @@ public class Keyboard2 extends InputMethodService
public void update_shift_state(boolean should_enable, boolean should_disable)
{
if (should_enable)
- _keyboardView.set_shift_state(true);
+ _keyboardView.set_shift_state(true, false);
else if (should_disable)
- _keyboardView.set_shift_state(false);
+ _keyboardView.set_shift_state(false, false);
}
private List<InputMethodSubtype> getEnabledSubtypes(InputMethodManager imm)
@@ -314,6 +314,11 @@ public class Keyboard2 extends InputMethodService
conn.performEditorAction(_config.actionId);
}
+ public void enableCapsLock()
+ {
+ _keyboardView.set_shift_state(true, true);
+ }
+
public void switchMain()
{
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index e613925..4742235 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -100,12 +100,12 @@ public class Keyboard2View extends View
}
/** Called by auto-capitalisation. */
- public void set_shift_state(boolean state)
+ public void set_shift_state(boolean state, boolean lock)
{
if (_keyboard == null || _shift_key == null)
return;
if (state)
- _pointers.add_fake_pointer(_shift_kv, _shift_key);
+ _pointers.add_fake_pointer(_shift_kv, _shift_key, lock);
else
_pointers.remove_fake_pointer(_shift_kv, _shift_key);
invalidate();
diff --git a/srcs/juloo.keyboard2/Pointers.java b/srcs/juloo.keyboard2/Pointers.java
index 2ac55bb..35299ab 100644
--- a/srcs/juloo.keyboard2/Pointers.java
+++ b/srcs/juloo.keyboard2/Pointers.java
@@ -75,13 +75,14 @@ public final class Pointers implements Handler.Callback
}
/** Fake pointers are latched and not lockable. */
- public void add_fake_pointer(KeyValue kv, KeyboardData.Key key)
+ public void add_fake_pointer(KeyValue kv, KeyboardData.Key key, boolean locked)
{
- // Avoid adding a fake pointer to a key that is already down.
- if (isKeyDown(key))
- return;
+ remove_fake_pointer(kv, key);
Pointer ptr = new Pointer(-1, key, kv, 0.f, 0.f, Modifiers.EMPTY);
- ptr.flags = ptr.flags & ~(KeyValue.FLAG_LATCH | KeyValue.FLAG_LOCK | KeyValue.FLAG_FAKE_PTR);
+ ptr.flags &= ~KeyValue.FLAG_LATCH;
+ ptr.flags |= KeyValue.FLAG_LOCK | KeyValue.FLAG_FAKE_PTR;
+ if (locked)
+ ptr.flags = (ptr.flags & ~KeyValue.FLAG_LOCK) | KeyValue.FLAG_LOCKED;
_ptrs.add(ptr);
}