MCPcopy Create free account
hub / github.com/BobdaProgrammer/doWM / fitToLayout

Method fitToLayout

wm/window_manager.go:1503–1567  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1501}
1502
1503func (wm *WindowManager) fitToLayout() {
1504 if !wm.currWorkspace.tiling {
1505 return
1506 }
1507 // if there are more than 4 windows then just don't do it
1508
1509 windowNum := len(wm.currWorkspace.windowList)
1510
1511 if _, ok := wm.config.Layouts[windowNum]; !ok {
1512 return
1513 }
1514
1515 if len(wm.config.Layouts[windowNum])-1 < wm.layoutIndex && len(wm.config.Layouts[windowNum]) > 0 {
1516 wm.currWorkspace.layoutIndex = 0
1517 wm.layoutIndex = 0
1518 }
1519
1520 if windowNum > len(wm.config.Layouts) || windowNum < 1 || windowNum > len(wm.config.Layouts[windowNum][wm.layoutIndex].Windows) {
1521 fmt.Println("too many or too few windows to fit to layout in workspace", wm.workspaceIndex+1)
1522 return
1523 }
1524 wm.createTilingSpace()
1525 layout := wm.config.Layouts[windowNum][wm.layoutIndex]
1526 if wm.currWorkspace.resized && len(wm.currWorkspace.resizedLayout.Windows)!=windowNum{
1527 wm.currWorkspace.resized = false
1528 wm.currWorkspace.resizedLayout = ResizeLayout{}
1529 }
1530 fmt.Println("fit to layout")
1531 fmt.Println(wm.currWorkspace.windowList)
1532 //fmt.Println(wm.currWorkspace.windows)
1533 //fmt.Println(len(wm.currWorkspace.windows))
1534 // for each window put it in its place and size specified by that layout
1535 fullscreen := []xproto.Window{}
1536 for i, WindowData := range wm.currWorkspace.windowList {
1537 fmt.Println(WindowData)
1538 if WindowData.Fullscreen {
1539 fullscreen = append(fullscreen, WindowData.id)
1540 continue
1541 }
1542 if wm.currWorkspace.resized{
1543 layoutWindow := wm.currWorkspace.resizedLayout.Windows[i]
1544 X := uint32(layoutWindow.X) + wm.config.Gap + uint32(wm.tilingspace.X)
1545 Y := uint32(layoutWindow.Y) + wm.config.Gap + uint32(wm.tilingspace.Y)
1546 Width := uint32(layoutWindow.Width) - (wm.config.Gap*2)
1547 Height := uint32(layoutWindow.Height) - (wm.config.Gap*2)
1548 fmt.Println("window:", WindowData.id, "X:", X, "rounded:", "Y:", Y, "Width:", Width, "Height:", Height)
1549 wm.configureWindow(WindowData.id, int(X), int(Y), int(Width), int(Height))
1550 }else{
1551 layoutWindow := layout.Windows[i]
1552 // because we use percentages we have to times the width and height of the tiling space to get the raw value, it is simple maths to do the gap, I shouldn't have to explain it (since I am 12 I would expect u to know XD)
1553 X := wm.tilingspace.X + int((float64(wm.tilingspace.Width) * layoutWindow.XPercentage)) + int(wm.config.Gap)
1554 Y := wm.tilingspace.Y + int((float64(wm.tilingspace.Height) * layoutWindow.YPercentage)) + int(wm.config.Gap)
1555 Width := (float64(wm.tilingspace.Width) * layoutWindow.WidthPercentage) - float64(wm.config.Gap*2)
1556 Height := (float64(wm.tilingspace.Height) * layoutWindow.HeightPercentage) - float64(wm.config.Gap*2)
1557 fmt.Println("window:", WindowData.id, "X:", X, "rounded:", int(math.Round(Width)), "Y:", Y, "Width:", Width, "Height:", Height)
1558 wm.configureWindow(WindowData.id, X, Y, int(math.Round(Width)), int(math.Round(Height)))
1559 }
1560 }

Callers 8

reloadMethod · 0.95
RunMethod · 0.95
resizeTiledXMethod · 0.95
resizeTiledYMethod · 0.95
enableTilingMethod · 0.95
disableFullscreenMethod · 0.95
OnUnmapNotifyMethod · 0.95
OnMapRequestMethod · 0.95

Calls 3

createTilingSpaceMethod · 0.95
configureWindowMethod · 0.95
fullscreenMethod · 0.95

Tested by

no test coverage detected