oh mmy god
This commit is contained in:
parent
912f939f2e
commit
4692b2c898
@ -42,6 +42,14 @@ func (sum *scrollSum) add (button xproto.Button, window *Window, state uint16) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (window *Window) handleExpose (
|
||||||
|
connection *xgbutil.XUtil,
|
||||||
|
event xevent.ExposeEvent,
|
||||||
|
) {
|
||||||
|
_ = window.compressExpose(*event.ExposeEvent)
|
||||||
|
window.redrawChildEntirely()
|
||||||
|
}
|
||||||
|
|
||||||
func (window *Window) handleConfigureNotify (
|
func (window *Window) handleConfigureNotify (
|
||||||
connection *xgbutil.XUtil,
|
connection *xgbutil.XUtil,
|
||||||
event xevent.ConfigureNotifyEvent,
|
event xevent.ConfigureNotifyEvent,
|
||||||
@ -64,9 +72,29 @@ func (window *Window) handleConfigureNotify (
|
|||||||
window.metrics.height = int(configureEvent.Height)
|
window.metrics.height = int(configureEvent.Height)
|
||||||
window.reallocateCanvas()
|
window.reallocateCanvas()
|
||||||
window.resizeChildToFit()
|
window.resizeChildToFit()
|
||||||
|
|
||||||
|
if !window.exposeEventFollows(configureEvent) {
|
||||||
|
window.redrawChildEntirely()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (window *Window) exposeEventFollows (event xproto.ConfigureNotifyEvent) (found bool) {
|
||||||
|
nextEvents := xevent.Peek(window.backend.connection)
|
||||||
|
if len(nextEvents) > 0 {
|
||||||
|
untypedEvent := nextEvents[0]
|
||||||
|
if untypedEvent.Err == nil {
|
||||||
|
typedEvent, ok :=
|
||||||
|
untypedEvent.Event.(xproto.ConfigureNotifyEvent)
|
||||||
|
|
||||||
|
if ok && typedEvent.Window == event.Window {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (window *Window) modifiersFromState (
|
func (window *Window) modifiersFromState (
|
||||||
state uint16,
|
state uint16,
|
||||||
) (
|
) (
|
||||||
@ -201,6 +229,32 @@ func (window *Window) handleMotionNotify (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (window *Window) compressExpose (
|
||||||
|
firstEvent xproto.ExposeEvent,
|
||||||
|
) (
|
||||||
|
lastEvent xproto.ExposeEvent,
|
||||||
|
) {
|
||||||
|
window.backend.connection.Sync()
|
||||||
|
xevent.Read(window.backend.connection, false)
|
||||||
|
lastEvent = firstEvent
|
||||||
|
|
||||||
|
for index, untypedEvent := range xevent.Peek(window.backend.connection) {
|
||||||
|
if untypedEvent.Err != nil { continue }
|
||||||
|
|
||||||
|
typedEvent, ok := untypedEvent.Event.(xproto.ExposeEvent)
|
||||||
|
if !ok { continue }
|
||||||
|
|
||||||
|
// FIXME: union all areas into the last event
|
||||||
|
if firstEvent.Window == typedEvent.Window {
|
||||||
|
lastEvent = typedEvent
|
||||||
|
defer func (index int) {
|
||||||
|
xevent.DequeueAt(window.backend.connection, index)
|
||||||
|
} (index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (window *Window) compressConfigureNotify (
|
func (window *Window) compressConfigureNotify (
|
||||||
firstEvent xproto.ConfigureNotifyEvent,
|
firstEvent xproto.ConfigureNotifyEvent,
|
||||||
|
@ -39,6 +39,7 @@ func (backend *Backend) NewWindow (
|
|||||||
backend.connection.RootWin(),
|
backend.connection.RootWin(),
|
||||||
0, 0, width, height, 0)
|
0, 0, width, height, 0)
|
||||||
err = window.xWindow.Listen (
|
err = window.xWindow.Listen (
|
||||||
|
xproto.EventMaskExposure,
|
||||||
xproto.EventMaskStructureNotify,
|
xproto.EventMaskStructureNotify,
|
||||||
xproto.EventMaskPointerMotion,
|
xproto.EventMaskPointerMotion,
|
||||||
xproto.EventMaskKeyPress,
|
xproto.EventMaskKeyPress,
|
||||||
@ -50,7 +51,9 @@ func (backend *Backend) NewWindow (
|
|||||||
window.xWindow.WMGracefulClose (func (xWindow *xwindow.Window) {
|
window.xWindow.WMGracefulClose (func (xWindow *xwindow.Window) {
|
||||||
window.Close()
|
window.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
xevent.ExposeFun(window.handleExpose).
|
||||||
|
Connect(backend.connection, window.xWindow.Id)
|
||||||
xevent.ConfigureNotifyFun(window.handleConfigureNotify).
|
xevent.ConfigureNotifyFun(window.handleConfigureNotify).
|
||||||
Connect(backend.connection, window.xWindow.Id)
|
Connect(backend.connection, window.xWindow.Id)
|
||||||
xevent.KeyPressFun(window.handleKeyPress).
|
xevent.KeyPressFun(window.handleKeyPress).
|
||||||
@ -108,6 +111,7 @@ func (window *Window) Adopt (child tomo.Element) {
|
|||||||
})
|
})
|
||||||
window.resizeChildToFit()
|
window.resizeChildToFit()
|
||||||
window.childMinimumSizeChangeCallback(child.MinimumSize())
|
window.childMinimumSizeChangeCallback(child.MinimumSize())
|
||||||
|
window.redrawChildEntirely()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,12 +204,14 @@ func (window *Window) reallocateCanvas () {
|
|||||||
window.metrics.width,
|
window.metrics.width,
|
||||||
window.metrics.height))
|
window.metrics.height))
|
||||||
|
|
||||||
window.xCanvas.XSurfaceSet(window.xWindow.Id)
|
window.xCanvas.CreatePixmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *Window) redrawChildEntirely () {
|
func (window *Window) redrawChildEntirely () {
|
||||||
data, stride := window.child.Buffer()
|
data, stride := window.child.Buffer()
|
||||||
|
bounds := window.child.Bounds()
|
||||||
window.xCanvas.For (func (x, y int) (c xgraphics.BGRA) {
|
window.xCanvas.For (func (x, y int) (c xgraphics.BGRA) {
|
||||||
|
if !(image.Point { x, y }).In(bounds) { return }
|
||||||
rgba := data[x + y * stride]
|
rgba := data[x + y * stride]
|
||||||
c.R, c.G, c.B, c.A = rgba.R, rgba.G, rgba.B, rgba.A
|
c.R, c.G, c.B, c.A = rgba.R, rgba.G, rgba.B, rgba.A
|
||||||
return
|
return
|
||||||
@ -235,13 +241,11 @@ func (window *Window) resizeChildToFit () {
|
|||||||
window.child.Resize (
|
window.child.Resize (
|
||||||
window.metrics.width,
|
window.metrics.width,
|
||||||
window.metrics.height)
|
window.metrics.height)
|
||||||
window.redrawChildEntirely()
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.child.Resize (
|
window.child.Resize (
|
||||||
window.metrics.width,
|
window.metrics.width,
|
||||||
window.metrics.height)
|
window.metrics.height)
|
||||||
window.redrawChildEntirely()
|
|
||||||
}
|
}
|
||||||
window.skipChildDrawCallback = false
|
window.skipChildDrawCallback = false
|
||||||
}
|
}
|
||||||
@ -310,6 +314,9 @@ func (window *Window) pushRegion (region image.Rectangle) {
|
|||||||
image, ok := window.xCanvas.SubImage(region).(*xgraphics.Image)
|
image, ok := window.xCanvas.SubImage(region).(*xgraphics.Image)
|
||||||
if ok {
|
if ok {
|
||||||
image.XDraw()
|
image.XDraw()
|
||||||
window.xCanvas.XPaint(window.xWindow.Id)
|
image.XExpPaint (
|
||||||
|
window.xWindow.Id,
|
||||||
|
image.Bounds().Min.X,
|
||||||
|
image.Bounds().Min.Y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user