Skip to content
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
40 changes: 17 additions & 23 deletions desktop/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use massive_renderer::RenderPacing;
use massive_shell::{ApplicationContext, FontManager, Scene, ShellEvent};
use massive_shell::{AsyncWindowRenderer, ShellWindow};

use crate::desktop_presenter::{BandLocation, DesktopFocusPath};
use crate::desktop_presenter::{BandLocation, DesktopFocusPath, DesktopTarget};
use crate::projects::Project;
use crate::{
DesktopEnvironment, DesktopInteraction, DesktopPresenter, UserIntent,
Expand Down Expand Up @@ -106,11 +106,13 @@ impl Desktop {
instance_manager.add_view(primary_instance, &creation_info);

let ui = DesktopInteraction::new(
DesktopFocusPath::from_instance_and_view(
BandLocation::TopBand,
primary_instance,
primary_view,
),
vec![
DesktopTarget::Desktop,
DesktopTarget::TopBand,
DesktopTarget::Instance(primary_instance),
DesktopTarget::View(primary_view),
]
.into(),
&instance_manager,
&mut presenter,
&scene,
Expand Down Expand Up @@ -217,22 +219,16 @@ impl Desktop {
let focused = self.interaction.focused();
let originating_instance = focused.instance();

// Simplify: Use the currently focused instance for determining the originating one.
let band_location = focused
.band_location()
.expect("Failed to start an instance without a focused instance target");

self.presenter.present_instance(
band_location,
let presented_instance_path = self.presenter.present_instance(
focused,
instance,
originating_instance,
self.primary_instance_panel_size,
&self.scene,
)?;

self.interaction.make_foreground(
band_location,
instance,
self.interaction.focus(
presented_instance_path,
&self.instance_manager,
&mut self.presenter,
)?;
Expand Down Expand Up @@ -265,15 +261,13 @@ impl Desktop {
let focused = self.interaction.focused();
// If this instance is currently focused and the new view is primary, make it
// foreground so that the view is focused.
//
// Ergonomics: instance() and band_location() are usually used together.
if focused.instance() == Some(instance)
&& let Some(band_location) = focused.band_location()
if matches!(focused.last(), Some(DesktopTarget::Instance(..)))
&& focused.instance() == Some(instance)
&& info.role == ViewRole::Primary
{
self.interaction.make_foreground(
band_location,
instance,
let view_focus = focused.clone().join(DesktopTarget::View(info.id));
self.interaction.focus(
view_focus,
&self.instance_manager,
&mut self.presenter,
)?;
Expand Down
32 changes: 1 addition & 31 deletions desktop/src/desktop_interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,6 @@ impl DesktopInteraction {
self.camera.value()
}

pub fn make_foreground(
&mut self,
band_location: BandLocation,
instance: InstanceId,
instance_manager: &InstanceManager,
presenter: &mut DesktopPresenter,
) -> Result<()> {
// If the window is not focus, we just focus the instance.
let primary_view = instance_manager.get_view_by_role(instance, ViewRole::Primary)?;
let focus_path =
DesktopFocusPath::from_instance_and_view(band_location, instance, primary_view);
assert_eq!(
self.focus(focus_path, instance_manager, presenter)?,
UserIntent::None,
"Unexpected UserIntent in response to make_foreground"
);
Ok(())
}

pub fn focus(
&mut self,
focus_path: DesktopFocusPath,
Expand Down Expand Up @@ -138,18 +119,7 @@ impl DesktopInteraction {
let hit_test = NavigationHitTester::new(navigation, render_geometry);
self.event_router.process(event, &hit_test)?
};
let intent =
presenter.forward_event_transitions(transitions.transitions, instance_manager)?;

// Robustness: Currently we don't check if the only the instance actually changed.
if let Some(new_focus) = transitions.focus_changed
&& let Some(instance) = new_focus.instance()
&& let Some(band_location) = new_focus.band_location()
{
self.make_foreground(band_location, instance, instance_manager, presenter)?;
};

Ok(intent)
presenter.forward_event_transitions(transitions.transitions, instance_manager)
}

fn preprocess_keyboard_commands(&self, event: &Event<ViewEvent>) -> Result<UserIntent> {
Expand Down
Loading
Loading