@@ -6,6 +6,7 @@ use cctk::{cosmic_protocols, sctk::reexports::calloop, toplevel_info::ToplevelIn
6
6
use cosmic_protocols:: toplevel_info:: v1:: client:: zcosmic_toplevel_handle_v1:: ZcosmicToplevelHandleV1 ;
7
7
use fde:: DesktopEntry ;
8
8
use freedesktop_desktop_entry as fde;
9
+ use toplevel_handler:: TopLevelsUpdate ;
9
10
use tracing:: { debug, error, info, warn} ;
10
11
11
12
use crate :: desktop_entries:: utils:: { get_description, is_session_cosmic} ;
@@ -21,10 +22,9 @@ use pop_launcher::{
21
22
} ;
22
23
use std:: borrow:: Cow ;
23
24
use std:: iter;
24
- use std:: collections:: VecDeque ;
25
25
use tokio:: io:: { AsyncWrite , AsyncWriteExt } ;
26
26
27
- use self :: toplevel_handler:: { toplevel_handler, ToplevelAction , ToplevelEvent } ;
27
+ use self :: toplevel_handler:: { toplevel_handler, ToplevelAction } ;
28
28
29
29
pub async fn main ( ) {
30
30
let mut tx = async_stdout ( ) ;
@@ -66,40 +66,33 @@ pub async fn main() {
66
66
}
67
67
} ;
68
68
}
69
- Either :: Right ( ( Some ( event ) , second_to_next_request) ) => {
69
+ Either :: Right ( ( Some ( updates ) , second_to_next_request) ) => {
70
70
next_event = toplevel_rx. next ( ) ;
71
71
next_request = second_to_next_request;
72
72
73
- match event {
74
- ToplevelEvent :: Add ( handle , info) => {
75
- debug ! ( "add {}" , & info. app_id ) ;
76
- app. toplevels . retain ( |t| t. 0 != handle) ;
77
- app . toplevels . push_front ( ( handle , info ) ) ;
78
- }
79
- ToplevelEvent :: Remove ( handle ) => {
80
- if let Some ( pos ) = app . toplevels . iter ( ) . position ( |t| t . 0 == handle ) {
81
- app. toplevels . remove ( pos ) ;
82
- // ignore requests for this id until after the next search
83
- app . ids_to_ignore . push ( handle . id ( ) . protocol_id ( ) ) ;
84
- } else {
85
- warn ! ( "ToplevelEvent::Remove, no toplevel found" ) ;
73
+ for ( handle , info ) in updates {
74
+ match info {
75
+ Some ( info) => {
76
+ if let Some ( pos ) = app. toplevels . iter ( ) . position ( |t| t. 0 == handle) {
77
+ if info . state . contains ( & State :: Activated ) {
78
+ app . toplevels . remove ( pos ) ;
79
+ app . toplevels . push ( ( handle , Box :: new ( info ) ) ) ;
80
+ } else {
81
+ app. toplevels [ pos ] . 1 = Box :: new ( info ) ;
82
+ }
83
+ } else {
84
+ app . toplevels . push ( ( handle , Box :: new ( info ) ) ) ;
85
+ }
86
86
}
87
- }
88
- ToplevelEvent :: Update ( handle, info) => {
89
- debug ! ( "Update {}" , & info. app_id) ;
90
- debug ! ( "Update {:?}" , & info. state) ;
91
-
92
- if let Some ( pos) = app. toplevels . iter ( ) . position ( |t| t. 0 == handle) {
93
- if info. state . contains ( & State :: Activated ) {
94
- debug ! ( "Update {:?}: push front" , & info. app_id) ;
87
+ // no info means remove
88
+ None => {
89
+ if let Some ( pos) = app. toplevels . iter ( ) . position ( |t| t. 0 == handle) {
95
90
app. toplevels . remove ( pos) ;
96
- app. toplevels . push_front ( ( handle, info) ) ;
91
+ // ignore requests for this id until after the next search
92
+ app. ids_to_ignore . push ( handle. id ( ) . protocol_id ( ) ) ;
97
93
} else {
98
- app . toplevels [ pos ] . 1 = info ;
94
+ warn ! ( "no toplevel to remove" ) ;
99
95
}
100
- } else {
101
- warn ! ( "ToplevelEvent::Update, no toplevel found" ) ;
102
- app. toplevels . push_front ( ( handle, info) ) ;
103
96
}
104
97
}
105
98
}
@@ -113,14 +106,13 @@ struct App<W> {
113
106
locales : Vec < String > ,
114
107
desktop_entries : Vec < DesktopEntry < ' static > > ,
115
108
ids_to_ignore : Vec < u32 > ,
116
- // XXX: use LinkedList, and Box the tuple because it will be re ordered a lot?
117
- toplevels : VecDeque < ( ZcosmicToplevelHandleV1 , ToplevelInfo ) > ,
109
+ toplevels : Vec < ( ZcosmicToplevelHandleV1 , Box < ToplevelInfo > ) > ,
118
110
calloop_tx : calloop:: channel:: Sender < ToplevelAction > ,
119
111
tx : W ,
120
112
}
121
113
122
114
impl < W : AsyncWrite + Unpin > App < W > {
123
- fn new ( tx : W ) -> ( Self , mpsc:: UnboundedReceiver < ToplevelEvent > ) {
115
+ fn new ( tx : W ) -> ( Self , mpsc:: UnboundedReceiver < TopLevelsUpdate > ) {
124
116
let ( toplevels_tx, toplevel_rx) = mpsc:: unbounded ( ) ;
125
117
let ( calloop_tx, calloop_rx) = calloop:: channel:: channel ( ) ;
126
118
let _handle = std:: thread:: spawn ( move || toplevel_handler ( toplevels_tx, calloop_rx) ) ;
@@ -138,7 +130,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
138
130
locales,
139
131
desktop_entries,
140
132
ids_to_ignore : Vec :: new ( ) ,
141
- toplevels : VecDeque :: new ( ) ,
133
+ toplevels : Vec :: new ( ) ,
142
134
calloop_tx,
143
135
tx,
144
136
} ,
@@ -181,7 +173,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
181
173
async fn search ( & mut self , query : & str ) {
182
174
let query = query. to_ascii_lowercase ( ) ;
183
175
184
- for ( handle, info) in & self . toplevels {
176
+ for ( handle, info) in self . toplevels . iter ( ) . rev ( ) {
185
177
let entry = if query. is_empty ( ) {
186
178
fde:: matching:: get_best_match (
187
179
& [ & info. app_id , & info. title ] ,
0 commit comments