@@ -35,8 +35,8 @@ impl Config {
35
35
if !cfg_path. exists ( ) {
36
36
let mut config_file = File :: create ( & cfg_path) . expect ( "Can't create config dir" ) ;
37
37
let default_icons = r#"# Add your icons mapping
38
- # Take care to lowercase app name
39
- # and use double quote the key and the value
38
+ # use double quote the key and the value
39
+ # take class name from 'hyprctl clients'
40
40
"DEFAULT" = ""
41
41
"kitty" = "term"
42
42
"firefox" = "browser"
@@ -51,26 +51,31 @@ impl Config {
51
51
}
52
52
}
53
53
54
- fn main ( ) -> Result < ( ) , Box < dyn Error > > {
54
+ fn main ( ) {
55
55
let cfg = Config :: new ( ) ;
56
56
// Init
57
57
let renamer = Arc :: new ( Renamer :: new ( cfg, Args :: parse ( ) ) ) ;
58
- _ = renamer. renameworkspace ( ) ;
58
+ renamer
59
+ . renameworkspace ( )
60
+ . expect ( "App can't rename workspaces on start" ) ;
59
61
60
62
// Handle unix signals
61
- let mut signals = Signals :: new ( [ SIGINT , SIGTERM ] ) ? ;
63
+ let mut signals = Signals :: new ( [ SIGINT , SIGTERM ] ) . expect ( "Can't listen on SIGINT or SIGTERM" ) ;
62
64
let final_renamer = renamer. clone ( ) ;
63
65
thread:: spawn ( move || {
64
66
for _ in signals. forever ( ) {
65
- _ = final_renamer. reset_workspaces ( ) ;
67
+ match final_renamer. reset_workspaces ( ) {
68
+ Err ( _) => println ! ( "Workspaces name can't be cleared" ) ,
69
+ Ok ( _) => println ! ( "Workspaces name cleared, bye" ) ,
70
+ } ;
66
71
process:: exit ( 0 ) ;
67
72
}
68
73
} ) ;
69
74
70
75
// Run on window events
71
- renamer. start_listeners ( ) ? ;
72
-
73
- Ok ( ( ) )
76
+ renamer
77
+ . start_listeners ( )
78
+ . expect ( "Can't listen Hyprland events, sorry" ) ;
74
79
}
75
80
76
81
struct Renamer {
@@ -109,14 +114,14 @@ impl Renamer {
109
114
. collect :: < HashMap < _ , _ > > ( ) ;
110
115
111
116
for client in clients {
112
- let class = client. clone ( ) . class . to_lowercase ( ) ;
117
+ let class = client. class ;
113
118
let fullscreen = client. fullscreen ;
114
119
let icon = self . class_to_icon ( & class) ;
115
- let workspace_id = client. clone ( ) . workspace . id ;
116
- let is_dup = !deduper. insert ( format ! ( "{}-{}" , workspace_id . clone ( ) , icon ) ) ;
120
+ let workspace_id = client. workspace . id ;
121
+ let is_dup = !deduper. insert ( format ! ( "{workspace_id }-{icon}" ) ) ;
117
122
let should_dedup = self . args . dedup && is_dup;
118
123
119
- self . workspaces . lock ( ) ?. insert ( client. clone ( ) . workspace . id ) ;
124
+ self . workspaces . lock ( ) ?. insert ( client. workspace . id ) ;
120
125
121
126
let workspace = workspaces. entry ( workspace_id) . or_insert ( "" . to_string ( ) ) ;
122
127
@@ -130,9 +135,8 @@ impl Renamer {
130
135
}
131
136
132
137
workspaces
133
- . clone ( )
134
138
. iter ( )
135
- . try_for_each ( |( & id, apps) | rename_cmd ( id, & apps. clone ( ) ) ) ?;
139
+ . try_for_each ( |( & id, apps) | rename_cmd ( id, & apps) ) ?;
136
140
137
141
Ok ( ( ) )
138
142
}
@@ -183,7 +187,7 @@ impl Renamer {
183
187
}
184
188
185
189
fn rename_cmd ( id : i32 , apps : & str ) -> Result < ( ) , Box < dyn Error > > {
186
- let text = format ! ( "{}:{}" , id . clone ( ) , apps ) ;
190
+ let text = format ! ( "{id }:{apps}" ) ;
187
191
let content = ( !apps. is_empty ( ) ) . then_some ( text. as_str ( ) ) ;
188
192
hyprland:: dispatch!( RenameWorkspace , id, content) ?;
189
193
0 commit comments