Пример #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()
}
Пример #2
0
func SetWorkspace(wrk *workspace.Workspace, greedy bool) {
	old := Workspace()
	wrk.Activate(greedy)
	if old != Workspace() {
		FYI("%s", wrk)
	}

	ewmhCurrentDesktop()
	ewmhVisibleDesktops()
	Heads.EwmhWorkarea()
}
Пример #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
}
Пример #4
0
func SetWorkspace(wrk *workspace.Workspace, greedy bool) {
	mousebind.GrabPointer(X, Root.Id, Root.Id, 0)
	old := Workspace()
	wrk.Activate(greedy)
	if old != Workspace() {
		FYI("%s", wrk)
	}

	ewmhVisibleDesktops()
	ewmhCurrentDesktop()
	Heads.EwmhWorkarea()
	mousebind.UngrabPointer(X)
}
Пример #5
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)
	}
}
Пример #6
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) {
		return
	}

	// There's a bit of complexity in choosing where to move the clients to.
	// Namely, if we're removing a hidden workspace, it's a simple matter of
	// moving the clients. However, if we're removing a visible workspace,
	// we have to make sure to make another workspace that is hidden take
	// its place. (Such a workspace is guaranteed to exist because we have at
	// least one more workspace than there are active physical heads.)
	if !wk.IsVisible() {
		moveClientsTo := hds.workspaces.Wrks[len(hds.workspaces.Wrks)-1]
		if moveClientsTo == wk {
			moveClientsTo = hds.workspaces.Wrks[len(hds.workspaces.Wrks)-2]
		}
		wk.RemoveAllAndAdd(moveClientsTo)
	} else {
		// Find the last-most hidden workspace that is not itself.
		for i := len(hds.workspaces.Wrks) - 1; i >= 0; i-- {
			work := hds.workspaces.Wrks[i]
			if work != wk && !work.IsVisible() {
				hds.SwitchWorkspaces(wk, work)
				wk.RemoveAllAndAdd(work)
				break
			}
		}
	}
	hds.workspaces.Remove(wk)
}
Пример #7
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)
}
Пример #8
0
func (hds *Heads) SwitchWorkspaces(wk1, wk2 *workspace.Workspace) {
	v1, v2 := hds.visibleIndex(wk1), hds.visibleIndex(wk2)
	switch {
	case v1 > -1 && v2 > -1:
		hds.visibles[v1], hds.visibles[v2] = hds.visibles[v2], hds.visibles[v1]
		wk1.Place()
		wk2.Place()
	case v1 > -1 && v2 == -1:
		hds.visibles[v1] = wk2
		wk1.Hide()
		wk2.Show()
	case v1 == -1 && v2 > -1:
		hds.visibles[v2] = wk1
		wk2.Hide()
		wk1.Show()
	case v1 == -1 && v2 == -1:
		// Meaningless
	default:
		panic("unreachable")
	}
}