Skip to content

Commit

Permalink
Simplify arguments to process_viewport_commands
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 12, 2023
1 parent 6e17040 commit e1f261b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
18 changes: 12 additions & 6 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,12 @@ mod glow_integration {
viewport.window = None;
viewport.gl_surface = None;
} else if let Some(window) = &viewport.window {
process_viewport_commands(commands, *id, None, &window.borrow());
let is_viewport_focused = false; // TODO
process_viewport_commands(
commands,
&window.borrow(),
is_viewport_focused,
);
}
active_viewports_ids.insert(*id);
false
Expand Down Expand Up @@ -1616,11 +1621,11 @@ mod glow_integration {
for (viewport_id, command) in viewport_commands {
if let Some(viewport) = glutin.borrow().viewports.get(&viewport_id) {
if let Some(window) = &viewport.borrow().window {
let is_viewport_focused = self.focused_viewport == Some(viewport_id);
egui_winit::process_viewport_commands(
vec![command],
viewport_id,
self.focused_viewport,
&window.borrow(),
is_viewport_focused,
);
}
}
Expand Down Expand Up @@ -2541,7 +2546,8 @@ mod wgpu_integration {
..
}) = viewports.get(&id_pair.this)
{
process_viewport_commands(commands, id_pair.this, None, &window.borrow());
let is_viewport_focused = false; // TODO
process_viewport_commands(commands, &window.borrow(), is_viewport_focused);
}
} else {
viewports.insert(
Expand All @@ -2561,11 +2567,11 @@ mod wgpu_integration {

for (viewport_id, command) in viewport_commands {
if let Some(window) = viewports.get(&viewport_id).and_then(|w| w.window.clone()) {
let is_viewport_focused = self.focused_viewport == Some(viewport_id);
egui_winit::process_viewport_commands(
vec![command],
viewport_id,
self.focused_viewport,
&window.borrow(),
is_viewport_focused,
);
}
}
Expand Down
11 changes: 4 additions & 7 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,21 +990,18 @@ fn translate_cursor(cursor_icon: egui::CursorIcon) -> Option<winit::window::Curs

pub fn process_viewport_commands(
commands: Vec<ViewportCommand>,
viewport_id: ViewportId,
focused: Option<ViewportId>,
window: &winit::window::Window,
is_viewport_focused: bool,
) {
use winit::window::ResizeDirection;

for command in commands {
match command {
egui::ViewportCommand::Drag => {
// if this is not checked on x11 the input will be permanently taken until the app is killed!
if let Some(focus) = focused {
if focus == viewport_id {
// TODO possible return the error to `egui::Context`
let _ = window.drag_window();
}
if is_viewport_focused {
// TODO possible return the error to `egui::Context`
let _ = window.drag_window();
}
}
egui::ViewportCommand::InnerSize(size) => {
Expand Down

0 comments on commit e1f261b

Please sign in to comment.