@@ -426,21 +426,56 @@ let
426
426
auto-display-scale
427
427
pkgs . mako
428
428
pkgs . wlr-randr
429
+ pkgs . jq
429
430
] ;
430
431
bashOptions = [ ] ;
431
432
text = ''
432
- # Run the following commands in order every time a display change event is detected
433
+ stop_services() {
434
+ echo "No displays connected. Stopping ghaf-launcher and ewwbar services."
435
+ systemctl --user stop ewwbar ghaf-launcher
436
+ }
437
+
433
438
auto-display-scale # Auto scaling
434
439
makoctl set-mode default # Reset mako mode so notifications don't break
435
440
436
- if wlr-randr > /dev/null 2>&1; then
437
- # If displays are connected (not headless mode), ensure ewwbar and ghaf-launcher are running
438
- systemctl --user is-active --quiet ewwbar || systemctl --user reload-or-restart ewwbar
439
- systemctl --user is-active --quiet ghaf-launcher || systemctl --user reload-or-restart ghaf-launcher
440
- else
441
- # If all displays were disconnected, we can stop ghaf-launcher and ewwbar services
442
- echo "No displays connected. Stopping ghaf-launcher and ewwbar services"
443
- systemctl --user stop ewwbar ghaf-launcher
441
+ # Retrieve display information
442
+ if ! wlr_output_json=$(wlr-randr --json); then
443
+ echo "Error: Failed to get display info from wlr-randr"
444
+ stop_services
445
+ fi
446
+
447
+ # Check if any displays are connected
448
+ if ! echo "$wlr_output_json" | jq -e 'length > 0' > /dev/null; then
449
+ echo "Error: No connected displays found."
450
+ stop_services
451
+ fi
452
+
453
+ # If displays are connected (not headless mode), ensure ewwbar and ghaf-launcher are running
454
+ systemctl --user is-active --quiet ewwbar || systemctl --user reload-or-restart ewwbar
455
+ systemctl --user is-active --quiet ghaf-launcher || systemctl --user reload-or-restart ghaf-launcher
456
+ '' ;
457
+ } ;
458
+
459
+ display-connected = pkgs . writeShellApplication {
460
+ name = "display-connected" ;
461
+ runtimeInputs = [
462
+ pkgs . jq
463
+ pkgs . wlr-randr
464
+ ] ;
465
+ bashOptions = [ ] ;
466
+ text = ''
467
+ # Exits with error if no display is detected
468
+
469
+ # Retrieve display information
470
+ if ! wlr_output_json=$(wlr-randr --json); then
471
+ echo "Error: Failed to get display info from wlr-randr"
472
+ exit 1
473
+ fi
474
+
475
+ # Check if any displays are connected
476
+ if ! echo "$wlr_output_json" | jq -e 'length > 0' > /dev/null; then
477
+ echo "Error: No connected displays found."
478
+ exit 1
444
479
fi
445
480
'' ;
446
481
} ;
501
536
serviceConfig = {
502
537
Type = "simple" ;
503
538
EnvironmentFile = "-/etc/locale.conf" ;
504
- ExecCondition = ''
505
- ${ pkgs . bash } /bin/bash -c "${ pkgs . wlr-randr } /bin/wlr-randr > /dev/null 2>&1"
506
- '' ;
539
+ ExecCondition = "${ display-connected } /bin/display-connected" ;
507
540
ExecStart = "${ pkgs . nwg-drawer } /bin/nwg-drawer -r -nofs -nocats -s ${ drawerStyle } " ;
508
541
Restart = "always" ;
509
542
RestartSec = "1" ;
569
602
Type = "simple" ;
570
603
Restart = "always" ;
571
604
RestartSec = "5" ;
605
+ ExecCondition = "${ display-connected } /bin/display-connected" ;
572
606
ExecStart = "${ pkgs . ghaf-audio-control } /bin/GhafAudioControlStandalone --pulseaudio_server=audio-vm:${ toString config . ghaf . services . audio . pulseaudioTcpControlPort } --deamon_mode=true --indicator_icon_name=audio-subwoofer" ;
573
607
} ;
574
608
0 commit comments