From d82d2a7f8e9de48fa65642e9f98e04c51db51f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 9 Mar 2024 20:34:21 +0100 Subject: [PATCH] Initial commit --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 40 ++++++++++++++++++++++++++++++++++++++++ go.mod | 8 ++++++++ go.sum | 4 ++++ main.go | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a897d3d --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1709703039, + "narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b950edf --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "A small listener for notifications"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs }: + let + allSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in + { + overlays.default = final: prev: { + notlistener = self.packages.${prev.system}.default; + }; + + packages = forAllSystems ({ pkgs }: { + default = pkgs.buildGoModule { + name = "ghettoptt"; + src = ./.; + vendorHash = "sha256-S/t8EkMRjceGhNcNqGhmnMviQrhqt7n9FiCmpxbKUoI="; + buildInputs = [ pkgs.libnotify ]; + nativeBuildInputs = [ pkgs.pkg-config ]; + }; + }); + devShells = forAllSystems ({ pkgs }: { + default = pkgs.mkShell { + packages = with pkgs; [ + go + ]; + }; + }); + }; +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9305699 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module git.t-juice.club/torjus/ghettoptt + +go 1.21.6 + +require ( + github.com/godbus/dbus/v5 v5.1.0 // indirect + github.com/holoplot/go-evdev v0.0.0-20240306072622-217e18f17db1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..44fa5d2 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= +github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/holoplot/go-evdev v0.0.0-20240306072622-217e18f17db1 h1:92OsBIf5KB1Tatx+uUGOhah73jyNUrt7DmfDRXXJ5Xo= +github.com/holoplot/go-evdev v0.0.0-20240306072622-217e18f17db1/go.mod h1:iHAf8OIncO2gcQ8XOjS7CMJ2aPbX2Bs0wl5pZyanEqk= diff --git a/main.go b/main.go new file mode 100644 index 0000000..7e07790 --- /dev/null +++ b/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + "os" + + "github.com/godbus/dbus/v5" + "github.com/holoplot/go-evdev" +) + +func main() { + conn, err := dbus.ConnectSessionBus() + if err != nil { + panic(err) + } + defer conn.Close() + + obj := conn.Object("net.sourceforge.mumble.mumble", "/") + + // Start reading input events + input, err := evdev.OpenWithFlags("/dev/input/event1", os.O_RDONLY) + if err != nil { + panic(err) + } + + for { + ev, err := input.ReadOne() + if err != nil { + panic(err) + } + if ev.Code == evdev.KEY_F24 && ev.Value == 1 { + fmt.Printf("PTT ON!\n") + obj.Go("net.sourceforge.mumble.Mumble.startTalking", 0, nil) + } + if ev.Code == evdev.KEY_F24 && ev.Value == 0 { + fmt.Printf("PTT OFF!\n") + obj.Go("net.sourceforge.mumble.Mumble.stopTalking", 0, nil) + } + } +}