hotkey-rs icon indicating copy to clipboard operation
hotkey-rs copied to clipboard

Allows to quit on `WM_QUIT` message for Windows

Open koutoftimer opened this issue 4 years ago • 2 comments

Pull requests consist of the following changes:

  • constant's type changed from u32 to i32 to stay consistant with winapi constant's type
  • listen method modified to interupt infinite loop when WM_QUIT message received
  • added post_quit_message helper function that simply calls PostQuitMessage that sends WM_QUIT
  • added a bit of docs for listen and post_quit_message

From PostQuitMessage docs:

Indicates to the system that a thread has made a request to terminate (quit).

I have verified that posting WM_QUIT by calling PostQuitMessage message from different process have no effect on the listen loop.

koutoftimer avatar Mar 31 '21 21:03 koutoftimer

Looks good, my only concern is that by making the key codes of type i32, it technically makes the windows and linux versions slightly incompatible I guess. I'm not sure if this is really a concern or not though?

also would this not also need to change to i32? https://github.com/UnwrittenFun/hotkey-rs/blob/1610e8e7726b316fc48a6f132162a42a3af58b15/src/windows.rs#L53

jamesbirtles avatar Apr 03 '21 14:04 jamesbirtles

I've got errors about type mismatch by preparing this pull request, that is why I've changed it to i32 and my primary focus was on correct interupting infinite loop, but now I see what happened with that slight change.

I can't see any negative constants, maybe it is "better" to cast i32 to u32.

it technically makes the windows and linux versions slightly incompatible

I'm not a developer of winapi crate and have no idea why do they choose to use i32 for VK_* constants and isize for modifiers. Maybe it is better to ask them whether or not it is safe to cast constants to u32.

I understand that compatibility is an important question, but it is not what I'm concerned with right now. I do not like that "callbacks" are called in the same thread, blocking infinite loop and dispatching events which corresponds to event miss and a ton of additional code for library user.

Recalling your conserns: I do not know right answer.

koutoftimer avatar Apr 06 '21 18:04 koutoftimer