Compare commits

...

15 commits
main ... go

Author SHA1 Message Date
bc50f37187
better version 2024-06-20 15:57:51 -05:00
95e640c9e8
eww closes the bar on it's own 2024-06-20 15:49:13 -05:00
68c90481fc
add --json flag to hyprman mako 2024-06-11 11:53:13 -05:00
b31326b529
update flake 2024-06-06 13:31:35 -05:00
36dd259822
simplify mako impl 2024-06-06 13:25:01 -05:00
269cc8e53f
go mod 2024-06-06 13:11:30 -05:00
64813f5a9c
formatting 2024-06-06 13:11:21 -05:00
a32a141867
implement basic makoctl notification list 2024-06-01 01:28:23 -05:00
372fd3b36f
use 2 seconds not 200... 2024-05-31 16:31:14 -05:00
95e7001077
split off eww file 2024-05-31 16:30:18 -05:00
f698f2614e
fix completions 2024-05-31 15:10:28 -05:00
05b641bc97
gofmt 2024-05-31 14:59:23 -05:00
42ac8bee8c
flake.lock: Update
Flake lock file updates:

• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/e381a1288138aceda0ac63db32c7be545b446921' (2024-05-21)
  → 'github:nixos/nixpkgs/6132b0f6e344ce2fe34fc051b72fb46e34f668e0' (2024-05-30)
2024-05-31 14:50:53 -05:00
4fcd597b6d
update nix vendor hash 2024-05-31 14:50:48 -05:00
f7284f1104
go 2024-05-31 14:45:50 -05:00
16 changed files with 731 additions and 0 deletions

31
.gitignore vendored Normal file
View file

@ -0,0 +1,31 @@
# Created by https://www.toptal.com/developers/gitignore/api/go
# Edit at https://www.toptal.com/developers/gitignore?templates=go
### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
# End of https://www.toptal.com/developers/gitignore/api/go
# nix
result
hyprman

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Daylin Morgan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

17
cmd/eww.go Normal file
View file

@ -0,0 +1,17 @@
package cmd
import (
"github.com/spf13/cobra"
)
var ewwCmd = &cobra.Command{
Use: "eww",
Short: "eww integration",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
hm.LoadConfig(configPath)
},
}
func init() {
rootCmd.AddCommand(ewwCmd)
}

17
cmd/eww_start.go Normal file
View file

@ -0,0 +1,17 @@
package cmd
import (
"github.com/spf13/cobra"
)
var startCmd = &cobra.Command{
Use: "start",
Short: "Launch eww",
Run: func(cmd *cobra.Command, args []string) {
hm.LaunchEww()
},
}
func init() {
ewwCmd.AddCommand(startCmd)
}

17
cmd/eww_watch.go Normal file
View file

@ -0,0 +1,17 @@
package cmd
import (
"github.com/spf13/cobra"
)
var watchCmd = &cobra.Command{
Use: "watch",
Short: "Watch hyprland events and propagate to eww",
Run: func(cmd *cobra.Command, args []string) {
hm.Watch()
},
}
func init() {
ewwCmd.AddCommand(watchCmd)
}

26
cmd/mako.go Normal file
View file

@ -0,0 +1,26 @@
package cmd
import (
"github.com/spf13/cobra"
hyprman "git.dayl.in/daylin/hyprman/internal"
)
var makoCmd = &cobra.Command{
Use: "mako",
Short: "mako integration",
Run: func(cmd *cobra.Command, args []string) {
hyprman.ListNotifications(number, json)
},
}
var (
number int
json bool
)
func init() {
rootCmd.AddCommand(makoCmd)
makoCmd.Flags().IntVarP(&number, "number", "n", 10, "number of notifications")
makoCmd.Flags().BoolVar(&json, "json", false, "output data as json")
}

42
cmd/root.go Normal file
View file

@ -0,0 +1,42 @@
package cmd
import (
"os"
cc "github.com/ivanpirog/coloredcobra"
"github.com/spf13/cobra"
hyprman "git.dayl.in/daylin/hyprman/internal"
)
func Execute() {
cc.Init(&cc.Config{
RootCmd: rootCmd,
Headings: cc.HiMagenta + cc.Bold,
Commands: cc.Bold,
Example: cc.Italic,
ExecName: cc.Bold,
Flags: cc.Bold,
NoExtraNewlines: true,
NoBottomNewline: true,
})
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
var (
configPath string
hm = &hyprman.Hyprman{}
)
var rootCmd = &cobra.Command{
Use: "hyprman",
Short: "hyprland companion app",
}
func init() {
rootCmd.CompletionOptions.HiddenDefaultCmd = true
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", hyprman.DefaultConfigPath(), "path to config file")
}

27
flake.lock Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1717646450,
"narHash": "sha256-KE+UmfSVk5PG8jdKdclPVcMrUB8yVZHbsjo7ZT1Bm3c=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "818dbe2f96df233d2041739d6079bb616d3e5597",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

48
flake.nix Normal file
View file

@ -0,0 +1,48 @@
{
description = "hyprman";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
outputs =
inputs@{
nixpkgs,
self,
...
}:
let
inherit (nixpkgs.lib) genAttrs cleanSource;
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
forAllSystems = f: genAttrs supportedSystems (system: f nixpkgs.legacyPackages.${system});
in
{
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [go];
};
});
packages = forAllSystems (pkgs: {
default = self.packages.${pkgs.system}.hyprman;
hyprman = pkgs.buildGoModule {
pname = "hyprman";
version = "${self.shortRev or "dirty"}";
src = cleanSource ./.;
vendorHash = "sha256-hJwRLVIiWxLbX2tAPVVVLGFk4OaAy5qiFcICEqhVMJM=";
nativeBuildInputs = with pkgs; [installShellFiles];
postInstall = ''
installShellCompletion --cmd hyprman \
--zsh <($out/bin/hyprman completion zsh)
'';
};
});
formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
};
}

28
go.mod Normal file
View file

@ -0,0 +1,28 @@
module git.dayl.in/daylin/hyprman
go 1.22.2
require (
github.com/charmbracelet/lipgloss v0.11.0
github.com/goccy/go-yaml v1.11.3
github.com/ivanpirog/coloredcobra v1.0.1
github.com/spf13/cobra v1.8.0
)
require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.1.2 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
)
replace github.com/ivanpirog/coloredcobra => github.com/daylinmorgan/coloredcobra v0.0.0-20240527152736-9d3ce38297a6

60
go.sum Normal file
View file

@ -0,0 +1,60 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/lipgloss v0.11.0 h1:UoAcbQ6Qml8hDwSWs0Y1cB5TEQuZkDPH/ZqwWWYTG4g=
github.com/charmbracelet/lipgloss v0.11.0/go.mod h1:1UdRTH9gYgpcdNN5oBtjbu/IzNKtzVtb7sqN1t9LNn8=
github.com/charmbracelet/x/ansi v0.1.2 h1:6+LR39uG8DE6zAmbu023YlqjJHkYXDF1z36ZwzO4xZY=
github.com/charmbracelet/x/ansi v0.1.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/daylinmorgan/coloredcobra v0.0.0-20240527152736-9d3ce38297a6 h1:Zst7HlWvQj8LPJ3mhIWtGH2DxqUo6VEq0oekNyAho6M=
github.com/daylinmorgan/coloredcobra v0.0.0-20240527152736-9d3ce38297a6/go.mod h1:csDZxFD5oWCy1x8hxXVD4txpYQgo12WOcLS7JON5SVE=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I=
github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

122
internal/eww.go Normal file
View file

@ -0,0 +1,122 @@
package hyprman
import (
"bufio"
"encoding/json"
"fmt"
"io"
"log"
"net"
"os/exec"
"strings"
"time"
)
type EwwWorkspace struct {
Icon string `json:"icon"`
Class string `json:"class"`
Id int `json:"id"`
}
func (hm *Hyprman) pickIcon(class string) string {
for k, v := range hm.Config.Classes {
if strings.Contains(k, class) {
return v
}
}
return hm.Config.DefaultIcon
}
func (hm *Hyprman) generateEwwClasses() {
monitors := getMonitors()
clients := getClients()
var ewwClasses [][]EwwWorkspace
monitor := make([]EwwWorkspace, 9)
for i := range 9 {
monitor[i] = EwwWorkspace{
hm.Config.NoClientIcon,
fmt.Sprintf("ws-button-%d", i+1),
i + 1,
}
}
for _, client := range clients {
id := client.Workspace.Id - 1
currentIcon := monitor[id].Icon
if currentIcon == hm.Config.NoClientIcon {
monitor[id].Icon = hm.pickIcon(client.Class)
} else {
monitor[id].Icon = fmt.Sprintf("%s%s", currentIcon, hm.pickIcon(client.Class))
}
}
for _, id := range openWorkspaces(monitors) {
// activeId := m.ActiveWorkspace.Id
monitor[id-1].Class = fmt.Sprintf("%s %s", monitor[id-1].Class, "ws-button-open")
}
for i, m := range monitors {
activeId := m.ActiveWorkspace.Id - 1
ewwClasses = append(ewwClasses, make([]EwwWorkspace, 9))
copy(ewwClasses[i], monitor)
ewwClasses[i][activeId].Class = fmt.Sprintf("%s %s-%d", monitor[activeId].Class, "ws-button-active", activeId+1)
}
bytes, err := json.Marshal(ewwClasses)
if err != nil {
panic(err)
}
fmt.Println(string(bytes))
}
func ewwBar1(cmd string) {
time.Sleep(3 * time.Second)
output, err := exec.Command("eww", cmd, "bar1").CombinedOutput()
if err != nil {
notify(fmt.Sprintf("failed to %s bar 1\n\n%s\n\n%v", cmd, output, err))
}
}
func (hm *Hyprman) handleHyprEvent(line string) {
s := strings.Split(line, ">>")
event, _ := s[0], s[1]
if event == "monitoradded" {
notify("Monitor added opening bar1")
go ewwBar1("open")
}
hm.generateEwwClasses()
}
func (hm *Hyprman) LaunchEww() {
for i := range getMonitors() {
if err := exec.Command("eww", "open", fmt.Sprintf("bar%d", i)).Run(); err != nil {
notify(fmt.Sprintf("Error lanching eww:\n%v", err))
}
}
}
func (hm *Hyprman) Watch() {
socketPath := hyprSocket2()
conn, err := net.Dial("unix", socketPath)
if err != nil {
log.Fatalln("Error connecting to hyprland IPC:", err)
}
defer conn.Close()
reader := bufio.NewReader(conn)
hm.generateEwwClasses()
for {
line, err := reader.ReadString('\n')
if err != nil {
if err == io.EOF {
// log.Printf("reached EOF for %s\n", socketPath)
break
}
// log.Println("error reading line")
continue
}
hm.handleHyprEvent(line)
}
}

148
internal/hyprman.go Normal file
View file

@ -0,0 +1,148 @@
package hyprman
import (
"encoding/json"
"fmt"
"log"
"net"
"os"
"os/exec"
"path/filepath"
yaml "github.com/goccy/go-yaml"
)
func DefaultConfigPath() string {
configPath, exists := os.LookupEnv("XDG_CONFIG_HOME")
if !exists {
home, exists := os.LookupEnv("HOME")
if !exists {
log.Fatalln("failed to set default icons.json path is $HOME or $XDG_CONFIG_HOME set?")
}
configPath = filepath.Join(home, ".config")
}
return filepath.Join(configPath, "hyprman", "config.yml")
}
func hyprSocketBase() string {
runtimeDir, exists := os.LookupEnv("XDG_RUNTIME_DIR")
if !exists {
log.Fatalln("XDG_RUNTIME_DIR not set")
}
instanceSig, exists := os.LookupEnv("HYPRLAND_INSTANCE_SIGNATURE")
if !exists {
log.Fatalln("HYPRLAND_INSTANCE_SIGNATURE not set")
}
return filepath.Join(runtimeDir, "hypr", instanceSig)
}
func hyprSocket() string {
return filepath.Join(hyprSocketBase(), ".socket.sock")
}
func hyprSocket2() string {
return filepath.Join(hyprSocketBase(), ".socket2.sock")
}
type Workspace struct {
Name string
Id int
}
type Client struct {
Class string
Workspace Workspace
}
type Icons map[string]string
type Hyprman struct {
Config Config
}
type Config struct {
Classes Icons
NoClientIcon string `yaml:"no-client"`
DefaultIcon string `yaml:"default-icon"`
}
func (hm *Hyprman) LoadConfig(path string) {
var config Config
data, err := os.ReadFile(path)
if err != nil {
log.Fatal(fmt.Errorf("failed to read config at %s:\n%w", path, err))
}
if err := yaml.Unmarshal([]byte(data), &config); err != nil {
log.Fatal(fmt.Errorf("failed to read config at %s:\n%w", path, err))
}
hm.Config = config
}
func hyprctl(cmd string) []byte {
socketPath := hyprSocket()
conn, err := net.Dial("unix", socketPath)
if err != nil {
log.Fatalln("Error connecting to hyprland IPC:", err)
}
defer conn.Close()
_, err = conn.Write([]byte(cmd))
if err != nil {
log.Fatal(err)
}
buf := make([]byte, 1024*8) // Bigger?
n, err := conn.Read(buf)
if err != nil {
log.Fatal(err)
}
return buf[0:n]
}
type ActiveWorkspace struct {
Name string
Id int
}
type Monitor struct {
ActiveWorkspace ActiveWorkspace
Id int
}
// generic or interface?
func getMonitors() []Monitor {
data := hyprctl("[-j]/monitors")
var monitors []Monitor
err := json.Unmarshal(data, &monitors)
if err != nil {
log.Fatalln(err)
}
return monitors
}
func getClients() []Client {
data := hyprctl("[-j]/clients")
var clients []Client
err := json.Unmarshal(data, &clients)
if err != nil {
log.Fatalln(err)
}
return clients
}
func openWorkspaces(monitors []Monitor) []int {
open := make([]int, len(monitors))
for i, m := range monitors {
open[i] = m.ActiveWorkspace.Id
}
return open
}
func notify(message string) {
cmd := exec.Command(
"notify-send",
"--app-name=hyprman",
"--transient",
message,
)
cmd.Run()
}

112
internal/mako.go Normal file
View file

@ -0,0 +1,112 @@
package hyprman
import (
"encoding/json"
"fmt"
"log"
"os/exec"
"github.com/charmbracelet/lipgloss"
)
type MakoHistory struct {
Type string `json:"type"`
Data [][]MakoNotification `json:"data"`
}
type MakoNotification struct {
AppName MakoNotificationData `json:"app-name"`
Summary MakoNotificationData
Body MakoNotificationData
// AppIcon MakoNotificationData `json:"app-icon"`
// Category MakoNotificationData
// DesktopEntry MakoNotificationData `json:"desktop-entry"`
// Id MakoNotificationData
// Urgency MakoNotificationData
// Actions MakoNotificationData
}
type MakoNotificationData struct {
Type string `json:"type"`
Data string `json:"data"`
}
type History struct {
Notifications []Notifcation
}
type Notifcation struct {
AppName string
Summary string
Body string
}
func (mn MakoNotification) toNotification() Notifcation {
var n Notifcation
n.AppName = mn.AppName.Data
n.Summary = mn.Summary.Data
n.Body = mn.Body.Data
return n
}
func (mh MakoHistory) toHistory() History {
var h History
var notifications []Notifcation
for _, mn := range mh.Data[0] {
notifications = append(notifications, mn.toNotification())
}
h.Notifications = notifications
return h
}
func getHistory() History {
var makoHistory MakoHistory
makoOutput, err := exec.Command("makoctl", "history").CombinedOutput()
if err != nil {
log.Fatal(err)
}
json.Unmarshal(makoOutput, &makoHistory)
return makoHistory.toHistory()
}
func (h *History) truncate(number int) {
h.Notifications = h.Notifications[:min(len(h.Notifications), number)]
}
func ListNotifications(number int, outputJson bool) {
history := getHistory()
history.truncate(number)
if !outputJson {
for _, n := range history.Notifications {
n.Render()
}
} else {
b, err := json.MarshalIndent(history.Notifications, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(b))
}
}
func (n Notifcation) Render() {
appStyle := lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("3")).
PaddingTop(1)
textStyle := lipgloss.NewStyle().Width(80).PaddingLeft(2).
BorderStyle(lipgloss.ThickBorder()).
BorderLeft(true)
fmt.Println(appStyle.Render(n.AppName))
if len(n.Summary) > 0 {
fmt.Println(textStyle.
BorderForeground(lipgloss.Color("14")).
Render(n.Summary))
}
if len(n.Body) > 0 {
fmt.Println(textStyle.
BorderForeground(lipgloss.Color("2")).
Render(n.Body))
}
}

7
main.go Normal file
View file

@ -0,0 +1,7 @@
package main
import "git.dayl.in/daylin/hyprman/cmd"
func main() {
cmd.Execute()
}

8
todo.md Normal file
View file

@ -0,0 +1,8 @@
# hyprman-go todo's
- [ ] include in class the 'other' active monitor?
- [ ] use goroutine with slightly delay to "open/close"
bar to give hyprland time to draw/setup monitor
<!-- generated with <3 by daylinmorgan/todo -->