26
26
#include "xrectsel.h"
27
27
28
28
#ifdef HAVE_NOTIFY
29
+ #include <libnotify/notification.h>
29
30
#include <libnotify/notify.h>
30
31
#endif
31
32
@@ -366,11 +367,42 @@ static int notify_cancel() {
366
367
"%s: %s" , PROGRAM_NAME , "recording was cancelled" );
367
368
NotifyNotification * success_notification =
368
369
notify_notification_new (success_notification_summary , NULL , NULL );
369
- return notify_notification_show (success_notification , NULL );
370
+ int result = notify_notification_show (success_notification , NULL );
371
+ g_object_unref (success_notification );
372
+ return result ;
370
373
#endif
371
374
return 0 ;
372
375
}
373
376
377
+ #ifdef HAVE_NOTIFY
378
+
379
+ typedef struct ActionPayload ActionPayload ;
380
+ struct ActionPayload {
381
+ GMainLoop * loop ;
382
+ const char * target_file ;
383
+ };
384
+
385
+ static void show_in_file_manager_callback (NotifyNotification * notification ,
386
+ char * action , gpointer payload ) {
387
+ ActionPayload p = (* (ActionPayload * )payload );
388
+ if (p .target_file != NULL ) {
389
+ show_file_in_default_file_manager (p .target_file );
390
+ }
391
+ g_main_loop_quit (p .loop );
392
+ }
393
+
394
+ static int on_notification_closed (NotifyNotification * notification ,
395
+ gpointer loop ) {
396
+ g_main_loop_quit (* ((GMainLoop * * )loop ));
397
+ return 0 ;
398
+ }
399
+
400
+ static int on_notification_timeout (gpointer loop ) {
401
+ g_main_loop_quit (* ((GMainLoop * * )loop ));
402
+ return 0 ;
403
+ }
404
+ #endif
405
+
374
406
int main (int argc , char * argv []) {
375
407
#ifdef HAVE_NOTIFY
376
408
notify_init (PROGRAM_NAME );
@@ -475,13 +507,27 @@ int main(int argc, char *argv[]) {
475
507
476
508
remove_file (tmp_file );
477
509
#ifdef HAVE_NOTIFY
510
+ GMainLoop * main_loop = g_main_loop_new (0 , 1 );
511
+ ActionPayload action_payload = {.loop = main_loop ,
512
+ .target_file = new_file };
478
513
char success_notification_summary [50 ];
479
514
snprintf (success_notification_summary ,
480
515
ARR_SIZE (success_notification_summary ), "%s: %s" , PROGRAM_NAME ,
481
516
"recording saved successfuly" );
482
517
NotifyNotification * success_notification = notify_notification_new (
483
518
success_notification_summary , new_file , NULL );
519
+ notify_notification_add_action (
520
+ success_notification , "default" , "Show in file manager" ,
521
+ show_in_file_manager_callback , & action_payload , NULL );
484
522
notify_notification_show (success_notification , NULL );
523
+ int timeout = 5000 ;
524
+ notify_notification_set_timeout (success_notification , timeout );
525
+ g_signal_connect (success_notification , "closed" ,
526
+ G_CALLBACK (on_notification_closed ), & main_loop );
527
+ g_timeout_add (timeout , on_notification_timeout , & main_loop );
528
+ g_main_loop_run (main_loop );
529
+ g_main_loop_unref (main_loop );
530
+ g_object_unref (success_notification );
485
531
#endif
486
532
break ;
487
533
}
@@ -495,6 +541,7 @@ int main(int argc, char *argv[]) {
495
541
NotifyNotification * success_notification =
496
542
notify_notification_new (success_notification_summary , NULL , NULL );
497
543
notify_notification_show (success_notification , NULL );
544
+ g_object_unref (success_notification );
498
545
#endif
499
546
break ;
500
547
}
0 commit comments