Some X backend fixes

This commit is contained in:
Sasha Koshka 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
}

View File

@ -29,7 +29,7 @@ type Button struct {
// NewButton creates a new button with the specified label text.
func NewButton (text string) (element *Button) {
element = &Button { showText: true }
element = &Button { showText: true, enabled: true }
element.theme.Case = tomo.C("tomo", "button")
element.drawer.SetFace (element.theme.FontFace (
tomo.FontStyleRegular,
@ -126,7 +126,6 @@ func (element *Button) SetConfig (new tomo.Config) {
// Draw causes the element to draw to the specified destination canvas.
func (element *Button) Draw (destination canvas.Canvas) {
if element.entity == nil { return }
state := element.state()
bounds := element.entity.Bounds()
pattern := element.theme.Pattern(tomo.PatternButton, state)
@ -183,17 +182,15 @@ func (element *Button) Draw (destination canvas.Canvas) {
}
func (element *Button) HandleFocusChange () {
if element.entity == nil { return }
element.entity.Invalidate()
if element.entity != nil { element.entity.Invalidate() }
}
func (element *Button) HandleMouseDown (x, y int, button input.Button) {
if element.entity == nil { return }
if !element.Enabled() { return }
element.Focus()
if button != input.ButtonLeft { return }
element.pressed = true
element.entity.Invalidate()
if element.entity != nil { element.entity.Invalidate() }
}
func (element *Button) HandleMouseUp (x, y int, button input.Button) {
@ -204,23 +201,21 @@ func (element *Button) HandleMouseUp (x, y int, button input.Button) {
if element.Enabled() && within && element.onClick != nil {
element.onClick()
}
element.entity.Invalidate()
if element.entity != nil { element.entity.Invalidate() }
}
func (element *Button) HandleKeyDown (key input.Key, modifiers input.Modifiers) {
if element.entity == nil { return }
if !element.Enabled() { return }
if key == input.KeyEnter {
element.pressed = true
element.entity.Invalidate()
if element.entity != nil { element.entity.Invalidate() }
}
}
func (element *Button) HandleKeyUp(key input.Key, modifiers input.Modifiers) {
if element.entity == nil { return }
if key == input.KeyEnter && element.pressed {
element.pressed = false
element.entity.Invalidate()
if element.entity != nil { element.entity.Invalidate() }
if !element.Enabled() { return }
if element.onClick != nil {
element.onClick()

View File

@ -26,7 +26,7 @@ type Checkbox struct {
// NewCheckbox creates a new cbeckbox with the specified label text.
func NewCheckbox (text string, checked bool) (element *Checkbox) {
element = &Checkbox { checked: checked }
element = &Checkbox { checked: checked, enabled: true }
element.theme.Case = tomo.C("tomo", "checkbox")
element.drawer.SetFace (element.theme.FontFace (
tomo.FontStyleRegular,