Add Bounds, InnerBounds to x.Window

This commit is contained in:
Sasha Koshka 2024-08-16 17:25:17 -04:00
parent 93d7eed21f
commit ab6bdeaba3
2 changed files with 32 additions and 20 deletions

View File

@ -145,12 +145,15 @@ func (window *window) updateBounds () {
// need to sum up all their positions.
decorGeometry, _ := window.xWindow.DecorGeometry()
windowGeometry, _ := window.xWindow.Geometry()
origin := image.Pt(
windowGeometry.X() + decorGeometry.X(),
windowGeometry.Y() + decorGeometry.Y())
window.metrics.bounds = image.Rectangle {
Min: origin,
Max: origin.Add(image.Pt(windowGeometry.Width(), windowGeometry.Height())),
origin := image.Pt (
decorGeometry.X(),
decorGeometry.Y())
innerOrigin := origin.Add(image.Pt (
windowGeometry.X(),
windowGeometry.Y()))
window.metrics.innerBounds = image.Rectangle {
Min: innerOrigin,
Max: innerOrigin.Add(image.Pt(windowGeometry.Width(), windowGeometry.Height())),
}
}
@ -161,9 +164,9 @@ func (window *window) handleConfigureNotify (
configureEvent := *event.ConfigureNotifyEvent
configureEvent = window.compressConfigureNotify(configureEvent)
oldBounds := window.metrics.bounds
oldBounds := window.metrics.innerBounds
window.updateBounds()
newBounds := window.metrics.bounds
newBounds := window.metrics.innerBounds
sizeChanged :=
oldBounds.Dx() != newBounds.Dx() ||

View File

@ -37,7 +37,8 @@ type window struct {
resizeY bool
metrics struct {
bounds image.Rectangle
bounds image.Rectangle // bounds, including frame
innerBounds image.Rectangle // bounds of the drawable area
}
onClose event.FuncBroadcaster
@ -156,7 +157,7 @@ func (this *Backend) newWindow (
// xevent.SelectionRequestFun(window.handleSelectionRequest).
// Connect(this.x, window.xWindow.Id)
window.metrics.bounds = bounds
window.metrics.innerBounds = bounds
window.doMinimumSize()
this.windows[window.xWindow.Id] = window
@ -165,6 +166,14 @@ func (this *Backend) newWindow (
return
}
func (this *window) Bounds () image.Rectangle {
return this.metrics.bounds.Sub(this.metrics.innerBounds.Min)
}
func (this *window) InnerBounds () image.Rectangle {
return this.metrics.innerBounds.Sub(this.metrics.innerBounds.Min)
}
func (this *window) SetRoot (root tomo.Object) {
if root == nil {
this.hierarchy.SetRoot(nil)
@ -242,7 +251,7 @@ func (this *window) NewChild (bounds image.Rectangle) (tomo.Window, error) {
leader := this.leader
child, err := this.backend.newWindow (
bounds.Add(this.metrics.bounds.Min), false)
bounds.Add(this.metrics.innerBounds.Min), false)
child.leader = leader
if err != nil { return nil, err }
@ -260,7 +269,7 @@ func (this *window) NewChild (bounds image.Rectangle) (tomo.Window, error) {
func (this *window) NewMenu (bounds image.Rectangle) (tomo.Window, error) {
menu, err := this.backend.newWindow (
bounds.Add(this.metrics.bounds.Min), true)
bounds.Add(this.metrics.innerBounds.Min), true)
menu.shy = true
icccm.WmTransientForSet (
this.backend.x,
@ -273,7 +282,7 @@ func (this *window) NewMenu (bounds image.Rectangle) (tomo.Window, error) {
func (this *window) NewModal (bounds image.Rectangle) (tomo.Window, error) {
modal, err := this.backend.newWindow (
bounds.Add(this.metrics.bounds.Min), false)
bounds.Add(this.metrics.innerBounds.Min), false)
icccm.WmTransientForSet (
this.backend.x,
modal.xWindow.Id,
@ -382,8 +391,8 @@ func (this *window) reallocateCanvas () {
previousHeight = this.xCanvas.Bounds().Dy()
}
newWidth := this.metrics.bounds.Dx()
newHeight := this.metrics.bounds.Dy()
newWidth := this.metrics.innerBounds.Dx()
newHeight := this.metrics.innerBounds.Dy()
larger := newWidth > previousWidth || newHeight > previousHeight
smaller := newWidth < previousWidth / 2 || newHeight < previousHeight / 2
@ -403,7 +412,7 @@ func (this *window) reallocateCanvas () {
}
this.hierarchy.SetCanvas(this.xCanvas.SubCanvas (
this.metrics.bounds.Sub(this.metrics.bounds.Min)))
this.metrics.innerBounds.Sub(this.metrics.innerBounds.Min)))
}
func (this *window) pushAll () {
@ -458,12 +467,12 @@ func (this *window) doMinimumSize () {
this.backend.x,
this.xWindow.Id,
&hints)
newWidth := this.metrics.bounds.Dx()
newHeight := this.metrics.bounds.Dy()
newWidth := this.metrics.innerBounds.Dx()
newHeight := this.metrics.innerBounds.Dy()
if newWidth < size.X { newWidth = size.X }
if newHeight < size.Y { newHeight = size.Y }
if newWidth != this.metrics.bounds.Dx() ||
newHeight != this.metrics.bounds.Dy() {
if newWidth != this.metrics.innerBounds.Dx() ||
newHeight != this.metrics.innerBounds.Dy() {
this.xWindow.Resize(newWidth, newHeight)
}
}