Some X backend fixes

This commit is contained in:
2023-04-14 23:58:14 -04:00
parent 68128c94d8
commit 6e4310b9ad
5 changed files with 33 additions and 31 deletions

View File

@@ -76,8 +76,11 @@ func (entity *entity) Window () tomo.Window {
func (entity *entity) SetMinimumSize (width, height int) {
entity.minWidth = width
entity.minHeight = height
if entity.parent == nil { return }
entity.parent.element.(tomo.Container).HandleChildMinimumSizeChange()
if entity.parent == nil {
entity.window.setMinimumSize(width, height)
} else {
entity.parent.element.(tomo.Container).HandleChildMinimumSizeChange()
}
}
func (entity *entity) DrawBackground (destination canvas.Canvas, bounds image.Rectangle) {
@@ -169,7 +172,7 @@ func (entity *entity) FocusPrevious () {
// ----------- FlexibleEntity ----------- //
func (entity *entity) NotifyFlexibleHeightChange () {
func (entity *entity) NotifyFlexibleHeightChange (child tomo.Flexible) {
if entity.parent == nil { return }
if parent, ok := entity.parent.element.(tomo.FlexibleContainer); ok {
parent.HandleChildFlexibleHeightChange()

View File

@@ -121,8 +121,7 @@ func (window *window) handleKeyPress (
connection *xgbutil.XUtil,
event xevent.KeyPressEvent,
) {
if window.system.focused == nil { return }
if window.hasModal { return }
if window.hasModal { return }
keyEvent := *event.KeyPressEvent
key, numberPad := window.backend.keycodeToKey(keyEvent.Detail, keyEvent.State)
@@ -149,7 +148,6 @@ func (window *window) handleKeyRelease (
connection *xgbutil.XUtil,
event xevent.KeyReleaseEvent,
) {
if window.system.focused == nil { return }
keyEvent := *event.KeyReleaseEvent
// do not process this event if it was generated from a key repeat
@@ -172,11 +170,13 @@ func (window *window) handleKeyRelease (
key, numberPad := window.backend.keycodeToKey(keyEvent.Detail, keyEvent.State)
modifiers := window.modifiersFromState(keyEvent.State)
modifiers.NumberPad = numberPad
focused, ok := window.focused.element.(tomo.KeyboardTarget)
if ok { focused.HandleKeyUp(key, modifiers) }
window.system.afterEvent()
if window.focused != nil {
focused, ok := window.focused.element.(tomo.KeyboardTarget)
if ok { focused.HandleKeyUp(key, modifiers) }
window.system.afterEvent()
}
}
func (window *window) handleButtonPress (

View File

@@ -48,9 +48,6 @@ func (backend *Backend) NewWindow (
) {
if backend == nil { panic("nil backend") }
window, err := backend.newWindow(bounds, false)
window.system.initialize()
window.system.pushFunc = window.paste
output = mainWindow { window }
return output, err
@@ -68,6 +65,9 @@ func (backend *Backend) newWindow (
window := &window { backend: backend }
window.system.initialize()
window.system.pushFunc = window.pasteAndPush
window.xWindow, err = xwindow.Generate(backend.connection)
if err != nil { return }
@@ -125,7 +125,7 @@ func (backend *Backend) newWindow (
window.SetConfig(backend.config)
window.metrics.bounds = bounds
window.childMinimumSizeChangeCallback(8, 8)
window.setMinimumSize(8, 8)
window.reallocateCanvas()
@@ -404,6 +404,11 @@ func (window *window) reallocateCanvas () {
}
func (window *window) pasteAndPush (region image.Rectangle) {
window.paste(region)
window.pushRegion(region)
}
func (window *window) paste (region image.Rectangle) {
canvas := canvas.Cut(window.canvas, region)
data, stride := canvas.Buffer()
@@ -438,7 +443,9 @@ func (window *window) pushRegion (region image.Rectangle) {
}
}
func (window *window) childMinimumSizeChangeCallback (width, height int) (resized bool) {
func (window *window) setMinimumSize (width, height int) {
if width < 8 { width = 8 }
if height < 8 { height = 8 }
icccm.WmNormalHintsSet (
window.backend.connection,
window.xWindow.Id,
@@ -454,8 +461,5 @@ func (window *window) childMinimumSizeChangeCallback (width, height int) (resize
if newWidth != window.metrics.bounds.Dx() ||
newHeight != window.metrics.bounds.Dy() {
window.xWindow.Resize(newWidth, newHeight)
return true
}
return false
}