Browse Source

notification programs that work over the local network

master
whiteline 5 months ago
parent
commit
252ae8d03c
5 changed files with 85 additions and 4 deletions
  1. +3
    -3
      coding-terminal
  2. +1
    -1
      host-cwd.sh
  3. +1
    -0
      makefile-notifyd
  4. +30
    -0
      net-notify.scm
  5. +50
    -0
      net-notifyd.scm

+ 3
- 3
coding-terminal View File

@@ -1,4 +1,4 @@
#!/bin/zsh
#xrdb -merge ~/.Xresources.green
urxvt -fn xft:inconsolata-26:hinting=false -letsp 1 -im none -b 26 &
#xrdb -merge ~/.Xresources
xrdb -merge ~/.Xresources.green
urxvt -fn xft:inconsolata-26:antialias=true:hinting=true -letsp 1 -b 26 &
xrdb -merge ~/.Xresources

+ 1
- 1
host-cwd.sh View File

@@ -1,2 +1,2 @@
#!/bin/zsh
ruby -run -e httpd . -p 8080 --bind-address=192.168.1.2
ruby -run -e httpd . -p 8080 --bind-address=`~/Scripts/current-ip.sh`

+ 1
- 0
makefile-notifyd View File

@@ -0,0 +1 @@
csc net-notifyd.scm -o net-notifyd -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libpng16 -I/usr/include/x86_64-linux-gnu -I/usr/include/libmount -I/usr/include/blkid -L -lnotify -L -lgio-2.0 -L -lgdk_pixbuf-2.0 -L -lgobject-2.0 -L -lglib-2.0

+ 30
- 0
net-notify.scm View File

@@ -0,0 +1,30 @@
(import scheme)
(import (chicken base))
(import srfi-1)
(import srfi-13)
(import socket)
(import (chicken process-context))

(define broadcast-socket #f)

(define bind-address (inet-address "0.0.0.0" #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 bind-address))

(define (broadcast-send str)
(socket-send-to broadcast-socket str broadcast-address))

(define (main)
(let ((args (drop (argv) 1)))
(if (null? args)
(begin (display "usage: net-notify <message>")
(newline))
(begin (broadcast-setup)
(broadcast-send (string-concatenate (intersperse (cons "net-notify:" args) " ")))))))

(main)

+ 50
- 0
net-notifyd.scm View File

@@ -0,0 +1,50 @@
(import scheme)
(import (chicken base))
(import srfi-1)
(import srfi-13)
(import socket)

(foreign-declare "#include <libnotify/notify.h>")

(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)


Loading…
Cancel
Save