Skip to content

Make dialogs on windows non-sychronous. #1328

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

Merged
merged 3 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ You can find its changes [documented below](#060---2020-06-01).
- Fix `widget::Either` using the wrong paint insets ([#1299] by [@andrewhickman])
- Various fixes to cross-platform menus ([#1306] by [@raphlinus])
- Improve Windows 7 DXGI compatibility ([#1311] by [@raphlinus])
- Don't drop events while showing file dialogs ([#1302], [#1328] by [@jneem])

### Visual

Expand Down Expand Up @@ -511,10 +512,12 @@ Last release without a changelog :(
[#1295]: https://github.com/linebender/druid/pull/1280
[#1298]: https://github.com/linebender/druid/pull/1298
[#1299]: https://github.com/linebender/druid/pull/1299
[#1302]: https://github.com/linebender/druid/pull/1302
[#1306]: https://github.com/linebender/druid/pull/1306
[#1311]: https://github.com/linebender/druid/pull/1311
[#1320]: https://github.com/linebender/druid/pull/1320
[#1326]: https://github.com/linebender/druid/pull/1326
[#1328]: https://github.com/linebender/druid/pull/1328
[#1346]: https://github.com/linebender/druid/pull/1346

[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
Expand Down
11 changes: 7 additions & 4 deletions druid-shell/examples/shello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use druid_shell::kurbo::{Line, Size};
use druid_shell::piet::{Color, RenderContext};

use druid_shell::{
Application, Cursor, FileDialogOptions, FileSpec, HotKey, KeyEvent, Menu, MouseEvent, Region,
SysMods, TimerToken, WinHandler, WindowBuilder, WindowHandle,
Application, Cursor, FileDialogOptions, FileDialogToken, FileInfo, FileSpec, HotKey, KeyEvent,
Menu, MouseEvent, Region, SysMods, TimerToken, WinHandler, WindowBuilder, WindowHandle,
};

const BG_COLOR: Color = Color::rgb8(0x27, 0x28, 0x22);
Expand Down Expand Up @@ -56,13 +56,16 @@ impl WinHandler for HelloState {
FileSpec::TEXT,
FileSpec::JPG,
]);
let filename = self.handle.open_file_sync(options);
println!("result: {:?}", filename);
self.handle.open_file(options);
}
_ => println!("unexpected id {}", id),
}
}

fn open_file(&mut self, _token: FileDialogToken, file_info: Option<FileInfo>) {
println!("open file result: {:?}", file_info);
}

fn key_down(&mut self, event: KeyEvent) -> bool {
println!("keydown: {:?}", event);
false
Expand Down
16 changes: 4 additions & 12 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@ impl WindowBuilder {
// Note that we're borrowing the surface while calling the handler. This is ok,
// because we don't return control to the system or re-borrow the surface from
// any code that the client can call.
// (TODO: the above comment isn't true yet because of save_as_sync and
// open_sync, but it will be true soon)
state.with_handler_and_dont_check_the_other_borrows(|handler| {
let surface_context = cairo::Context::new(surface);

Expand Down Expand Up @@ -753,6 +751,10 @@ impl WindowState {
.map(|s| FileInfo { path: s.into() });
self.with_handler(|h| h.save_as(token, file_info));
}
e => {
// The other deferred ops shouldn't appear, because we don't defer them in GTK.
log::error!("unexpected deferred op {:?}", e);
}
}
}
}
Expand Down Expand Up @@ -986,16 +988,6 @@ impl WindowHandle {
}
}

pub fn save_as_sync(&mut self, _options: FileDialogOptions) -> Option<FileInfo> {
log::error!("save as sync no longer supported on GTK");
None
}

pub fn open_file_sync(&mut self, _options: FileDialogOptions) -> Option<FileInfo> {
log::error!("open file sync no longer supported on GTK");
None
}

/// Get a handle that can be used to schedule an idle task.
pub fn get_idle_handle(&self) -> Option<IdleHandle> {
self.state.upgrade().map(|s| IdleHandle {
Expand Down
10 changes: 0 additions & 10 deletions druid-shell/src/platform/mac/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,20 +934,10 @@ impl WindowHandle {
}
}

pub fn open_file_sync(&mut self, _options: FileDialogOptions) -> Option<FileInfo> {
log::warn!("open_file_sync should no longer be called on mac!");
None
}

pub fn open_file(&mut self, options: FileDialogOptions) -> Option<FileDialogToken> {
self.open_save_impl(FileDialogType::Open, options)
}

pub fn save_as_sync(&mut self, _options: FileDialogOptions) -> Option<FileInfo> {
log::warn!("save_as_sync should no longer be called on mac!");
None
}

pub fn save_as(&mut self, options: FileDialogOptions) -> Option<FileDialogToken> {
self.open_save_impl(FileDialogType::Save, options)
}
Expand Down
16 changes: 2 additions & 14 deletions druid-shell/src/platform/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,25 +564,13 @@ impl WindowHandle {
None
}

pub fn open_file_sync(&mut self, options: FileDialogOptions) -> Option<FileInfo> {
log::warn!("open_file_sync is currently unimplemented for web.");
self.file_dialog(FileDialogType::Open, options)
.ok()
.map(|s| FileInfo { path: s.into() })
}

pub fn open_file(&mut self, _options: FileDialogOptions) -> Option<FileDialogToken> {
log::warn!("open_file is currently unimplemented for web.");
None
}

pub fn save_as_sync(&mut self, options: FileDialogOptions) -> Option<FileInfo> {
log::warn!("save_as_sync is currently unimplemented for web.");
self.file_dialog(FileDialogType::Save, options)
.ok()
.map(|s| FileInfo { path: s.into() })
}

pub fn save_as(&mut self, _options: FileDialogOptions) -> Option<FileDialogToken> {
log::warn!("save_as is currently unimplemented for web.");
None
}

Expand Down
11 changes: 3 additions & 8 deletions druid-shell/src/platform/windows/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use winapi::um::errhandlingapi::GetLastError;
use winapi::um::shellscalingapi::PROCESS_PER_MONITOR_DPI_AWARE;
use winapi::um::winuser::{
DispatchMessageW, GetAncestor, GetMessageW, LoadIconW, PeekMessageW, PostMessageW,
PostQuitMessage, RegisterClassW, SendMessageW, TranslateAcceleratorW, TranslateMessage,
GA_ROOT, IDI_APPLICATION, MSG, PM_NOREMOVE, WM_TIMER, WNDCLASSW,
PostQuitMessage, RegisterClassW, TranslateAcceleratorW, TranslateMessage, GA_ROOT,
IDI_APPLICATION, MSG, PM_NOREMOVE, WM_TIMER, WNDCLASSW,
};

use crate::application::AppHandler;
Expand All @@ -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_HANDLE_DEFERRED, DS_REQUEST_DESTROY};
use super::window::{self, DS_REQUEST_DESTROY};

#[derive(Clone)]
pub(crate) struct Application {
Expand Down Expand Up @@ -112,11 +112,6 @@ impl Application {
// NOTE: Code here will not run when we aren't in charge of the message loop. That
// will include when moving or resizing the window, and when showing modal dialogs.
loop {
if let Ok(state) = self.state.try_borrow() {
for hwnd in &state.windows {
SendMessageW(*hwnd, DS_HANDLE_DEFERRED, 0, 0);
}
}
let mut msg = mem::MaybeUninit::uninit();

// Timer messages have a low priority and tend to get delayed. Peeking for them
Expand Down
Loading