(import scheme) (import (chicken base)) (import srfi-1) (import srfi-13) (import socket) (foreign-declare "#include ") (define (forever tn) (tn) (forever tn)) (define-syntax thunk (syntax-rules () ((_ exp ...) (lambda () exp ...)))) (define notify (foreign-lambda* void ((c-string title) (c-string body)) "NotifyNotification *notif;\n" "notify_init(title);\n" "notif = notify_notification_new(title, body, NULL);\n" "notify_notification_show(notif, NULL);\n" "g_object_unref(notif);\n")) (define broadcast-socket #f) (define broadcast-address (inet-address "255.255.255.255" 3742)) (define (broadcast-setup) (set! broadcast-socket (socket af/inet sock/dgram)) (set! (so-broadcast? broadcast-socket) #t) (socket-bind broadcast-socket broadcast-address)) (define (broadcast-receive) (condition-case (socket-receive broadcast-socket 256) ((exn timeout) (broadcast-receive)))) (define (net-notify-listen) (let ((response (broadcast-receive))) (if (equal? (string-take response 12) "net-notify: ") (string-drop response 12) (net-notify-listen)))) (define (main) (broadcast-setup) (forever (thunk (notify "net-notify" (net-notify-listen))))) (main)