Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement set_maximized, get_current_monitor, set_fullscreen and set_decorations for windows #457
Conversation
edwin0cheng
added some commits
Apr 10, 2018
edwin0cheng
changed the title
Implement set_maximized, set_fullscreen and set_decorations for windows
Implement set_maximized, get_current_monitor, set_fullscreen and set_decorations for windows
Apr 10, 2018
This comment has been minimized.
This comment has been minimized.
|
Should fixed part of the #72 |
This comment has been minimized.
This comment has been minimized.
|
Thanks so much for this! This will be useful for a lot of people. I won't have time to give this a full review until later today, though what I've looked at so far looks good. However, this needs a CHANGELOG entry. |
This comment has been minimized.
This comment has been minimized.
|
Thanks , and CHANGELOG entry added. And here is some implementation details about this PR;
|
edwin0minv
added some commits
Apr 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Just a minor bug first for rust-stable (I use nightly) and added support for with_maximized. (So that with_decorations, with_fullscreen all works now). It should be completed. Thanks :) |
This comment has been minimized.
This comment has been minimized.
|
After testing this on Windows 10, everything works as expected. However, I've succeeded in breaking things: while toggling either decorations or fullscreen rapidly repeatedly, the window in question eventually freezes. My other windows don't freeze, continuing to play their animations, but as soon as one of those windows is focused (in other words, as soon as it interacts with the backend), it freezes as well. This can happen using your updated fullscreen example program, though it's far easier to reproduce if you change the key handlers to respond to |
This comment has been minimized.
This comment has been minimized.
|
@francesca64 I changed the fullscreen example use PRESSED and I just tested this and it should works now. By the way, the cause of freezes are related to this block, |
francesca64
referenced this pull request
Apr 11, 2018
Merged
Doc typo fix for struct winit::Window #452
francesca64
requested changes
Apr 12, 2018
|
Excellent work! Not only does everything work fine now, but after reviewing every single line, I haven't found any real mistakes. That said, I do have some changes to request. They're all pretty minor, and most of them are related to formatting/maintainability, so they won't take very long. |
| // See : https://stackoverflow.com/questions/10740346/setforegroundwindow-only-working-while-visual-studio-is-open | ||
| const ALT : i32 = 0xA4; | ||
| const EXTENDEDKEY : u32 = 0x1; | ||
| const KEYUP : u32 = 0x2; |
This comment has been minimized.
This comment has been minimized.
| winuser::keybd_event(ALT as _, 0x45, EXTENDEDKEY | 0, 0); | ||
|
|
||
| // Simulate a key release | ||
| winuser::keybd_event(0xA4, 0x45, EXTENDEDKEY | KEYUP, 0); |
This comment has been minimized.
This comment has been minimized.
francesca64
Apr 12, 2018
Collaborator
keybd_event has been superseded by SendInput, which can also be used to send both events at once.
I saw the 0x45 scancode used in the example you linked, but judging by the official example, it's actually the scancode for numlock. For getting the correct scancode, MapVirtualKey looks appropriate.
| } else { | ||
| (None, None) | ||
| }; | ||
| let (x, y) = (None, None); |
This comment has been minimized.
This comment has been minimized.
francesca64
Apr 12, 2018
Collaborator
This doesn't appear to have any use anymore, since it will always just get unwrap_or'd to CW_USEDEFAULT in the call to CreateWindowExW.
| @@ -1,5 +1,6 @@ | |||
| # Unreleased | |||
|
|
|||
| - Implement Window::set_fullscreen, Window::set_maximized and Window::set_decorations for windows. | |||
This comment has been minimized.
This comment has been minimized.
francesca64
Apr 12, 2018
Collaborator
- Don't forget about
WindowBuilder::with_maximized WindowBuilder::with_fullscreenno longer changing display resolution is an important behavior change- Windows should be capitalized, to prevent ambiguity
- Use backticks to format method names/etc. as code
| { | ||
| unsafe { | ||
| let boxed = Box::new(function) as Box<FnMut(_)>; | ||
| let boxed2 = Box::new(boxed); |
This comment has been minimized.
This comment has been minimized.
francesca64
Apr 12, 2018
Collaborator
It would be good to have a comment that makes it more obvious that the double-boxing is intentional, as it looks very surprising to anyone who's not already well-acquainted with the backend.
This comment has been minimized.
This comment has been minimized.
edwin0cheng
Apr 12, 2018
Author
Contributor
This execute_in_thread function i just copy from EventsLoop::execute_in_thread. Maybe i should copy the comment as well? Or i should refactor it out as a common implementation function ?
This comment has been minimized.
This comment has been minimized.
| let raw = Box::into_raw(boxed2); | ||
|
|
||
| let res = winuser::PostThreadMessageA(self.thread_id, *EXEC_MSG_ID, | ||
| raw as *mut () as usize as WPARAM, 0); |
This comment has been minimized.
This comment has been minimized.
francesca64
Apr 12, 2018
Collaborator
For calls that can't fit on one line, it's standard to have each argument on its own line with a trailing comma.
| let win = Window { | ||
| window: real_window, | ||
| window_state: window_state, | ||
| events_loop_proxy |
This comment has been minimized.
This comment has been minimized.
| // And because ShowWindow will resize the window | ||
| // We call it in the main thread | ||
| self.events_loop_proxy.execute_in_thread(move |_| { | ||
| winuser::ShowWindow(window.0, if maximized { winuser::SW_MAXIMIZE } else {winuser::SW_RESTORE} ); |
This comment has been minimized.
This comment has been minimized.
francesca64
Apr 12, 2018
Collaborator
Formatting:
winuser::ShowWindow(window.0, if maximized { winuser::SW_MAXIMIZE } else { winuser::SW_RESTORE });There's a similar formatting issue at the end of mark_fullscreen, so please address it there as well.
| } | ||
|
|
||
| unsafe impl Send for Window {} | ||
| unsafe impl Sync for Window {} | ||
|
|
||
| // https://blogs.msdn.microsoft.com/oldnewthing/20131017-00/?p=2903 |
This comment has been minimized.
This comment has been minimized.
francesca64
Apr 12, 2018
Collaborator
While I doubt this will 404 any time soon, it's always good to explain things in comments.
| @@ -1,4 +1,7 @@ | |||
| #![cfg(target_os = "windows")] | |||
| #![allow(non_upper_case_globals)] | |||
| #![allow(non_snake_case)] | |||
| #![allow(dead_code)] | |||
This comment has been minimized.
This comment has been minimized.
francesca64
Apr 12, 2018
Collaborator
I'd prefer if you used #[allow(dead_code)] per-definition rather than for the whole module.
edwin0cheng
added some commits
Apr 12, 2018
This comment has been minimized.
This comment has been minimized.
|
Done ^^ |
francesca64
approved these changes
Apr 12, 2018
This comment has been minimized.
This comment has been minimized.
|
Magnificent! I can tell you went above and beyond to make things cleaner. I was ready to merge this, but I've found one more bug. Here are the steps to reproduce:
The same thing happens with toggling maximization while in fullscreen, though that only takes 2 presses. |
This comment has been minimized.
This comment has been minimized.
|
Good catch, but im away from keyboard now, would check it tonight(asia time), thanks |
This comment has been minimized.
This comment has been minimized.
|
@francesca64 It should be fixed :) |
This comment has been minimized.
This comment has been minimized.
|
Great, I've confirmed that it's fixed. Here's another bug:
This fortunately doesn't happen for decoration toggling. Using the built-in maximization button causes things like this to happen:
It's also important to account for the user un-maximizing the window by moving it:
|
This comment has been minimized.
This comment has been minimized.
It is because the fullscreen example just use a bool to indicate Maximize status, which is not sync to the system status. And we do not have an api to query this status. : ) |
This comment has been minimized.
This comment has been minimized.
9f52ed1 should fixed this |
This comment has been minimized.
This comment has been minimized.
|
Right, good point about it being an issue in the example and not your implementation, sorry about that. While it does fix my first issue, there are still issues with the wrong state being restored after using the built-in maximization button or moving to un-maximize.
and:
|
This comment has been minimized.
This comment has been minimized.
|
Sorry about that, the maximized state is a little bit tricky to implement correctly. Anyway, it should be fixed all the issues listed. |
This comment has been minimized.
This comment has been minimized.
|
Awesome! This is the last thing, I promise: in the CHANGELOG, you accidentally put |
This comment has been minimized.
This comment has been minimized.
|
Sorry about that, thank you so much to help me to catch out these bugs. It will be my second closed PR :) |
This comment has been minimized.
This comment has been minimized.
|
No problem! This PR is very much appreciated. |
edwin0cheng commentedApr 10, 2018
No description provided.