Refactored to i3 module
This commit is contained in:
parent
f9e815b4e3
commit
3516c0a618
@ -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
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package i3
|
||||
|
||||
import (
|
||||
// Standard
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package i3
|
||||
|
||||
import (
|
||||
// Standard
|
26
main.go
26
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user