@@ -100,52 +100,54 @@ live_design! {
100
100
}
101
101
102
102
App = { { App } } {
103
- ui: <Window > {
104
- window: { inner_size: vec2( 1280 , 800 ) , title: "Robrix" } ,
105
- caption_bar = { caption_label = { label = { text: "Robrix" } } }
106
- pass: { clear_color: #2 A }
107
-
108
- body = {
109
- // A wrapper view for showing top-level app modals/dialogs/popups
110
- <View > {
111
- width: Fill , height: Fill ,
112
- flow: Overlay ,
113
-
114
- home_screen_view = <View > {
115
- visible: false
116
- home_screen = <HomeScreen > { }
117
- }
118
- login_screen_view = <View > {
119
- visible: true
120
- login_screen = <LoginScreen > { }
121
- }
122
- app_tooltip = <CalloutTooltip > { }
123
- popup = <PopupNotification > {
124
- margin: { top: 45 , right: 13 } ,
125
- content: {
126
- <PopupList > { }
103
+ ui: <Root >{
104
+ main_window = <Window > {
105
+ window: { inner_size: vec2( 1280 , 800 ) , title: "Robrix" } ,
106
+ caption_bar = { caption_label = { label = { text: "Robrix" } } }
107
+ pass: { clear_color: #2 A }
108
+
109
+ body = {
110
+ // A wrapper view for showing top-level app modals/dialogs/popups
111
+ <View > {
112
+ width: Fill , height: Fill ,
113
+ flow: Overlay ,
114
+
115
+ home_screen_view = <View > {
116
+ visible: false
117
+ home_screen = <HomeScreen > { }
118
+ }
119
+ login_screen_view = <View > {
120
+ visible: true
121
+ login_screen = <LoginScreen > { }
122
+ }
123
+ app_tooltip = <CalloutTooltip > { }
124
+ popup = <PopupNotification > {
125
+ margin: { top: 45 , right: 13 } ,
126
+ content: {
127
+ <PopupList > { }
128
+ }
127
129
}
128
- }
129
130
130
- // Context menus should be shown above other UI elements,
131
- // but beneath the verification modal.
132
- new_message_context_menu = <NewMessageContextMenu > { }
133
-
134
- // message_source_modal = <Modal> {
135
- // content: {
136
- // message_source_modal_inner = <MessageSourceModal> {}
137
- // }
138
- // }
139
-
140
- // We want the verification modal to always show up on top of
141
- // all other elements when an incoming verification request is received.
142
- verification_modal = <Modal > {
143
- content: {
144
- verification_modal_inner = <VerificationModal > { }
131
+ // Context menus should be shown above other UI elements,
132
+ // but beneath the verification modal.
133
+ new_message_context_menu = <NewMessageContextMenu > { }
134
+
135
+ // message_source_modal = <Modal> {
136
+ // content: {
137
+ // message_source_modal_inner = <MessageSourceModal> {}
138
+ // }
139
+ // }
140
+
141
+ // We want the verification modal to always show up on top of
142
+ // all other elements when an incoming verification request is received.
143
+ verification_modal = <Modal > {
144
+ content: {
145
+ verification_modal_inner = <VerificationModal > { }
146
+ }
145
147
}
146
148
}
147
- }
148
- } // end of body
149
+ } // end of body
150
+ }
149
151
}
150
152
}
151
153
}
@@ -235,16 +237,13 @@ impl MatchEvent for App {
235
237
cx. action ( DockStateAction :: RestoreFromAppState ) ;
236
238
}
237
239
Some ( RoomsPanelRestoreAction :: RestoreWindow ( window_state) ) => {
238
- cx. push_unique_platform_op ( CxOsOp :: ResizeWindow (
239
- CxWindowPool :: id_zero ( ) ,
240
- window_state. window_size . 0 ,
241
- ) ) ;
242
- cx. push_unique_platform_op ( CxOsOp :: RepositionWindow (
243
- CxWindowPool :: id_zero ( ) ,
244
- window_state. window_position . 0 ,
245
- ) ) ;
246
- if window_state. window_is_fullscreen {
247
- cx. push_unique_platform_op ( CxOsOp :: MaximizeWindow ( CxWindowPool :: id_zero ( ) ) ) ;
240
+ let window = self . ui . window ( id ! ( main_window) ) ;
241
+ window. resize ( cx, window_state. inner_size . 0 ) ;
242
+ window. reposition ( cx, window_state. position . 0 ) ;
243
+ if window_state. is_fullscreen {
244
+ if let Some ( mut window) = window. borrow_mut ( ) {
245
+ window. fullscreen ( cx) ;
246
+ }
248
247
}
249
248
}
250
249
_ => { }
@@ -366,18 +365,21 @@ impl MatchEvent for App {
366
365
367
366
impl AppMain for App {
368
367
fn handle_event ( & mut self , cx : & mut Cx , event : & Event ) {
369
- if let Event :: WindowGeomChange ( window_geom_change_event) = event {
370
- self . app_state . window_geom = Some ( window_geom_change_event. new_geom . clone ( ) ) ;
371
- }
372
- if let Event :: WindowClosed ( _) | Event :: Shutdown = event {
373
- if let Some ( window_geom) = & self . app_state . window_geom {
374
- let window_geom = window_geom. clone ( ) ;
375
- cx. spawn_thread ( move || {
376
- if let Err ( e) = save_window_state ( window_geom) {
377
- error ! ( "Bug! Failed to save window_state: {}" , e) ;
378
- }
379
- } ) ;
380
- }
368
+ // Handling Event::Shutdown is not required as Window Closed event is guaranteed when closing.
369
+ if let Event :: WindowClosed ( _) = event {
370
+ let window = self . ui . window ( id ! ( main_window) ) ;
371
+ let inner_size = DVec2Wrapper ( window. get_inner_size ( cx) ) ;
372
+ let position = DVec2Wrapper ( window. get_position ( cx) ) ;
373
+ let window_geom = WindowGeomState {
374
+ inner_size,
375
+ position,
376
+ is_fullscreen : window. is_fullscreen ( cx) ,
377
+ } ;
378
+ cx. spawn_thread ( move || {
379
+ if let Err ( e) = save_window_state ( window_geom) {
380
+ error ! ( "Bug! Failed to save window_state: {}" , e) ;
381
+ }
382
+ } ) ;
381
383
if let Some ( user_id) = current_user_id ( ) {
382
384
let rooms_panel = self . app_state . rooms_panel . clone ( ) ;
383
385
let user_id = user_id. clone ( ) ;
@@ -446,8 +448,6 @@ pub struct AppState {
446
448
pub rooms_panel : RoomsPanelState ,
447
449
/// Whether a user is currently logged in.
448
450
pub logged_in : bool ,
449
- /// The current window geometry.
450
- pub window_geom : Option < event:: WindowGeom > ,
451
451
}
452
452
453
453
#[ derive( Default , Debug , Clone , Serialize , Deserialize ) ]
@@ -469,11 +469,11 @@ pub struct RoomsPanelState {
469
469
/// The state of the window geometry
470
470
pub struct WindowGeomState {
471
471
/// A tuple containing the window's width and height.
472
- pub window_size : DVec2Wrapper ,
472
+ pub inner_size : DVec2Wrapper ,
473
473
/// A tuple containing the window's x and y position.
474
- pub window_position : DVec2Wrapper ,
474
+ pub position : DVec2Wrapper ,
475
475
/// Maximise fullscreen if true.
476
- pub window_is_fullscreen : bool
476
+ pub is_fullscreen : bool
477
477
}
478
478
479
479
/// Represents a room currently or previously selected by the user.
0 commit comments