Partial store/restore functionality implemented
This commit is contained in:
parent
6822cf93fb
commit
08e84947ef
15
main.go
15
main.go
@ -67,12 +67,25 @@ func main() {
|
||||
|
||||
cmd := strings.TrimSpace(string(buf[:n]))
|
||||
switch(cmd) {
|
||||
case "store workspaces":
|
||||
err = session.StoreWorkspaces()
|
||||
if err != nil {
|
||||
fmt.Printf("Store workspaces: %s\n", err)
|
||||
}
|
||||
conn.Close()
|
||||
|
||||
case "restore workspaces":
|
||||
err = session.RestoreWorkspaces()
|
||||
if err != nil {
|
||||
fmt.Printf("Restore workspaces: %s\n", err)
|
||||
}
|
||||
conn.Close()
|
||||
|
||||
case "fix workspaces":
|
||||
err = session.FixWorkspaces()
|
||||
if err != nil {
|
||||
fmt.Printf("Fix workspaces: %s\n", err)
|
||||
}
|
||||
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
48
session.go
48
session.go
@ -85,14 +85,10 @@ func (sess I3Session) Workspaces() (workspaces []I3Workspace, err error) {
|
||||
}
|
||||
|
||||
// Subscribe subscribes to events.
|
||||
func (sess I3Session) Subscribe(events []string) error {
|
||||
func (sess I3Session) Subscribe(events []string) (err error) {
|
||||
eventsJSON, _ := json.Marshal(events)
|
||||
res, err := sess.Socket.Request(SUBSCRIBE, string(eventsJSON))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Subscribe: %s\n", res)
|
||||
return nil
|
||||
_, err = sess.Socket.Request(SUBSCRIBE, string(eventsJSON))
|
||||
return
|
||||
}
|
||||
|
||||
// Config returns the currently running configuration data, as
|
||||
@ -299,6 +295,44 @@ func (sess I3Session) MarkMove() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// StoreWorkspaces stores the output of each workspace.
|
||||
func (sess *I3Session) StoreWorkspaces() (err error) {
|
||||
var workspaces []I3Workspace
|
||||
|
||||
sess.workspaces = make(map[int]string)
|
||||
workspaces, err = sess.Workspaces()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, ws := range workspaces {
|
||||
sess.workspaces[ws.Id] = ws.Output
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// RestoreWorkspaces moves the workspace back to its stored place, if possible.
|
||||
func (sess *I3Session) RestoreWorkspaces() (err error) {
|
||||
err = sess.UpdateOutputIndices()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for wsId, output := range sess.workspaces {
|
||||
cmd := fmt.Sprintf(
|
||||
"[workspace=%d] move workspace to output %s",
|
||||
wsId,
|
||||
output,
|
||||
)
|
||||
res, err := sess.Socket.Request(RUN_COMMAND, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s\n", res)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// FixWorkspaces moves windows from workspaces on the wrong monitor to
|
||||
// to workspaces on the correct monitor. For fixing when going to less
|
||||
// outputs.
|
||||
|
Loading…
Reference in New Issue
Block a user