@@ -5,6 +5,7 @@ use cctk::{
5
5
toplevel_info:: { ToplevelInfo , ToplevelInfoHandler , ToplevelInfoState } ,
6
6
toplevel_management:: { ToplevelManagerHandler , ToplevelManagerState } ,
7
7
wayland_client:: { self , WEnum } ,
8
+ wayland_protocols:: ext:: foreign_toplevel_list:: v1:: client:: ext_foreign_toplevel_handle_v1:: ExtForeignToplevelHandleV1 ,
8
9
} ;
9
10
use sctk:: {
10
11
self ,
@@ -15,7 +16,7 @@ use sctk::{
15
16
} ;
16
17
17
18
use cosmic_protocols:: {
18
- toplevel_info:: v1:: client:: zcosmic_toplevel_handle_v1:: { self , ZcosmicToplevelHandleV1 } ,
19
+ toplevel_info:: v1:: client:: zcosmic_toplevel_handle_v1:: ZcosmicToplevelHandleV1 ,
19
20
toplevel_management:: v1:: client:: zcosmic_toplevel_manager_v1,
20
21
} ;
21
22
use futures:: channel:: mpsc:: UnboundedSender ;
@@ -25,23 +26,35 @@ use wayland_client::{globals::registry_queue_init, Connection, QueueHandle};
25
26
26
27
#[ derive( Debug , Clone ) ]
27
28
pub enum ToplevelAction {
28
- Activate ( ZcosmicToplevelHandleV1 ) ,
29
- Close ( ZcosmicToplevelHandleV1 ) ,
29
+ Activate ( ExtForeignToplevelHandleV1 ) ,
30
+ Close ( ExtForeignToplevelHandleV1 ) ,
30
31
}
31
32
32
- pub type TopLevelsUpdate = Vec < (
33
- zcosmic_toplevel_handle_v1 :: ZcosmicToplevelHandleV1 ,
34
- Option < ToplevelInfo > ,
35
- ) > ;
33
+ pub enum ToplevelUpdate {
34
+ Info ( ToplevelInfo ) ,
35
+ Remove ( ExtForeignToplevelHandleV1 ) ,
36
+ }
36
37
37
38
struct AppData {
38
39
exit : bool ,
39
- tx : UnboundedSender < TopLevelsUpdate > ,
40
+ tx : UnboundedSender < Vec < ToplevelUpdate > > ,
40
41
registry_state : RegistryState ,
41
42
toplevel_info_state : ToplevelInfoState ,
42
43
toplevel_manager_state : ToplevelManagerState ,
43
44
seat_state : SeatState ,
44
- pending_update : HashSet < zcosmic_toplevel_handle_v1:: ZcosmicToplevelHandleV1 > ,
45
+ pending_update : HashSet < ExtForeignToplevelHandleV1 > ,
46
+ }
47
+
48
+ impl AppData {
49
+ fn cosmic_toplevel_for_foreign (
50
+ & self ,
51
+ foreign_toplevel : & ExtForeignToplevelHandleV1 ,
52
+ ) -> Option < & ZcosmicToplevelHandleV1 > {
53
+ self . toplevel_info_state
54
+ . info ( foreign_toplevel) ?
55
+ . cosmic_toplevel
56
+ . as_ref ( )
57
+ }
45
58
}
46
59
47
60
impl ProvidesRegistryState for AppData {
@@ -103,7 +116,7 @@ impl ToplevelInfoHandler for AppData {
103
116
& mut self ,
104
117
_conn : & Connection ,
105
118
_qh : & QueueHandle < Self > ,
106
- toplevel : & zcosmic_toplevel_handle_v1 :: ZcosmicToplevelHandleV1 ,
119
+ toplevel : & ExtForeignToplevelHandleV1 ,
107
120
) {
108
121
self . pending_update . insert ( toplevel. clone ( ) ) ;
109
122
}
@@ -112,7 +125,7 @@ impl ToplevelInfoHandler for AppData {
112
125
& mut self ,
113
126
_conn : & Connection ,
114
127
_qh : & QueueHandle < Self > ,
115
- toplevel : & zcosmic_toplevel_handle_v1 :: ZcosmicToplevelHandleV1 ,
128
+ toplevel : & ExtForeignToplevelHandleV1 ,
116
129
) {
117
130
self . pending_update . insert ( toplevel. clone ( ) ) ;
118
131
}
@@ -121,20 +134,20 @@ impl ToplevelInfoHandler for AppData {
121
134
& mut self ,
122
135
_conn : & Connection ,
123
136
_qh : & QueueHandle < Self > ,
124
- toplevel : & zcosmic_toplevel_handle_v1 :: ZcosmicToplevelHandleV1 ,
137
+ toplevel : & ExtForeignToplevelHandleV1 ,
125
138
) {
126
139
self . pending_update . insert ( toplevel. clone ( ) ) ;
127
140
}
128
141
129
142
fn info_done ( & mut self , _conn : & Connection , _qh : & QueueHandle < Self > ) {
130
- let mut res = Vec :: with_capacity ( self . pending_update . len ( ) ) ;
131
-
132
- for toplevel_handle in self . pending_update . drain ( ) {
133
- res . push ( (
134
- toplevel_handle . clone ( ) ,
135
- self . toplevel_info_state . info ( & toplevel_handle ) . cloned ( ) ,
136
- ) ) ;
137
- }
143
+ let res = self
144
+ . pending_update
145
+ . drain ( )
146
+ . map ( |handle| match self . toplevel_info_state . info ( & handle ) {
147
+ Some ( info ) => ToplevelUpdate :: Info ( info . clone ( ) ) ,
148
+ None => ToplevelUpdate :: Remove ( handle ) ,
149
+ } )
150
+ . collect ( ) ;
138
151
139
152
if let Err ( err) = self . tx . unbounded_send ( res) {
140
153
warn ! ( "{err}" ) ;
@@ -143,7 +156,7 @@ impl ToplevelInfoHandler for AppData {
143
156
}
144
157
145
158
pub ( crate ) fn toplevel_handler (
146
- tx : UnboundedSender < TopLevelsUpdate > ,
159
+ tx : UnboundedSender < Vec < ToplevelUpdate > > ,
147
160
rx : calloop:: channel:: Channel < ToplevelAction > ,
148
161
) -> anyhow:: Result < ( ) > {
149
162
let conn = Connection :: connect_to_env ( ) ?;
@@ -159,15 +172,18 @@ pub(crate) fn toplevel_handler(
159
172
calloop:: channel:: Event :: Msg ( req) => match req {
160
173
ToplevelAction :: Activate ( handle) => {
161
174
let manager = & state. toplevel_manager_state . manager ;
162
- let state = & state. seat_state ;
163
175
// TODO Ashley how to choose the seat in a multi-seat setup?
164
- for s in state. seats ( ) {
165
- manager. activate ( & handle, & s) ;
176
+ if let Some ( cosmic_toplevel) = state. cosmic_toplevel_for_foreign ( & handle) {
177
+ for s in state. seat_state . seats ( ) {
178
+ manager. activate ( cosmic_toplevel, & s) ;
179
+ }
166
180
}
167
181
}
168
182
ToplevelAction :: Close ( handle) => {
169
183
let manager = & state. toplevel_manager_state . manager ;
170
- manager. close ( & handle) ;
184
+ if let Some ( cosmic_toplevel) = state. cosmic_toplevel_for_foreign ( & handle) {
185
+ manager. close ( cosmic_toplevel) ;
186
+ }
171
187
}
172
188
} ,
173
189
calloop:: channel:: Event :: Closed => {
0 commit comments