Skip to content

Commit bfcf382

Browse files
committed
feat: move active window to screen #67
1 parent 376e386 commit bfcf382

File tree

7 files changed

+163
-84
lines changed

7 files changed

+163
-84
lines changed

desktop/layout.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Layout interface {
1111
RemoveClient(c *store.Client)
1212
MakeMaster(c *store.Client)
1313
SwapClient(c1 *store.Client, c2 *store.Client)
14+
ActiveClient() *store.Client
1415
NextClient() *store.Client
1516
PreviousClient() *store.Client
1617
IncreaseMaster()

desktop/tracker.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ type Handlers struct {
3535
SwapScreen *Handler // Stores client for screen swap
3636
}
3737

38+
func (h *Handlers) Reset() {
39+
h.ResizeClient.Reset()
40+
h.MoveClient.Reset()
41+
h.SwapClient.Reset()
42+
h.SwapScreen.Reset()
43+
}
44+
3845
type Handler struct {
3946
Dragging bool // Indicates pointer dragging event
4047
Source interface{} // Stores moved/resized client
@@ -194,6 +201,17 @@ func (tr *Tracker) ClientAt(ws *Workspace, p common.Point) *store.Client {
194201
return nil
195202
}
196203

204+
func (tr *Tracker) ActiveClient() *store.Client {
205+
c, exists := tr.Clients[store.Windows.Active.Id]
206+
207+
// Validate client
208+
if !exists {
209+
return nil
210+
}
211+
212+
return c
213+
}
214+
197215
func (tr *Tracker) unlockClients() {
198216
ws := tr.ActiveWorkspace()
199217
mg := ws.ActiveLayout().GetManager()
@@ -486,18 +504,15 @@ func (tr *Tracker) onStateUpdate(state string, desktop uint, screen uint) {
486504
// Update sticky windows
487505
for _, c := range tr.Clients {
488506
if store.IsSticky(c.Latest) && c.Latest.Location.Desktop != store.Workplace.CurrentDesktop {
489-
c.MoveDesktop(^uint32(0))
507+
c.MoveToDesktop(^uint32(0))
490508
}
491509
}
492510
}
493511

494512
if viewportChanged || clientsChanged || focusChanged {
495513

496514
// Deactivate handlers
497-
tr.Handlers.ResizeClient.Reset()
498-
tr.Handlers.MoveClient.Reset()
499-
tr.Handlers.SwapClient.Reset()
500-
tr.Handlers.SwapScreen.Reset()
515+
tr.Handlers.Reset()
501516

502517
// Unlock clients
503518
tr.unlockClients()

input/action.go

+111-69
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func ExecuteAction(action string, tr *desktop.Tracker, ws *desktop.Workspace) bo
5050
success = ToggleDecoration(tr, ws)
5151
case "restore":
5252
success = Restore(tr, ws)
53+
case "reset":
54+
success = Reset(tr, ws)
5355
case "cycle_next":
5456
success = CycleNext(tr, ws)
5557
case "cycle_previous":
@@ -66,30 +68,32 @@ func ExecuteAction(action string, tr *desktop.Tracker, ws *desktop.Workspace) bo
6668
success = MaximizedLayout(tr, ws)
6769
case "layout_fullscreen":
6870
success = FullscreenLayout(tr, ws)
71+
case "slave_increase":
72+
success = IncreaseSlave(tr, ws)
73+
case "slave_decrease":
74+
success = DecreaseSlave(tr, ws)
75+
case "master_increase":
76+
success = IncreaseMaster(tr, ws)
77+
case "master_decrease":
78+
success = DecreaseMaster(tr, ws)
79+
case "window_next":
80+
success = NextWindow(tr, ws)
81+
case "window_previous":
82+
success = PreviousWindow(tr, ws)
83+
case "screen_next":
84+
success = NextScreen(tr, ws)
85+
case "screen_previous":
86+
success = PreviousScreen(tr, ws)
6987
case "master_make":
7088
success = MakeMaster(tr, ws)
7189
case "master_make_next":
7290
success = MakeMasterNext(tr, ws)
7391
case "master_make_previous":
7492
success = MakeMasterPrevious(tr, ws)
75-
case "master_increase":
76-
success = IncreaseMaster(tr, ws)
77-
case "master_decrease":
78-
success = DecreaseMaster(tr, ws)
79-
case "slave_increase":
80-
success = IncreaseSlave(tr, ws)
81-
case "slave_decrease":
82-
success = DecreaseSlave(tr, ws)
8393
case "proportion_increase":
8494
success = IncreaseProportion(tr, ws)
8595
case "proportion_decrease":
8696
success = DecreaseProportion(tr, ws)
87-
case "window_next":
88-
success = NextWindow(tr, ws)
89-
case "window_previous":
90-
success = PreviousWindow(tr, ws)
91-
case "reset":
92-
success = Reset(tr, ws)
9397
case "restart":
9498
success = Restart(tr)
9599
case "exit":
@@ -217,6 +221,19 @@ func Restore(tr *desktop.Tracker, ws *desktop.Workspace) bool {
217221
return true
218222
}
219223

224+
func Reset(tr *desktop.Tracker, ws *desktop.Workspace) bool {
225+
if ws.TilingDisabled() {
226+
return false
227+
}
228+
ws.ResetLayouts()
229+
tr.Tile(ws)
230+
231+
ui.ShowLayout(ws)
232+
ui.UpdateIcon(ws)
233+
234+
return true
235+
}
236+
220237
func CycleNext(tr *desktop.Tracker, ws *desktop.Workspace) bool {
221238
if ws.TilingDisabled() {
222239
return false
@@ -353,47 +370,30 @@ func FullscreenLayout(tr *desktop.Tracker, ws *desktop.Workspace) bool {
353370
return true
354371
}
355372

356-
func MakeMaster(tr *desktop.Tracker, ws *desktop.Workspace) bool {
357-
if ws.TilingDisabled() {
358-
return false
359-
}
360-
if c, ok := tr.Clients[store.Windows.Active.Id]; ok {
361-
ws.ActiveLayout().MakeMaster(c)
362-
tr.Tile(ws)
363-
return true
364-
}
365-
366-
return false
367-
}
368-
369-
func MakeMasterNext(tr *desktop.Tracker, ws *desktop.Workspace) bool {
373+
func IncreaseSlave(tr *desktop.Tracker, ws *desktop.Workspace) bool {
370374
if ws.TilingDisabled() {
371375
return false
372376
}
373-
c := ws.ActiveLayout().NextClient()
374-
if c == nil {
375-
return false
376-
}
377-
378-
ws.ActiveLayout().MakeMaster(c)
377+
ws.ActiveLayout().IncreaseSlave()
379378
tr.Tile(ws)
380379

381-
return NextWindow(tr, ws)
380+
ui.ShowLayout(ws)
381+
ui.UpdateIcon(ws)
382+
383+
return true
382384
}
383385

384-
func MakeMasterPrevious(tr *desktop.Tracker, ws *desktop.Workspace) bool {
386+
func DecreaseSlave(tr *desktop.Tracker, ws *desktop.Workspace) bool {
385387
if ws.TilingDisabled() {
386388
return false
387389
}
388-
c := ws.ActiveLayout().PreviousClient()
389-
if c == nil {
390-
return false
391-
}
392-
393-
ws.ActiveLayout().MakeMaster(c)
390+
ws.ActiveLayout().DecreaseSlave()
394391
tr.Tile(ws)
395392

396-
return PreviousWindow(tr, ws)
393+
ui.ShowLayout(ws)
394+
ui.UpdateIcon(ws)
395+
396+
return true
397397
}
398398

399399
func IncreaseMaster(tr *desktop.Tracker, ws *desktop.Workspace) bool {
@@ -422,53 +422,86 @@ func DecreaseMaster(tr *desktop.Tracker, ws *desktop.Workspace) bool {
422422
return true
423423
}
424424

425-
func IncreaseSlave(tr *desktop.Tracker, ws *desktop.Workspace) bool {
425+
func NextWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
426426
if ws.TilingDisabled() {
427427
return false
428428
}
429-
ws.ActiveLayout().IncreaseSlave()
430-
tr.Tile(ws)
429+
c := ws.ActiveLayout().NextClient()
430+
if c == nil {
431+
return false
432+
}
431433

432-
ui.ShowLayout(ws)
433-
ui.UpdateIcon(ws)
434+
store.ActiveWindowSet(store.X, c.Window)
434435

435436
return true
436437
}
437438

438-
func DecreaseSlave(tr *desktop.Tracker, ws *desktop.Workspace) bool {
439+
func PreviousWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
439440
if ws.TilingDisabled() {
440441
return false
441442
}
442-
ws.ActiveLayout().DecreaseSlave()
443-
tr.Tile(ws)
443+
c := ws.ActiveLayout().PreviousClient()
444+
if c == nil {
445+
return false
446+
}
444447

445-
ui.ShowLayout(ws)
446-
ui.UpdateIcon(ws)
448+
store.ActiveWindowSet(store.X, c.Window)
447449

448450
return true
449451
}
450452

451-
func IncreaseProportion(tr *desktop.Tracker, ws *desktop.Workspace) bool {
453+
func NextScreen(tr *desktop.Tracker, ws *desktop.Workspace) bool {
452454
if ws.TilingDisabled() {
453455
return false
454456
}
455-
ws.ActiveLayout().IncreaseProportion()
456-
tr.Tile(ws)
457+
c := tr.ActiveClient()
458+
if c == nil {
459+
return false
460+
}
457461

458-
return true
462+
screen := int(c.Latest.Location.Screen) + 1
463+
if screen > int(store.Workplace.ScreenCount)-1 {
464+
return false
465+
}
466+
tr.Handlers.Reset()
467+
468+
return c.MoveToScreen(uint32(screen))
459469
}
460470

461-
func DecreaseProportion(tr *desktop.Tracker, ws *desktop.Workspace) bool {
471+
func PreviousScreen(tr *desktop.Tracker, ws *desktop.Workspace) bool {
462472
if ws.TilingDisabled() {
463473
return false
464474
}
465-
ws.ActiveLayout().DecreaseProportion()
475+
c := tr.ActiveClient()
476+
if c == nil {
477+
return false
478+
}
479+
480+
screen := int(c.Latest.Location.Screen) - 1
481+
if screen < 0 {
482+
return false
483+
}
484+
tr.Handlers.Reset()
485+
486+
return c.MoveToScreen(uint32(screen))
487+
}
488+
489+
func MakeMaster(tr *desktop.Tracker, ws *desktop.Workspace) bool {
490+
if ws.TilingDisabled() {
491+
return false
492+
}
493+
c := ws.ActiveLayout().ActiveClient()
494+
if c == nil {
495+
return false
496+
}
497+
498+
ws.ActiveLayout().MakeMaster(c)
466499
tr.Tile(ws)
467500

468501
return true
469502
}
470503

471-
func NextWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
504+
func MakeMasterNext(tr *desktop.Tracker, ws *desktop.Workspace) bool {
472505
if ws.TilingDisabled() {
473506
return false
474507
}
@@ -477,12 +510,13 @@ func NextWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
477510
return false
478511
}
479512

480-
store.ActiveWindowSet(store.X, c.Window)
513+
ws.ActiveLayout().MakeMaster(c)
514+
tr.Tile(ws)
481515

482-
return true
516+
return NextWindow(tr, ws)
483517
}
484518

485-
func PreviousWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
519+
func MakeMasterPrevious(tr *desktop.Tracker, ws *desktop.Workspace) bool {
486520
if ws.TilingDisabled() {
487521
return false
488522
}
@@ -491,20 +525,28 @@ func PreviousWindow(tr *desktop.Tracker, ws *desktop.Workspace) bool {
491525
return false
492526
}
493527

494-
store.ActiveWindowSet(store.X, c.Window)
528+
ws.ActiveLayout().MakeMaster(c)
529+
tr.Tile(ws)
495530

496-
return true
531+
return PreviousWindow(tr, ws)
497532
}
498533

499-
func Reset(tr *desktop.Tracker, ws *desktop.Workspace) bool {
534+
func IncreaseProportion(tr *desktop.Tracker, ws *desktop.Workspace) bool {
500535
if ws.TilingDisabled() {
501536
return false
502537
}
503-
ws.ResetLayouts()
538+
ws.ActiveLayout().IncreaseProportion()
504539
tr.Tile(ws)
505540

506-
ui.ShowLayout(ws)
507-
ui.UpdateIcon(ws)
541+
return true
542+
}
543+
544+
func DecreaseProportion(tr *desktop.Tracker, ws *desktop.Workspace) bool {
545+
if ws.TilingDisabled() {
546+
return false
547+
}
548+
ws.ActiveLayout().DecreaseProportion()
549+
tr.Tile(ws)
508550

509551
return true
510552
}

input/dbusbinding.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ func (m Methods) WindowToDesktop(id int32, desktop int32) (string, *dbus.Error)
9292
// Move window to desktop
9393
valid := desktop >= 0 && uint(desktop) < store.Workplace.DesktopCount
9494
if c, ok := m.Tracker.Clients[xproto.Window(id)]; ok && valid {
95-
c.MoveDesktop(uint32(desktop))
96-
success = true
95+
success = c.MoveToDesktop(uint32(desktop))
9796
}
9897

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

117113
// Return result

input/traybinding.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ var (
2727
)
2828

2929
type Menu struct {
30-
Exit *systray.MenuItem // Exit application
3130
Toggle *systray.MenuItem // Toggle checkbox item
3231
Decoration *systray.MenuItem // Decoration checkbox item
3332
Actions []*systray.MenuItem // Actions for commands
@@ -189,9 +188,10 @@ func items(tr *desktop.Tracker) {
189188
case "decoration":
190189
item = systray.AddMenuItemCheckbox(text, text, common.Config.WindowDecoration)
191190
menu.Decoration = item
191+
case "restart":
192+
item = systray.AddMenuItem(text, text)
192193
case "exit":
193194
item = systray.AddMenuItem(text, text)
194-
menu.Exit = item
195195
default:
196196
item = systray.AddMenuItem(text, text)
197197
menu.Actions = append(menu.Actions, item)

0 commit comments

Comments
 (0)