16
16
#include <wordexp.h>
17
17
#include "config.h"
18
18
#include "idle-client-protocol.h"
19
+ #include "ext-idle-notify-v1-client-protocol.h"
19
20
#include "log.h"
20
21
#if HAVE_SYSTEMD
21
22
#include <systemd/sd-bus.h>
25
26
#include <elogind/sd-login.h>
26
27
#endif
27
28
28
- static struct org_kde_kwin_idle * idle_manager = NULL ;
29
+ static struct org_kde_kwin_idle * kde_idle_manager = NULL ;
30
+ static struct ext_idle_notifier_v1 * idle_notifier = NULL ;
29
31
static struct wl_seat * seat = NULL ;
30
32
31
33
struct swayidle_state {
@@ -46,7 +48,8 @@ struct swayidle_state {
46
48
struct swayidle_timeout_cmd {
47
49
struct wl_list link ;
48
50
int timeout , registered_timeout ;
49
- struct org_kde_kwin_idle_timeout * idle_timer ;
51
+ struct org_kde_kwin_idle_timeout * kde_idle_timer ;
52
+ struct ext_idle_notification_v1 * idle_notification ;
50
53
char * idle_cmd ;
51
54
char * resume_cmd ;
52
55
bool idlehint ;
@@ -543,8 +546,11 @@ static const struct wl_seat_listener wl_seat_listener = {
543
546
static void handle_global (void * data , struct wl_registry * registry ,
544
547
uint32_t name , const char * interface , uint32_t version ) {
545
548
if (strcmp (interface , org_kde_kwin_idle_interface .name ) == 0 ) {
546
- idle_manager =
549
+ kde_idle_manager =
547
550
wl_registry_bind (registry , name , & org_kde_kwin_idle_interface , 1 );
551
+ } else if (strcmp (interface , ext_idle_notifier_v1_interface .name ) == 0 ) {
552
+ idle_notifier =
553
+ wl_registry_bind (registry , name , & ext_idle_notifier_v1_interface , 1 );
548
554
} else if (strcmp (interface , wl_seat_interface .name ) == 0 ) {
549
555
struct seat * s = calloc (1 , sizeof (struct seat ));
550
556
s -> proxy = wl_registry_bind (registry , name , & wl_seat_interface , 2 );
@@ -564,13 +570,18 @@ static const struct wl_registry_listener registry_listener = {
564
570
.global_remove = handle_global_remove ,
565
571
};
566
572
567
- static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener ;
573
+ static const struct org_kde_kwin_idle_timeout_listener kde_idle_timer_listener ;
574
+ static const struct ext_idle_notification_v1_listener idle_notification_listener ;
568
575
569
576
static void destroy_cmd_timer (struct swayidle_timeout_cmd * cmd ) {
570
- if (cmd -> idle_timer != NULL ) {
577
+ if (cmd -> kde_idle_timer != NULL ) {
571
578
swayidle_log (LOG_DEBUG , "Release idle timer" );
572
- org_kde_kwin_idle_timeout_release (cmd -> idle_timer );
573
- cmd -> idle_timer = NULL ;
579
+ org_kde_kwin_idle_timeout_release (cmd -> kde_idle_timer );
580
+ cmd -> kde_idle_timer = NULL ;
581
+ }
582
+ if (cmd -> idle_notification != NULL ) {
583
+ ext_idle_notification_v1_destroy (cmd -> idle_notification );
584
+ cmd -> idle_notification = NULL ;
574
585
}
575
586
}
576
587
@@ -583,10 +594,17 @@ static void register_timeout(struct swayidle_timeout_cmd *cmd,
583
594
return ;
584
595
}
585
596
swayidle_log (LOG_DEBUG , "Register with timeout: %d" , timeout );
586
- cmd -> idle_timer =
587
- org_kde_kwin_idle_get_idle_timeout (idle_manager , seat , timeout );
588
- org_kde_kwin_idle_timeout_add_listener (cmd -> idle_timer ,
589
- & idle_timer_listener , cmd );
597
+ if (idle_notifier != NULL ) {
598
+ cmd -> idle_notification =
599
+ ext_idle_notifier_v1_get_idle_notification (idle_notifier , timeout , seat );
600
+ ext_idle_notification_v1_add_listener (cmd -> idle_notification ,
601
+ & idle_notification_listener , cmd );
602
+ } else {
603
+ cmd -> kde_idle_timer =
604
+ org_kde_kwin_idle_get_idle_timeout (kde_idle_manager , seat , timeout );
605
+ org_kde_kwin_idle_timeout_add_listener (cmd -> kde_idle_timer ,
606
+ & kde_idle_timer_listener , cmd );
607
+ }
590
608
cmd -> registered_timeout = timeout ;
591
609
}
592
610
@@ -627,8 +645,7 @@ static void disable_timeouts(void) {
627
645
}
628
646
#endif
629
647
630
- static void handle_idle (void * data , struct org_kde_kwin_idle_timeout * timer ) {
631
- struct swayidle_timeout_cmd * cmd = data ;
648
+ static void handle_idled (struct swayidle_timeout_cmd * cmd ) {
632
649
cmd -> resume_pending = true;
633
650
swayidle_log (LOG_DEBUG , "idle state" );
634
651
#if HAVE_SYSTEMD || HAVE_ELOGIND
@@ -641,8 +658,7 @@ static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
641
658
}
642
659
}
643
660
644
- static void handle_resume (void * data , struct org_kde_kwin_idle_timeout * timer ) {
645
- struct swayidle_timeout_cmd * cmd = data ;
661
+ static void handle_resumed (struct swayidle_timeout_cmd * cmd ) {
646
662
cmd -> resume_pending = false;
647
663
swayidle_log (LOG_DEBUG , "active state" );
648
664
if (cmd -> registered_timeout != cmd -> timeout ) {
@@ -658,9 +674,34 @@ static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) {
658
674
}
659
675
}
660
676
661
- static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
662
- .idle = handle_idle ,
663
- .resumed = handle_resume ,
677
+ static void kde_handle_idle (void * data , struct org_kde_kwin_idle_timeout * timer ) {
678
+ struct swayidle_timeout_cmd * cmd = data ;
679
+ handle_idled (cmd );
680
+ }
681
+
682
+ static void kde_handle_resumed (void * data , struct org_kde_kwin_idle_timeout * timer ) {
683
+ struct swayidle_timeout_cmd * cmd = data ;
684
+ handle_resumed (cmd );
685
+ }
686
+
687
+ static const struct org_kde_kwin_idle_timeout_listener kde_idle_timer_listener = {
688
+ .idle = kde_handle_idle ,
689
+ .resumed = kde_handle_resumed ,
690
+ };
691
+
692
+ static void ext_handle_idled (void * data , struct ext_idle_notification_v1 * notif ) {
693
+ struct swayidle_timeout_cmd * cmd = data ;
694
+ handle_idled (cmd );
695
+ }
696
+
697
+ static void ext_handle_resumed (void * data , struct ext_idle_notification_v1 * notif ) {
698
+ struct swayidle_timeout_cmd * cmd = data ;
699
+ handle_resumed (cmd );
700
+ }
701
+
702
+ static const struct ext_idle_notification_v1_listener idle_notification_listener = {
703
+ .idled = ext_handle_idled ,
704
+ .resumed = ext_handle_resumed ,
664
705
};
665
706
666
707
static char * parse_command (int argc , char * * argv ) {
@@ -893,7 +934,7 @@ static int handle_signal(int sig, void *data) {
893
934
swayidle_log (LOG_DEBUG , "Got SIGTERM" );
894
935
wl_list_for_each (cmd , & state .timeout_cmds , link ) {
895
936
if (cmd -> resume_pending ) {
896
- handle_resume (cmd , cmd -> idle_timer );
937
+ handle_resumed (cmd );
897
938
}
898
939
}
899
940
sway_terminate (0 );
@@ -1071,7 +1112,7 @@ int main(int argc, char *argv[]) {
1071
1112
}
1072
1113
}
1073
1114
1074
- if (idle_manager == NULL ) {
1115
+ if (kde_idle_manager == NULL && idle_notifier == NULL ) {
1075
1116
swayidle_log (LOG_ERROR , "Display doesn't support idle protocol" );
1076
1117
swayidle_finish ();
1077
1118
return -4 ;
0 commit comments