-
Notifications
You must be signed in to change notification settings - Fork 567
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
Screen Module, window titlebar, position, size, DPI #1037
Changes from 19 commits
5fc5bb8
0c677ef
81412f1
e6aa4d4
98e823d
22b755d
3d52493
6c8ba46
262abc7
69fddf5
196fbe9
adcac2d
11838fc
ecdf087
0e9dbac
0f3f319
e7f0b56
8444bfc
83b2759
ffb743f
bc1f83a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ pub mod keycodes; | |
pub mod menu; | ||
pub mod util; | ||
pub mod window; | ||
pub mod screen; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2020 The Druid Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! GTK Monitors and Screen information. | ||
use crate::screen::Monitor; | ||
|
||
pub(crate) fn get_monitors() -> Vec<Monitor> { | ||
log::warn!("Screen::get_monitors() is currently unimplemented for gtk."); | ||
Vec::new() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ mod keyboard; | |
pub mod menu; | ||
pub mod util; | ||
pub mod window; | ||
pub mod screen; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2020 The Druid Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! macOS Monitors and Screen information. | ||
use crate::screen::Monitor; | ||
|
||
pub(crate) fn get_monitors() -> Vec<Monitor> { | ||
log::warn!("Screen::get_monitors() is currently unimplemented for Mac."); | ||
Vec::new() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ pub mod error; | |
pub mod keycodes; | ||
pub mod menu; | ||
pub mod window; | ||
pub mod screen; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2020 The Druid Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Monitor and Screen information ignored for web. | ||
use crate::screen::Monitor; | ||
|
||
pub(crate) fn get_monitors() -> Vec<Monitor> { | ||
log::warn!("Screen::get_monitors() is not implemented for web."); | ||
Vec::new() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,14 @@ use std::rc::Rc; | |
|
||
use winapi::shared::minwindef::{FALSE, HINSTANCE}; | ||
use winapi::shared::ntdef::LPCWSTR; | ||
use winapi::shared::windef::{HCURSOR, HWND}; | ||
use winapi::shared::windef::{HCURSOR, HWND, DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2}; | ||
use winapi::shared::winerror::HRESULT_FROM_WIN32; | ||
use winapi::um::errhandlingapi::GetLastError; | ||
use winapi::um::shellscalingapi::PROCESS_SYSTEM_DPI_AWARE; | ||
use winapi::um::shellscalingapi::PROCESS_PER_MONITOR_DPI_AWARE; | ||
use winapi::um::winuser::{ | ||
DispatchMessageW, GetAncestor, GetMessageW, LoadIconW, PostMessageW, PostQuitMessage, | ||
RegisterClassW, TranslateAcceleratorW, TranslateMessage, GA_ROOT, IDI_APPLICATION, MSG, | ||
WNDCLASSW, | ||
WNDCLASSW, SendMessageW | ||
}; | ||
|
||
use crate::application::AppHandler; | ||
|
@@ -38,7 +38,7 @@ use super::accels; | |
use super::clipboard::Clipboard; | ||
use super::error::Error; | ||
use super::util::{self, ToWide, CLASS_NAME, OPTIONAL_FUNCTIONS}; | ||
use super::window::{self, DS_REQUEST_DESTROY}; | ||
use super::window::{self, DS_REQUEST_DESTROY, DS_HANDLE_DEFERRED}; | ||
|
||
#[derive(Clone)] | ||
pub(crate) struct Application { | ||
|
@@ -50,6 +50,8 @@ struct State { | |
windows: HashSet<HWND>, | ||
} | ||
|
||
|
||
|
||
impl Application { | ||
pub fn new() -> Result<Application, Error> { | ||
Application::init()?; | ||
|
@@ -64,10 +66,15 @@ impl Application { | |
fn init() -> Result<(), Error> { | ||
// TODO: Report back an error instead of panicking | ||
util::attach_console(); | ||
if let Some(func) = OPTIONAL_FUNCTIONS.SetProcessDpiAwareness { | ||
if let Some(func) = OPTIONAL_FUNCTIONS.SetProcessDpiAwarenessContext { | ||
// This function is only supported on windows 10 | ||
unsafe { | ||
func(PROCESS_SYSTEM_DPI_AWARE); // TODO: per monitor (much harder) | ||
func(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); | ||
} | ||
} | ||
else if let Some(func) = OPTIONAL_FUNCTIONS.SetProcessDpiAwareness { | ||
unsafe { | ||
func(PROCESS_PER_MONITOR_DPI_AWARE); | ||
} | ||
} | ||
unsafe { | ||
|
@@ -105,6 +112,11 @@ impl Application { | |
unsafe { | ||
// Handle windows messages | ||
loop { | ||
if let Ok(state) = self.state.try_borrow() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My experience is that putting any additional functionality in the runloop is problematic. The logic doesn't get invoked when the system is using its own runloop, which happens on live resize and also while a file dialog is open. Also, if and when we ever run as a guest (for example as a VST plugin), then we'll also be at the mercy of the host's runloop. But if we use the function sparingly, maybe we're ok. Also, I think the name "DS_HANDLE_DROPPED" is confusing and should be changed to "BLOCKED" to be consistent with other functions. See below where I suggest a comment to add. |
||
for hwnd in &state.windows { | ||
SendMessageW(*hwnd, DS_HANDLE_DEFERRED, 0,0); | ||
} | ||
} | ||
let mut msg = mem::MaybeUninit::uninit(); | ||
let res = GetMessageW(msg.as_mut_ptr(), ptr::null_mut(), 0, 0); | ||
if res <= 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.
I do have a concern here. The old implementation worked on Windows 8.1 (the comment was wrong), now it seems like there won't be any dpi.
A related concern is that this function will fail on Windows 10 versions previous to 1703, and will result in no dpi scaling. I think fallback handling based on the optional function should take care of this though.
Also, we should probably at least log an error return value, though I think runtime failure is not likely. That's certainly on me from the old code though :)