Initial commit

This commit is contained in:
Torjus Håkestad 2024-03-09 20:34:21 +01:00
commit d82d2a7f8e
5 changed files with 119 additions and 0 deletions

27
flake.lock Normal file
View File

@ -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
}

40
flake.nix Normal file
View File

@ -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
];
};
});
};
}

8
go.mod Normal file
View File

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

4
go.sum Normal file
View File

@ -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=

40
main.go Normal file
View File

@ -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)
}
}
}