Improved window positioning - still not great
This commit is contained in:
parent
9745112ccd
commit
1f0030383a
@ -25,6 +25,15 @@ ffi.cdef[[
|
||||
uint64_t lparam[1];
|
||||
const char * title;
|
||||
} 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")
|
||||
@ -262,10 +271,22 @@ end
|
||||
local pid = user32.GetWindowThreadProcessId( wvhwnd or 0, nil )
|
||||
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 {
|
||||
CreateWindow = CreateWindow,
|
||||
SetWindowPos = SetWindowPos,
|
||||
SetTransparentBlend = SetTransparentBlend,
|
||||
GetHwndFromProcess = GetHwndFromProcess,
|
||||
RemoveWindowBorders = RemoveWindowBorders,
|
||||
|
||||
@ -15,18 +15,18 @@ local user32 = winu.user
|
||||
local gdi32 = winu.gdi
|
||||
local comdlg32 = winu.comdlg
|
||||
|
||||
local CreateWindow = winu.CreateWindow
|
||||
local GetFile = winu.GetFile
|
||||
local GetHwndFromProcess = winu.GetHwndFromProcess
|
||||
local RemoveWindowBorders = winu.RemoveWindowBorders
|
||||
local execute = winu.execute
|
||||
local shellexecute = winu.shellexecute
|
||||
local sleep = winu.Sleep
|
||||
local CreateWindow = winu.CreateWindow
|
||||
local GetFile = winu.GetFile
|
||||
local GetHwndFromProcess = winu.GetHwndFromProcess
|
||||
local RemoveWindowBorders = winu.RemoveWindowBorders
|
||||
local execute = winu.execute
|
||||
local shellexecute = winu.shellexecute
|
||||
local sleep = winu.Sleep
|
||||
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local hproc_browser, hthread_browser, si_browser = nil
|
||||
local hproc_sokol, hthread_sokol, si_sokol = nil
|
||||
local hproc_browser, hthread_browser, si_browser = nil
|
||||
local hproc_sokol, hthread_sokol, si_sokol = nil
|
||||
|
||||
local browserhwnd = nil
|
||||
local sokolhwnd = nil
|
||||
@ -39,30 +39,42 @@ print("BROWSER SETUP")
|
||||
local browser, bsize = winu.getDefaultBrowser()
|
||||
local browser_path = ffi.string(browser)..[[ -new-window "http://localhost:9190/index.html"]]
|
||||
hproc_browser, hthread_browser, si_browser = execute(browser_path)
|
||||
sleep(100)
|
||||
sleep(200)
|
||||
-- Need to make this more generic (ie browser agnostic)
|
||||
local browserhwnd = GetHwndFromProcess( hthread_browser, "Mozilla Firefox" )
|
||||
-- local browserhwnd = user32.FindWindowA( nil, "http://localhost:9190/index.html")
|
||||
print(hproc_browser, hthread_browser, si_browser)
|
||||
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
|
||||
return browserhwnd
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local function SetupSokolLuajit(rect)
|
||||
local function SetupSokolLuajit(rect, diff)
|
||||
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)
|
||||
sleep(100)
|
||||
sleep(200)
|
||||
print(hproc_sokol, hthread_sokol, si_sokol)
|
||||
local sokolhwnd = GetHwndFromProcess( hthread_sokol, "editor - sokol" )
|
||||
-- local sokolhwnd = user32.FindWindowA( nil, "editor - sokol")
|
||||
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
|
||||
return sokolhwnd
|
||||
end
|
||||
@ -71,25 +83,31 @@ end
|
||||
|
||||
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]")
|
||||
-- Get a handle to the desktop window
|
||||
hDesktop = user32.GetDesktopWindow()
|
||||
-- Get the size of screen to the variable desktop
|
||||
user32.GetWindowRect(hDesktop, desktop)
|
||||
local diff = desktop[0].bottom - desktop_height - 2
|
||||
print(diff)
|
||||
|
||||
local l = desktop[0].left
|
||||
local r = desktop[0].right
|
||||
desktop[0].bottom = desktop[0].bottom - 50
|
||||
local dwidth = desktop_width/2.0
|
||||
desktop[0].bottom = desktop_height
|
||||
|
||||
desktop[0].left = 0
|
||||
desktop[0].right = (r-l)/2
|
||||
desktop[0].right = dwidth
|
||||
browserhwnd = SetupBrowser(desktop)
|
||||
sleep(100) -- Let things setup (window pos etc)
|
||||
|
||||
desktop[0].left = (r-l)/2
|
||||
desktop[0].right = r
|
||||
sokolhwnd = SetupSokolLuajit(desktop)
|
||||
sleep(100) -- Let things setup (window pos etc)
|
||||
desktop[0].left = dwidth
|
||||
desktop[0].right = desktop_width
|
||||
sokolhwnd = SetupSokolLuajit(desktop, diff)
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -20,6 +20,16 @@ ffi.cdef[[
|
||||
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)
|
||||
-- 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].cleanup_cb = cleanup
|
||||
app_desc[0].event_cb = input
|
||||
app_desc[0].width = 1920
|
||||
app_desc[0].height = 1080
|
||||
app_desc[0].width = width
|
||||
app_desc[0].height = height
|
||||
app_desc[0].window_title = "editor - sokol"
|
||||
app_desc[0].fullscreen = false
|
||||
app_desc[0].icon.sokol_default = true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user