Exemplo n.º 1
0
func WorkspaceToHead(headIndex int, wrk *workspace.Workspace) {
	if headIndex == Heads.VisibleIndex(wrk) {
		return
	}

	// If headIndex is the currently active head, then just activate 'wrk'
	// greedily.
	if headIndex == Heads.VisibleIndex(Workspace()) {
		SetWorkspace(wrk, true)
		return
	}

	// Now we know that we're setting the workspace of a head that isn't
	// active. The last special case to check for is whether the workspace
	// we're setting is the currently activate workspace. If it is, then we
	// simply activate the workspace at headIndex greedily.
	if wrk.IsActive() {
		Heads.WithVisibleWorkspace(headIndex, func(w *workspace.Workspace) {
			SetWorkspace(w, true)
		})
		return
	}

	// Finally, we can just swap workspaces now without worrying about the
	// active workspace changing.
	Heads.WithVisibleWorkspace(headIndex, func(w *workspace.Workspace) {
		Heads.SwitchWorkspaces(wrk, w)
	})
	ewmhVisibleDesktops()
	ewmhCurrentDesktop()
	Heads.EwmhWorkarea()
}
Exemplo n.º 2
0
func SetWorkspace(wrk *workspace.Workspace, greedy bool) {
	old := Workspace()
	wrk.Activate(greedy)
	if old != Workspace() {
		FYI("%s", wrk)
	}

	ewmhVisibleDesktops()
	ewmhCurrentDesktop()
	Heads.EwmhWorkarea()
}
Exemplo n.º 3
0
func RenameWorkspace(wrk *workspace.Workspace, newName string) error {
	if len(newName) == 0 {
		return fmt.Errorf("workspaces must have a name of length at least one.")
	}
	if Heads.Workspaces.Find(newName) != nil {
		return fmt.Errorf("a workspace with name '%s' already exists.", newName)
	}
	wrk.Rename(newName)

	ewmhDesktopNames()
	return nil
}
Exemplo n.º 4
0
func (c *Client) CheckNewWorkspace() {
	var newWrk *workspace.Workspace = nil
	curWrk := c.Workspace()

	if dragGeom := c.DragGeom(); dragGeom != nil {
		newWrk = wm.Heads.FindMostOverlap(dragGeom)
	} else {
		newWrk = wm.Heads.FindMostOverlap(c.frame.Geom())
	}
	if newWrk == nil || curWrk == newWrk {
		return
	}

	newWrk.Add(c)

	// If this is the active window, switch to this workspace too.
	if c.IsActive() {
		wm.SetWorkspace(newWrk, false)
	}
}
Exemplo n.º 5
0
func (hds *Heads) RemoveWorkspace(wk *workspace.Workspace) {
	// Don't allow it if this would result in fewer workspaces than there
	// are active physical heads.
	if len(hds.geom) == len(hds.Workspaces.Wrks) {
		panic("Cannot have fewer workspaces than active monitors.")
	}

	// A non-empty workspace cannot be removed.
	if len(wk.Clients) > 0 {
		panic(fmt.Sprintf("Non-empty workspace '%s' cannot be removed.", wk))
	}

	if wk.IsVisible() {
		// Find the last-most hidden workspace that is not itself and switch.
		for i := len(hds.Workspaces.Wrks) - 1; i >= 0; i-- {
			work := hds.Workspaces.Wrks[i]
			if work != wk && !work.IsVisible() {
				hds.SwitchWorkspaces(wk, work)
				break
			}
		}
	}
	hds.Workspaces.Remove(wk)
}
Exemplo n.º 6
0
func (hds *Heads) SwitchWorkspaces(wk1, wk2 *workspace.Workspace) {
	v1, v2 := hds.VisibleIndex(wk1), hds.VisibleIndex(wk2)
	switch {
	case v1 > -1 && v2 > -1:
		wk1.Hide()
		wk2.Hide()
		hds.visibles[v1], hds.visibles[v2] = hds.visibles[v2], hds.visibles[v1]
		wk1.Show()
		wk2.Show()
	case v1 > -1 && v2 == -1:
		wk1.Hide()
		hds.visibles[v1] = wk2
		wk2.Show()
	case v1 == -1 && v2 > -1:
		wk2.Hide()
		hds.visibles[v2] = wk1
		wk1.Show()
	case v1 == -1 && v2 == -1:
		// Meaningless
	default:
		panic("unreachable")
	}
}