Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window navigation by direction #89

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,19 @@ func MinInt(a int, b int) int {
func MaxInt(a int, b int) int {
return int(math.Max(float64(a), float64(b)))
}

type Direction int

const (
Up Direction = iota
Down
Left
Right
)

func AbsInt(n int) int {
if n < 0 {
return -n
}
return n
}
2 changes: 2 additions & 0 deletions desktop/layout.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package desktop

import (
"github.com/leukipp/cortile/v2/common"
"github.com/leukipp/cortile/v2/store"
)

Expand All @@ -14,6 +15,7 @@ type Layout interface {
ActiveClient() *store.Client
NextClient() *store.Client
PreviousClient() *store.Client
DirectionClient(d common.Direction) *store.Client
IncreaseMaster()
DecreaseMaster()
IncreaseSlave()
Expand Down
23 changes: 23 additions & 0 deletions input/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func ExecuteAction(action string, tr *desktop.Tracker, ws *desktop.Workspace) bo
success = NextWindow(tr, ws)
case "window_previous":
success = PreviousWindow(tr, ws)
case "window_up":
success = DirectionWindow(ws, common.Up)
case "window_down":
success = DirectionWindow(ws, common.Down)
case "window_left":
success = DirectionWindow(ws, common.Left)
case "window_right":
success = DirectionWindow(ws, common.Right)
case "position_next":
success = NextPosition(tr, ws)
case "position_previous":
Expand Down Expand Up @@ -449,6 +457,21 @@ func PreviousWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
return true
}

func DirectionWindow(ws *desktop.Workspace, d common.Direction) bool {
if ws.TilingDisabled() {
return false
}

c := ws.ActiveLayout().DirectionClient(d)
if c == nil {
return false
}

store.ActiveWindowSet(store.X, c.Window)

return true
}

func NextPosition(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
Expand Down
50 changes: 50 additions & 0 deletions store/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,56 @@ func (mg *Manager) PreviousClient() *Client {
return clients[prev]
}

func (mg *Manager) DirectionClient(direction common.Direction) *Client {
var targetClient *Client
var targetDelta int
// Update the target client that we will move to
updateTarget := func(c *Client, delta int) {
newDelta := common.AbsInt(delta)
if targetClient == nil {
targetClient = c
targetDelta = newDelta
} else {
if newDelta < targetDelta {
targetClient = c
targetDelta = newDelta
}
}
}

activeClientX := mg.ActiveClient().Latest.Dimensions.Geometry.X
activeClientY := mg.ActiveClient().Latest.Dimensions.Geometry.Y
clients := mg.Clients(Stacked)
// Find the client in the proper screen segment and closest to the active origin
for _, c := range clients {
if c.Window.Id != Windows.Active.Id {
cX := c.Latest.Dimensions.Geometry.X
cY := c.Latest.Dimensions.Geometry.Y
switch {
case direction == common.Up && cY < activeClientY:
updateTarget(c, activeClientX-cX)
break
case direction == common.Down && cY > activeClientY:
updateTarget(c, activeClientX-cX)
break
case direction == common.Left && cX < activeClientX:
updateTarget(c, activeClientY-cY)
break
case direction == common.Right && cX > activeClientX:
updateTarget(c, activeClientY-cY)
break
}
}
}

if targetClient != nil {
log.Info("Selected [", targetClient.Latest.Class, "]")
return targetClient
}

return nil
}

func (mg *Manager) IncreaseMaster() {

// Increase master area
Expand Down