Fix dragging of `custom_window_frame` example on Windows (#4656)

* Related #4592 
* Closes #4647 

Fix dragging of custom_window_frame on Windows (re-edited)
This commit is contained in:
rustbasic 2024-06-19 23:19:41 +09:00 committed by GitHub
parent 52a8e11764
commit d9c5fb04ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 5 additions and 27 deletions

View File

@ -1284,7 +1284,6 @@ impl GlutinWindowContext {
if let Some(window) = &viewport.window { if let Some(window) = &viewport.window {
let old_inner_size = window.inner_size(); let old_inner_size = window.inner_size();
let is_viewport_focused = self.focused_viewport == Some(viewport_id);
viewport.deferred_commands.append(&mut commands); viewport.deferred_commands.append(&mut commands);
egui_winit::process_viewport_commands( egui_winit::process_viewport_commands(
@ -1292,7 +1291,6 @@ impl GlutinWindowContext {
&mut viewport.info, &mut viewport.info,
std::mem::take(&mut viewport.deferred_commands), std::mem::take(&mut viewport.deferred_commands),
window, window,
is_viewport_focused,
&mut viewport.actions_requested, &mut viewport.actions_requested,
); );

View File

@ -635,7 +635,7 @@ impl WgpuWinitRunning {
viewports, viewports,
painter, painter,
viewport_from_window, viewport_from_window,
focused_viewport, ..
} = &mut *shared_mut; } = &mut *shared_mut;
let FullOutput { let FullOutput {
@ -724,7 +724,6 @@ impl WgpuWinitRunning {
viewports, viewports,
painter, painter,
viewport_from_window, viewport_from_window,
*focused_viewport,
); );
// Prune dead viewports: // Prune dead viewports:
@ -996,7 +995,6 @@ fn render_immediate_viewport(
viewports, viewports,
painter, painter,
viewport_from_window, viewport_from_window,
focused_viewport,
.. ..
} = &mut *shared_mut; } = &mut *shared_mut;
@ -1036,7 +1034,6 @@ fn render_immediate_viewport(
viewports, viewports,
painter, painter,
viewport_from_window, viewport_from_window,
*focused_viewport,
); );
} }
@ -1061,7 +1058,6 @@ fn handle_viewport_output(
viewports: &mut ViewportIdMap<Viewport>, viewports: &mut ViewportIdMap<Viewport>,
painter: &mut egui_wgpu::winit::Painter, painter: &mut egui_wgpu::winit::Painter,
viewport_from_window: &mut HashMap<WindowId, ViewportId>, viewport_from_window: &mut HashMap<WindowId, ViewportId>,
focused_viewport: Option<ViewportId>,
) { ) {
for ( for (
viewport_id, viewport_id,
@ -1083,7 +1079,6 @@ fn handle_viewport_output(
if let Some(window) = viewport.window.as_ref() { if let Some(window) = viewport.window.as_ref() {
let old_inner_size = window.inner_size(); let old_inner_size = window.inner_size();
let is_viewport_focused = focused_viewport == Some(viewport_id);
viewport.deferred_commands.append(&mut commands); viewport.deferred_commands.append(&mut commands);
egui_winit::process_viewport_commands( egui_winit::process_viewport_commands(
@ -1091,7 +1086,6 @@ fn handle_viewport_output(
&mut viewport.info, &mut viewport.info,
std::mem::take(&mut viewport.deferred_commands), std::mem::take(&mut viewport.deferred_commands),
window, window,
is_viewport_focused,
&mut viewport.actions_requested, &mut viewport.actions_requested,
); );

View File

@ -1284,18 +1284,10 @@ pub fn process_viewport_commands(
info: &mut ViewportInfo, info: &mut ViewportInfo,
commands: impl IntoIterator<Item = ViewportCommand>, commands: impl IntoIterator<Item = ViewportCommand>,
window: &Window, window: &Window,
is_viewport_focused: bool,
actions_requested: &mut HashSet<ActionRequested>, actions_requested: &mut HashSet<ActionRequested>,
) { ) {
for command in commands { for command in commands {
process_viewport_command( process_viewport_command(egui_ctx, window, command, info, actions_requested);
egui_ctx,
window,
command,
info,
is_viewport_focused,
actions_requested,
);
} }
} }
@ -1304,7 +1296,6 @@ fn process_viewport_command(
window: &Window, window: &Window,
command: ViewportCommand, command: ViewportCommand,
info: &mut ViewportInfo, info: &mut ViewportInfo,
is_viewport_focused: bool,
actions_requested: &mut HashSet<ActionRequested>, actions_requested: &mut HashSet<ActionRequested>,
) { ) {
crate::profile_function!(); crate::profile_function!();
@ -1323,12 +1314,8 @@ fn process_viewport_command(
// Need to be handled elsewhere // Need to be handled elsewhere
} }
ViewportCommand::StartDrag => { ViewportCommand::StartDrag => {
// If `is_viewport_focused` is not checked on x11 the input will be permanently taken until the app is killed! // If `.has_focus()` is not checked on x11 the input will be permanently taken until the app is killed!
if window.has_focus() {
// TODO(emilk): check that the left mouse-button was pressed down recently,
// or we will have bugs on Windows.
// See https://github.com/emilk/egui/pull/1108
if is_viewport_focused {
if let Err(err) = window.drag_window() { if let Err(err) = window.drag_window() {
log::warn!("{command:?}: {err}"); log::warn!("{command:?}: {err}");
} }

View File

@ -85,7 +85,6 @@ impl EguiGlow {
&mut self.viewport_info, &mut self.viewport_info,
commands, commands,
window, window,
true,
&mut actions_requested, &mut actions_requested,
); );
for action in actions_requested { for action in actions_requested {

View File

@ -112,7 +112,7 @@ fn title_bar_ui(ui: &mut egui::Ui, title_bar_rect: eframe::epaint::Rect, title:
.send_viewport_cmd(ViewportCommand::Maximized(!is_maximized)); .send_viewport_cmd(ViewportCommand::Maximized(!is_maximized));
} }
if title_bar_response.dragged_by(PointerButton::Primary) { if title_bar_response.drag_started_by(PointerButton::Primary) {
ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag); ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag);
} }