diff --git a/src/nimdowpkg/layouts/layout.nim b/src/nimdowpkg/layouts/layout.nim index d6aad0c..26ca3dd 100644 --- a/src/nimdowpkg/layouts/layout.nim +++ b/src/nimdowpkg/layouts/layout.nim @@ -25,5 +25,5 @@ method updateSettings*( method arrange*(this: Layout, display: PDisplay, clients: seq[Client], offset: LayoutOffset) {.base.} = echo "arrange not implemented for base class" -method availableCommands*(this: LayoutSettings): seq[tuple[command: string, action: proc(layout: Layout, display: PDisplay, taggedClients: TaggedClients) {.nimcall.}]] {.base.} = +method availableCommands*(this: LayoutSettings): seq[tuple[command: string, action: proc(layout: Layout, taggedClients: TaggedClients) {.nimcall.}]] {.base.} = echo "availableCommands not implemented for base class" diff --git a/src/nimdowpkg/layouts/masterstacklayout.nim b/src/nimdowpkg/layouts/masterstacklayout.nim index 4e087ab..daa4f21 100644 --- a/src/nimdowpkg/layouts/masterstacklayout.nim +++ b/src/nimdowpkg/layouts/masterstacklayout.nim @@ -120,10 +120,10 @@ method populateLayoutSettings*(this: var MasterStackLayoutSettings, settingsTabl else: raise newException(Exception, "invalid defaultMasterWidthPercentage for tag") -proc increaseMasterCount(layout: Layout, _: PDisplay, _: TaggedClients) = +proc increaseMasterCount(layout: Layout, _: TaggedClients) = MasterStackLayout(layout).masterSlots.inc -proc decreaseMasterCount(layout: Layout, _: PDisplay, _: TaggedClients) = +proc decreaseMasterCount(layout: Layout, _: TaggedClients) = var masterStackLayout = MasterStackLayout(layout) if masterStackLayout.masterSlots.int > 0: masterStackLayout.masterSlots.dec @@ -138,13 +138,13 @@ template modWidthDiff(layout: Layout, diff: int) = diff).int > 0: masterStackLayout.widthDiff += diff -proc increaseMasterWidth(layout: Layout, _: PDisplay, _: TaggedClients) = +proc increaseMasterWidth(layout: Layout, _: TaggedClients) = layout.modWidthDiff(layout.MasterStackLayout.resizeStep.int) -proc decreaseMasterWidth(layout: Layout, _: PDisplay, _: TaggedClients) = +proc decreaseMasterWidth(layout: Layout, _: TaggedClients) = layout.modWidthDiff(-layout.MasterStackLayout.resizeStep.int) -method availableCommands*(this: MasterStackLayoutSettings): seq[tuple[command: string, action: proc(layout: Layout, display: PDisplay, taggedClients: TaggedClients) {.nimcall.}]] = +method availableCommands*(this: MasterStackLayoutSettings): seq[tuple[command: string, action: proc(layout: Layout, taggedClients: TaggedClients) {.nimcall.}]] = result = @[ ($mscIncreaseMasterWidth, increaseMasterWidth), ($mscDecreaseMasterWidth, decreaseMasterWidth), diff --git a/src/nimdowpkg/layouts/pimo.nim b/src/nimdowpkg/layouts/pimo.nim index 4095997..a8d46db 100644 --- a/src/nimdowpkg/layouts/pimo.nim +++ b/src/nimdowpkg/layouts/pimo.nim @@ -3,7 +3,6 @@ import parsetoml, strutils, sequtils, - math, layout, ../client, ../area, @@ -281,10 +280,8 @@ proc iterGrow(this: PimoLayout, dir: Direction) = sortedEdge = if towardsStart: this.trackedClients.sortedByIt(it.client.area.startEdge) else: this.trackedClients.sortedByIt((if dir == Right: usableWidth else: usableHeight).int - it.client.area.endEdge) - # TODO; Scale down previously expanded windows as well for square in this.trackedClients: if (horizontal and square.expandX) or (vertical and square.expandY): - #stdout.writeLine "Resizing ", square, " from ", square.size square.resize(min(0, square.pureRequestedSize.int - square.client.area.size.int)) var resized = true while resized: @@ -341,22 +338,6 @@ proc iterDistr(this: PimoLayout, dir: Direction) = changed = true inc i -proc distribLeft(this: PimoLayout) = - this.iterGrow(Left) - this.iterDistr(Left) - -proc distribUp(this: PimoLayout) = - this.iterGrow(Up) - this.iterDistr(Up) - -proc distribRight(this: PimoLayout) = - this.iterGrow(Right) - this.iterDistr(Right) - -proc distribDown(this: PimoLayout) = - this.iterGrow(Down) - this.iterDistr(Down) - proc collapse(this: PimoLayout, dir: Direction) = generalizeForDirection(dir) for square in this.trackedClients: @@ -591,122 +572,101 @@ method arrange*(this: PimoLayout, display: PDisplay, clients: seq[Client], offse client.client.area.height -= client.client.borderWidth * 2'u + this.settings.gapSize client.client.adjustToState(display) -template expand(layout: Layout, display: PDisplay, dir: untyped): untyped = - var - window: Window - reverse: cint - discard display.XGetInputFocus(window.addr, reverse.addr) - for client in layout.trackedClients: - if client.client.window == window: - client.client.isFloating = false - client.`expand dir` = not client.`expand dir` - break - -proc expandX(layout: Layout, display: PDisplay, _: TaggedClients) = - var layout = cast[PimoLayout](layout) - expand(layout, display, X) +template expand(layout: Layout, tc: TaggedClients, dir: untyped): untyped = + tc.withSomeCurrClient(client): + for trackedClient in layout.trackedClients: + if trackedClient.client.window == client.window: + trackedClient.client.isFloating = false + trackedClient.`expand dir` = not trackedClient.`expand dir` + break -proc expandY(layout: Layout, display: PDisplay, _: TaggedClients) = +proc expandX(layout: Layout, tc: TaggedClients) = var layout = cast[PimoLayout](layout) - expand(layout, display, Y) + expand(layout, tc, X) -template grow(layout: Layout, display: PDisplay, dir, dim: untyped): untyped = - var - window: Window - reverse: cint - discard display.XGetInputFocus(window.addr, reverse.addr) - for client in layout.trackedClients: - if client.client.window == window: - client.requested.dim = max(client.client.area.dim, client.requested.dim) - client.requested.dim += layout.settings.resizeStep - break - layout.shuffle(Left) - layout.distribRight() - # TODO: If size hasn't changed, shrink all "seen" windows in the given dimension? - -proc growX(layout: Layout, display: PDisplay, _: TaggedClients) = +proc expandY(layout: Layout, tc: TaggedClients) = var layout = cast[PimoLayout](layout) - grow(layout, display, x, width) - -proc growY(layout: Layout, display: PDisplay, _: TaggedClients) = + expand(layout, tc, Y) + +template grow(layout: Layout, tc: TaggedClients, dir, dim: untyped): untyped = + tc.withSomeCurrClient(client): + for trackedClient in layout.trackedClients: + if trackedClient.client.window == client.window: + trackedClient.requested.dim = max(trackedClient.client.area.dim, trackedClient.requested.dim) + trackedClient.requested.dim += layout.settings.resizeStep + break + # TODO: If size hasn't changed, shrink all "seen" windows in the given dimension? + # Problem is that requested size would have to change by doing it this way.. + +proc growX(layout: Layout, tc: TaggedClients) = var layout = cast[PimoLayout](layout) - grow(layout, display, y, height) + grow(layout, tc, x, width) -template shrink(layout: Layout, display: PDisplay, dir, dim: untyped): untyped = - var - window: Window - reverse: cint - discard display.XGetInputFocus(window.addr, reverse.addr) - for client in layout.trackedClients: - if client.client.window == window: - if client.`expand dir`: - client.`expand dir` = false - client.requested.dim = client.client.area.dim - client.requested.dim = max(client.requested.dim - layout.settings.resizeStep, 100) - break - layout.shuffle(Left) - layout.distribRight() - -proc shrinkX(layout: Layout, display: PDisplay, _: TaggedClients) = +proc growY(layout: Layout, tc: TaggedClients) = var layout = cast[PimoLayout](layout) - shrink(layout, display, x, width) - -proc shrinkY(layout: Layout, display: PDisplay, _: TaggedClients) = + grow(layout, tc, y, height) + +template shrink(layout: Layout, tc: TaggedClients, dir, dim: untyped): untyped = + tc.withSomeCurrClient(client): + for taggedClient in layout.trackedClients: + if taggedClient.client.window == client.window: + if taggedClient.`expand dir`: + taggedClient.`expand dir` = false + taggedClient.requested.dim = taggedClient.client.area.dim + taggedClient.requested.dim = max(taggedClient.requested.dim - layout.settings.resizeStep, 100) + break + +proc shrinkX(layout: Layout, tc: TaggedClients) = var layout = cast[PimoLayout](layout) - shrink(layout, display, y, height) + shrink(layout, tc, x, width) -proc move(layout: Layout, display: PDisplay, dir: Direction) = - var - window: Window - reverse: cint - discard display.XGetInputFocus(window.addr, reverse.addr) +proc shrinkY(layout: Layout, tc: TaggedClients) = var layout = cast[PimoLayout](layout) - for client in layout.trackedClients: - if client.client.window == window: - client.client.isFloating = false - layout.move(client, dir) - break + shrink(layout, tc, y, height) -proc moveRight(layout: Layout, display: PDisplay, _: TaggedClients) = - layout.move(display, Right) +proc move(layout: Layout, tc: TaggedClients, dir: Direction) = + tc.withSomeCurrClient(client): + var layout = cast[PimoLayout](layout) + for taggedClient in layout.trackedClients: + if taggedClient.client.window == client.window: + taggedClient.client.isFloating = false + layout.move(taggedClient, dir) + break -proc moveLeft(layout: Layout, display: PDisplay, _: TaggedClients) = - layout.move(display, Left) +proc moveRight(layout: Layout, tc: TaggedClients) = + layout.move(tc, Right) -proc moveUp(layout: Layout, display: PDisplay, _: TaggedClients) = - layout.move(display, Up) +proc moveLeft(layout: Layout, tc: TaggedClients) = + layout.move(tc, Left) -proc moveDown(layout: Layout, display: PDisplay, _: TaggedClients) = - layout.move(display, Down) +proc moveUp(layout: Layout, tc: TaggedClients) = + layout.move(tc, Up) -proc focus(layout: PimoLayout, dir: Direction, display: PDisplay, taggedClients: TaggedClients) = - var - window: Window - reverse: cint - discard display.XGetInputFocus(window.addr, reverse.addr) - for client in layout.trackedClients: - if client.client.window == window: - let sees = layout.see(client, dir) - if sees.len > 0: - #echo "Changing focus from ", client.client.window, " to ", sees[0].client.window - taggedClients.selectClient(sees[0].client.window) - #echo XSetInputFocus(display, sees[0].client.window, RevertToPointerRoot, CurrentTime) - #echo XFlush(display) - break - -proc focusLeft(layout: Layout, display: PDisplay, taggedClients: TaggedClients) = - cast[PimoLayout](layout).focus(Left, display, taggedClients) - -proc focusRight(layout: Layout, display: PDisplay, taggedClients: TaggedClients) = - cast[PimoLayout](layout).focus(Right, display, taggedClients) - -proc focusUp(layout: Layout, display: PDisplay, taggedClients: TaggedClients) = - cast[PimoLayout](layout).focus(Up, display, taggedClients) - -proc focusDown(layout: Layout, display: PDisplay, taggedClients: TaggedClients) = - cast[PimoLayout](layout).focus(Down, display, taggedClients) - -method availableCommands*(this: PimoLayoutSettings): seq[tuple[command: string, action: proc(layout: Layout, display: PDisplay, taggedClients: TaggedClients) {.nimcall.}]] = +proc moveDown(layout: Layout, tc: TaggedClients) = + layout.move(tc, Down) + +proc focus(layout: PimoLayout, dir: Direction, tc: TaggedClients) = + tc.withSomeCurrClient(client): + for taggedClient in layout.trackedClients: + if taggedClient.client.window == client.window: + let sees = layout.see(taggedClient, dir) + if sees.len > 0: + tc.selectClient(sees[0].client.window) + break + +proc focusLeft(layout: Layout, taggedClients: TaggedClients) = + cast[PimoLayout](layout).focus(Left, taggedClients) + +proc focusRight(layout: Layout, taggedClients: TaggedClients) = + cast[PimoLayout](layout).focus(Right, taggedClients) + +proc focusUp(layout: Layout, taggedClients: TaggedClients) = + cast[PimoLayout](layout).focus(Up, taggedClients) + +proc focusDown(layout: Layout, taggedClients: TaggedClients) = + cast[PimoLayout](layout).focus(Down, taggedClients) + +method availableCommands*(this: PimoLayoutSettings): seq[tuple[command: string, action: proc(layout: Layout, taggedClients: TaggedClients) {.nimcall.}]] = result = @[ ($pFocusLeft, focusLeft), ($pFocusRight, focusRight), diff --git a/src/nimdowpkg/windowmanager.nim b/src/nimdowpkg/windowmanager.nim index 119226e..31cc397 100644 --- a/src/nimdowpkg/windowmanager.nim +++ b/src/nimdowpkg/windowmanager.nim @@ -727,7 +727,7 @@ proc mapConfigActions*(this: WindowManager) = layout = firstSelectedTag.layout window: Window reverse: cint - action(layout, this.display, this.selectedMonitor.taggedClients) + action(layout, this.selectedMonitor.taggedClients) this.selectedMonitor.doLayout() proc focus*(this: WindowManager, client: Client, warpToClient: bool) =