Skip to content
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

Fix dragging of custom_window_frame example on Windows #4656

Merged
merged 6 commits into from
Jun 19, 2024
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
2 changes: 0 additions & 2 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,15 +1284,13 @@ impl GlutinWindowContext {
if let Some(window) = &viewport.window {
let old_inner_size = window.inner_size();

let is_viewport_focused = self.focused_viewport == Some(viewport_id);
viewport.deferred_commands.append(&mut commands);

egui_winit::process_viewport_commands(
egui_ctx,
&mut viewport.info,
std::mem::take(&mut viewport.deferred_commands),
window,
is_viewport_focused,
&mut viewport.actions_requested,
);

Expand Down
8 changes: 1 addition & 7 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl WgpuWinitRunning {
viewports,
painter,
viewport_from_window,
focused_viewport,
..
} = &mut *shared_mut;

let FullOutput {
Expand Down Expand Up @@ -724,7 +724,6 @@ impl WgpuWinitRunning {
viewports,
painter,
viewport_from_window,
*focused_viewport,
);

// Prune dead viewports:
Expand Down Expand Up @@ -996,7 +995,6 @@ fn render_immediate_viewport(
viewports,
painter,
viewport_from_window,
focused_viewport,
..
} = &mut *shared_mut;

Expand Down Expand Up @@ -1036,7 +1034,6 @@ fn render_immediate_viewport(
viewports,
painter,
viewport_from_window,
*focused_viewport,
);
}

Expand All @@ -1061,7 +1058,6 @@ fn handle_viewport_output(
viewports: &mut ViewportIdMap<Viewport>,
painter: &mut egui_wgpu::winit::Painter,
viewport_from_window: &mut HashMap<WindowId, ViewportId>,
focused_viewport: Option<ViewportId>,
) {
for (
viewport_id,
Expand All @@ -1083,15 +1079,13 @@ fn handle_viewport_output(
if let Some(window) = viewport.window.as_ref() {
let old_inner_size = window.inner_size();

let is_viewport_focused = focused_viewport == Some(viewport_id);
viewport.deferred_commands.append(&mut commands);

egui_winit::process_viewport_commands(
egui_ctx,
&mut viewport.info,
std::mem::take(&mut viewport.deferred_commands),
window,
is_viewport_focused,
&mut viewport.actions_requested,
);

Expand Down
19 changes: 3 additions & 16 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,18 +1284,10 @@ pub fn process_viewport_commands(
info: &mut ViewportInfo,
commands: impl IntoIterator<Item = ViewportCommand>,
window: &Window,
is_viewport_focused: bool,
actions_requested: &mut HashSet<ActionRequested>,
) {
for command in commands {
process_viewport_command(
egui_ctx,
window,
command,
info,
is_viewport_focused,
actions_requested,
);
process_viewport_command(egui_ctx, window, command, info, actions_requested);
}
}

Expand All @@ -1304,7 +1296,6 @@ fn process_viewport_command(
window: &Window,
command: ViewportCommand,
info: &mut ViewportInfo,
is_viewport_focused: bool,
actions_requested: &mut HashSet<ActionRequested>,
) {
crate::profile_function!();
Expand All @@ -1323,12 +1314,8 @@ fn process_viewport_command(
// Need to be handled elsewhere
}
ViewportCommand::StartDrag => {
// If `is_viewport_focused` is not checked on x11 the input will be permanently taken until the app is killed!

// 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 `.has_focus()` is not checked on x11 the input will be permanently taken until the app is killed!
if window.has_focus() {
if let Err(err) = window.drag_window() {
log::warn!("{command:?}: {err}");
}
Expand Down
1 change: 0 additions & 1 deletion crates/egui_glow/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ impl EguiGlow {
&mut self.viewport_info,
commands,
window,
true,
&mut actions_requested,
);
for action in actions_requested {
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_window_frame/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

if title_bar_response.dragged_by(PointerButton::Primary) {
if title_bar_response.drag_started_by(PointerButton::Primary) {
ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag);
}

Expand Down
Loading