-
+
diff --git a/ws_controller.go b/ws_controller.go
index 8ce91ce..051a29f 100644
--- a/ws_controller.go
+++ b/ws_controller.go
@@ -8,7 +8,9 @@ import (
"github.com/gorilla/websocket"
"github.com/kbinani/screenshot"
"github.com/labstack/echo/v4"
+ "image/color"
"image/jpeg"
+ "math"
"os/exec"
"strconv"
"strings"
@@ -37,6 +39,7 @@ type MessagesData struct {
type ScreenshotMessageData struct {
Quality string `json:quality`
+ Pointer bool `json:pointer`
}
type MessageResponse struct {
@@ -56,6 +59,24 @@ func sendMessageResponse(ws *websocket.Conn, r MessageResponse) {
ws.WriteMessage(websocket.TextMessage, value)
}
+func getPointerPosition() (float64, float64) {
+ location := exec.Command("xdotool", "getmouselocation")
+ output, _ := location.Output()
+ position := string(output)
+ currentX := 0.0
+ currentY := 0.0
+
+ for key, value := range strings.Split(position, " ") {
+ if key == 0 {
+ currentX, _ = strconv.ParseFloat(strings.Replace(value, "x:", "", 1), 32)
+ } else if key == 1 {
+ currentY, _ = strconv.ParseFloat(strings.Replace(value, "y:", "", 1), 32)
+ }
+ }
+
+ return currentX, currentY
+}
+
func createActions() Actions {
actions := Actions{
Functions: make(map[string]func(ws *websocket.Conn, msg []byte) error),
@@ -83,19 +104,7 @@ func createActions() Actions {
return cmd.Run()
}
- location := exec.Command("xdotool", "getmouselocation")
- output, _ := location.Output()
- position := string(output)
- currentX := 0.0
- currentY := 0.0
-
- for key, value := range strings.Split(position, " ") {
- if key == 0 {
- currentX, _ = strconv.ParseFloat(strings.Replace(value, "x:", "", 1), 32)
- } else if key == 1 {
- currentY, _ = strconv.ParseFloat(strings.Replace(value, "y:", "", 1), 32)
- }
- }
+ currentX, currentY := getPointerPosition()
newX, _ := strconv.ParseFloat(data.X, 32)
newY, _ := strconv.ParseFloat(data.Y, 32)
@@ -253,6 +262,8 @@ func createActions() Actions {
key = "Control_L"
} else if key == "alt" {
key = "Alt_L"
+ } else if key == "tab" {
+ key = "Tab"
}
if key != "" {
@@ -325,6 +336,24 @@ func createActions() Actions {
quality = 90
}
+ if data.Pointer {
+ currentX, currentY := getPointerPosition()
+ pointerSize := 2 * 16.0
+
+ pixelColor := color.RGBA{
+ R: 255,
+ G: 0,
+ B: 0,
+ A: 255,
+ }
+
+ for x := math.Max(0.0, currentX-pointerSize/2); x <= currentX+3; x++ {
+ for y := math.Max(0.0, currentY-pointerSize/2); y < currentY+3; y++ {
+ img.SetRGBA(int(x), int(y), pixelColor)
+ }
+ }
+ }
+
buff := new(bytes.Buffer)
jpeg.Encode(buff, img, &jpeg.Options{Quality: quality})