Skip to content
Snippets Groups Projects
Unverified Commit 6b7a3c62 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Receive clicks...

parent e673ca8c
Branches
No related tags found
No related merge requests found
......@@ -3,29 +3,30 @@
package bar
import (
"bufio"
"fmt"
"os"
)
type Clicks struct {
Button int64 `json:"button"`
Modifiers []string `json:"modifiers"`
X int64 `json:"x"`
Y int64 `json:"y"`
RelativeX int64 `json:"relative_x"`
RelativeY int64 `json:"relative_y"`
Width int64 `json:"width"`
Height int64 `json:"height"`
}
"gitlab.ie.suberic.net/kevin/i3going-on/modules"
"gopkg.in/yaml.v2"
)
//{"button":1,"modifiers":[],"x":1952,"y":1144,"relative_x":62,"relative_y":14,"width":112,"height":22}
func handleCommands() {
logger, err := os.Create("/tmp/i3going-on.log")
func handleCommands(clicks chan modules.Click) {
logger, _ := os.Create("/tmp/i3going-on.log")
for {
logger.WriteString("Looking for a click...\n")
clickParser := yaml.NewDecoder(os.Stdin)
click := modules.Click{}
err := clickParser.Decode(&click)
if err != nil {
panic(err)
logger.WriteString(fmt.Sprintf("Error on click: %s\n", err))
clicks <- modules.Click{
Name: fmt.Sprintf("ERROR: %s", err),
}
continue
}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
logger.WriteString(scanner.Text())
logger.WriteString(fmt.Sprintf("Error on click: %s\n", err))
clicks <- click
}
}
......@@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gitlab.ie.suberic.net/kevin/i3going-on/modules"
"golang.org/x/sys/unix"
)
......@@ -17,7 +18,10 @@ func Run(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
cfg, err := readConfig(viper.GetString("config"))
cobra.CheckErr(err)
go handleCommands()
clicks := make(chan modules.Click, 1)
go handleCommands(clicks)
fmt.Printf(`{ "version": 1, "stop_signal": %d, "cont_signal": %d, "click_events": true }`+"\n",
unix.SignalNum("SIGSTOP"), unix.SignalNum("SIGCONT"))
......@@ -30,6 +34,18 @@ func Run(cmd *cobra.Command, args []string) {
fmt.Printf("%s\n[%s]", separator, strings.Join(line, ","))
separator = ","
select {
case click := <-clicks:
found := false
for _, module := range cfg.Modules {
if click.Name == module.Name {
found = true
fmt.Print(`[{"full_text": "CLICK!"},{"name": "post", "full_text": "post", "color": "#11ff11"},{"name": "date", "full_text": "22-12-01 22:54"}]`)
}
}
if !found {
fmt.Print(`[{"full_text": "ERROR!"},{"name": "post", "full_text": "post", "color": "#11ff11"},{"name": "date", "full_text": "22-12-01 22:54"}]`)
}
time.Sleep(5 * time.Second)
case <-time.After(time.Duration(cfg.Refresh) * time.Second):
}
}
......
// Package module implements all the modules.
// Copyright (C) 2022 Kevin Lyda <kevin@lyda.ie>
package modules
type Click struct {
Name string `json:"name"`
Button int64 `json:"button"`
Modifiers []string `json:"modifiers"`
X int64 `json:"x"`
Y int64 `json:"y"`
RelativeX int64 `json:"relative_x"`
RelativeY int64 `json:"relative_y"`
Width int64 `json:"width"`
Height int64 `json:"height"`
}
// Package module implements all the modules.
// Copyright (C) 2022 Kevin Lyda <kevin@lyda.ie>
package modules
import (
......@@ -47,5 +49,5 @@ func (d *DateMod) Render() string {
}
d.blink = !d.blink
}
return fmt.Sprintf("{\"full_text\": \"%s\"}", now)
return fmt.Sprintf(`{"name": "%s", "full_text": "%s"}`, d.name, now)
}
// Package module implements all the modules.
// Copyright (C) 2022 Kevin Lyda <kevin@lyda.ie>
package modules
import (
......
// Package module implements all the modules.
// Copyright (C) 2022 Kevin Lyda <kevin@lyda.ie>
package modules
import (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment