1
- use crate :: { access, config, file_chooser, fl, screencast_dialog, screenshot, subscription} ;
1
+ use crate :: {
2
+ access, background, config, file_chooser, fl, screencast_dialog, screenshot, subscription,
3
+ } ;
2
4
use cosmic:: iced_core:: event:: wayland:: OutputEvent ;
3
5
use cosmic:: widget:: { self , dropdown} ;
4
6
use cosmic:: Command ;
@@ -29,6 +31,7 @@ pub struct CosmicPortal {
29
31
30
32
pub config_handler : Option < cosmic_config:: Config > ,
31
33
pub config : config:: Config ,
34
+ pub tx_conf : Option < tokio:: sync:: watch:: Sender < config:: Config > > ,
32
35
33
36
pub access_args : Option < access:: AccessDialogArgs > ,
34
37
pub access_choices : Vec < ( Option < usize > , Vec < String > ) > ,
@@ -43,6 +46,8 @@ pub struct CosmicPortal {
43
46
pub prev_rectangle : Option < screenshot:: Rect > ,
44
47
pub wayland_helper : crate :: wayland:: WaylandHelper ,
45
48
49
+ pub background_prompts : HashMap < window:: Id , background:: Args > ,
50
+
46
51
pub outputs : Vec < OutputState > ,
47
52
pub active_output : Option < WlOutput > ,
48
53
}
@@ -64,8 +69,10 @@ pub enum Msg {
64
69
FileChooser ( window:: Id , file_chooser:: Msg ) ,
65
70
Screenshot ( screenshot:: Msg ) ,
66
71
Screencast ( screencast_dialog:: Msg ) ,
72
+ Background ( background:: Msg ) ,
67
73
Portal ( subscription:: Event ) ,
68
74
Output ( OutputEvent , WlOutput ) ,
75
+ ConfigNotifyWatcher ,
69
76
ConfigSetScreenshot ( config:: screenshot:: Screenshot ) ,
70
77
/// Update config from external changes
71
78
ConfigSubUpdate ( config:: Config ) ,
@@ -127,6 +134,7 @@ impl cosmic::Application for CosmicPortal {
127
134
core,
128
135
config_handler,
129
136
config,
137
+ tx_conf : None ,
130
138
access_args : Default :: default ( ) ,
131
139
access_choices : Default :: default ( ) ,
132
140
file_choosers : Default :: default ( ) ,
@@ -135,6 +143,7 @@ impl cosmic::Application for CosmicPortal {
135
143
screencast_tab_model : Default :: default ( ) ,
136
144
location_options : Vec :: new ( ) ,
137
145
prev_rectangle : Default :: default ( ) ,
146
+ background_prompts : Default :: default ( ) ,
138
147
outputs : Default :: default ( ) ,
139
148
active_output : Default :: default ( ) ,
140
149
wayland_helper,
@@ -155,6 +164,8 @@ impl cosmic::Application for CosmicPortal {
155
164
screencast_dialog:: view ( self ) . map ( Msg :: Screencast )
156
165
} else if self . outputs . iter ( ) . any ( |o| o. id == id) {
157
166
screenshot:: view ( self , id) . map ( Msg :: Screenshot )
167
+ } else if self . background_prompts . contains_key ( & id) {
168
+ background:: view ( self , id) . map ( Msg :: Background )
158
169
} else {
159
170
file_chooser:: view ( self , id)
160
171
}
@@ -181,19 +192,25 @@ impl cosmic::Application for CosmicPortal {
181
192
subscription:: Event :: CancelScreencast ( handle) => {
182
193
screencast_dialog:: cancel ( self , handle) . map ( cosmic:: app:: Message :: App )
183
194
}
195
+ subscription:: Event :: Background ( args) => {
196
+ background:: update_args ( self , args) . map ( cosmic:: app:: Message :: App )
197
+ }
184
198
subscription:: Event :: Config ( config) => self . update ( Msg :: ConfigSubUpdate ( config) ) ,
185
199
subscription:: Event :: Accent ( _)
186
200
| subscription:: Event :: IsDark ( _)
187
- | subscription:: Event :: HighContrast ( _) => cosmic:: iced:: Command :: none ( ) ,
188
- subscription:: Event :: Init ( tx) => {
201
+ | subscription:: Event :: HighContrast ( _)
202
+ | subscription:: Event :: BackgroundToplevels => cosmic:: iced:: Command :: none ( ) ,
203
+ subscription:: Event :: Init { tx, tx_conf } => {
189
204
self . tx = Some ( tx) ;
190
- Command :: none ( )
205
+ self . tx_conf = Some ( tx_conf) ;
206
+ self . update ( Msg :: ConfigNotifyWatcher )
191
207
}
192
208
} ,
193
209
Msg :: Screenshot ( m) => screenshot:: update_msg ( self , m) . map ( cosmic:: app:: Message :: App ) ,
194
210
Msg :: Screencast ( m) => {
195
211
screencast_dialog:: update_msg ( self , m) . map ( cosmic:: app:: Message :: App )
196
212
}
213
+ Msg :: Background ( m) => background:: update_msg ( self , m) . map ( cosmic:: app:: Message :: App ) ,
197
214
Msg :: Output ( o_event, wl_output) => {
198
215
match o_event {
199
216
OutputEvent :: Created ( Some ( info) )
@@ -266,6 +283,12 @@ impl cosmic::Application for CosmicPortal {
266
283
267
284
cosmic:: iced:: Command :: none ( )
268
285
}
286
+ Msg :: ConfigNotifyWatcher => {
287
+ if let Some ( tx) = self . tx_conf . as_mut ( ) {
288
+ tx. send_replace ( self . config . clone ( ) ) ;
289
+ }
290
+ cosmic:: iced:: Command :: none ( )
291
+ }
269
292
Msg :: ConfigSetScreenshot ( screenshot) => {
270
293
match & mut self . config_handler {
271
294
Some ( handler) => {
@@ -275,12 +298,11 @@ impl cosmic::Application for CosmicPortal {
275
298
}
276
299
None => log:: error!( "Failed to save config: No config handler" ) ,
277
300
}
278
-
279
- cosmic:: iced:: Command :: none ( )
301
+ self . update ( Msg :: ConfigNotifyWatcher )
280
302
}
281
303
Msg :: ConfigSubUpdate ( config) => {
282
304
self . config = config;
283
- cosmic :: iced :: Command :: none ( )
305
+ self . update ( Msg :: ConfigNotifyWatcher )
284
306
}
285
307
}
286
308
}
0 commit comments