diff options
author | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-05-05 18:21:48 -0400 |
---|---|---|
committer | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-05-05 18:21:48 -0400 |
commit | b6715f376f5ea3efb58146c58924dcc7b1536181 (patch) | |
tree | e1213eb0678619a74b1ba57153827d58b645c48a /nexgb/xgbgen/go_event.go | |
parent | 4a7b05be36b96134b4dae3ca385e9bfbb797d531 (diff) | |
download | haven-b6715f376f5ea3efb58146c58924dcc7b1536181.tar.gz haven-b6715f376f5ea3efb58146c58924dcc7b1536181.tar.xz haven-b6715f376f5ea3efb58146c58924dcc7b1536181.zip |
fixing bugs related mostly to extension handling
Diffstat (limited to 'nexgb/xgbgen/go_event.go')
-rw-r--r-- | nexgb/xgbgen/go_event.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nexgb/xgbgen/go_event.go b/nexgb/xgbgen/go_event.go index 41f9320..9bc6dfe 100644 --- a/nexgb/xgbgen/go_event.go +++ b/nexgb/xgbgen/go_event.go @@ -1,5 +1,9 @@ package main +import ( + "fmt" +) + // Event types func (e *Event) Define(c *Context) { c.Putln("// Event definition %s (%d)", e.SrcName(), e.Number) @@ -36,6 +40,10 @@ func (e *Event) Define(c *Context) { } c.Putln("}") c.Putln("") + c.Putln("func (v %s) String() string {", e.EvType()) + EventFieldString(c, e.Fields, e.SrcName()) + c.Putln("}") + c.Putln("") // Let's the XGB event loop read this event. c.Putln("func init() {") @@ -115,6 +123,10 @@ func (e *EventCopy) Define(c *Context) { } c.Putln("}") c.Putln("") + c.Putln("func (v %s) String() string {", e.EvType()) + EventFieldString(c, e.Old.(*Event).Fields, e.SrcName()) + c.Putln("}") + c.Putln("") // Let's the XGB event loop read this event. c.Putln("func init() {") @@ -137,3 +149,42 @@ func (e *EventCopy) Write(c *Context) { c.Putln("}") c.Putln("") } + +// EventFieldString works for both Event and EventCopy. It assembles all of the +// fields in an event and formats them into a single string. +func EventFieldString(c *Context, fields []Field, evName string) { + c.Putln("fieldVals := make([]string, 0, %d)", len(fields)) + if evName != "KeymapNotify" { + c.Putln("fieldVals = append(fieldVals, " + + "sprintf(\"Sequence: %s\", v.Sequence))", "%d") + } + for _, field := range fields { + switch f := field.(type) { + case *PadField: + continue + case *SingleField: + switch f.Type.(type) { + case *Base: + case *Resource: + case *TypeDef: + default: continue + } + + switch field.SrcType() { + case "string": + format := fmt.Sprintf("sprintf(\"%s: %s\", v.%s)", + field.SrcName(), "%s", field.SrcName()) + c.Putln("fieldVals = append(fieldVals, %s)", format) + case "bool": + format := fmt.Sprintf("sprintf(\"%s: %s\", v.%s)", + field.SrcName(), "%t", field.SrcName()) + c.Putln("fieldVals = append(fieldVals, %s)", format) + default: + format := fmt.Sprintf("sprintf(\"%s: %s\", v.%s)", + field.SrcName(), "%d", field.SrcName()) + c.Putln("fieldVals = append(fieldVals, %s)", format) + } + } + } + c.Putln("return \"%s {\" + stringsJoin(fieldVals, \", \") + \"}\"", evName) +} |