Improved window positioning - still not great

This commit is contained in:
dlannan 2025-10-15 17:57:27 +10:30
parent 9745112ccd
commit 1f0030383a
3 changed files with 75 additions and 26 deletions

View File

@ -25,6 +25,15 @@ ffi.cdef[[
uint64_t lparam[1]; uint64_t lparam[1];
const char * title; const char * title;
} enumData; } enumData;
typedef struct { long left; long top; long right; long bottom; } RECT;
int GetSystemMetrics(int nIndex);
int AdjustWindowRect(RECT* lpRect, unsigned long dwStyle, int bMenu);
long GetWindowLongA(unsigned int hWnd, int nIndex);
int SystemParametersInfoW(unsigned int uiAction, unsigned int uiParam, RECT* pvParam, unsigned int fWinIni);
int SetWindowPos(unsigned int hWnd, void* hWndInsertAfter, int X, int Y, int cx, int cy, unsigned int uFlags);
]] ]]
require("ffi.windows") require("ffi.windows")
@ -262,10 +271,22 @@ end
local pid = user32.GetWindowThreadProcessId( wvhwnd or 0, nil ) local pid = user32.GetWindowThreadProcessId( wvhwnd or 0, nil )
local hhookSysMsg = user32.SetWindowsHookExA( user32.WH_CALLWNDPROC, MsgFilter, 0, pid) local hhookSysMsg = user32.SetWindowsHookExA( user32.WH_CALLWNDPROC, MsgFilter, 0, pid)
local SWP_NOZORDER = 0x0004
local SWP_NOACTIVATE = 0x0010
local SWP_ASYNCWINDOWPOS = 0x4000
local SWP_SHOWWINDOW = 0x0040
local function SetWindowPos( hwnd, x, y, width, height )
user32.SetWindowPos(hwnd, nil, x, y, width, height, bit.bor(SWP_NOZORDER, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE))
end
------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------
return { return {
CreateWindow = CreateWindow, CreateWindow = CreateWindow,
SetWindowPos = SetWindowPos,
SetTransparentBlend = SetTransparentBlend, SetTransparentBlend = SetTransparentBlend,
GetHwndFromProcess = GetHwndFromProcess, GetHwndFromProcess = GetHwndFromProcess,
RemoveWindowBorders = RemoveWindowBorders, RemoveWindowBorders = RemoveWindowBorders,

View File

@ -39,30 +39,42 @@ print("BROWSER SETUP")
local browser, bsize = winu.getDefaultBrowser() local browser, bsize = winu.getDefaultBrowser()
local browser_path = ffi.string(browser)..[[ -new-window "http://localhost:9190/index.html"]] local browser_path = ffi.string(browser)..[[ -new-window "http://localhost:9190/index.html"]]
hproc_browser, hthread_browser, si_browser = execute(browser_path) hproc_browser, hthread_browser, si_browser = execute(browser_path)
sleep(100) sleep(200)
-- Need to make this more generic (ie browser agnostic) -- Need to make this more generic (ie browser agnostic)
local browserhwnd = GetHwndFromProcess( hthread_browser, "Mozilla Firefox" ) local browserhwnd = GetHwndFromProcess( hthread_browser, "Mozilla Firefox" )
-- local browserhwnd = user32.FindWindowA( nil, "http://localhost:9190/index.html") -- local browserhwnd = user32.FindWindowA( nil, "http://localhost:9190/index.html")
print(hproc_browser, hthread_browser, si_browser) print(hproc_browser, hthread_browser, si_browser)
if(browserhwnd) then if(browserhwnd) then
user32.MoveWindow(browserhwnd, rect[0].left, rect[0].top, rect[0].right-rect[0].left, rect[0].bottom-rect[0].top, 1) sleep(100) -- Let things setup (window pos etc)
local style = user32.GetWindowLongA(browserhwnd, -16)
print(string.format("0x%x", style))
user32.AdjustWindowRect(rect, 0x80040000, 0)
-- user32.MoveWindow(browserhwnd, rect[0].left, rect[0].top, rect[0].right-rect[0].left, rect[0].bottom-rect[0].top, 1)
winu.SetWindowPos(browserhwnd, rect[0].left, rect[0].top, rect[0].right-rect[0].left, rect[0].bottom-rect[0].top)
end end
return browserhwnd return browserhwnd
end end
------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------
local function SetupSokolLuajit(rect) local function SetupSokolLuajit(rect, diff)
print("SOKOL-LUAJIT SETUP") print("SOKOL-LUAJIT SETUP")
local sokolluajit_path = [["bin/win64/luajit.exe" "editor/editor.lua"]] local width = rect[0].right - rect[0].left
local height = rect[0].bottom - rect[0].top
local sokolluajit_path = [["bin/win64/luajit.exe" "editor/editor.lua" ]]..string.format(" %d %d", width, height)
hproc_sokol, hthread_sokol, si_sokol = execute(sokolluajit_path) hproc_sokol, hthread_sokol, si_sokol = execute(sokolluajit_path)
sleep(100) sleep(200)
print(hproc_sokol, hthread_sokol, si_sokol) print(hproc_sokol, hthread_sokol, si_sokol)
local sokolhwnd = GetHwndFromProcess( hthread_sokol, "editor - sokol" ) local sokolhwnd = GetHwndFromProcess( hthread_sokol, "editor - sokol" )
-- local sokolhwnd = user32.FindWindowA( nil, "editor - sokol") -- local sokolhwnd = user32.FindWindowA( nil, "editor - sokol")
if(sokolhwnd) then if(sokolhwnd) then
user32.MoveWindow(sokolhwnd, rect[0].left, rect[0].top, rect[0].right-rect[0].left, rect[0].bottom-rect[0].top, 1) sleep(100) -- Let things setup (window pos etc)
local style = user32.GetWindowLongA(sokolhwnd, -16)
print(string.format("0x%x", style))
user32.AdjustWindowRect(rect, style, 0)
-- user32.MoveWindow(sokolhwnd, rect[0].left, 0, rect[0].right-rect[0].left, rect[0].bottom-rect[0].top - diff, 0)
winu.SetWindowPos(sokolhwnd, rect[0].left, 0, rect[0].right-rect[0].left, rect[0].bottom-rect[0].top - diff)
end end
return sokolhwnd return sokolhwnd
end end
@ -71,25 +83,31 @@ end
local function setupWindows() local function setupWindows()
local workArea = ffi.new("RECT")
user32.SystemParametersInfoW(0x0030, 0, workArea, 0)
desktop_width = workArea.right - workArea.left
desktop_height = workArea.bottom - workArea.top
print("Screen size:", desktop_width, "x", desktop_height)
local desktop = ffi.new("RECT[1]") local desktop = ffi.new("RECT[1]")
-- Get a handle to the desktop window -- Get a handle to the desktop window
hDesktop = user32.GetDesktopWindow() hDesktop = user32.GetDesktopWindow()
-- Get the size of screen to the variable desktop -- Get the size of screen to the variable desktop
user32.GetWindowRect(hDesktop, desktop) user32.GetWindowRect(hDesktop, desktop)
local diff = desktop[0].bottom - desktop_height - 2
print(diff)
local l = desktop[0].left local dwidth = desktop_width/2.0
local r = desktop[0].right desktop[0].bottom = desktop_height
desktop[0].bottom = desktop[0].bottom - 50
desktop[0].left = 0 desktop[0].left = 0
desktop[0].right = (r-l)/2 desktop[0].right = dwidth
browserhwnd = SetupBrowser(desktop) browserhwnd = SetupBrowser(desktop)
sleep(100) -- Let things setup (window pos etc)
desktop[0].left = (r-l)/2 desktop[0].left = dwidth
desktop[0].right = r desktop[0].right = desktop_width
sokolhwnd = SetupSokolLuajit(desktop) sokolhwnd = SetupSokolLuajit(desktop, diff)
sleep(100) -- Let things setup (window pos etc)
end end
------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------

View File

@ -20,6 +20,16 @@ ffi.cdef[[
void * ShellExecuteA(const void * hwnd, const char * lpOperation, const char * lpFile, const char * lpParameters, char* lpDirectory, int nShowCmd); void * ShellExecuteA(const void * hwnd, const char * lpOperation, const char * lpFile, const char * lpParameters, char* lpDirectory, int nShowCmd);
]] ]]
-- --------------------------------------------------------------------------------------
local width = 1920
local height = 1080
if(arg[1] and arg[2]) then
width = tonumber(arg[1])
height = tonumber(arg[2])
end
print(width, height)
-- -------------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------------
-- The project manager handles configuration of the project data (build, debug etc) -- The project manager handles configuration of the project data (build, debug etc)
-- Project manager defines what worlds, assets and folders are accessible for the project -- Project manager defines what worlds, assets and folders are accessible for the project
@ -91,8 +101,8 @@ app_desc[0].init_cb = init
app_desc[0].frame_cb = frame app_desc[0].frame_cb = frame
app_desc[0].cleanup_cb = cleanup app_desc[0].cleanup_cb = cleanup
app_desc[0].event_cb = input app_desc[0].event_cb = input
app_desc[0].width = 1920 app_desc[0].width = width
app_desc[0].height = 1080 app_desc[0].height = height
app_desc[0].window_title = "editor - sokol" app_desc[0].window_title = "editor - sokol"
app_desc[0].fullscreen = false app_desc[0].fullscreen = false
app_desc[0].icon.sokol_default = true app_desc[0].icon.sokol_default = true