You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2KB

  1. (import scheme)
  2. (import (chicken base))
  3. (import srfi-1)
  4. (import srfi-13)
  5. (import socket)
  6. (foreign-declare "#include <libnotify/notify.h>")
  7. (define (forever tn)
  8. (tn)
  9. (forever tn))
  10. (define-syntax thunk
  11. (syntax-rules ()
  12. ((_ exp ...)
  13. (lambda () exp ...))))
  14. (define notify
  15. (foreign-lambda* void ((c-string title) (c-string body))
  16. "NotifyNotification *notif;\n"
  17. "notify_init(title);\n"
  18. "notif = notify_notification_new(title, body, NULL);\n"
  19. "notify_notification_show(notif, NULL);\n"
  20. "g_object_unref(notif);\n"))
  21. (define broadcast-socket #f)
  22. (define broadcast-address (inet-address "255.255.255.255" 3742))
  23. (define (broadcast-setup)
  24. (set! broadcast-socket (socket af/inet sock/dgram))
  25. (set! (so-broadcast? broadcast-socket) #t)
  26. (socket-bind broadcast-socket broadcast-address))
  27. (define (broadcast-receive)
  28. (condition-case (socket-receive broadcast-socket 256)
  29. ((exn timeout) (broadcast-receive))))
  30. (define (net-notify-listen)
  31. (let ((response (broadcast-receive)))
  32. (if (equal? (string-take response 12) "net-notify: ")
  33. (string-drop response 12)
  34. (net-notify-listen))))
  35. (define (main)
  36. (broadcast-setup)
  37. (forever (thunk (notify "net-notify" (net-notify-listen)))))
  38. (main)