1
1
mod toplevel_handler;
2
2
3
+ use cctk:: cosmic_protocols:: toplevel_info:: v1:: client:: zcosmic_toplevel_handle_v1:: State ;
3
4
use cctk:: wayland_client:: Proxy ;
4
5
use cctk:: { cosmic_protocols, sctk:: reexports:: calloop, toplevel_info:: ToplevelInfo } ;
5
6
use cosmic_protocols:: toplevel_info:: v1:: client:: zcosmic_toplevel_handle_v1:: ZcosmicToplevelHandleV1 ;
6
7
use fde:: DesktopEntry ;
7
8
use freedesktop_desktop_entry as fde;
9
+ use tracing:: { debug, info} ;
8
10
9
11
use crate :: desktop_entries:: utils:: get_description;
10
12
use crate :: send;
@@ -19,12 +21,13 @@ use pop_launcher::{
19
21
} ;
20
22
use std:: borrow:: Cow ;
21
23
use std:: iter;
24
+ use std:: collections:: VecDeque ;
22
25
use tokio:: io:: { AsyncWrite , AsyncWriteExt } ;
23
26
24
27
use self :: toplevel_handler:: { toplevel_handler, ToplevelAction , ToplevelEvent } ;
25
28
26
29
pub async fn main ( ) {
27
- tracing :: info!( "starting cosmic-toplevel" ) ;
30
+ info ! ( "starting cosmic-toplevel" ) ;
28
31
29
32
let mut tx = async_stdout ( ) ;
30
33
@@ -68,20 +71,37 @@ pub async fn main() {
68
71
Either :: Right ( ( Some ( event) , second_to_next_request) ) => {
69
72
next_event = toplevel_rx. next ( ) ;
70
73
next_request = second_to_next_request;
74
+
71
75
match event {
72
76
ToplevelEvent :: Add ( handle, info) => {
73
- tracing:: info!( "{}" , & info. app_id) ;
77
+ tracing:: info!( "add {}" , & info. app_id) ;
74
78
app. toplevels . retain ( |t| t. 0 != handle) ;
75
- app. toplevels . push ( ( handle, info) ) ;
79
+ app. toplevels . push_front ( ( handle, info) ) ;
76
80
}
77
81
ToplevelEvent :: Remove ( handle) => {
78
- app. toplevels . retain ( |t| t. 0 != handle) ;
79
- // ignore requests for this id until after the next search
80
- app. ids_to_ignore . push ( handle. id ( ) . protocol_id ( ) ) ;
82
+ if let Some ( pos) = app. toplevels . iter ( ) . position ( |t| t. 0 == handle) {
83
+ app. toplevels . remove ( pos) ;
84
+ // ignore requests for this id until after the next search
85
+ app. ids_to_ignore . push ( handle. id ( ) . protocol_id ( ) ) ;
86
+ } else {
87
+ tracing:: warn!( "ToplevelEvent::Remove, no toplevel found" ) ;
88
+ }
81
89
}
82
90
ToplevelEvent :: Update ( handle, info) => {
83
- if let Some ( t) = app. toplevels . iter_mut ( ) . find ( |t| t. 0 == handle) {
84
- t. 1 = info;
91
+ debug ! ( "Update {}" , & info. app_id) ;
92
+ debug ! ( "Update {:?}" , & info. state) ;
93
+
94
+ if let Some ( pos) = app. toplevels . iter ( ) . position ( |t| t. 0 == handle) {
95
+ if info. state . contains ( & State :: Activated ) {
96
+ tracing:: warn!( "Update {:?}: push front" , & info. app_id) ;
97
+ app. toplevels . remove ( pos) ;
98
+ app. toplevels . push_front ( ( handle, info) ) ;
99
+ } else {
100
+ app. toplevels [ pos] . 1 = info;
101
+ }
102
+ } else {
103
+ tracing:: warn!( "ToplevelEvent::Update, no toplevel found" ) ;
104
+ app. toplevels . push_front ( ( handle, info) ) ;
85
105
}
86
106
}
87
107
}
@@ -95,7 +115,8 @@ struct App<W> {
95
115
locales : Vec < String > ,
96
116
desktop_entries : Vec < DesktopEntry < ' static > > ,
97
117
ids_to_ignore : Vec < u32 > ,
98
- toplevels : Vec < ( ZcosmicToplevelHandleV1 , ToplevelInfo ) > ,
118
+ // XXX: use LinkedList?
119
+ toplevels : VecDeque < ( ZcosmicToplevelHandleV1 , ToplevelInfo ) > ,
99
120
calloop_tx : calloop:: channel:: Sender < ToplevelAction > ,
100
121
tx : W ,
101
122
}
@@ -119,7 +140,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
119
140
locales,
120
141
desktop_entries,
121
142
ids_to_ignore : Vec :: new ( ) ,
122
- toplevels : Vec :: new ( ) ,
143
+ toplevels : VecDeque :: new ( ) ,
123
144
calloop_tx,
124
145
tx,
125
146
} ,
0 commit comments