99// Added: store inhibition token
1010uint night_cookie = 0 ;
1111
12- void inhibit_nc (bool inhibit ){
12+ void inhibit_nc (bool inhibit )
13+ {
1314 QDBusInterface iface (
1415 "org.kde.KWin" ,
1516 "/org/kde/KWin/NightLight" ,
1617 "org.kde.KWin.NightLight" ,
17- QDBusConnection ::sessionBus ()
18- );
18+ QDBusConnection ::sessionBus ());
1919
20- if (inhibit ) {
20+ if (inhibit )
21+ {
2122 QDBusReply < uint > reply = iface .call ("inhibit" );
22- if (reply .isValid ()) night_cookie = reply .value ();
23- } else if (night_cookie != 0 ) {
23+ if (reply .isValid ())
24+ night_cookie = reply .value ();
25+ }
26+ else if (night_cookie != 0 )
27+ {
2428 iface .call ("uninhibit" , night_cookie );
2529 night_cookie = 0 ;
2630 }
2731}
2832
29- extern "C" {
30- int mpv_open_cplugin (mpv_handle * handle ){
33+ extern "C"
34+ {
35+ int mpv_open_cplugin (mpv_handle * handle )
36+ {
3137 bool night_light_inhibited = false;
3238
33- auto update_inhibition = [& ]() {
39+ auto update_inhibition = [& ]()
40+ {
3441 int64_t paused = 1 , idle = 1 ;
3542 mpv_get_property (handle , "pause" , MPV_FORMAT_FLAG , & paused );
3643 mpv_get_property (handle , "core-idle" , MPV_FORMAT_FLAG , & idle );
3744 int64_t seeking = 0 ;
3845 mpv_get_property (handle , "seeking" , MPV_FORMAT_FLAG , & seeking );
3946
4047 bool should_inhibit = (seeking || !idle ) && !paused ;
41- if (should_inhibit != night_light_inhibited ) {
48+ if (should_inhibit != night_light_inhibited )
49+ {
4250 inhibit_nc (should_inhibit );
4351 night_light_inhibited = should_inhibit ;
4452 }
@@ -54,11 +62,15 @@ extern "C"{
5462 {
5563 mpv_event * event = mpv_wait_event (handle , -1 ); // Blocking wait: more efficient than polling
5664 // We wait indefinitely for property changes (pause, core-idle), avoiding CPU waste
57- if (!event || event -> event_id == MPV_EVENT_NONE ) continue ;
58- if (event -> event_id == MPV_EVENT_SHUTDOWN ) break ;
59- if (event -> event_id == MPV_EVENT_PROPERTY_CHANGE ) {
60- mpv_event_property * prop = (mpv_event_property * )event -> data ;
61- if (strcmp (prop -> name , "pause" ) == 0 || strcmp (prop -> name , "core-idle" ) == 0 || strcmp (prop -> name , "seeking" ) == 0 ) {
65+ if (!event || event -> event_id == MPV_EVENT_NONE )
66+ continue ;
67+ if (event -> event_id == MPV_EVENT_SHUTDOWN )
68+ break ;
69+ if (event -> event_id == MPV_EVENT_PROPERTY_CHANGE )
70+ {
71+ mpv_event_property * prop = (mpv_event_property * )event -> data ;
72+ if (strcmp (prop -> name , "pause" ) == 0 || strcmp (prop -> name , "core-idle" ) == 0 || strcmp (prop -> name , "seeking" ) == 0 )
73+ {
6274 update_inhibition ();
6375 }
6476 }
0 commit comments