@@ -53,7 +53,6 @@ use cosmic_app_list_config::{APP_ID, AppListConfig};
53
53
use cosmic_protocols:: toplevel_info:: v1:: client:: zcosmic_toplevel_handle_v1:: State ;
54
54
use futures:: future:: pending;
55
55
use iced:: { Alignment , Background , Length } ;
56
- use itertools:: Itertools ;
57
56
use std:: { borrow:: Cow , collections:: HashMap , path:: PathBuf , rc:: Rc , str:: FromStr , time:: Duration } ;
58
57
use switcheroo_control:: Gpu ;
59
58
use tokio:: time:: sleep;
@@ -177,31 +176,24 @@ impl DockItem {
177
176
. width ( app_icon. icon_size . into ( ) )
178
177
. height ( app_icon. icon_size . into ( ) ) ;
179
178
180
- let dots = if toplevels. is_empty ( ) {
181
- ( 0 ..1 )
182
- . map ( |_| {
183
- container ( vertical_space ( ) . height ( Length :: Fixed ( 0.0 ) ) )
184
- . padding ( app_icon. dot_radius )
185
- . into ( )
186
- } )
187
- . collect_vec ( )
188
- } else {
189
- ( 0 ..1 )
190
- . map ( |_| {
191
- container ( if toplevels. len ( ) == 1 {
192
- vertical_space ( ) . height ( Length :: Fixed ( 0.0 ) )
193
- } else {
194
- match applet. anchor {
195
- PanelAnchor :: Left | PanelAnchor :: Right => {
196
- vertical_space ( ) . height ( app_icon. bar_size )
197
- }
198
- PanelAnchor :: Top | PanelAnchor :: Bottom => {
199
- horizontal_space ( ) . width ( app_icon. bar_size )
200
- }
201
- }
202
- } )
203
- . padding ( app_icon. dot_radius )
204
- . class ( theme:: style:: Container :: Custom ( Box :: new ( move |theme| {
179
+ let dot_constructor = || {
180
+ let space = if toplevels. len ( ) <= 1 {
181
+ vertical_space ( ) . height ( Length :: Fixed ( 0.0 ) )
182
+ } else {
183
+ match applet. anchor {
184
+ PanelAnchor :: Left | PanelAnchor :: Right => {
185
+ vertical_space ( ) . height ( app_icon. bar_size )
186
+ }
187
+ PanelAnchor :: Top | PanelAnchor :: Bottom => {
188
+ horizontal_space ( ) . width ( app_icon. bar_size )
189
+ }
190
+ }
191
+ } ;
192
+ let mut container = container ( space) . padding ( app_icon. dot_radius ) ;
193
+
194
+ if !toplevels. is_empty ( ) {
195
+ container =
196
+ container. class ( theme:: style:: Container :: Custom ( Box :: new ( move |theme| {
205
197
container:: Style {
206
198
text_color : Some ( Color :: TRANSPARENT ) ,
207
199
background : if is_focused {
@@ -218,34 +210,35 @@ impl DockItem {
218
210
icon_color : Some ( Color :: TRANSPARENT ) ,
219
211
}
220
212
} ) ) )
221
- . into ( )
222
- } )
223
- . collect_vec ( )
213
+ }
214
+ container. into ( )
224
215
} ;
225
216
217
+ let dots = std:: iter:: repeat_with ( dot_constructor) . take ( 2 ) ;
218
+
226
219
let icon_wrapper: Element < _ > = match applet. anchor {
227
- PanelAnchor :: Left => row ( vec ! [
220
+ PanelAnchor :: Left => row ( [
228
221
column ( dots) . into ( ) ,
229
222
horizontal_space ( ) . width ( Length :: Fixed ( 1.0 ) ) . into ( ) ,
230
223
cosmic_icon. clone ( ) . into ( ) ,
231
224
] )
232
225
. align_y ( Alignment :: Center )
233
226
. into ( ) ,
234
- PanelAnchor :: Right => row ( vec ! [
227
+ PanelAnchor :: Right => row ( [
235
228
cosmic_icon. clone ( ) . into ( ) ,
236
229
horizontal_space ( ) . width ( Length :: Fixed ( 1.0 ) ) . into ( ) ,
237
230
column ( dots) . into ( ) ,
238
231
] )
239
232
. align_y ( Alignment :: Center )
240
233
. into ( ) ,
241
- PanelAnchor :: Top => column ( vec ! [
234
+ PanelAnchor :: Top => column ( [
242
235
row ( dots) . into ( ) ,
243
236
vertical_space ( ) . height ( Length :: Fixed ( 1.0 ) ) . into ( ) ,
244
237
cosmic_icon. clone ( ) . into ( ) ,
245
238
] )
246
239
. align_x ( Alignment :: Center )
247
240
. into ( ) ,
248
- PanelAnchor :: Bottom => column ( vec ! [
241
+ PanelAnchor :: Bottom => column ( [
249
242
cosmic_icon. clone ( ) . into ( ) ,
250
243
vertical_space ( ) . height ( Length :: Fixed ( 1.0 ) ) . into ( ) ,
251
244
row ( dots) . into ( ) ,
@@ -470,7 +463,7 @@ where
470
463
img. img. clone( ) ,
471
464
) ) )
472
465
} else {
473
- Image :: new( Handle :: from_rgba( 1 , 1 , vec! [ 0 , 0 , 0 , 255 ] ) ) . into( )
466
+ Image :: new( Handle :: from_rgba( 1 , 1 , [ 0u8 , 0u8 , 0u8 , 255u8 ] . as_slice ( ) ) ) . into( )
474
467
} )
475
468
. class( Container :: Custom ( Box :: new( move |theme| {
476
469
container:: Style {
@@ -590,7 +583,7 @@ fn find_desktop_entries<'a>(
590
583
app_ids. iter ( ) . map ( |fav| {
591
584
let unicase_fav = fde:: unicase:: Ascii :: new ( fav. as_str ( ) ) ;
592
585
fde:: find_app_by_id ( desktop_entries, unicase_fav) . map_or_else (
593
- || fde:: DesktopEntry :: from_appid ( fav. clone ( ) ) . clone ( ) ,
586
+ || fde:: DesktopEntry :: from_appid ( fav. clone ( ) ) ,
594
587
ToOwned :: to_owned,
595
588
)
596
589
} )
@@ -612,7 +605,7 @@ impl CosmicAppList {
612
605
. map ( |( pinned_ctr, ( e, original_id) ) | DockItem {
613
606
id : pinned_ctr as u32 ,
614
607
toplevels : Vec :: new ( ) ,
615
- desktop_info : e. clone ( ) ,
608
+ desktop_info : e,
616
609
original_app_id : original_id. clone ( ) ,
617
610
} )
618
611
. collect ( ) ;
@@ -673,7 +666,7 @@ impl cosmic::Application for CosmicAppList {
673
666
} else {
674
667
self . overflow_active_popup = None ;
675
668
self . overflow_favorites_popup = None ;
676
- return Task :: batch ( vec ! [ destroy_popup( popup_id) , destroy_popup( parent) ] ) ;
669
+ return Task :: batch ( [ destroy_popup ( popup_id) , destroy_popup ( parent) ] ) ;
677
670
}
678
671
}
679
672
if let Some ( toplevel_group) = self
@@ -733,7 +726,7 @@ impl cosmic::Application for CosmicAppList {
733
726
} else {
734
727
self . overflow_active_popup = None ;
735
728
self . overflow_favorites_popup = None ;
736
- return Task :: batch ( vec ! [ destroy_popup( popup_id) , destroy_popup( parent) ] ) ;
729
+ return Task :: batch ( [ destroy_popup ( popup_id) , destroy_popup ( parent) ] ) ;
737
730
}
738
731
}
739
732
if let Some ( toplevel_group) = self
@@ -1490,7 +1483,10 @@ impl cosmic::Application for CosmicAppList {
1490
1483
} else {
1491
1484
0
1492
1485
} ;
1493
- let favorites: Vec < _ > = ( & mut self . pinned_list . iter ( ) . rev ( ) )
1486
+ let favorites: Vec < _ > = self
1487
+ . pinned_list
1488
+ . iter ( )
1489
+ . rev ( )
1494
1490
. filter ( |f| {
1495
1491
if favorite_to_remove > 0 && f. toplevels . is_empty ( ) {
1496
1492
favorite_to_remove -= 1 ;
@@ -1524,7 +1520,7 @@ impl cosmic::Application for CosmicAppList {
1524
1520
. desktop_info
1525
1521
. full_name ( & self . locales )
1526
1522
. unwrap_or_default ( )
1527
- . to_string ( ) ,
1523
+ . into_owned ( ) ,
1528
1524
self . popup . is_some ( ) ,
1529
1525
Message :: Surface ,
1530
1526
None ,
@@ -1618,7 +1614,7 @@ impl cosmic::Application for CosmicAppList {
1618
1614
. desktop_info
1619
1615
. full_name ( & self . locales )
1620
1616
. unwrap_or_default ( )
1621
- . to_string ( ) ,
1617
+ . into_owned ( ) ,
1622
1618
self . popup . is_some ( ) ,
1623
1619
Message :: Surface ,
1624
1620
None ,
@@ -1812,11 +1808,7 @@ impl cosmic::Application for CosmicAppList {
1812
1808
Message :: Exec ( exec. to_string ( ) , None , desktop_info. terminal ( ) ) ,
1813
1809
) ) ;
1814
1810
} else if let Some ( gpus) = self . gpus . as_ref ( ) {
1815
- let default_idx = if desktop_info. prefers_non_default_gpu ( ) {
1816
- gpus. iter ( ) . position ( |gpu| !gpu. default ) . unwrap_or ( 0 )
1817
- } else {
1818
- gpus. iter ( ) . position ( |gpu| gpu. default ) . unwrap_or ( 0 )
1819
- } ;
1811
+ let default_idx = preferred_gpu_idx ( desktop_info, gpus. iter ( ) ) ;
1820
1812
for ( i, gpu) in gpus. iter ( ) . enumerate ( ) {
1821
1813
content = content. push (
1822
1814
menu_button ( text:: body ( format ! (
@@ -2037,7 +2029,7 @@ impl cosmic::Application for CosmicAppList {
2037
2029
. desktop_info
2038
2030
. full_name ( & self . locales )
2039
2031
. unwrap_or_default ( )
2040
- . to_string ( ) ,
2032
+ . into_owned ( ) ,
2041
2033
self . popup . is_some ( ) ,
2042
2034
Message :: Surface ,
2043
2035
None ,
@@ -2101,7 +2093,10 @@ impl cosmic::Application for CosmicAppList {
2101
2093
0
2102
2094
} ;
2103
2095
let mut favorites_extra = Vec :: with_capacity ( favorite_to_remove) ;
2104
- let mut favorites: Vec < _ > = ( & mut self . pinned_list . iter ( ) . rev ( ) )
2096
+ let mut favorites: Vec < _ > = self
2097
+ . pinned_list
2098
+ . iter ( )
2099
+ . rev ( )
2105
2100
. filter ( |f| {
2106
2101
if favorite_to_remove > 0 && f. toplevels . is_empty ( ) {
2107
2102
favorite_to_remove -= 1 ;
@@ -2190,7 +2185,7 @@ impl cosmic::Application for CosmicAppList {
2190
2185
}
2191
2186
2192
2187
fn subscription ( & self ) -> Subscription < Message > {
2193
- Subscription :: batch ( vec ! [
2188
+ Subscription :: batch ( [
2194
2189
wayland_subscription ( ) . map ( Message :: Wayland ) ,
2195
2190
listen_with ( |e, _, id| match e {
2196
2191
cosmic:: iced_runtime:: core:: Event :: PlatformSpecific (
@@ -2299,9 +2294,9 @@ impl CosmicAppList {
2299
2294
if self . active_workspaces . is_empty ( ) {
2300
2295
return Vec :: new ( ) ;
2301
2296
}
2302
- let current_output = self . core . applet . output_name . clone ( ) ;
2297
+ let current_output = self . core . applet . output_name . as_ref ( ) ;
2303
2298
let mut focused_toplevels: Vec < ExtForeignToplevelHandleV1 > = Vec :: new ( ) ;
2304
- let active_workspaces = self . active_workspaces . clone ( ) ;
2299
+ let active_workspaces = & self . active_workspaces ;
2305
2300
for toplevel_list in self . active_list . iter ( ) . chain ( self . pinned_list . iter ( ) ) {
2306
2301
for ( t_info, _) in & toplevel_list. toplevels {
2307
2302
if t_info. state . contains ( & State :: Activated )
@@ -2349,10 +2344,8 @@ impl CosmicAppList {
2349
2344
let is_proton_game = info. app_id == "steam_app_default" ;
2350
2345
if is_proton_game || info. app_id . ends_with ( ".exe" ) {
2351
2346
for entry in & self . desktop_entries {
2352
- let localised_name = entry
2353
- . name ( & self . locales )
2354
- . map ( |x| x. to_string ( ) )
2355
- . unwrap_or_default ( ) ;
2347
+ let localised_name =
2348
+ entry. name ( & self . locales ) . unwrap_or_default ( ) . into_owned ( ) ;
2356
2349
2357
2350
if localised_name == info. title {
2358
2351
// if this is a proton game, we only want
@@ -2378,13 +2371,7 @@ impl CosmicAppList {
2378
2371
fn launch_on_preferred_gpu ( desktop_info : & DesktopEntry , gpus : Option < & [ Gpu ] > ) -> Option < Message > {
2379
2372
let exec = desktop_info. exec ( ) ?;
2380
2373
2381
- let gpu_idx = gpus. map ( |gpus| {
2382
- if desktop_info. prefers_non_default_gpu ( ) {
2383
- gpus. iter ( ) . position ( |gpu| !gpu. default ) . unwrap_or ( 0 )
2384
- } else {
2385
- gpus. iter ( ) . position ( |gpu| gpu. default ) . unwrap_or ( 0 )
2386
- }
2387
- } ) ;
2374
+ let gpu_idx = gpus. map ( |gpus| preferred_gpu_idx ( desktop_info, gpus. iter ( ) ) ) ;
2388
2375
2389
2376
Some ( Message :: Exec (
2390
2377
exec. to_string ( ) ,
@@ -2393,6 +2380,14 @@ fn launch_on_preferred_gpu(desktop_info: &DesktopEntry, gpus: Option<&[Gpu]>) ->
2393
2380
) )
2394
2381
}
2395
2382
2383
+ fn preferred_gpu_idx < ' a , I > ( desktop_info : & DesktopEntry , mut gpus : I ) -> usize
2384
+ where
2385
+ I : Iterator < Item = & ' a Gpu > ,
2386
+ {
2387
+ gpus. position ( |gpu| gpu. default ^ desktop_info. prefers_non_default_gpu ( ) )
2388
+ . unwrap_or ( 0 )
2389
+ }
2390
+
2396
2391
#[ derive( Debug , Default , Clone ) ]
2397
2392
pub struct DndPathBuf ( PathBuf ) ;
2398
2393
@@ -2428,8 +2423,6 @@ impl AsMimeTypes for DndPathBuf {
2428
2423
}
2429
2424
2430
2425
fn as_bytes ( & self , _mime_type : & str ) -> Option < std:: borrow:: Cow < ' static , [ u8 ] > > {
2431
- Some ( Cow :: Owned (
2432
- self . 0 . clone ( ) . to_str ( ) ?. to_string ( ) . into_bytes ( ) ,
2433
- ) )
2426
+ Some ( Cow :: Owned ( self . 0 . to_str ( ) ?. as_bytes ( ) . to_vec ( ) ) )
2434
2427
}
2435
2428
}
0 commit comments