@@ -397,6 +397,9 @@ int main(int argc, char **argv) {
397
397
if (!socket_path ) {
398
398
socket_path = get_socketpath ();
399
399
if (!socket_path ) {
400
+ if (quiet ) {
401
+ exit (EXIT_FAILURE );
402
+ }
400
403
sway_abort ("Unable to retrieve socket path" );
401
404
}
402
405
}
@@ -430,13 +433,18 @@ int main(int argc, char **argv) {
430
433
} else if (strcasecmp (cmdtype , "subscribe" ) == 0 ) {
431
434
type = IPC_SUBSCRIBE ;
432
435
} else {
436
+ if (quiet ) {
437
+ exit (EXIT_FAILURE );
438
+ }
433
439
sway_abort ("Unknown message type %s" , cmdtype );
434
440
}
435
441
436
442
free (cmdtype );
437
443
438
444
if (monitor && type != IPC_SUBSCRIBE ) {
439
- sway_log (SWAY_ERROR , "Monitor can only be used with -t SUBSCRIBE" );
445
+ if (!quiet ) {
446
+ sway_log (SWAY_ERROR , "Monitor can only be used with -t SUBSCRIBE" );
447
+ }
440
448
free (socket_path );
441
449
return 1 ;
442
450
}
@@ -454,29 +462,29 @@ int main(int argc, char **argv) {
454
462
ipc_set_recv_timeout (socketfd , timeout );
455
463
uint32_t len = strlen (command );
456
464
char * resp = ipc_single_command (socketfd , type , command , & len );
457
- if (!quiet ) {
458
- // pretty print the json
459
- json_object * obj = json_tokener_parse (resp );
460
465
461
- if (obj == NULL ) {
466
+ // pretty print the json
467
+ json_object * obj = json_tokener_parse (resp );
468
+ if (obj == NULL ) {
469
+ if (!quiet ) {
462
470
fprintf (stderr , "ERROR: Could not parse json response from ipc. "
463
471
"This is a bug in sway." );
464
472
printf ("%s\n" , resp );
473
+ }
474
+ ret = 1 ;
475
+ } else {
476
+ if (!success (obj , true)) {
465
477
ret = 1 ;
466
- } else {
467
- if (!success (obj , true)) {
468
- ret = 1 ;
469
- }
470
- if (type != IPC_SUBSCRIBE || ret != 0 ) {
471
- if (raw ) {
472
- printf ("%s\n" , json_object_to_json_string_ext (obj ,
473
- JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED ));
474
- } else {
475
- pretty_print (type , obj );
476
- }
478
+ }
479
+ if (!quiet && (type != IPC_SUBSCRIBE || ret != 0 )) {
480
+ if (raw ) {
481
+ printf ("%s\n" , json_object_to_json_string_ext (obj ,
482
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED ));
483
+ } else {
484
+ pretty_print (type , obj );
477
485
}
478
- json_object_put (obj );
479
486
}
487
+ json_object_put (obj );
480
488
}
481
489
free (command );
482
490
free (resp );
@@ -495,10 +503,14 @@ int main(int argc, char **argv) {
495
503
496
504
json_object * obj = json_tokener_parse (reply -> payload );
497
505
if (obj == NULL ) {
498
- fprintf (stderr , "ERROR: Could not parse json response from ipc"
499
- ". This is a bug in sway." );
500
- ret = 1 ;
506
+ if (!quiet ) {
507
+ fprintf (stderr , "ERROR: Could not parse json response from"
508
+ " ipc. This is a bug in sway." );
509
+ ret = 1 ;
510
+ }
501
511
break ;
512
+ } else if (quiet ) {
513
+ json_object_put (obj );
502
514
} else {
503
515
if (raw ) {
504
516
printf ("%s\n" , json_object_to_json_string (obj ));
0 commit comments