Bug 151676 - Odd behavior when setting window position/size with setPosSize
Summary: Odd behavior when setting window position/size with setPosSize
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.3.7.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-21 09:45 UTC by Jordi
Modified: 2022-10-24 21:38 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jordi 2022-10-21 09:45:30 UTC
I am trying to position documents side by side using a macro. I started by using Windows 10 snap feature to position two windows and retrieved their position and size. 

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


Then I tried to use .setPosSize on other windows but it didn't work exactly. Position was off.


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

Behavior is the same with v4.3 and latest v7.4.2.3

When snapping a window (sides or corners) and using the following code you can see the problem,

Sub TestPosSize
  Dim oDoc, oWindow, posSize
  oDoc=ThisComponent
  oWindow=ThisComponent.CurrentController.frame.ContainerWindow
  oWindow.IsMaximized=False
  posSize=oWindow.posSize
  With posSize
    oWindow.setPosSize .X, .Y, .width, .Height, 15 
  End With
End Sub

In Windows10 the above code, 
 - if the window is centered it does nothing. 
 - if snapped it moves it by about 10px
 - if part of the window is outside viewable area (left/right), it moves it back in + 10px. 
 - If window below bottom it snaps vertically!?! (I have Windows taskbar at the top should it matter).

In Ubuntu 21 with LO 7.1 
 - if snapped it moves and resizes window
 - if centered, repeated runs makes window smaller


Might this explain why when opening saved documents they never appear at their exact previous position?
Comment 1 Jordi 2022-10-21 09:50:09 UTC
LibreOffice 3.3.0 
OOO330m19 (Build:6)
tag libreoffice-3.3.0.4


Similar behavior with above version on Windows 10.
Comment 2 Jordi 2022-10-21 09:54:58 UTC
If this is a safety feature, so Windows don't get lost outside viewable area, might I suggest a new option under the Window menu, "Move window to viewable area"?
Comment 3 Jordi 2022-10-21 10:00:53 UTC
Additional info of versions tested:

Version: 7.0.5.2 (x64)
Build ID: 64390860c6cd0aca4beafafcfd84613dd9dfb63a
CPU threads: 12; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: en-AU (en_AU); UI: en-GB
Calc: CL

Version: 7.4.2.3 (x64) / LibreOffice Community
Build ID: 382eef1f22670f7f4118c8c2dd222ec7ad009daf
CPU threads: 12; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: en-AU (en_AU); UI: en-GB
Calc: CL

Version: 7.1.5.2 / LibreOffice Community
Build ID: 10(Build:2)
CPU threads: 2; OS: Linux 5.11; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Ubuntu package version: 1:7.1.5-0ubuntu0.21.04.1
Calc: threaded
Comment 4 Rafael Lima 2022-10-21 19:21:01 UTC
The problem is that the line

oWindow.IsMaximized = False

... restores the window position, as when you double-click the header bar. So in your code it first restores the window and then the position/size is applied.
Comment 5 Jordi 2022-10-23 18:37:31 UTC
(In reply to Rafael Lima from comment #4)
> The problem is that the line
> 
> oWindow.IsMaximized = False
> 
> ... restores the window position, as when you double-click the header bar.
> So in your code it first restores the window and then the position/size is
> applied.

ok but even if I comment this line, and with a non-snapped window, if I do 

oWindow.setPosSize(1,1,958,968,15)

the windows is still ~10px of the edge.