Skip to content

Commit 66cd7a3

Browse files
authored
Desktop: Add the transparent viewport hole punch and hook up window button plumbing (#2949)
1 parent d9de1a1 commit 66cd7a3

26 files changed

+300
-77
lines changed

editor/src/dispatcher.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct Dispatcher {
1414
#[derive(Debug, Default)]
1515
pub struct DispatcherMessageHandlers {
1616
animation_message_handler: AnimationMessageHandler,
17+
app_window_message_handler: AppWindowMessageHandler,
1718
broadcast_message_handler: BroadcastMessageHandler,
1819
debug_message_handler: DebugMessageHandler,
1920
dialog_message_handler: DialogMessageHandler,
@@ -129,6 +130,9 @@ impl Dispatcher {
129130
Message::Animation(message) => {
130131
self.message_handlers.animation_message_handler.process_message(message, &mut queue, ());
131132
}
133+
Message::AppWindow(message) => {
134+
self.message_handlers.app_window_message_handler.process_message(message, &mut queue, ());
135+
}
132136
Message::Broadcast(message) => self.message_handlers.broadcast_message_handler.process_message(message, &mut queue, ()),
133137
Message::Debug(message) => {
134138
self.message_handlers.debug_message_handler.process_message(message, &mut queue, ());
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use crate::messages::prelude::*;
2+
3+
#[impl_message(Message, AppWindow)]
4+
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
5+
pub enum AppWindowMessage {
6+
AppWindowMinimize,
7+
AppWindowMaximize,
8+
AppWindowClose,
9+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use crate::messages::app_window::AppWindowMessage;
2+
use crate::messages::prelude::*;
3+
use graphite_proc_macros::{ExtractField, message_handler_data};
4+
5+
#[derive(Debug, Clone, Default, ExtractField)]
6+
pub struct AppWindowMessageHandler {
7+
platform: AppWindowPlatform,
8+
maximized: bool,
9+
viewport_hole_punch_active: bool,
10+
}
11+
12+
#[message_handler_data]
13+
impl MessageHandler<AppWindowMessage, ()> for AppWindowMessageHandler {
14+
fn process_message(&mut self, message: AppWindowMessage, responses: &mut std::collections::VecDeque<Message>, _: ()) {
15+
match message {
16+
AppWindowMessage::AppWindowMinimize => {
17+
self.platform = if self.platform == AppWindowPlatform::Mac {
18+
AppWindowPlatform::Windows
19+
} else {
20+
AppWindowPlatform::Mac
21+
};
22+
responses.add(FrontendMessage::UpdatePlatform { platform: self.platform });
23+
}
24+
AppWindowMessage::AppWindowMaximize => {
25+
self.maximized = !self.maximized;
26+
responses.add(FrontendMessage::UpdateMaximized { maximized: self.maximized });
27+
28+
self.viewport_hole_punch_active = !self.viewport_hole_punch_active;
29+
responses.add(FrontendMessage::UpdateViewportHolePunch {
30+
active: self.viewport_hole_punch_active,
31+
});
32+
}
33+
AppWindowMessage::AppWindowClose => {
34+
self.platform = AppWindowPlatform::Web;
35+
responses.add(FrontendMessage::UpdatePlatform { platform: self.platform });
36+
}
37+
}
38+
}
39+
40+
fn actions(&self) -> ActionList {
41+
actions!(AppWindowMessageDiscriminant;)
42+
}
43+
}
44+
45+
#[derive(PartialEq, Eq, Clone, Copy, Default, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
46+
pub enum AppWindowPlatform {
47+
#[default]
48+
Web,
49+
Windows,
50+
Mac,
51+
Linux,
52+
}

editor/src/messages/app_window/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mod app_window_message;
2+
pub mod app_window_message_handler;
3+
4+
#[doc(inline)]
5+
pub use app_window_message::{AppWindowMessage, AppWindowMessageDiscriminant};
6+
#[doc(inline)]
7+
pub use app_window_message_handler::AppWindowMessageHandler;

editor/src/messages/frontend/frontend_message.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::utility_types::{FrontendDocumentDetails, MouseCursorIcon};
2+
use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
23
use crate::messages::layout::utility_types::widget_prelude::*;
34
use crate::messages::portfolio::document::node_graph::utility_types::{
45
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, Transform,
@@ -309,4 +310,13 @@ pub enum FrontendMessage {
309310
layout_target: LayoutTarget,
310311
diff: Vec<WidgetDiff>,
311312
},
313+
UpdatePlatform {
314+
platform: AppWindowPlatform,
315+
},
316+
UpdateMaximized {
317+
maximized: bool,
318+
},
319+
UpdateViewportHolePunch {
320+
active: bool,
321+
},
312322
}

editor/src/messages/message.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub enum Message {
99
#[child]
1010
Animation(AnimationMessage),
1111
#[child]
12+
AppWindow(AppWindowMessage),
13+
#[child]
1214
Broadcast(BroadcastMessage),
1315
#[child]
1416
Debug(DebugMessage),

editor/src/messages/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! The root-level messages forming the first layer of the message system architecture.
22
33
pub mod animation;
4+
pub mod app_window;
45
pub mod broadcast;
56
pub mod debug;
67
pub mod dialog;

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
107107

108108
let compatible_type = first_layer.and_then(|layer| {
109109
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, &document.network_interface);
110-
graph_layer.horizontal_layer_flow().nth(1).and_then(|node_id| {
110+
graph_layer.horizontal_layer_flow().nth(1).map(|node_id| {
111111
let (output_type, _) = document.network_interface.output_type(&node_id, 0, &[]);
112-
Some(format!("type:{}", output_type.nested_type()))
112+
format!("type:{}", output_type.nested_type())
113113
})
114114
});
115115

116116
let is_compatible = compatible_type.as_deref() == Some("type:Instances<VectorData>");
117117

118-
let is_modifiable = first_layer.map_or(false, |layer| {
118+
let is_modifiable = first_layer.is_some_and(|layer| {
119119
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, &document.network_interface);
120120
matches!(graph_layer.find_input("Path", 1), Some(TaggedValue::VectorModification(_)))
121121
});

editor/src/messages/portfolio/utility_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl From<String> for PanelType {
5353
"Layers" => PanelType::Layers,
5454
"Properties" => PanelType::Properties,
5555
"Spreadsheet" => PanelType::Spreadsheet,
56-
_ => panic!("Unknown panel type: {}", value),
56+
_ => panic!("Unknown panel type: {value}"),
5757
}
5858
}
5959
}

editor/src/messages/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub use crate::utility_traits::{ActionList, AsMessage, HierarchicalTree, Message
33
pub use crate::utility_types::{DebugMessageTree, MessageData};
44
// Message, MessageData, MessageDiscriminant, MessageHandler
55
pub use crate::messages::animation::{AnimationMessage, AnimationMessageDiscriminant, AnimationMessageHandler};
6+
pub use crate::messages::app_window::{AppWindowMessage, AppWindowMessageDiscriminant, AppWindowMessageHandler};
67
pub use crate::messages::broadcast::{BroadcastMessage, BroadcastMessageDiscriminant, BroadcastMessageHandler};
78
pub use crate::messages::debug::{DebugMessage, DebugMessageDiscriminant, DebugMessageHandler};
89
pub use crate::messages::dialog::export_dialog::{ExportDialogMessage, ExportDialogMessageContext, ExportDialogMessageDiscriminant, ExportDialogMessageHandler};

0 commit comments

Comments
 (0)