Skip to content

Commit

Permalink
feat: move active window to screen #67
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Aug 17, 2024
1 parent 376e386 commit bfcf382
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 84 deletions.
1 change: 1 addition & 0 deletions desktop/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Layout interface {
RemoveClient(c *store.Client)
MakeMaster(c *store.Client)
SwapClient(c1 *store.Client, c2 *store.Client)
ActiveClient() *store.Client
NextClient() *store.Client
PreviousClient() *store.Client
IncreaseMaster()
Expand Down
25 changes: 20 additions & 5 deletions desktop/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ type Handlers struct {
SwapScreen *Handler // Stores client for screen swap
}

func (h *Handlers) Reset() {
h.ResizeClient.Reset()
h.MoveClient.Reset()
h.SwapClient.Reset()
h.SwapScreen.Reset()
}

type Handler struct {
Dragging bool // Indicates pointer dragging event
Source interface{} // Stores moved/resized client
Expand Down Expand Up @@ -194,6 +201,17 @@ func (tr *Tracker) ClientAt(ws *Workspace, p common.Point) *store.Client {
return nil
}

func (tr *Tracker) ActiveClient() *store.Client {
c, exists := tr.Clients[store.Windows.Active.Id]

// Validate client
if !exists {
return nil
}

return c
}

func (tr *Tracker) unlockClients() {
ws := tr.ActiveWorkspace()
mg := ws.ActiveLayout().GetManager()
Expand Down Expand Up @@ -486,18 +504,15 @@ func (tr *Tracker) onStateUpdate(state string, desktop uint, screen uint) {
// Update sticky windows
for _, c := range tr.Clients {
if store.IsSticky(c.Latest) && c.Latest.Location.Desktop != store.Workplace.CurrentDesktop {
c.MoveDesktop(^uint32(0))
c.MoveToDesktop(^uint32(0))
}
}
}

if viewportChanged || clientsChanged || focusChanged {

// Deactivate handlers
tr.Handlers.ResizeClient.Reset()
tr.Handlers.MoveClient.Reset()
tr.Handlers.SwapClient.Reset()
tr.Handlers.SwapScreen.Reset()
tr.Handlers.Reset()

// Unlock clients
tr.unlockClients()
Expand Down
180 changes: 111 additions & 69 deletions input/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func ExecuteAction(action string, tr *desktop.Tracker, ws *desktop.Workspace) bo
success = ToggleDecoration(tr, ws)
case "restore":
success = Restore(tr, ws)
case "reset":
success = Reset(tr, ws)
case "cycle_next":
success = CycleNext(tr, ws)
case "cycle_previous":
Expand All @@ -66,30 +68,32 @@ func ExecuteAction(action string, tr *desktop.Tracker, ws *desktop.Workspace) bo
success = MaximizedLayout(tr, ws)
case "layout_fullscreen":
success = FullscreenLayout(tr, ws)
case "slave_increase":
success = IncreaseSlave(tr, ws)
case "slave_decrease":
success = DecreaseSlave(tr, ws)
case "master_increase":
success = IncreaseMaster(tr, ws)
case "master_decrease":
success = DecreaseMaster(tr, ws)
case "window_next":
success = NextWindow(tr, ws)
case "window_previous":
success = PreviousWindow(tr, ws)
case "screen_next":
success = NextScreen(tr, ws)
case "screen_previous":
success = PreviousScreen(tr, ws)
case "master_make":
success = MakeMaster(tr, ws)
case "master_make_next":
success = MakeMasterNext(tr, ws)
case "master_make_previous":
success = MakeMasterPrevious(tr, ws)
case "master_increase":
success = IncreaseMaster(tr, ws)
case "master_decrease":
success = DecreaseMaster(tr, ws)
case "slave_increase":
success = IncreaseSlave(tr, ws)
case "slave_decrease":
success = DecreaseSlave(tr, ws)
case "proportion_increase":
success = IncreaseProportion(tr, ws)
case "proportion_decrease":
success = DecreaseProportion(tr, ws)
case "window_next":
success = NextWindow(tr, ws)
case "window_previous":
success = PreviousWindow(tr, ws)
case "reset":
success = Reset(tr, ws)
case "restart":
success = Restart(tr)
case "exit":
Expand Down Expand Up @@ -217,6 +221,19 @@ func Restore(tr *desktop.Tracker, ws *desktop.Workspace) bool {
return true
}

func Reset(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
ws.ResetLayouts()
tr.Tile(ws)

ui.ShowLayout(ws)
ui.UpdateIcon(ws)

return true
}

func CycleNext(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
Expand Down Expand Up @@ -353,47 +370,30 @@ func FullscreenLayout(tr *desktop.Tracker, ws *desktop.Workspace) bool {
return true
}

func MakeMaster(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
if c, ok := tr.Clients[store.Windows.Active.Id]; ok {
ws.ActiveLayout().MakeMaster(c)
tr.Tile(ws)
return true
}

return false
}

func MakeMasterNext(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func IncreaseSlave(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
c := ws.ActiveLayout().NextClient()
if c == nil {
return false
}

ws.ActiveLayout().MakeMaster(c)
ws.ActiveLayout().IncreaseSlave()
tr.Tile(ws)

return NextWindow(tr, ws)
ui.ShowLayout(ws)
ui.UpdateIcon(ws)

return true
}

func MakeMasterPrevious(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func DecreaseSlave(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
c := ws.ActiveLayout().PreviousClient()
if c == nil {
return false
}

ws.ActiveLayout().MakeMaster(c)
ws.ActiveLayout().DecreaseSlave()
tr.Tile(ws)

return PreviousWindow(tr, ws)
ui.ShowLayout(ws)
ui.UpdateIcon(ws)

return true
}

func IncreaseMaster(tr *desktop.Tracker, ws *desktop.Workspace) bool {
Expand Down Expand Up @@ -422,53 +422,86 @@ func DecreaseMaster(tr *desktop.Tracker, ws *desktop.Workspace) bool {
return true
}

func IncreaseSlave(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func NextWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
ws.ActiveLayout().IncreaseSlave()
tr.Tile(ws)
c := ws.ActiveLayout().NextClient()
if c == nil {
return false
}

ui.ShowLayout(ws)
ui.UpdateIcon(ws)
store.ActiveWindowSet(store.X, c.Window)

return true
}

func DecreaseSlave(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func PreviousWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
ws.ActiveLayout().DecreaseSlave()
tr.Tile(ws)
c := ws.ActiveLayout().PreviousClient()
if c == nil {
return false
}

ui.ShowLayout(ws)
ui.UpdateIcon(ws)
store.ActiveWindowSet(store.X, c.Window)

return true
}

func IncreaseProportion(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func NextScreen(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
ws.ActiveLayout().IncreaseProportion()
tr.Tile(ws)
c := tr.ActiveClient()
if c == nil {
return false
}

return true
screen := int(c.Latest.Location.Screen) + 1
if screen > int(store.Workplace.ScreenCount)-1 {
return false
}
tr.Handlers.Reset()

return c.MoveToScreen(uint32(screen))
}

func DecreaseProportion(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func PreviousScreen(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
ws.ActiveLayout().DecreaseProportion()
c := tr.ActiveClient()
if c == nil {
return false
}

screen := int(c.Latest.Location.Screen) - 1
if screen < 0 {
return false
}
tr.Handlers.Reset()

return c.MoveToScreen(uint32(screen))
}

func MakeMaster(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
c := ws.ActiveLayout().ActiveClient()
if c == nil {
return false
}

ws.ActiveLayout().MakeMaster(c)
tr.Tile(ws)

return true
}

func NextWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func MakeMasterNext(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
Expand All @@ -477,12 +510,13 @@ func NextWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
return false
}

store.ActiveWindowSet(store.X, c.Window)
ws.ActiveLayout().MakeMaster(c)
tr.Tile(ws)

return true
return NextWindow(tr, ws)
}

func PreviousWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func MakeMasterPrevious(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
Expand All @@ -491,20 +525,28 @@ func PreviousWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
return false
}

store.ActiveWindowSet(store.X, c.Window)
ws.ActiveLayout().MakeMaster(c)
tr.Tile(ws)

return true
return PreviousWindow(tr, ws)
}

func Reset(tr *desktop.Tracker, ws *desktop.Workspace) bool {
func IncreaseProportion(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
ws.ResetLayouts()
ws.ActiveLayout().IncreaseProportion()
tr.Tile(ws)

ui.ShowLayout(ws)
ui.UpdateIcon(ws)
return true
}

func DecreaseProportion(tr *desktop.Tracker, ws *desktop.Workspace) bool {
if ws.TilingDisabled() {
return false
}
ws.ActiveLayout().DecreaseProportion()
tr.Tile(ws)

return true
}
Expand Down
8 changes: 2 additions & 6 deletions input/dbusbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ func (m Methods) WindowToDesktop(id int32, desktop int32) (string, *dbus.Error)
// Move window to desktop
valid := desktop >= 0 && uint(desktop) < store.Workplace.DesktopCount
if c, ok := m.Tracker.Clients[xproto.Window(id)]; ok && valid {
c.MoveDesktop(uint32(desktop))
success = true
success = c.MoveToDesktop(uint32(desktop))
}

// Return result
Expand All @@ -108,10 +107,7 @@ func (m Methods) WindowToScreen(id int32, screen int32) (string, *dbus.Error) {
// Move window to screen
valid := screen >= 0 && uint(screen) < store.Workplace.ScreenCount
if c, ok := m.Tracker.Clients[xproto.Window(id)]; ok && valid {
p := store.Workplace.Displays.Screens[screen].Geometry.Center()
ewmh.MoveWindow(store.X, c.Window.Id, int(p.X), int(p.Y))
store.Pointer.Press()
success = true
success = c.MoveToScreen(uint32(screen))
}

// Return result
Expand Down
4 changes: 2 additions & 2 deletions input/traybinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var (
)

type Menu struct {
Exit *systray.MenuItem // Exit application
Toggle *systray.MenuItem // Toggle checkbox item
Decoration *systray.MenuItem // Decoration checkbox item
Actions []*systray.MenuItem // Actions for commands
Expand Down Expand Up @@ -189,9 +188,10 @@ func items(tr *desktop.Tracker) {
case "decoration":
item = systray.AddMenuItemCheckbox(text, text, common.Config.WindowDecoration)
menu.Decoration = item
case "restart":
item = systray.AddMenuItem(text, text)
case "exit":
item = systray.AddMenuItem(text, text)
menu.Exit = item
default:
item = systray.AddMenuItem(text, text)
menu.Actions = append(menu.Actions, item)
Expand Down
Loading

0 comments on commit bfcf382

Please sign in to comment.