diff --git a/session.go b/i3/session.go similarity index 96% rename from session.go rename to i3/session.go index 134fd99..6fd6415 100644 --- a/session.go +++ b/i3/session.go @@ -1,4 +1,4 @@ -package main +package i3 import ( // Standard @@ -11,6 +11,19 @@ import ( "strings" ) +var ( + outputIndices map[string]int + workspaces []I3Workspace +) + +func init() { + outputIndices = make(map[string]int) +} + +func SetWorkspaces(wss []I3Workspace) { + workspaces = wss +} + func (sess *I3Session) Open() (err error) { // Find path to i3 socket i3SocketPathCmd := exec.Command("i3", "--get-socketpath") @@ -161,7 +174,7 @@ func (sess I3Session) SwitchOutput(output string) error { if nextWorkspace == "" { return fmt.Errorf( "Switch to output (%s) failed, "+ - "no visible workspace found", + "no visible workspace found", output, ) } @@ -184,7 +197,7 @@ func (sess *I3Session) ManageSession() error { } choice := strings.TrimSpace(string(out)) - switch(choice) { + switch choice { case "reload", "restart", "exit": _, err = sess.Socket.Request(RUN_COMMAND, choice) if err != nil { @@ -337,12 +350,11 @@ func (sess *I3Session) RestoreWorkspaces() (err error) { var list [][]string var wsNum int - for wsName, output := range sess.workspaces { //fmt.Printf("Restore workspace: %s to %s\n", wsName, output) components := strings.Split(wsName, ":") wsNum, err = strconv.Atoi(components[0]) - if err != nil { + if err != nil { return err } @@ -439,11 +451,12 @@ func (sess I3Session) FixWorkspaces() error { cmd := fmt.Sprintf( "[workspace=\"%s\"] move window to workspace "+ - "\"%d:%s\"", + "\"%d:%s\"", ws.Name, - outputIdx+(ws.Num % 10), - workspaces[(ws.Num % 10)].Name, + outputIdx+(ws.Num%10), + workspaces[(ws.Num%10)].Name, ) + fmt.Printf("Move windows: %s\n", cmd) _, err := sess.Socket.Request(RUN_COMMAND, cmd) if err != nil { return err diff --git a/socket.go b/i3/socket.go similarity index 99% rename from socket.go rename to i3/socket.go index 01b3dea..e2a5cdb 100644 --- a/socket.go +++ b/i3/socket.go @@ -1,4 +1,4 @@ -package main +package i3 import ( // Standard diff --git a/types.go b/i3/types.go similarity index 98% rename from types.go rename to i3/types.go index 8db8ece..811a3ff 100644 --- a/types.go +++ b/i3/types.go @@ -1,4 +1,4 @@ -package main +package i3 import ( // Standard diff --git a/main.go b/main.go index e409415..2268dfc 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,9 @@ package main import ( + // Internal + "i3-session-manager/i3" + // Standard "fmt" "net" @@ -10,21 +13,22 @@ import ( ) var ( - session I3Session - sessionSubscription I3Session - workspaces []I3Workspace - outputIndices map[string]int + session i3.I3Session + sessionSubscription i3.I3Session subscriptions []string ) func init() { - outputIndices = make(map[string]int) subscriptions = []string{ "binding", "shutdown", } +} - workspaces = []I3Workspace{ +func main() { + var err error + + i3.SetWorkspaces([]i3.I3Workspace{ { Num: 0, Name: "Development" }, { Num: 1, Name: "Terminal" }, { Num: 2, Name: "Browser" }, @@ -35,11 +39,7 @@ func init() { { Num: 7, Name: "Debug" }, { Num: 8, Name: "Email" }, { Num: 9, Name: "Virtualization" }, - } -} - -func main() { - var err error + }) go SessionLoop() @@ -87,6 +87,10 @@ func main() { fmt.Printf("Fix workspaces: %s\n", err) } conn.Close() + + case "test": + fmt.Printf("test\n") + conn.Close() } } }