@@ -31,6 +31,8 @@ struct swayidle_state {
3131 struct wl_display * display ;
3232 struct wl_event_loop * event_loop ;
3333 struct wl_list timeout_cmds ; // struct swayidle_timeout_cmd *
34+ struct wl_list seats ;
35+ char * seat_name ;
3436 char * before_sleep_cmd ;
3537 char * after_resume_cmd ;
3638 char * logind_lock_cmd ;
@@ -50,6 +52,14 @@ struct swayidle_timeout_cmd {
5052 bool resume_pending ;
5153};
5254
55+ struct seat {
56+ struct wl_list link ;
57+ struct wl_seat * proxy ;
58+
59+ char * name ;
60+ uint32_t capabilities ;
61+ };
62+
5363enum log_importance {
5464 LOG_DEBUG = 1 ,
5565 LOG_INFO = 2 ,
@@ -84,6 +94,7 @@ static void swayidle_log_errno(
8494static void swayidle_init () {
8595 memset (& state , 0 , sizeof (state ));
8696 wl_list_init (& state .timeout_cmds );
97+ wl_list_init (& state .seats );
8798}
8899
89100static void swayidle_finish () {
@@ -466,13 +477,34 @@ static void setup_property_changed_listener(void) {
466477}
467478#endif
468479
480+ static void seat_handle_capabilities (void * data , struct wl_seat * seat ,
481+ uint32_t capabilities ) {
482+ struct seat * self = data ;
483+ self -> capabilities = capabilities ;
484+ }
485+
486+ static void seat_handle_name (void * data , struct wl_seat * seat ,
487+ const char * name ) {
488+ struct seat * self = data ;
489+ self -> name = strdup (name );
490+ }
491+
492+ static const struct wl_seat_listener wl_seat_listener = {
493+ .name = seat_handle_name ,
494+ .capabilities = seat_handle_capabilities ,
495+ };
496+
469497static void handle_global (void * data , struct wl_registry * registry ,
470498 uint32_t name , const char * interface , uint32_t version ) {
471499 if (strcmp (interface , org_kde_kwin_idle_interface .name ) == 0 ) {
472500 idle_manager =
473501 wl_registry_bind (registry , name , & org_kde_kwin_idle_interface , 1 );
474502 } else if (strcmp (interface , wl_seat_interface .name ) == 0 ) {
475- seat = wl_registry_bind (registry , name , & wl_seat_interface , 1 );
503+ struct seat * s = calloc (1 , sizeof (struct seat ));
504+ s -> proxy = wl_registry_bind (registry , name , & wl_seat_interface , 2 );
505+
506+ wl_seat_add_listener (s -> proxy , & wl_seat_listener , s );
507+ wl_list_insert (& state .seats , & s -> link );
476508 }
477509}
478510
@@ -748,7 +780,7 @@ static int parse_idlehint(int argc, char **argv) {
748780
749781static int parse_args (int argc , char * argv [], char * * config_path ) {
750782 int c ;
751- while ((c = getopt (argc , argv , "C:hdw " )) != -1 ) {
783+ while ((c = getopt (argc , argv , "C:hdwS: " )) != -1 ) {
752784 switch (c ) {
753785 case 'C' :
754786 * config_path = strdup (optarg );
@@ -759,13 +791,17 @@ static int parse_args(int argc, char *argv[], char **config_path) {
759791 case 'w' :
760792 state .wait = true;
761793 break ;
794+ case 'S' :
795+ state .seat_name = strdup (optarg );
796+ break ;
762797 case 'h' :
763798 case '?' :
764799 printf ("Usage: %s [OPTIONS]\n" , argv [0 ]);
765800 printf (" -h\tthis help menu\n" );
766801 printf (" -C\tpath to config file\n" );
767802 printf (" -d\tdebug\n" );
768803 printf (" -w\twait for command to finish\n" );
804+ printf (" -S\tpick the seat to work with\n" );
769805 return 1 ;
770806 default :
771807 return 1 ;
@@ -974,14 +1010,26 @@ int main(int argc, char *argv[]) {
9741010 struct wl_registry * registry = wl_display_get_registry (state .display );
9751011 wl_registry_add_listener (registry , & registry_listener , NULL );
9761012 wl_display_roundtrip (state .display );
1013+ wl_display_roundtrip (state .display );
1014+
1015+ struct seat * seat_i ;
1016+ wl_list_for_each (seat_i , & state .seats , link ) {
1017+ if (state .seat_name == NULL || strcmp (seat_i -> name , state .seat_name ) == 0 ) {
1018+ seat = seat_i -> proxy ;
1019+ }
1020+ }
9771021
9781022 if (idle_manager == NULL ) {
9791023 swayidle_log (LOG_ERROR , "Display doesn't support idle protocol" );
9801024 swayidle_finish ();
9811025 return -4 ;
9821026 }
9831027 if (seat == NULL ) {
984- swayidle_log (LOG_ERROR , "Seat error" );
1028+ if (state .seat_name != NULL ) {
1029+ swayidle_log (LOG_ERROR , "Seat %s not found" , state .seat_name );
1030+ } else {
1031+ swayidle_log (LOG_ERROR , "No seat found" );
1032+ }
9851033 swayidle_finish ();
9861034 return -5 ;
9871035 }
0 commit comments