Skip to content

Commit

Permalink
Merge pull request #12 from marad/windowplacement
Browse files Browse the repository at this point in the history
Windowplacement
  • Loading branch information
marad authored Aug 22, 2023
2 parents c938e2b + 4232102 commit 751ae71
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import gh.marad.tiler.common.filteringrules.FilteringRules
import gh.marad.tiler.common.filteringrules.Rule
import gh.marad.tiler.common.layout.GapLayoutDecorator
import gh.marad.tiler.common.layout.Layout
import gh.marad.tiler.common.layout.MinWindowSizeLayoutDecorator
import gh.marad.tiler.common.layout.TwoColumnLayout
import gh.marad.tiler.config.ConfigFacade
import gh.marad.tiler.config.Hotkey
Expand Down Expand Up @@ -36,7 +35,7 @@ class SimpleConfig : ConfigFacade {
override fun reload() { }

override fun createLayout(): Layout {
var layout = TwoColumnLayout(0.55f)
val layout = TwoColumnLayout(0.55f)
// layout = MinWindowSizeLayoutDecorator(1500, 800, twoColumnLayout)
return GapLayoutDecorator(20, layout)
}
Expand Down Expand Up @@ -65,8 +64,8 @@ class SimpleConfig : ConfigFacade {
Hotkey("S-A-C-K", MoveWindowUp),

// Layout
Hotkey("S-A-L", LayoutIncrease(0.03f)),
Hotkey("S-A-H", LayoutDecrease(0.03f))
Hotkey("S-A-L", LayoutIncrease(0.05f)),
Hotkey("S-A-H", LayoutDecrease(0.05f))
)
}

Expand Down
43 changes: 26 additions & 17 deletions src/main/kotlin/gh/marad/tiler/os/internal/WindowsOs.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gh.marad.tiler.os.internal

import com.sun.jna.Native
import com.sun.jna.platform.win32.User32
import com.sun.jna.platform.win32.WinDef
import com.sun.jna.win32.W32APIOptions
import com.sun.jna.platform.win32.WinDef.RECT
import com.sun.jna.platform.win32.WinUser.WINDOWPLACEMENT
import gh.marad.tiler.common.*
import gh.marad.tiler.common.Window
import gh.marad.tiler.os.OsFacade
Expand All @@ -13,7 +13,7 @@ import gh.marad.tiler.os.internal.winapi.Window as OsWindow

class WindowsOs : OsFacade {
private val hotkeys = Hotkeys()
private val myU32 = Native.load("user32", MyUser32::class.java, W32APIOptions.DEFAULT_OPTIONS)
// private val myU32 = Native.load("user32", MyUser32::class.java, W32APIOptions.DEFAULT_OPTIONS)

override fun getDesktopState(): DesktopState {
val monitors = Monitors.list().map { Monitor(it.workArea.toLayoutSpace(), it.isPrimary) }
Expand Down Expand Up @@ -53,9 +53,17 @@ class WindowsOs : OsFacade {
// correct the window size to account for the invisible
// border of the window
val pos = command.position.addInvisibleBorders(windowBorders(hwnd))
User32.INSTANCE.SetWindowPos(hwnd, null,
pos.x, pos.y, pos.width, pos.height,
User32.SWP_ASYNCWINDOWPOS and User32.SWP_NOACTIVATE and User32.SWP_NOZORDER and User32.SWP_SHOWWINDOW)
val placement = WINDOWPLACEMENT()
placement.length = placement.size()
placement.flags = WINDOWPLACEMENT.WPF_ASYNCWINDOWPLACEMENT
placement.showCmd = User32.SW_SHOWNOACTIVATE and User32.SWP_NOZORDER
val r = RECT()
r.left = pos.x
r.top = pos.y
r.right = pos.x + pos.width
r.bottom = pos.y + pos.height
placement.rcNormalPosition = r
User32.INSTANCE.SetWindowPlacement(hwnd, placement)
}

is MinimizeWindow -> {
Expand All @@ -80,20 +88,21 @@ class WindowsOs : OsFacade {
}

override fun execute(commands: List<TilerCommand>) {
var deferStruct = myU32.BeginDeferWindowPos(commands.count { it is SetWindowPosition })
// var deferStruct = myU32.BeginDeferWindowPos(commands.count { it is SetWindowPosition })
commands.forEach {
if (it is SetWindowPosition) {
val hwnd = (it.windowId as WID).handle
val pos = it.position.addInvisibleBorders(windowBorders(hwnd))
deferStruct = myU32.DeferWindowPos(deferStruct, hwnd, null,
pos.x, pos.y, pos.width, pos.height,
User32.SWP_ASYNCWINDOWPOS and User32.SWP_NOACTIVATE and User32.SWP_NOZORDER and User32.SWP_SHOWWINDOW)
} else {
// if (it is SetWindowPosition) {
// val hwnd = (it.windowId as WID).handle
// val pos = it.position.addInvisibleBorders(windowBorders(hwnd))
// deferStruct = myU32.DeferWindowPos(deferStruct, hwnd, null,
// pos.x, pos.y, pos.width, pos.height,
// User32.SWP_ASYNCWINDOWPOS and User32.SWP_NOACTIVATE and User32.SWP_NOZORDER and User32.SWP_SHOWWINDOW
// )
// } else {
execute(it)
}
// }
}
Thread.sleep(50)
myU32.EndDeferWindowPos(deferStruct)
// Thread.sleep(50)
// myU32.EndDeferWindowPos(deferStruct)
}

override fun startEventHandling(handler: WindowEventHandler) {
Expand Down

0 comments on commit 751ae71

Please sign in to comment.