Macro to set window size/pos - Almost but not quite right

After seeing some posts in the OO forums, I tried setting the window position/size from a macro I have for opening related document. The code works but the positioning is just off by a little which means I have to use the Window Manager to fix, making the setSizePos function useless. :frowning:

Based on what the struct from getContainerWindow() returned from an existing window,

	Dim w: w = e.CurrentController.Frame.getContainerWindow()
	print "x=" & w.PosSize.X & " y=" & w.PosSize.Y _
					& " w=" & w.PosSize.width & " h=" & w.PosSize.height    

I did the following to apply pos/size to another,

    Dim w: w = altDoc.CurrentController.Frame.ContainerWindow
	'Coordinates for left side
	'	x=1 y=111 w=958 h=968
	'Coordinates for right side
	'	x=961 y=111 w=958 h=968

Am I doing something wrong or is this broken/not possible?


EDIT: Edited to clarify what I was trying to do. In essence copy one window’s pos/size to another.

PosSize does not include the window decoration added by the operating system. LibreOffice is unaware of the title bar and the outer borders.

Sure, but both windows have the same borders and decorations. So that shouldn’t matter right? I got the correct position by manually moving the window to the left or right and now I am applying it to another window. Result should be the same I think.

Do you mean the following sequence of actions?

Sub TestPosSize
  Dim oDoc, oWindow, posSize
  With posSize
    oWindow.setPosSize .X, .Y, .width, .Height, 15 
  End With
End Sub

Just like in your code except you are getting and setting the pos/size of the same window. In fact, if I run your code on a correctly positioned window, it moves if off by a bit just like when I set the pos/size to another. Seems like its a bug.

Note that the code by @sokol92 works for me without any window movement of Writer window using Version: (x64) / LibreOffice Community
Build ID: 382eef1f22670f7f4118c8c2dd222ec7ad009daf
CPU threads: 12; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: CL

(I also checked that oWindow.posSize gives the same values as before setPosSize.)

So when filing the bug, don’t forget to provide details like exact program version, OS, environment, used VCL plugin, etc. (start with full copy from Help|About).

Interesting. I usually stick to the stable branches but this annoys me to no end so I might try 7.4. I’ve already tested the code with versions 7.3 and 4.3 and they all behave the same. If 7.4 behaves correctly then seems they fixed it and I’ll upgrade to that.

It could simply be OS and/or VCL plugin. E.g., I have no idea how this would work on Windows XP, with its thick window borders…

OK. Just tested 7.4 and its the same. I am running Windows 10. Out of curiosity I also checked Ubuntu 21 (LO v7.1) and its doing odd things there too. In W10, if the window is in the middle the @sokol92 's code does nothing. But, if you snap it, left, right or in any of the corners, then it moves it. If part of the window is outside the lower end then it moves snaps it vertically. If outside on the left or right then it moves it back within the viewable area. In Ubuntu, repeated runs of @sokol92 's code on a centered window makes the window smaller every time. I’ll file a bug report but maybe its intentional trying to prevent windows from getting lost outside the viewable area? We’ll see what the devs say.

Code pointer: salframe.cxx (revision 75fd3093) - OpenGrok cross reference for /core/vcl/win/window/salframe.cxx

The calculated rectangle (including decorations) for a snapped window happens to have its side “outside” of the screen. The check should be adjusted to either tolerate the added delta, or to check client size (before the adjustment) instead of window size.

(A usual note: the less information you give, the more iterations it takes for helpers to see the problem. The “happens when you snap the window” was important…)


Thanks. Didn’t even think to mention it until you said it wasn’t happening on latest release but did for me. Then the penny dropped as they say… :slight_smile:


With Ubuntu 20.4 and:

Version: / LibreOffice Community
Build ID: 382eef1f22670f7f4118c8c2dd222ec7ad009daf
CPU threads: 8; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

I have various erratic behavior. However, when running LO with SAL_USE_VCLPLUGIN=gen all windows line up correctly.

Version: / LibreOffice Community
Build ID: 382eef1f22670f7f4118c8c2dd222ec7ad009daf
CPU threads: 8; OS: Linux 5.4; UI render: default; VCL: x11
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
1 Like