-
Notifications
You must be signed in to change notification settings - Fork 630
Add prev_layout method to keyboardlayout.new #4014
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
Open
eylles
wants to merge
1
commit into
awesomeWM:master
Choose a base branch
from
eylles:keyboardlayout_prev_layout
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(self._current - 1) % (#self._layout))would not loop back to MAX.(0-1)%MAXwill be stuck at 0. So the implementation doesn't mirror the circular behavior fromnext_layout.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes the math doesn't math, hence the frustration of the commit message, by all intents the math should not loop back and be stuck on 0, however something happens in some lower level of the API that avoids the off by one error, or rather has a reverse off by one error which causes the wrong incorrect math from this commit to do work and loop the layouts with a circular behaviour, but the "correct" math has the off by one behaviour where it gets stuck at 0 and doesn't loop...
yes it is incredibly frustrating, if you test adding those lines onto your awesome wm library it will work as intended, but the correct math won't...
i do not know why, but it does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not how modulo works. The remainder in the division always changes, so this always "loops".
Unless
MAX == 1, but then you'd have nothing to loop over anyways.The only pitfall is that some languages carry the sign and some don't.
E.g. in JavaScript:
-1 % 3 == -1or-4 % 3 == -1.But Lua doesn't carry the sign, so the result here is always a positive number:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if anything the concerning part here is not so much the looping of the modulo operation, but rather the off by one error that should appear but does not because of how the internal API is handling the indexing of the keyboard layout table (well, it is a table to lua but to the x11 API it ought to be an array, dynamic array or even a vector i'd guess) so the internal indexing that makes sense would probably be a starting on 0 index with some check like
table_elements >= passed_indexmaking the "3" index (assuming the user set 3 keyboard layouts for simplicity) loop back to (0) the first index of the table, or at least that would be my guess as why this works in such manner, but that is already speculating without looking at the source of the x11 API that lua interacts with...