@@ -7,22 +7,39 @@ use hyprland::{
77 event_listener:: { EventListener , WindowOpenEvent } ,
88 shared:: HyprData ,
99} ;
10+
11+ use clap:: Arg ;
12+ use clap:: Command as ClapCommand ;
1013use procfs:: process:: Process ;
1114use std:: env;
1215
1316fn main ( ) {
14- let args: Vec < String > = env:: args ( ) . collect ( ) ;
17+ let matches = ClapCommand :: new ( env ! ( "CARGO_PKG_NAME" ) )
18+ . version ( env ! ( "CARGO_PKG_VERSION" ) )
19+ . author ( env ! ( "CARGO_PKG_AUTHORS" ) )
20+ . about ( "Automatically tag newly launched Steam games in Hyprland." )
21+ . arg (
22+ Arg :: new ( "callback" )
23+ . required ( false )
24+ . help ( "A callback that will be called when a new window of a steam game appears" )
25+ . index ( 1 )
26+ )
27+ . arg (
28+ Arg :: new ( "callback-arguments" )
29+ . required ( false )
30+ . index ( 2 )
31+ . num_args ( 1 ..)
32+ . help ( "Arguments for the callback. The PID and Steam app ID will be appended to the arguments." )
33+ . allow_hyphen_values ( true )
34+ . value_parser ( clap:: value_parser!( String ) ) ,
35+ ) . get_matches ( ) ;
1536
16- let script_path = if args. len ( ) > 1 {
17- Some ( args[ 1 ] . clone ( ) )
18- } else {
19- None
20- } ;
21- let script_args = if args. len ( ) > 2 {
22- args[ 2 ..] . to_vec ( )
23- } else {
24- Vec :: new ( )
25- } ;
37+ let callback = matches. get_one :: < String > ( "callback" ) . cloned ( ) ;
38+ let callback_args: Vec < String > = matches
39+ . get_many :: < String > ( "callback-arguments" )
40+ . unwrap_or_default ( )
41+ . cloned ( )
42+ . collect ( ) ;
2643
2744 let mut listener = EventListener :: new ( ) ;
2845 listener. add_window_opened_handler ( move |event| {
@@ -35,8 +52,8 @@ fn main() {
3552 true
3653 }
3754 Ok ( GameResult :: Game { pid, app_id } ) => {
38- if let Some ( script_path) = & script_path {
39- let mut new_args = script_args . clone ( ) ;
55+ if let Some ( script_path) = & callback {
56+ let mut new_args = callback_args . clone ( ) ;
4057 new_args. push ( pid. to_string ( ) ) ;
4158 new_args. push ( app_id) ;
4259 let mut child = Command :: new ( script_path) . args ( & new_args) . spawn ( ) . unwrap ( ) ;
0 commit comments