Some X backend fixes
This commit is contained in:
parent
68128c94d8
commit
6e4310b9ad
@ -76,8 +76,11 @@ func (entity *entity) Window () tomo.Window {
|
|||||||
func (entity *entity) SetMinimumSize (width, height int) {
|
func (entity *entity) SetMinimumSize (width, height int) {
|
||||||
entity.minWidth = width
|
entity.minWidth = width
|
||||||
entity.minHeight = height
|
entity.minHeight = height
|
||||||
if entity.parent == nil { return }
|
if entity.parent == nil {
|
||||||
entity.parent.element.(tomo.Container).HandleChildMinimumSizeChange()
|
entity.window.setMinimumSize(width, height)
|
||||||
|
} else {
|
||||||
|
entity.parent.element.(tomo.Container).HandleChildMinimumSizeChange()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entity *entity) DrawBackground (destination canvas.Canvas, bounds image.Rectangle) {
|
func (entity *entity) DrawBackground (destination canvas.Canvas, bounds image.Rectangle) {
|
||||||
@ -169,7 +172,7 @@ func (entity *entity) FocusPrevious () {
|
|||||||
|
|
||||||
// ----------- FlexibleEntity ----------- //
|
// ----------- FlexibleEntity ----------- //
|
||||||
|
|
||||||
func (entity *entity) NotifyFlexibleHeightChange () {
|
func (entity *entity) NotifyFlexibleHeightChange (child tomo.Flexible) {
|
||||||
if entity.parent == nil { return }
|
if entity.parent == nil { return }
|
||||||
if parent, ok := entity.parent.element.(tomo.FlexibleContainer); ok {
|
if parent, ok := entity.parent.element.(tomo.FlexibleContainer); ok {
|
||||||
parent.HandleChildFlexibleHeightChange()
|
parent.HandleChildFlexibleHeightChange()
|
||||||
|
@ -121,8 +121,7 @@ func (window *window) handleKeyPress (
|
|||||||
connection *xgbutil.XUtil,
|
connection *xgbutil.XUtil,
|
||||||
event xevent.KeyPressEvent,
|
event xevent.KeyPressEvent,
|
||||||
) {
|
) {
|
||||||
if window.system.focused == nil { return }
|
if window.hasModal { return }
|
||||||
if window.hasModal { return }
|
|
||||||
|
|
||||||
keyEvent := *event.KeyPressEvent
|
keyEvent := *event.KeyPressEvent
|
||||||
key, numberPad := window.backend.keycodeToKey(keyEvent.Detail, keyEvent.State)
|
key, numberPad := window.backend.keycodeToKey(keyEvent.Detail, keyEvent.State)
|
||||||
@ -149,7 +148,6 @@ func (window *window) handleKeyRelease (
|
|||||||
connection *xgbutil.XUtil,
|
connection *xgbutil.XUtil,
|
||||||
event xevent.KeyReleaseEvent,
|
event xevent.KeyReleaseEvent,
|
||||||
) {
|
) {
|
||||||
if window.system.focused == nil { return }
|
|
||||||
keyEvent := *event.KeyReleaseEvent
|
keyEvent := *event.KeyReleaseEvent
|
||||||
|
|
||||||
// do not process this event if it was generated from a key repeat
|
// 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)
|
key, numberPad := window.backend.keycodeToKey(keyEvent.Detail, keyEvent.State)
|
||||||
modifiers := window.modifiersFromState(keyEvent.State)
|
modifiers := window.modifiersFromState(keyEvent.State)
|
||||||
modifiers.NumberPad = numberPad
|
modifiers.NumberPad = numberPad
|
||||||
|
|
||||||
focused, ok := window.focused.element.(tomo.KeyboardTarget)
|
if window.focused != nil {
|
||||||
if ok { focused.HandleKeyUp(key, modifiers) }
|
focused, ok := window.focused.element.(tomo.KeyboardTarget)
|
||||||
|
if ok { focused.HandleKeyUp(key, modifiers) }
|
||||||
window.system.afterEvent()
|
|
||||||
|
window.system.afterEvent()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *window) handleButtonPress (
|
func (window *window) handleButtonPress (
|
||||||
|
@ -48,9 +48,6 @@ func (backend *Backend) NewWindow (
|
|||||||
) {
|
) {
|
||||||
if backend == nil { panic("nil backend") }
|
if backend == nil { panic("nil backend") }
|
||||||
window, err := backend.newWindow(bounds, false)
|
window, err := backend.newWindow(bounds, false)
|
||||||
|
|
||||||
window.system.initialize()
|
|
||||||
window.system.pushFunc = window.paste
|
|
||||||
|
|
||||||
output = mainWindow { window }
|
output = mainWindow { window }
|
||||||
return output, err
|
return output, err
|
||||||
@ -68,6 +65,9 @@ func (backend *Backend) newWindow (
|
|||||||
|
|
||||||
window := &window { backend: backend }
|
window := &window { backend: backend }
|
||||||
|
|
||||||
|
window.system.initialize()
|
||||||
|
window.system.pushFunc = window.pasteAndPush
|
||||||
|
|
||||||
window.xWindow, err = xwindow.Generate(backend.connection)
|
window.xWindow, err = xwindow.Generate(backend.connection)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ func (backend *Backend) newWindow (
|
|||||||
window.SetConfig(backend.config)
|
window.SetConfig(backend.config)
|
||||||
|
|
||||||
window.metrics.bounds = bounds
|
window.metrics.bounds = bounds
|
||||||
window.childMinimumSizeChangeCallback(8, 8)
|
window.setMinimumSize(8, 8)
|
||||||
|
|
||||||
window.reallocateCanvas()
|
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) {
|
func (window *window) paste (region image.Rectangle) {
|
||||||
canvas := canvas.Cut(window.canvas, region)
|
canvas := canvas.Cut(window.canvas, region)
|
||||||
data, stride := canvas.Buffer()
|
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 (
|
icccm.WmNormalHintsSet (
|
||||||
window.backend.connection,
|
window.backend.connection,
|
||||||
window.xWindow.Id,
|
window.xWindow.Id,
|
||||||
@ -454,8 +461,5 @@ func (window *window) childMinimumSizeChangeCallback (width, height int) (resize
|
|||||||
if newWidth != window.metrics.bounds.Dx() ||
|
if newWidth != window.metrics.bounds.Dx() ||
|
||||||
newHeight != window.metrics.bounds.Dy() {
|
newHeight != window.metrics.bounds.Dy() {
|
||||||
window.xWindow.Resize(newWidth, newHeight)
|
window.xWindow.Resize(newWidth, newHeight)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ type Button struct {
|
|||||||
|
|
||||||
// NewButton creates a new button with the specified label text.
|
// NewButton creates a new button with the specified label text.
|
||||||
func NewButton (text string) (element *Button) {
|
func NewButton (text string) (element *Button) {
|
||||||
element = &Button { showText: true }
|
element = &Button { showText: true, enabled: true }
|
||||||
element.theme.Case = tomo.C("tomo", "button")
|
element.theme.Case = tomo.C("tomo", "button")
|
||||||
element.drawer.SetFace (element.theme.FontFace (
|
element.drawer.SetFace (element.theme.FontFace (
|
||||||
tomo.FontStyleRegular,
|
tomo.FontStyleRegular,
|
||||||
@ -126,7 +126,6 @@ func (element *Button) SetConfig (new tomo.Config) {
|
|||||||
// Draw causes the element to draw to the specified destination canvas.
|
// Draw causes the element to draw to the specified destination canvas.
|
||||||
func (element *Button) Draw (destination canvas.Canvas) {
|
func (element *Button) Draw (destination canvas.Canvas) {
|
||||||
if element.entity == nil { return }
|
if element.entity == nil { return }
|
||||||
|
|
||||||
state := element.state()
|
state := element.state()
|
||||||
bounds := element.entity.Bounds()
|
bounds := element.entity.Bounds()
|
||||||
pattern := element.theme.Pattern(tomo.PatternButton, state)
|
pattern := element.theme.Pattern(tomo.PatternButton, state)
|
||||||
@ -183,17 +182,15 @@ func (element *Button) Draw (destination canvas.Canvas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (element *Button) HandleFocusChange () {
|
func (element *Button) HandleFocusChange () {
|
||||||
if element.entity == nil { return }
|
if element.entity != nil { element.entity.Invalidate() }
|
||||||
element.entity.Invalidate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Button) HandleMouseDown (x, y int, button input.Button) {
|
func (element *Button) HandleMouseDown (x, y int, button input.Button) {
|
||||||
if element.entity == nil { return }
|
|
||||||
if !element.Enabled() { return }
|
if !element.Enabled() { return }
|
||||||
element.Focus()
|
element.Focus()
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
element.pressed = true
|
element.pressed = true
|
||||||
element.entity.Invalidate()
|
if element.entity != nil { element.entity.Invalidate() }
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Button) HandleMouseUp (x, y int, button input.Button) {
|
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 {
|
if element.Enabled() && within && element.onClick != nil {
|
||||||
element.onClick()
|
element.onClick()
|
||||||
}
|
}
|
||||||
element.entity.Invalidate()
|
if element.entity != nil { element.entity.Invalidate() }
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Button) HandleKeyDown (key input.Key, modifiers input.Modifiers) {
|
func (element *Button) HandleKeyDown (key input.Key, modifiers input.Modifiers) {
|
||||||
if element.entity == nil { return }
|
|
||||||
if !element.Enabled() { return }
|
if !element.Enabled() { return }
|
||||||
if key == input.KeyEnter {
|
if key == input.KeyEnter {
|
||||||
element.pressed = true
|
element.pressed = true
|
||||||
element.entity.Invalidate()
|
if element.entity != nil { element.entity.Invalidate() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Button) HandleKeyUp(key input.Key, modifiers input.Modifiers) {
|
func (element *Button) HandleKeyUp(key input.Key, modifiers input.Modifiers) {
|
||||||
if element.entity == nil { return }
|
|
||||||
if key == input.KeyEnter && element.pressed {
|
if key == input.KeyEnter && element.pressed {
|
||||||
element.pressed = false
|
element.pressed = false
|
||||||
element.entity.Invalidate()
|
if element.entity != nil { element.entity.Invalidate() }
|
||||||
if !element.Enabled() { return }
|
if !element.Enabled() { return }
|
||||||
if element.onClick != nil {
|
if element.onClick != nil {
|
||||||
element.onClick()
|
element.onClick()
|
||||||
|
@ -26,7 +26,7 @@ type Checkbox struct {
|
|||||||
|
|
||||||
// NewCheckbox creates a new cbeckbox with the specified label text.
|
// NewCheckbox creates a new cbeckbox with the specified label text.
|
||||||
func NewCheckbox (text string, checked bool) (element *Checkbox) {
|
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.theme.Case = tomo.C("tomo", "checkbox")
|
||||||
element.drawer.SetFace (element.theme.FontFace (
|
element.drawer.SetFace (element.theme.FontFace (
|
||||||
tomo.FontStyleRegular,
|
tomo.FontStyleRegular,
|
||||||
|
Reference in New Issue
Block a user