@@ -6,9 +6,9 @@ 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 tracing:: { debug, info} ;
9
+ use tracing:: { debug, error , info, warn } ;
10
10
11
- use crate :: desktop_entries:: utils:: get_description;
11
+ use crate :: desktop_entries:: utils:: { get_description, is_session_cosmic } ;
12
12
use crate :: send;
13
13
use futures:: {
14
14
channel:: mpsc,
@@ -27,11 +27,9 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
27
27
use self :: toplevel_handler:: { toplevel_handler, ToplevelAction , ToplevelEvent } ;
28
28
29
29
pub async fn main ( ) {
30
- info ! ( "starting cosmic-toplevel" ) ;
31
-
32
30
let mut tx = async_stdout ( ) ;
33
31
34
- if !session_is_cosmic ( ) {
32
+ if !is_session_cosmic ( ) {
35
33
send ( & mut tx, PluginResponse :: Deactivate ) . await ;
36
34
return ;
37
35
}
@@ -50,12 +48,12 @@ pub async fn main() {
50
48
match request {
51
49
Ok ( request) => match request {
52
50
Request :: Activate ( id) => {
53
- tracing :: info !( "activating {id}" ) ;
51
+ debug ! ( "activating {id}" ) ;
54
52
app. activate ( id) ;
55
53
}
56
54
Request :: Quit ( id) => app. quit ( id) ,
57
55
Request :: Search ( query) => {
58
- tracing :: info !( "searching {query}" ) ;
56
+ debug ! ( "searching {query}" ) ;
59
57
app. search ( & query) . await ;
60
58
// clear the ids to ignore, as all just sent are valid
61
59
app. ids_to_ignore . clear ( ) ;
@@ -64,7 +62,7 @@ pub async fn main() {
64
62
_ => ( ) ,
65
63
} ,
66
64
Err ( why) => {
67
- tracing :: error!( "malformed JSON request: {}" , why) ;
65
+ error ! ( "malformed JSON request: {}" , why) ;
68
66
}
69
67
} ;
70
68
}
@@ -74,7 +72,7 @@ pub async fn main() {
74
72
75
73
match event {
76
74
ToplevelEvent :: Add ( handle, info) => {
77
- tracing :: info !( "add {}" , & info. app_id) ;
75
+ debug ! ( "add {}" , & info. app_id) ;
78
76
app. toplevels . retain ( |t| t. 0 != handle) ;
79
77
app. toplevels . push_front ( ( handle, info) ) ;
80
78
}
@@ -84,7 +82,7 @@ pub async fn main() {
84
82
// ignore requests for this id until after the next search
85
83
app. ids_to_ignore . push ( handle. id ( ) . protocol_id ( ) ) ;
86
84
} else {
87
- tracing :: warn!( "ToplevelEvent::Remove, no toplevel found" ) ;
85
+ warn ! ( "ToplevelEvent::Remove, no toplevel found" ) ;
88
86
}
89
87
}
90
88
ToplevelEvent :: Update ( handle, info) => {
@@ -93,14 +91,14 @@ pub async fn main() {
93
91
94
92
if let Some ( pos) = app. toplevels . iter ( ) . position ( |t| t. 0 == handle) {
95
93
if info. state . contains ( & State :: Activated ) {
96
- tracing :: debug!( "Update {:?}: push front" , & info. app_id) ;
94
+ debug ! ( "Update {:?}: push front" , & info. app_id) ;
97
95
app. toplevels . remove ( pos) ;
98
96
app. toplevels . push_front ( ( handle, info) ) ;
99
97
} else {
100
98
app. toplevels [ pos] . 1 = info;
101
99
}
102
100
} else {
103
- tracing :: warn!( "ToplevelEvent::Update, no toplevel found" ) ;
101
+ warn ! ( "ToplevelEvent::Update, no toplevel found" ) ;
104
102
app. toplevels . push_front ( ( handle, info) ) ;
105
103
}
106
104
}
@@ -115,7 +113,7 @@ struct App<W> {
115
113
locales : Vec < String > ,
116
114
desktop_entries : Vec < DesktopEntry < ' static > > ,
117
115
ids_to_ignore : Vec < u32 > ,
118
- // XXX: use LinkedList?
116
+ // XXX: use LinkedList, and Box the tuple because it will be re ordered a lot ?
119
117
toplevels : VecDeque < ( ZcosmicToplevelHandleV1 , ToplevelInfo ) > ,
120
118
calloop_tx : calloop:: channel:: Sender < ToplevelAction > ,
121
119
tx : W ,
@@ -149,7 +147,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
149
147
}
150
148
151
149
fn activate ( & mut self , id : u32 ) {
152
- tracing :: info!( "requested to activate: {id}" ) ;
150
+ info ! ( "requested to activate: {id}" ) ;
153
151
if self . ids_to_ignore . contains ( & id) {
154
152
return ;
155
153
}
@@ -160,7 +158,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
160
158
None
161
159
}
162
160
} ) {
163
- tracing :: info!( "activating: {id}" ) ;
161
+ info ! ( "activating: {id}" ) ;
164
162
let _res = self . calloop_tx . send ( ToplevelAction :: Activate ( handle) ) ;
165
163
}
166
164
}
@@ -240,12 +238,3 @@ impl<W: AsyncWrite + Unpin> App<W> {
240
238
let _ = self . tx . flush ( ) . await ;
241
239
}
242
240
}
243
-
244
- #[ must_use]
245
- fn session_is_cosmic ( ) -> bool {
246
- if let Ok ( var) = std:: env:: var ( "XDG_CURRENT_DESKTOP" ) {
247
- return var. contains ( "COSMIC" ) ;
248
- }
249
-
250
- false
251
- }
0 commit comments