1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
use crate::protocol::ServerMessage;
/// Effects that are meaningful only for the endpoint currently holding the host presentation
/// lease. During a frozen handoff they are intentionally dropped and the committed target asks
/// for one bounded replay, rather than allowing target graphics or modes onto the source frame.
pub(crate) fn is_presentation_effect(message: &ServerMessage) -> bool {
matches!(
message,
ServerMessage::MouseCapture { .. }
| ServerMessage::ClientShellKeyboardReportAll { .. }
| ServerMessage::WindowTitle { .. }
| ServerMessage::Graphics { .. }
| ServerMessage::GraphicsFile { .. }
| ServerMessage::GraphicsTransmissionRetired { .. }
| ServerMessage::TerminalBell { .. }
)
}
pub(crate) fn accepts_endpoint_message(
endpoint_active: bool,
activation_message: bool,
command_response: bool,
message: &ServerMessage,
) -> bool {
endpoint_active
|| matches!(
message,
ServerMessage::EndpointControl { .. }
| ServerMessage::SemanticNotification(_)
| ServerMessage::ServerShutdown { .. }
| ServerMessage::ClientShellSnapshot(_)
| ServerMessage::Welcome { .. }
)
|| (activation_message
&& matches!(
message,
ServerMessage::PaneSurface(_)
| ServerMessage::ClientShellEndpointResponseChunk { .. }
))
|| (command_response
&& matches!(
message,
ServerMessage::ClientShellEndpointResponseChunk { .. }
))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn inactive_endpoints_deliver_metadata_but_not_presentation_effects() {
assert!(accepts_endpoint_message(
false,
false,
false,
&ServerMessage::EndpointControl {
kind: "snapshot".into(),
data: "{}".into(),
}
));
assert!(!accepts_endpoint_message(
false,
false,
false,
&ServerMessage::Clipboard {
data: "text".into()
}
));
assert!(!accepts_endpoint_message(
false,
false,
false,
&ServerMessage::WindowTitle {
title: Some("remote".into())
}
));
}
#[test]
fn frozen_handoffs_drop_target_effects_until_the_post_commit_resync() {
assert!(is_presentation_effect(&ServerMessage::MouseCapture {
enabled: true,
sgr_pixels: false,
}));
assert!(is_presentation_effect(&ServerMessage::GraphicsFile {
path: "asset".into(),
expected_len: 1,
image_id: 1,
transfer_id: 1,
leading: Vec::new(),
control: "a=t".into(),
surface_asset: None,
}));
assert!(!is_presentation_effect(&ServerMessage::EndpointControl {
kind: "shell.snapshot.v1".into(),
data: "{}".into(),
}));
}
#[test]
fn pending_activation_accepts_only_its_surface_lane() {
assert!(accepts_endpoint_message(
false,
true,
false,
&ServerMessage::ClientShellEndpointResponseChunk {
boot_id: "boot".into(),
request_id: "surface".into(),
final_chunk: true,
data: Vec::new(),
}
));
assert!(!accepts_endpoint_message(
false,
true,
false,
&ServerMessage::MouseCapture {
enabled: true,
sgr_pixels: false,
}
));
}
}
|