Skip to content

Commit

Permalink
update socket communication scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed May 31, 2023
1 parent 85c2b4d commit 6d18363
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ nc -Ulk /tmp/cortile.sock.out
socat UNIX-LISTEN:/tmp/cortile.sock.out,reuseaddr,fork STDOUT
```

For debugging purposes, you can also dump the json messages into a file:
```bash
# Netcat
nc -Ulk /tmp/cortile.sock.out 2>&1 | tee /tmp/cortile.json

# Socat
socat -v UNIX-LISTEN:/tmp/cortile.sock.out,reuseaddr,fork OPEN:/tmp/cortile.json,create,truncate
```

Similarly, requests about the status of cortile can be sent to the incoming socket:
```bash
# Netcat
Expand Down
15 changes: 9 additions & 6 deletions assets/scripts/listen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,22 @@ while json=$(nc -Ulw 1 $sockout | jq -r "."); do

case ${type} in
"Action")
ws=$(echo $data | jq -r ".Workspace")
desk=$(echo $data | jq -r ".Desk")
screen=$(echo $data | jq -r ".Screen")

# EXAMPLE: retrieve action event on active workspace
echo "Received 'action' with name '$name' on 'workspace = $ws'";;
echo "Received 'action' with name '$name' on 'desktop = $desk' and 'screen = $screen'";;
"State")
case ${name} in
"workspaces")
ws=$(xprop -root -notype _NET_CURRENT_DESKTOP | awk -F " = " '{print $2}')
enabled=$(echo $data | jq -r ".\"$ws\".TilingEnabled")
layout=$(echo $data | jq -r ".\"$ws\".ActiveLayoutNum")
desk=$(echo $data | jq -r ".Desk")
screen=$(echo $data | jq -r ".Screen")
workspace=$(echo $data | jq -r ".Workspaces[] | select((.Location.DeskNum==$desk) and (.Location.ScreenNum==$screen))")
enabled=$(echo $workspace | jq -r ".TilingEnabled")
layout=$(echo $workspace | jq -r ".ActiveLayoutNum")

# EXAMPLE: retrieve tiling state and layout on active workspace
echo "Received '$name' with tiling 'enabled = $enabled' on 'workspace = $ws' with 'layout = $layout'";;
echo "Received '$name' with tiling 'enabled = $enabled' on 'desktop = $desk' and 'screen = $screen' with 'layout = $layout'";;
"arguments")
config=$(echo $data | jq -r ".Config")

Expand Down
7 changes: 5 additions & 2 deletions desktop/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

type Workspace struct {
Location Location // Desktop and screen location
Layouts []Layout // List of available layouts
TilingEnabled bool // Tiling is enabled or not
ActiveLayoutNum uint // Active layout index
Expand All @@ -24,8 +25,10 @@ func CreateWorkspaces() map[Location]*Workspace {
// Create layouts for each desktop and screen
layouts := CreateLayouts(location)
ws := &Workspace{
Layouts: layouts,
TilingEnabled: common.Config.TilingEnabled,
Location: location,
Layouts: layouts,
TilingEnabled: common.Config.TilingEnabled,
ActiveLayoutNum: 0,
}

// Activate default layout
Expand Down
20 changes: 16 additions & 4 deletions input/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ func Execute(a string, tr *desktop.Tracker) bool {

// Notify socket
if success {
type Action struct{ Workspace, Screen uint }
type Action struct {
Desk uint
Screen uint
}
NotifySocket(Message[Action]{
Type: "Action",
Name: a,
Data: Action{Workspace: common.CurrentDesk, Screen: common.CurrentScreen},
Data: Action{Desk: common.CurrentDesk, Screen: common.CurrentScreen},
})
}

Expand All @@ -92,10 +95,19 @@ func Query(s string, tr *desktop.Tracker) bool {

switch s {
case "workspaces":
NotifySocket(Message[map[desktop.Location]*desktop.Workspace]{
type Workspaces struct {
Desk uint
Screen uint
Workspaces []*desktop.Workspace
}
ws := Workspaces{Desk: common.CurrentDesk, Screen: common.CurrentScreen}
for _, v := range tr.Workspaces {
ws.Workspaces = append(ws.Workspaces, v)
}
NotifySocket(Message[Workspaces]{
Type: "State",
Name: s,
Data: tr.Workspaces,
Data: ws,
})
success = true
case "arguments":
Expand Down

0 comments on commit 6d18363

Please sign in to comment.