-
Notifications
You must be signed in to change notification settings - Fork 80
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 windows: mouse wheel scroll broken since v605 #379 #381
Conversation
Thanks, I can confirm this fixes the mouse wheel scroll issue for me. Nit: the new code is added with space-indenting, while the surrounding code uses tab indenting. currentKey.unicode = ip.Event.KeyEvent.uChar.UnicodeChar;
currentKey.ascii = ip.Event.KeyEvent.uChar.AsciiChar; While this is not part of the current patch, and I guess it works, I believe C doesn't guarantee that currentKey.ascii = currentKey.unicode & 0xff; (or even |
utf8_current_byte = 0; | ||
if (utf8_size == 0 ) { | ||
utf8_size == 1; | ||
utf8[0] = '\0'; |
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.
As I've learned recently, if WIN32getch
returns 0, then it's an indication that the next value which WIN32getch
returns should be interpreted as a keyboard scan code rather than ascii/UTF8 byte.
So maybe win32_kbhit
should just return FALSE if it can't convert it to UTF8?
Yes, this "pending scan" logic is a little bit weird to me. |
Can you describe what the problem actually is? I.e. why mouse wheel got broken in that commit (or at the current code)?
IMHO this issue is not urgent or critical. Being able to enter non-BMP codepoints like emoji is nice, but probably doesn't really stand in anyone's way if it doesn't work. So if the solution for typing emojis carries risks or too much complexity, it might be better off without it IMHO. |
It's quite similar to how unicode works: ReadConsoleInput[W] delivers a value that doesn't quite fit into one byte, so WIN32getch splits it into two: 0 and the scan code, delivered one after the other in two consecutive calls. The "buffer" is You can see that the unicode and the scancode are very similar at the begining of WIN32getch. In fact, they might benefit from a shared infrastructure of queuing a sequence of return values. Currently unicode and scancode each have its own mechanism for basically the same thing. |
The fact that AsciiChar is signed char does not mean it is treated as a signed number. Which characters above 127 are UTF8 that are not correctly saved in AsciiChar? I want to test this theory. |
What do you mean not correctly saved? What is not correctly saved?
What theory? All the codepoints which are not ASCII-7 are above 127, for instance any non-English European or Asian character ends up as a sequence of UFT-8 bytes which are all bigger than 127. I don't know what the context of the question is, the fact that it's stored in signed char doesn't necessarily mean it gets broken. But casting values between signed and unsigned, especially with different storage sizes, can sometimes break things. |
Actually, So we have the mouse events which are queued at We have unicode which is queued as UTF-8 at And we have scan code which is buffered at I really do think that a unified system of queuing a sequenc e of return values would make these three systems much much simpler. |
Maybe I misunderstood what you said about AsciiChar and UnicodeChar:
The way I interpret your statement is that AsciiChar != (UnicodeChar 0xFF). How is it possible if they are unioned in memory? |
Ah, now I understand :)
No. I said that C doesn't guarantee this. It might or might not be equal.
If the architecture is Big Endian, then I don't think there's a Windows system which is Big Endian, so I don't think it's an issue. But what is the purpose of that test? to check whether it exceeds 8 bits in value? then you could do, for instance: if (UnidoceChar != (unsigned char)UnicodeChar)
... or something with Accessing a union member which was not set is a bit of a gray area. |
If you want to test whether it will be more than one UTF-8 byte (i.e. if you need to call |
The reason the mouse wheel is broken because of the UTF code in WIN32getch() overwrites the value of currentKey.ascii variable. The UTF code needs to be in win32_kbhit() not to step on the mouse code. I am puzzled why the mouse code is inside the loop and the key events code is outside the loop. Shouldn't they follow similar logic? Also why are there two variables for the mouse buffer: x11mousePos and x11mouseCount? Isn't one enough to move around the buffer? Couldn't it be like:
|
I agree.
They do follow similar logic: if the code knows right away that it's going to ignore this INPUT_RECORD, then it will continue the loop. This happens with mouse move events, KEY_EVENT which is not "down", key events without either scan code or unicode, etc. It's not only for mouse.
There's more than one way to write the same code. Your example will probably work fine too. It comes down to personal preference, and at this case I'm guessing the author preferred to keep it more generic, for instance if one day the mouse sequence could have different lengths. |
About UnicodeChar vs AsciiChar: ReadConsoleInputW() writes to UnicodeChar and ReadConsoleInputA() writes to AsciiChar. |
In which case wVirtualScanCode can be 0? |
So I unified the unicode/scancode/x11mouse keyboard queues. All three need to return more than one value via Now they all use the same queue. Also moved the unicode code from This happens to fix the mouse wheel issue without any specific effort. Also fixes repeat count (at the KEY_EVENT) which was not working for unicode. The Unicode still doesn't handle surrogate pairs, and uses the exact same "system" as before: read one The patch is the top commit here https://github.com/avih/less/commits/winkbq For now I'm not opening a PR for it, but leaving it there if others want to have a look. |
Is mouse supposed to do text selection and copy/paste? |
I opened a new pull request #385 with the working code |
Separate mouse and keyboard events.