Skip to content

Commit

Permalink
Disable automatically Shift when pressing Ctrl
Browse files Browse the repository at this point in the history
Automatic capitalisation might interferes with keyboard shortcuts.
  • Loading branch information
Julow committed Aug 26, 2023
1 parent cf76118 commit f4c11d9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
7 changes: 7 additions & 0 deletions srcs/juloo.keyboard2/Autocapitalisation.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public void event_sent(int code, int meta)
callback(true);
}

public void stop()
{
_should_enable_shift = false;
_should_update_caps_mode = false;
callback(true);
}

public static interface Callback
{
public void update_shift_state(boolean should_enable, boolean should_disable);
Expand Down
1 change: 1 addition & 0 deletions srcs/juloo.keyboard2/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ public static Config globalConfig()

public static interface IKeyEventHandler
{
public void key_down(KeyValue value, boolean is_swipe);
public void key_up(KeyValue value, Pointers.Modifiers flags);
}

Expand Down
23 changes: 23 additions & 0 deletions srcs/juloo.keyboard2/KeyEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ public void selection_updated(int oldSelStart, int newSelStart)
_autocap.selection_updated(oldSelStart, newSelStart);
}

/** A key is being pressed. There will not necessarily be a corresponding
[key_up] event. */
public void key_down(KeyValue key, boolean isSwipe)
{
if (key == null)
return;
switch (key.getKind())
{
case Modifier:
// Stop auto capitalisation when activating a system modifier
switch (key.getModifier())
{
case CTRL:
case ALT:
case META:
_autocap.stop();
break;
}
break;
default: break;
}
}

/** A key has been released. */
public void key_up(KeyValue key, Pointers.Modifiers mods)
{
Expand Down
5 changes: 3 additions & 2 deletions srcs/juloo.keyboard2/Keyboard2View.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void set_shift_state(boolean state, boolean lock)
}
else
{
if ((flags & KeyValue.FLAG_FAKE_PTR) != 0)
if ((flags & KeyValue.FLAG_FAKE_PTR) == 0)
return; // Don't remove locked pointers
_pointers.remove_fake_pointer(_shift_kv, _shift_key);
}
Expand All @@ -134,8 +134,9 @@ public KeyValue modifyKey(KeyValue k, Pointers.Modifiers mods)
return KeyModifier.modify(k, mods);
}

public void onPointerDown(boolean isSwipe)
public void onPointerDown(KeyValue k, boolean isSwipe)
{
_config.handler.key_down(k, isSwipe);
invalidate();
vibrate();
}
Expand Down
11 changes: 6 additions & 5 deletions srcs/juloo.keyboard2/Pointers.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void onTouchDown(float x, float y, int pointerId, KeyboardData.Key key)
Pointer ptr = new Pointer(pointerId, key, value, x, y, mods);
_ptrs.add(ptr);
startKeyRepeat(ptr);
_handler.onPointerDown(false);
_handler.onPointerDown(value, false);
}

static final int[] DIRECTION_TO_INDEX = new int[]{
Expand Down Expand Up @@ -263,7 +263,7 @@ public void onTouchMove(float x, float y, int pointerId)
{
startSliding(ptr, dy);
}
_handler.onPointerDown(true);
_handler.onPointerDown(newValue, true);
}
}
}
Expand Down Expand Up @@ -383,7 +383,7 @@ private boolean handleKeyRepeat(Pointer ptr)
{
ptr.value = kv;
ptr.flags = kv.getFlags();
_handler.onPointerDown(true);
_handler.onPointerDown(kv, true);
return true;
}
// Stop repeating: Special keys
Expand Down Expand Up @@ -522,8 +522,9 @@ public interface IPointerEventHandler
public KeyValue modifyKey(KeyValue k, Modifiers flags);

/** A key is pressed. [getModifiers()] is uptodate. Might be called after a
press or a swipe to a different value. */
public void onPointerDown(boolean isSwipe);
press or a swipe to a different value. Down events are not paired with
up events. */
public void onPointerDown(KeyValue k, boolean isSwipe);

/** Key is released. [k] is the key that was returned by
[modifySelectedKey] or [modifySelectedKey]. */
Expand Down

0 comments on commit f4c11d9

Please sign in to comment.