Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mac): OSK layers displayed consistently for hardware and OSK modifiers #12829

Merged
merged 4 commits into from
Dec 17, 2024

Conversation

sgschantz
Copy link
Contributor

@sgschantz sgschantz commented Dec 13, 2024

The correct layers of the keyboard are displayed whether layers are changed with the physical keyboard or by clicking a modifier on the OSK or a combination of the two.

Fixes: #12582

User Testing

  • TEST_BASE_LAYER_CONSISTENT: OSK displays correct character for base layer
  1. Install and run the Keyman build associated with this PR
  2. Switch to the Khmer Angkor keyboard and open the OSK
  3. Open a note in the Stickies app
  4. Confirm that the 'T' key on the OSK displays 'ត'
  • TEST_SHIFT_LAYER_CONSISTENT: OSK displays correct character for shift layer
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the shift key on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays 'ទ'
  5. Release the shift key on the physical keyboard
  6. Confirm that the 'T' key on the OSK displays 'ត'
  7. Click with the mouse on the shift key of the OSK
  8. Confirm that the 'T' key on the OSK displays 'ទ'
  • TEST_OPTION/ALT_LAYER_CONSISTENT: OSK displays correct character for option/alt layer
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the option key on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays 'ឨ'
  5. Release the option key on the physical keyboard
  6. Confirm that the 'T' key on the OSK displays 'ត'
  7. Click with the mouse on the alt key of the OSK
  8. Confirm that the 'T' key on the OSK displays 'ឨ'
  • TEST_SHIFT_OPTION_LAYER_CONSISTENT: OSK displays correct character for shift-option layer
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the shift and option keys on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays '᧤'
  5. Release the shift and option keys on the physical keyboard
  6. Confirm that the 'T' key on the OSK displays 'ត'
  7. Click with the mouse on the shift and alt keys of the OSK
  8. Confirm that the 'T' key on the OSK displays '᧤'
  • TEST_SHIFT_LAYER_CONSISTENT_AFTER_OPTION_PRESSED: OSK displays correct character for shift layer after pressing and releasing the option key
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the option key on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays 'ឨ'
  5. Press and continue holding down the shift key on the physical keyboard
  6. Confirm that the 'T' key on the OSK displays '᧤'
  7. Release the option key on the physical keyboard
  8. Confirm that the 'T' key on the OSK displays 'ទ'
  9. Type T on the physical keyboard and confirm that the ouptut is 'ទ'
  • TEST_COMBINATION_OF_PHYSICAL_OPTION_AND_OSK_SHIFT: OSK displays correct character for shift-option layer when one modifier is physical and one modifier is OSK
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the option key on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays 'ឨ'
  5. Click with the mouse on the shift of the OSK
  6. Confirm that the 'T' key on the OSK displays '᧤'

additional logic applied to keep two modifier types
consistent with each other
also lots of refactoring to keep naming clear

Fixes: #12582
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Dec 13, 2024

User Test Results

Test specification and instructions

Test Artifacts

@sgschantz sgschantz added the mac/ label Dec 13, 2024
@keymanapp-test-bot keymanapp-test-bot bot added this to the A18S17 milestone Dec 13, 2024
@github-actions github-actions bot added the fix label Dec 13, 2024
@keymanapp-test-bot keymanapp-test-bot bot added has-user-test user-test-required User tests have not been completed labels Dec 16, 2024
@sgschantz
Copy link
Contributor Author

@SabineSIL I did some refactoring (mostly renaming) as part of this PR to more easily distinguish the difference between OSK modifiers and modifier keys on the physical keyboard. The actual changes in logic are limited.

The most substantial is the replacement of setKeyLabels with displayKeyLabelsForLayer in the class OSKiew. The old method had three arguments and required the modifiers states to be specified. However, the class already has access to the modifier states for both the OSK and the physical keyboard, and it uses the state of both to derive the correct labels. So the new method has no arguments and simply uses its existing state.

Secondly, for all methods in OSKView where the physical state of the shift, option and control keys is set (e.g. setPhysicalShiftState), the corresponding OSK state for the modifier is also cleared. This is because a change in the physical keyboard modifier state needs to override the OSK modifier state.

@sgschantz sgschantz marked this pull request as ready for review December 16, 2024 06:03
@sgschantz sgschantz requested a review from SabineSIL as a code owner December 16, 2024 06:03
Copy link
Contributor

@SabineSIL SabineSIL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

A suggested change on if/else blocks in setPhysicalShiftState, setOskShiftState, setPhysicalOptionState, setOskOptionState, setPhysicalControlState, setOskControlState

if (state) {
os_log_debug([KMELogs oskLog], "hardware shift key pressed");
[self displayKeyLabelsForLayer];
[self displaysShiftKeysAsPressed:YES];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[self displayKeyLabelsForLayer]; occurs in the if and the else block, Can this be moved outside the if/else?
The same happens in functions: setOskShiftState, setPhysicalOptionState, setOskOptionState, setPhysicalControlState, setOskControlState

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering doing that for the three physical state changes -- the osk state changes are not a simple if/else -- but I am holding off for now. I am about to work on another PR where I may be refactoring this further. I'd like to move this logic elsewhere as it shouldn't be located in the view class.

@dinakaranr
Copy link

Test Results

I tested this issue with the attached "Keyman 18.0.160-aplha-local" build on macOS and am sharing my observations here.
Setup:
Installed the "Keyman 18.0.160-alpha-local" build.dmg" file
Installed the "Khmer_Angkor" keyboard.

  • TEST_BASE_LAYER_CONSISTENT (Passed):
  1. Switch the keyboard from English to Khmer Angkor keyboard.
  2. Open the OSK.
  3. Open a note in the Stickies app.
  4. Confirm that the 'T' key on the OSK displays 'ត'
  5. Verified that the OSK displays the correct character for the base layer.
  6. It works great for me.
  • TEST_SHIFT_LAYER_CONSISTENT (Passed):
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the "Shift" key on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays 'ទ'
  5. Release the shift key on the physical keyboard
  6. Confirm that the 'T' key on the OSK displays 'ត'
  7. Click with the mouse on the shift key of the OSK
  8. Confirm that the 'T' key on the OSK displays 'ទ'
  9. Verified that the OSK displays the correct character for the shift layer
    It works well.
  • TEST_OPTION (Passed):
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the option key on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays 'ឨ'
  5. Release the option key on the physical keyboard
  6. Confirm that the 'T' key on the OSK displays 'ត'
  7. Click with the mouse on the alt key of the OSK
  8. Confirm that the 'T' key on the OSK displays 'ឨ'
  9. Verified that the OSK displays the correct character for the option/alt layer.
    It works great for me.
  • TEST_SHIFT_OPTION_LAYER_CONSISTENT (Passed):
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the shift and option keys on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays '᧤'
  5. Release the shift and option keys on the physical keyboard
  6. Confirm that the 'T' key on the OSK displays 'ត'
  7. Click with the mouse on the shift and alt keys of the OSK
  8. Confirm that the 'T' key on the OSK displays '᧤'
  9. Verified that the OSK displays the correct character for the shift-option layer
    It works great for me.
  • TEST_SHIFT_LAYER_CONSISTENT_AFTER_OPTION_PRESSED (Passed):
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the option key on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays 'ឨ'
  5. Press and continue holding down the shift key on the physical keyboard
  6. Confirm that the 'T' key on the OSK displays '᧤'
  7. Release the option key on the physical keyboard
  8. Confirm that the 'T' key on the OSK displays 'ទ'
  9. Type T on the physical keyboard and confirm that the output is 'ទ'
  10. Verified that the OSK displays the correct character for the shift layer after pressing and releasing the option key.
    It works great for me.
  • TEST_COMBINATION_OF_PHYSICAL_OPTION_AND_OSK_SHIFT (Passed):
  1. Switch to the Khmer Angkor keyboard and open the OSK
  2. Open a note in the Stickies app
  3. Press and continue holding down the option key on the physical keyboard
  4. Confirm that the 'T' key on the OSK displays 'ឨ'
  5. Click with the mouse on the shift of the OSK
  6. Confirm that the 'T' key on the OSK displays '᧤'
  7. Verified that the OSK displays the correct character for the shift-option layer when one modifier is physical and one modifier is OSK
    It works great for me.

@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-required User tests have not been completed label Dec 16, 2024
@sgschantz sgschantz merged commit 0f9dc8f into master Dec 17, 2024
5 checks passed
@sgschantz sgschantz deleted the fix/mac/12582-sync-osk-with-keyboard branch December 17, 2024 06:54
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 18.0.161-alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

bug(mac): physical modifier key state not reflected consistently in OSK
4 participants