hpcu: the slightest cleanup

This commit is contained in:
Přemysl Eric Janouch 2018-11-01 11:38:17 +01:00
parent f99615c850
commit 056391eeca
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 172 additions and 158 deletions

View File

@ -133,18 +133,16 @@ func requestOwnership(origin *selectionState, time xproto.Timestamp) {
} }
} }
func handleEvent(ev nexgb.Event) { func handleXfixesSelectionNotify(e xfixes.SelectionNotifyEvent) {
switch e := ev.(type) {
case xfixes.SelectionNotifyEvent:
state, ok := selections[e.Selection] state, ok := selections[e.Selection]
if !ok { if !ok {
break return
} }
// Ownership request has been granted, don't ask ourselves for data. // Ownership request has been granted, don't ask ourselves for data.
if e.Owner == wid { if e.Owner == wid {
state.owning = e.SelectionTimestamp state.owning = e.SelectionTimestamp
break return
} }
// This should always be true. // This should always be true.
@ -155,7 +153,7 @@ func handleEvent(ev nexgb.Event) {
// Not checking whether we should give up when our current retrieval // Not checking whether we should give up when our current retrieval
// attempt is interrupted--the timeout mostly solves this. // attempt is interrupted--the timeout mostly solves this.
if e.Owner == xproto.WindowNone { if e.Owner == xproto.WindowNone {
break return
} }
// Don't try to process two things at once. Each request gets a few // Don't try to process two things at once. Each request gets a few
@ -163,7 +161,7 @@ func handleEvent(ev nexgb.Event) {
// doesn't commence. Ideally we'd set up a separate queue for these // doesn't commence. Ideally we'd set up a separate queue for these
// skipped requests and process them later. // skipped requests and process them later.
if state.inProgress != 0 && e.Timestamp-state.inProgress < 5000 { if state.inProgress != 0 && e.Timestamp-state.inProgress < 5000 {
break return
} }
// ICCCM says we should ensure the named property doesn't exist. // ICCCM says we should ensure the named property doesn't exist.
@ -174,22 +172,23 @@ func handleEvent(ev nexgb.Event) {
state.inProgress = e.Timestamp state.inProgress = e.Timestamp
state.incr = false state.incr = false
}
case xproto.SelectionNotifyEvent: func handleSelectionNotify(e xproto.SelectionNotifyEvent) {
state, ok := selections[e.Selection] state, ok := selections[e.Selection]
if e.Requestor != wid || !ok || e.Time != state.inProgress { if e.Requestor != wid || !ok || e.Time != state.inProgress {
break return
} }
state.inProgress = 0 state.inProgress = 0
if e.Property == xproto.AtomNone { if e.Property == xproto.AtomNone {
break return
} }
state.buffer = nil state.buffer = nil
reply, err := getProperty(e.Requestor, e.Property) reply, err := getProperty(e.Requestor, e.Property)
if err != nil { if err != nil {
break return
} }
// When you select a lot of text in VIM, it starts the ICCCM // When you select a lot of text in VIM, it starts the ICCCM
@ -203,18 +202,19 @@ func handleEvent(ev nexgb.Event) {
} }
_ = xproto.DeleteProperty(X, e.Requestor, e.Property) _ = xproto.DeleteProperty(X, e.Requestor, e.Property)
}
case xproto.PropertyNotifyEvent: func handlePropertyNotify(e xproto.PropertyNotifyEvent) {
state, ok := selections[e.Atom] state, ok := selections[e.Atom]
if e.Window != wid || e.State != xproto.PropertyNewValue || if e.Window != wid || e.State != xproto.PropertyNewValue ||
!ok || !state.incr { !ok || !state.incr {
break return
} }
reply, err := getProperty(e.Window, e.Atom) reply, err := getProperty(e.Window, e.Atom)
if err != nil { if err != nil {
state.incrFailed = true state.incrFailed = true
break return
} }
if !appendText(state, reply) { if !appendText(state, reply) {
@ -232,7 +232,9 @@ func handleEvent(ev nexgb.Event) {
_ = xproto.DeleteProperty(X, e.Window, e.Atom) _ = xproto.DeleteProperty(X, e.Window, e.Atom)
case xproto.SelectionRequestEvent: }
func handleSelectionRequest(e xproto.SelectionRequestEvent) {
property := e.Property property := e.Property
if property == xproto.AtomNone { if property == xproto.AtomNone {
property = e.Target property = e.Target
@ -240,7 +242,7 @@ func handleEvent(ev nexgb.Event) {
state, ok := selections[e.Selection] state, ok := selections[e.Selection]
if e.Owner != wid || !ok { if e.Owner != wid || !ok {
break return
} }
var ( var (
@ -308,6 +310,18 @@ func handleEvent(ev nexgb.Event) {
_ = xproto.SendEvent(X, false /* propagate */, e.Requestor, _ = xproto.SendEvent(X, false /* propagate */, e.Requestor,
0 /* event mask */, string(response.Bytes())) 0 /* event mask */, string(response.Bytes()))
} }
func handleXEvent(ev nexgb.Event) {
switch e := ev.(type) {
case xfixes.SelectionNotifyEvent:
handleXfixesSelectionNotify(e)
case xproto.SelectionNotifyEvent:
handleSelectionNotify(e)
case xproto.PropertyNotifyEvent:
handlePropertyNotify(e)
case xproto.SelectionRequestEvent:
handleSelectionRequest(e)
}
} }
func main() { func main() {
@ -345,7 +359,7 @@ func main() {
return return
} }
if ev != nil { if ev != nil {
handleEvent(ev) handleXEvent(ev)
} }
} }
} }