id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
2,500 | coreos/fleet | registry/unit_state.go | statesByMUSKey | func (r *EtcdRegistry) statesByMUSKey() (map[MUSKey]*unit.UnitState, error) {
mus := make(map[MUSKey]*unit.UnitState)
key := r.prefixed(statesPrefix)
opts := &etcd.GetOptions{
Recursive: true,
}
res, err := r.kAPI.Get(context.Background(), key, opts)
if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
return nil, err
}
if res != nil {
for _, dir := range res.Node.Nodes {
_, name := path.Split(dir.Key)
for _, node := range dir.Nodes {
_, machID := path.Split(node.Key)
var usm unitStateModel
if err := unmarshal(node.Value, &usm); err != nil {
log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
continue
}
us := modelToUnitState(&usm, name)
if us != nil {
key := MUSKey{name, machID}
mus[key] = us
}
}
}
}
return mus, nil
} | go | func (r *EtcdRegistry) statesByMUSKey() (map[MUSKey]*unit.UnitState, error) {
mus := make(map[MUSKey]*unit.UnitState)
key := r.prefixed(statesPrefix)
opts := &etcd.GetOptions{
Recursive: true,
}
res, err := r.kAPI.Get(context.Background(), key, opts)
if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
return nil, err
}
if res != nil {
for _, dir := range res.Node.Nodes {
_, name := path.Split(dir.Key)
for _, node := range dir.Nodes {
_, machID := path.Split(node.Key)
var usm unitStateModel
if err := unmarshal(node.Value, &usm); err != nil {
log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
continue
}
us := modelToUnitState(&usm, name)
if us != nil {
key := MUSKey{name, machID}
mus[key] = us
}
}
}
}
return mus, nil
} | [
"func",
"(",
"r",
"*",
"EtcdRegistry",
")",
"statesByMUSKey",
"(",
")",
"(",
"map",
"[",
"MUSKey",
"]",
"*",
"unit",
".",
"UnitState",
",",
"error",
")",
"{",
"mus",
":=",
"make",
"(",
"map",
"[",
"MUSKey",
"]",
"*",
"unit",
".",
"UnitState",
")",
... | // statesByMUSKey returns a map of all UnitStates stored in the registry indexed by MUSKey | [
"statesByMUSKey",
"returns",
"a",
"map",
"of",
"all",
"UnitStates",
"stored",
"in",
"the",
"registry",
"indexed",
"by",
"MUSKey"
] | 4522498327e92ffe6fa24eaa087c73e5af4adb53 | https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/unit_state.go#L108-L137 |
2,501 | coreos/fleet | registry/unit_state.go | getUnitState | func (r *EtcdRegistry) getUnitState(uName, machID string) (*unit.UnitState, error) {
key := r.unitStatePath(machID, uName)
res, err := r.kAPI.Get(context.Background(), key, nil)
if err != nil {
if isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
err = nil
}
return nil, err
}
var usm unitStateModel
if err := unmarshal(res.Node.Value, &usm); err != nil {
return nil, err
}
return modelToUnitState(&usm, uName), nil
} | go | func (r *EtcdRegistry) getUnitState(uName, machID string) (*unit.UnitState, error) {
key := r.unitStatePath(machID, uName)
res, err := r.kAPI.Get(context.Background(), key, nil)
if err != nil {
if isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
err = nil
}
return nil, err
}
var usm unitStateModel
if err := unmarshal(res.Node.Value, &usm); err != nil {
return nil, err
}
return modelToUnitState(&usm, uName), nil
} | [
"func",
"(",
"r",
"*",
"EtcdRegistry",
")",
"getUnitState",
"(",
"uName",
",",
"machID",
"string",
")",
"(",
"*",
"unit",
".",
"UnitState",
",",
"error",
")",
"{",
"key",
":=",
"r",
".",
"unitStatePath",
"(",
"machID",
",",
"uName",
")",
"\n",
"res",... | // getUnitState retrieves the current UnitState, if any exists, for the
// given unit that originates from the indicated machine | [
"getUnitState",
"retrieves",
"the",
"current",
"UnitState",
"if",
"any",
"exists",
"for",
"the",
"given",
"unit",
"that",
"originates",
"from",
"the",
"indicated",
"machine"
] | 4522498327e92ffe6fa24eaa087c73e5af4adb53 | https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/unit_state.go#L177-L193 |
2,502 | coreos/fleet | registry/unit_state.go | SaveUnitState | func (r *EtcdRegistry) SaveUnitState(jobName string, unitState *unit.UnitState, ttl time.Duration) {
usm := unitStateToModel(unitState)
if usm == nil {
log.Errorf("Unable to save nil UnitState model")
return
}
val, err := marshal(usm)
if err != nil {
log.Errorf("Error marshalling UnitState: %v", err)
return
}
opts := &etcd.SetOptions{
TTL: ttl,
}
legacyKey := r.legacyUnitStatePath(jobName)
r.kAPI.Set(context.Background(), legacyKey, val, opts)
newKey := r.unitStatePath(unitState.MachineID, jobName)
r.kAPI.Set(context.Background(), newKey, val, opts)
} | go | func (r *EtcdRegistry) SaveUnitState(jobName string, unitState *unit.UnitState, ttl time.Duration) {
usm := unitStateToModel(unitState)
if usm == nil {
log.Errorf("Unable to save nil UnitState model")
return
}
val, err := marshal(usm)
if err != nil {
log.Errorf("Error marshalling UnitState: %v", err)
return
}
opts := &etcd.SetOptions{
TTL: ttl,
}
legacyKey := r.legacyUnitStatePath(jobName)
r.kAPI.Set(context.Background(), legacyKey, val, opts)
newKey := r.unitStatePath(unitState.MachineID, jobName)
r.kAPI.Set(context.Background(), newKey, val, opts)
} | [
"func",
"(",
"r",
"*",
"EtcdRegistry",
")",
"SaveUnitState",
"(",
"jobName",
"string",
",",
"unitState",
"*",
"unit",
".",
"UnitState",
",",
"ttl",
"time",
".",
"Duration",
")",
"{",
"usm",
":=",
"unitStateToModel",
"(",
"unitState",
")",
"\n",
"if",
"us... | // SaveUnitState persists the given UnitState to the Registry | [
"SaveUnitState",
"persists",
"the",
"given",
"UnitState",
"to",
"the",
"Registry"
] | 4522498327e92ffe6fa24eaa087c73e5af4adb53 | https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/unit_state.go#L196-L218 |
2,503 | coreos/fleet | registry/unit_state.go | RemoveUnitState | func (r *EtcdRegistry) RemoveUnitState(jobName string) error {
// TODO(jonboulle): consider https://github.com/coreos/fleet/issues/465
legacyKey := r.legacyUnitStatePath(jobName)
_, err := r.kAPI.Delete(context.Background(), legacyKey, nil)
if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
return err
}
// TODO(jonboulle): deal properly with multiple states
newKey := r.unitStatesNamespace(jobName)
opts := &etcd.DeleteOptions{
Recursive: true,
}
_, err = r.kAPI.Delete(context.Background(), newKey, opts)
if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
return err
}
return nil
} | go | func (r *EtcdRegistry) RemoveUnitState(jobName string) error {
// TODO(jonboulle): consider https://github.com/coreos/fleet/issues/465
legacyKey := r.legacyUnitStatePath(jobName)
_, err := r.kAPI.Delete(context.Background(), legacyKey, nil)
if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
return err
}
// TODO(jonboulle): deal properly with multiple states
newKey := r.unitStatesNamespace(jobName)
opts := &etcd.DeleteOptions{
Recursive: true,
}
_, err = r.kAPI.Delete(context.Background(), newKey, opts)
if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"EtcdRegistry",
")",
"RemoveUnitState",
"(",
"jobName",
"string",
")",
"error",
"{",
"// TODO(jonboulle): consider https://github.com/coreos/fleet/issues/465",
"legacyKey",
":=",
"r",
".",
"legacyUnitStatePath",
"(",
"jobName",
")",
"\n",
"_",
"... | // Delete the state from the Registry for the given Job's Unit | [
"Delete",
"the",
"state",
"from",
"the",
"Registry",
"for",
"the",
"given",
"Job",
"s",
"Unit"
] | 4522498327e92ffe6fa24eaa087c73e5af4adb53 | https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/unit_state.go#L221-L239 |
2,504 | go-chi/render | content_type.go | SetContentType | func SetContentType(contentType ContentType) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
r = r.WithContext(context.WithValue(r.Context(), ContentTypeCtxKey, contentType))
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
} | go | func SetContentType(contentType ContentType) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
r = r.WithContext(context.WithValue(r.Context(), ContentTypeCtxKey, contentType))
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
} | [
"func",
"SetContentType",
"(",
"contentType",
"ContentType",
")",
"func",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"func",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"fn",
":=",
"func",
... | // SetContentType is a middleware that forces response Content-Type. | [
"SetContentType",
"is",
"a",
"middleware",
"that",
"forces",
"response",
"Content",
"-",
"Type",
"."
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/content_type.go#L48-L56 |
2,505 | go-chi/render | content_type.go | GetRequestContentType | func GetRequestContentType(r *http.Request) ContentType {
if contentType, ok := r.Context().Value(ContentTypeCtxKey).(ContentType); ok {
return contentType
}
return GetContentType(r.Header.Get("Content-Type"))
} | go | func GetRequestContentType(r *http.Request) ContentType {
if contentType, ok := r.Context().Value(ContentTypeCtxKey).(ContentType); ok {
return contentType
}
return GetContentType(r.Header.Get("Content-Type"))
} | [
"func",
"GetRequestContentType",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"ContentType",
"{",
"if",
"contentType",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ContentTypeCtxKey",
")",
".",
"(",
"ContentType",
")",
";",
"ok",
... | // GetRequestContentType is a helper function that returns ContentType based on
// context or request headers. | [
"GetRequestContentType",
"is",
"a",
"helper",
"function",
"that",
"returns",
"ContentType",
"based",
"on",
"context",
"or",
"request",
"headers",
"."
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/content_type.go#L60-L65 |
2,506 | go-chi/render | responder.go | Status | func Status(r *http.Request, status int) {
*r = *r.WithContext(context.WithValue(r.Context(), StatusCtxKey, status))
} | go | func Status(r *http.Request, status int) {
*r = *r.WithContext(context.WithValue(r.Context(), StatusCtxKey, status))
} | [
"func",
"Status",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"status",
"int",
")",
"{",
"*",
"r",
"=",
"*",
"r",
".",
"WithContext",
"(",
"context",
".",
"WithValue",
"(",
"r",
".",
"Context",
"(",
")",
",",
"StatusCtxKey",
",",
"status",
")",
"... | // Status sets a HTTP response status code hint into request context at any point
// during the request life-cycle. Before the Responder sends its response header
// it will check the StatusCtxKey | [
"Status",
"sets",
"a",
"HTTP",
"response",
"status",
"code",
"hint",
"into",
"request",
"context",
"at",
"any",
"point",
"during",
"the",
"request",
"life",
"-",
"cycle",
".",
"Before",
"the",
"Responder",
"sends",
"its",
"response",
"header",
"it",
"will",
... | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/responder.go#L31-L33 |
2,507 | go-chi/render | responder.go | DefaultResponder | func DefaultResponder(w http.ResponseWriter, r *http.Request, v interface{}) {
if v != nil {
switch reflect.TypeOf(v).Kind() {
case reflect.Chan:
switch GetAcceptedContentType(r) {
case ContentTypeEventStream:
channelEventStream(w, r, v)
return
default:
v = channelIntoSlice(w, r, v)
}
}
}
// Format response based on request Accept header.
switch GetAcceptedContentType(r) {
case ContentTypeJSON:
JSON(w, r, v)
case ContentTypeXML:
XML(w, r, v)
default:
JSON(w, r, v)
}
} | go | func DefaultResponder(w http.ResponseWriter, r *http.Request, v interface{}) {
if v != nil {
switch reflect.TypeOf(v).Kind() {
case reflect.Chan:
switch GetAcceptedContentType(r) {
case ContentTypeEventStream:
channelEventStream(w, r, v)
return
default:
v = channelIntoSlice(w, r, v)
}
}
}
// Format response based on request Accept header.
switch GetAcceptedContentType(r) {
case ContentTypeJSON:
JSON(w, r, v)
case ContentTypeXML:
XML(w, r, v)
default:
JSON(w, r, v)
}
} | [
"func",
"DefaultResponder",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"interface",
"{",
"}",
")",
"{",
"if",
"v",
"!=",
"nil",
"{",
"switch",
"reflect",
".",
"TypeOf",
"(",
"v",
")",
".",
"Kind",
"(",... | // Respond handles streaming JSON and XML responses, automatically setting the
// Content-Type based on request headers. It will default to a JSON response. | [
"Respond",
"handles",
"streaming",
"JSON",
"and",
"XML",
"responses",
"automatically",
"setting",
"the",
"Content",
"-",
"Type",
"based",
"on",
"request",
"headers",
".",
"It",
"will",
"default",
"to",
"a",
"JSON",
"response",
"."
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/responder.go#L37-L60 |
2,508 | go-chi/render | responder.go | channelIntoSlice | func channelIntoSlice(w http.ResponseWriter, r *http.Request, from interface{}) interface{} {
ctx := r.Context()
var to []interface{}
for {
switch chosen, recv, ok := reflect.Select([]reflect.SelectCase{
{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(ctx.Done())},
{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(from)},
}); chosen {
case 0: // equivalent to: case <-ctx.Done()
http.Error(w, "Server Timeout", 504)
return nil
default: // equivalent to: case v, ok := <-stream
if !ok {
return to
}
v := recv.Interface()
// Render each channel item.
if rv, ok := v.(Renderer); ok {
err := renderer(w, r, rv)
if err != nil {
v = err
} else {
v = rv
}
}
to = append(to, v)
}
}
} | go | func channelIntoSlice(w http.ResponseWriter, r *http.Request, from interface{}) interface{} {
ctx := r.Context()
var to []interface{}
for {
switch chosen, recv, ok := reflect.Select([]reflect.SelectCase{
{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(ctx.Done())},
{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(from)},
}); chosen {
case 0: // equivalent to: case <-ctx.Done()
http.Error(w, "Server Timeout", 504)
return nil
default: // equivalent to: case v, ok := <-stream
if !ok {
return to
}
v := recv.Interface()
// Render each channel item.
if rv, ok := v.(Renderer); ok {
err := renderer(w, r, rv)
if err != nil {
v = err
} else {
v = rv
}
}
to = append(to, v)
}
}
} | [
"func",
"channelIntoSlice",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"from",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n\n",
"var",
"to",
"[",
"... | // channelIntoSlice buffers channel data into a slice. | [
"channelIntoSlice",
"buffers",
"channel",
"data",
"into",
"a",
"slice",
"."
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/responder.go#L202-L234 |
2,509 | go-chi/render | render.go | Bind | func Bind(r *http.Request, v Binder) error {
if err := Decode(r, v); err != nil {
return err
}
return binder(r, v)
} | go | func Bind(r *http.Request, v Binder) error {
if err := Decode(r, v); err != nil {
return err
}
return binder(r, v)
} | [
"func",
"Bind",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"Binder",
")",
"error",
"{",
"if",
"err",
":=",
"Decode",
"(",
"r",
",",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"binder",
"(",
"r",
... | // Bind decodes a request body and executes the Binder method of the
// payload structure. | [
"Bind",
"decodes",
"a",
"request",
"body",
"and",
"executes",
"the",
"Binder",
"method",
"of",
"the",
"payload",
"structure",
"."
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/render.go#L20-L25 |
2,510 | go-chi/render | render.go | Render | func Render(w http.ResponseWriter, r *http.Request, v Renderer) error {
if err := renderer(w, r, v); err != nil {
return err
}
Respond(w, r, v)
return nil
} | go | func Render(w http.ResponseWriter, r *http.Request, v Renderer) error {
if err := renderer(w, r, v); err != nil {
return err
}
Respond(w, r, v)
return nil
} | [
"func",
"Render",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"Renderer",
")",
"error",
"{",
"if",
"err",
":=",
"renderer",
"(",
"w",
",",
"r",
",",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
... | // Render renders a single payload and respond to the client request. | [
"Render",
"renders",
"a",
"single",
"payload",
"and",
"respond",
"to",
"the",
"client",
"request",
"."
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/render.go#L28-L34 |
2,511 | go-chi/render | render.go | RenderList | func RenderList(w http.ResponseWriter, r *http.Request, l []Renderer) error {
for _, v := range l {
if err := renderer(w, r, v); err != nil {
return err
}
}
Respond(w, r, l)
return nil
} | go | func RenderList(w http.ResponseWriter, r *http.Request, l []Renderer) error {
for _, v := range l {
if err := renderer(w, r, v); err != nil {
return err
}
}
Respond(w, r, l)
return nil
} | [
"func",
"RenderList",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"l",
"[",
"]",
"Renderer",
")",
"error",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"l",
"{",
"if",
"err",
":=",
"renderer",
"(",
"w",
",",
... | // RenderList renders a slice of payloads and responds to the client request. | [
"RenderList",
"renders",
"a",
"slice",
"of",
"payloads",
"and",
"responds",
"to",
"the",
"client",
"request",
"."
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/render.go#L37-L45 |
2,512 | go-chi/render | render.go | renderer | func renderer(w http.ResponseWriter, r *http.Request, v Renderer) error {
rv := reflect.ValueOf(v)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
// We call it top-down.
if err := v.Render(w, r); err != nil {
return err
}
// We're done if the Renderer isn't a struct object
if rv.Kind() != reflect.Struct {
return nil
}
// For structs, we call Render on each field that implements Renderer
for i := 0; i < rv.NumField(); i++ {
f := rv.Field(i)
if f.Type().Implements(rendererType) {
if isNil(f) {
continue
}
fv := f.Interface().(Renderer)
if err := renderer(w, r, fv); err != nil {
return err
}
}
}
return nil
} | go | func renderer(w http.ResponseWriter, r *http.Request, v Renderer) error {
rv := reflect.ValueOf(v)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
// We call it top-down.
if err := v.Render(w, r); err != nil {
return err
}
// We're done if the Renderer isn't a struct object
if rv.Kind() != reflect.Struct {
return nil
}
// For structs, we call Render on each field that implements Renderer
for i := 0; i < rv.NumField(); i++ {
f := rv.Field(i)
if f.Type().Implements(rendererType) {
if isNil(f) {
continue
}
fv := f.Interface().(Renderer)
if err := renderer(w, r, fv); err != nil {
return err
}
}
}
return nil
} | [
"func",
"renderer",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"Renderer",
")",
"error",
"{",
"rv",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"rv",
".",
"Kind",
"(",
")",
"==",
"ref... | // Executed top-down | [
"Executed",
"top",
"-",
"down"
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/render.go#L57-L91 |
2,513 | go-chi/render | render.go | binder | func binder(r *http.Request, v Binder) error {
rv := reflect.ValueOf(v)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
// Call Binder on non-struct types right away
if rv.Kind() != reflect.Struct {
return v.Bind(r)
}
// For structs, we call Bind on each field that implements Binder
for i := 0; i < rv.NumField(); i++ {
f := rv.Field(i)
if f.Type().Implements(binderType) {
if isNil(f) {
continue
}
fv := f.Interface().(Binder)
if err := binder(r, fv); err != nil {
return err
}
}
}
// We call it bottom-up
if err := v.Bind(r); err != nil {
return err
}
return nil
} | go | func binder(r *http.Request, v Binder) error {
rv := reflect.ValueOf(v)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
// Call Binder on non-struct types right away
if rv.Kind() != reflect.Struct {
return v.Bind(r)
}
// For structs, we call Bind on each field that implements Binder
for i := 0; i < rv.NumField(); i++ {
f := rv.Field(i)
if f.Type().Implements(binderType) {
if isNil(f) {
continue
}
fv := f.Interface().(Binder)
if err := binder(r, fv); err != nil {
return err
}
}
}
// We call it bottom-up
if err := v.Bind(r); err != nil {
return err
}
return nil
} | [
"func",
"binder",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"Binder",
")",
"error",
"{",
"rv",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"rv",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"rv",
"=",
"rv",
... | // Executed bottom-up | [
"Executed",
"bottom",
"-",
"up"
] | 3215478343fbc559bd3fc08f7031bb134d6bdad5 | https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/render.go#L94-L127 |
2,514 | BurntSushi/xgbutil | xgbutil.go | ExtInitialized | func (xu *XUtil) ExtInitialized(extName string) bool {
_, ok := xu.Conn().Extensions[extName]
return ok
} | go | func (xu *XUtil) ExtInitialized(extName string) bool {
_, ok := xu.Conn().Extensions[extName]
return ok
} | [
"func",
"(",
"xu",
"*",
"XUtil",
")",
"ExtInitialized",
"(",
"extName",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"xu",
".",
"Conn",
"(",
")",
".",
"Extensions",
"[",
"extName",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // ExtInitialized returns true if an extension has been initialized.
// This is useful for determining whether an extension is available or not. | [
"ExtInitialized",
"returns",
"true",
"if",
"an",
"extension",
"has",
"been",
"initialized",
".",
"This",
"is",
"useful",
"for",
"determining",
"whether",
"an",
"extension",
"is",
"available",
"or",
"not",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgbutil.go#L285-L288 |
2,515 | BurntSushi/xgbutil | xgraphics/new.go | NewFileName | func NewFileName(X *xgbutil.XUtil, fileName string) (*Image, error) {
srcReader, err := os.Open(fileName)
if err != nil {
return nil, err
}
defer srcReader.Close()
img, _, err := image.Decode(srcReader)
if err != nil {
return nil, err
}
return NewConvert(X, img), nil
} | go | func NewFileName(X *xgbutil.XUtil, fileName string) (*Image, error) {
srcReader, err := os.Open(fileName)
if err != nil {
return nil, err
}
defer srcReader.Close()
img, _, err := image.Decode(srcReader)
if err != nil {
return nil, err
}
return NewConvert(X, img), nil
} | [
"func",
"NewFileName",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"fileName",
"string",
")",
"(",
"*",
"Image",
",",
"error",
")",
"{",
"srcReader",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // NewFileName uses the image package's decoder and converts a file specified
// by fileName to an xgraphics.Image value.
// Opening a file or decoding an image can cause an error. | [
"NewFileName",
"uses",
"the",
"image",
"package",
"s",
"decoder",
"and",
"converts",
"a",
"file",
"specified",
"by",
"fileName",
"to",
"an",
"xgraphics",
".",
"Image",
"value",
".",
"Opening",
"a",
"file",
"or",
"decoding",
"an",
"image",
"can",
"cause",
"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/new.go#L64-L76 |
2,516 | BurntSushi/xgbutil | xgraphics/new.go | NewBytes | func NewBytes(X *xgbutil.XUtil, bs []byte) (*Image, error) {
img, _, err := image.Decode(bytes.NewReader(bs))
if err != nil {
return nil, err
}
return NewConvert(X, img), nil
} | go | func NewBytes(X *xgbutil.XUtil, bs []byte) (*Image, error) {
img, _, err := image.Decode(bytes.NewReader(bs))
if err != nil {
return nil, err
}
return NewConvert(X, img), nil
} | [
"func",
"NewBytes",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"bs",
"[",
"]",
"byte",
")",
"(",
"*",
"Image",
",",
"error",
")",
"{",
"img",
",",
"_",
",",
"err",
":=",
"image",
".",
"Decode",
"(",
"bytes",
".",
"NewReader",
"(",
"bs",
")",
... | // NewBytes uses the image package's decoder to convert the bytes given to
// an xgraphics.Imag value.
// Decoding an image can cause an error. | [
"NewBytes",
"uses",
"the",
"image",
"package",
"s",
"decoder",
"to",
"convert",
"the",
"bytes",
"given",
"to",
"an",
"xgraphics",
".",
"Imag",
"value",
".",
"Decoding",
"an",
"image",
"can",
"cause",
"an",
"error",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/new.go#L81-L87 |
2,517 | BurntSushi/xgbutil | xgraphics/new.go | NewDrawable | func NewDrawable(X *xgbutil.XUtil, did xproto.Drawable) (*Image, error) {
// Get the geometry of the pixmap for use in the GetImage request.
pgeom, err := xwindow.RawGeometry(X, xproto.Drawable(did))
if err != nil {
return nil, err
}
// Get the image data for each pixmap.
pixmapData, err := xproto.GetImage(X.Conn(), xproto.ImageFormatZPixmap,
did,
0, 0, uint16(pgeom.Width()), uint16(pgeom.Height()),
(1<<32)-1).Reply()
if err != nil {
return nil, err
}
// Now create the xgraphics.Image and populate it with data from
// pixmapData and maskData.
ximg := New(X, image.Rect(0, 0, pgeom.Width(), pgeom.Height()))
// We'll try to be a little flexible with the image format returned,
// but not completely flexible.
err = readDrawableData(X, ximg, did, pixmapData,
pgeom.Width(), pgeom.Height())
if err != nil {
return nil, err
}
return ximg, nil
} | go | func NewDrawable(X *xgbutil.XUtil, did xproto.Drawable) (*Image, error) {
// Get the geometry of the pixmap for use in the GetImage request.
pgeom, err := xwindow.RawGeometry(X, xproto.Drawable(did))
if err != nil {
return nil, err
}
// Get the image data for each pixmap.
pixmapData, err := xproto.GetImage(X.Conn(), xproto.ImageFormatZPixmap,
did,
0, 0, uint16(pgeom.Width()), uint16(pgeom.Height()),
(1<<32)-1).Reply()
if err != nil {
return nil, err
}
// Now create the xgraphics.Image and populate it with data from
// pixmapData and maskData.
ximg := New(X, image.Rect(0, 0, pgeom.Width(), pgeom.Height()))
// We'll try to be a little flexible with the image format returned,
// but not completely flexible.
err = readDrawableData(X, ximg, did, pixmapData,
pgeom.Width(), pgeom.Height())
if err != nil {
return nil, err
}
return ximg, nil
} | [
"func",
"NewDrawable",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"did",
"xproto",
".",
"Drawable",
")",
"(",
"*",
"Image",
",",
"error",
")",
"{",
"// Get the geometry of the pixmap for use in the GetImage request.",
"pgeom",
",",
"err",
":=",
"xwindow",
".",... | // NewDrawable converts an X drawable into a xgraphics.Image.
// This is used in NewIcccmIcon. | [
"NewDrawable",
"converts",
"an",
"X",
"drawable",
"into",
"a",
"xgraphics",
".",
"Image",
".",
"This",
"is",
"used",
"in",
"NewIcccmIcon",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/new.go#L175-L204 |
2,518 | BurntSushi/xgbutil | xgraphics/new.go | GetFormat | func GetFormat(X *xgbutil.XUtil, depth byte) *xproto.Format {
for _, pixForm := range X.Setup().PixmapFormats {
if pixForm.Depth == depth {
return &pixForm
}
}
return nil
} | go | func GetFormat(X *xgbutil.XUtil, depth byte) *xproto.Format {
for _, pixForm := range X.Setup().PixmapFormats {
if pixForm.Depth == depth {
return &pixForm
}
}
return nil
} | [
"func",
"GetFormat",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"depth",
"byte",
")",
"*",
"xproto",
".",
"Format",
"{",
"for",
"_",
",",
"pixForm",
":=",
"range",
"X",
".",
"Setup",
"(",
")",
".",
"PixmapFormats",
"{",
"if",
"pixForm",
".",
"Dep... | // GetFormat searches SetupInfo for a Format matching the depth provided. | [
"GetFormat",
"searches",
"SetupInfo",
"for",
"a",
"Format",
"matching",
"the",
"depth",
"provided",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/new.go#L291-L298 |
2,519 | BurntSushi/xgbutil | xgraphics/xsurface.go | XExpPaint | func (im *Image) XExpPaint(wid xproto.Window, x, y int) {
if im.Pixmap == 0 {
return
}
xproto.CopyArea(im.X.Conn(),
xproto.Drawable(im.Pixmap), xproto.Drawable(wid), im.X.GC(),
int16(im.Rect.Min.X), int16(im.Rect.Min.Y),
int16(x), int16(y),
uint16(im.Rect.Dx()), uint16(im.Rect.Dy()))
} | go | func (im *Image) XExpPaint(wid xproto.Window, x, y int) {
if im.Pixmap == 0 {
return
}
xproto.CopyArea(im.X.Conn(),
xproto.Drawable(im.Pixmap), xproto.Drawable(wid), im.X.GC(),
int16(im.Rect.Min.X), int16(im.Rect.Min.Y),
int16(x), int16(y),
uint16(im.Rect.Dx()), uint16(im.Rect.Dy()))
} | [
"func",
"(",
"im",
"*",
"Image",
")",
"XExpPaint",
"(",
"wid",
"xproto",
".",
"Window",
",",
"x",
",",
"y",
"int",
")",
"{",
"if",
"im",
".",
"Pixmap",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"xproto",
".",
"CopyArea",
"(",
"im",
".",
"X",
... | // XExpPaint achieves a similar result as XPaint and XSurfaceSet, but
// uses CopyArea instead of setting a background pixmap and using ClearArea.
// CreatePixmap must be called before using XExpPaint.
// XExpPaint can be called on sub-images.
// x and y correspond to the destination x and y to copy the image to.
//
// This should not be used on the same image with XSurfaceSet and XPaint. | [
"XExpPaint",
"achieves",
"a",
"similar",
"result",
"as",
"XPaint",
"and",
"XSurfaceSet",
"but",
"uses",
"CopyArea",
"instead",
"of",
"setting",
"a",
"background",
"pixmap",
"and",
"using",
"ClearArea",
".",
"CreatePixmap",
"must",
"be",
"called",
"before",
"usin... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/xsurface.go#L95-L104 |
2,520 | BurntSushi/xgbutil | xgraphics/xsurface.go | XPaintRects | func (im *Image) XPaintRects(wid xproto.Window, rects ...image.Rectangle) {
for _, rect := range rects {
if si := im.SubImage(rect).(*Image); si != nil {
si.XDraw()
}
}
im.XPaint(wid)
} | go | func (im *Image) XPaintRects(wid xproto.Window, rects ...image.Rectangle) {
for _, rect := range rects {
if si := im.SubImage(rect).(*Image); si != nil {
si.XDraw()
}
}
im.XPaint(wid)
} | [
"func",
"(",
"im",
"*",
"Image",
")",
"XPaintRects",
"(",
"wid",
"xproto",
".",
"Window",
",",
"rects",
"...",
"image",
".",
"Rectangle",
")",
"{",
"for",
"_",
",",
"rect",
":=",
"range",
"rects",
"{",
"if",
"si",
":=",
"im",
".",
"SubImage",
"(",
... | // XPaintRects is a convenience function for issuing XDraw requests on
// each sub-image generated by the rects in the slice provided, and then
// painting the updated pixmap all at once to the window provided.
// This is efficient because no pixels are copied when taking a SubImage,
// and each XDraw call on a sub-image updates the pixels represented by that
// sub-image and only that sub-image. | [
"XPaintRects",
"is",
"a",
"convenience",
"function",
"for",
"issuing",
"XDraw",
"requests",
"on",
"each",
"sub",
"-",
"image",
"generated",
"by",
"the",
"rects",
"in",
"the",
"slice",
"provided",
"and",
"then",
"painting",
"the",
"updated",
"pixmap",
"all",
... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/xsurface.go#L112-L119 |
2,521 | BurntSushi/xgbutil | xgraphics/xsurface.go | XShowExtra | func (im *Image) XShowExtra(name string, quit bool) *xwindow.Window {
if len(name) == 0 {
name = "xgbutil Image Window"
}
w, h := im.Rect.Dx(), im.Rect.Dy()
win, err := xwindow.Generate(im.X)
if err != nil {
xgbutil.Logger.Printf("Could not generate new window id: %s", err)
return nil
}
// Create a very simple window with dimensions equal to the image.
win.Create(im.X.RootWin(), 0, 0, w, h, 0)
// Make this window close gracefully.
win.WMGracefulClose(func(w *xwindow.Window) {
xevent.Detach(w.X, w.Id)
keybind.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
if quit {
xevent.Quit(w.X)
}
})
// Set WM_STATE so it is interpreted as a top-level window.
err = icccm.WmStateSet(im.X, win.Id, &icccm.WmState{
State: icccm.StateNormal,
})
if err != nil { // not a fatal error
xgbutil.Logger.Printf("Could not set WM_STATE: %s", err)
}
// Set WM_NORMAL_HINTS so the window can't be resized.
err = icccm.WmNormalHintsSet(im.X, win.Id, &icccm.NormalHints{
Flags: icccm.SizeHintPMinSize | icccm.SizeHintPMaxSize,
MinWidth: uint(w),
MinHeight: uint(h),
MaxWidth: uint(w),
MaxHeight: uint(h),
})
if err != nil { // not a fatal error
xgbutil.Logger.Printf("Could not set WM_NORMAL_HINTS: %s", err)
}
// Set _NET_WM_NAME so it looks nice.
err = ewmh.WmNameSet(im.X, win.Id, name)
if err != nil { // not a fatal error
xgbutil.Logger.Printf("Could not set _NET_WM_NAME: %s", err)
}
// Paint our image before mapping.
im.XSurfaceSet(win.Id)
im.XDraw()
im.XPaint(win.Id)
// Now we can map, since we've set all our properties.
// (The initial map is when the window manager starts managing.)
win.Map()
return win
} | go | func (im *Image) XShowExtra(name string, quit bool) *xwindow.Window {
if len(name) == 0 {
name = "xgbutil Image Window"
}
w, h := im.Rect.Dx(), im.Rect.Dy()
win, err := xwindow.Generate(im.X)
if err != nil {
xgbutil.Logger.Printf("Could not generate new window id: %s", err)
return nil
}
// Create a very simple window with dimensions equal to the image.
win.Create(im.X.RootWin(), 0, 0, w, h, 0)
// Make this window close gracefully.
win.WMGracefulClose(func(w *xwindow.Window) {
xevent.Detach(w.X, w.Id)
keybind.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
if quit {
xevent.Quit(w.X)
}
})
// Set WM_STATE so it is interpreted as a top-level window.
err = icccm.WmStateSet(im.X, win.Id, &icccm.WmState{
State: icccm.StateNormal,
})
if err != nil { // not a fatal error
xgbutil.Logger.Printf("Could not set WM_STATE: %s", err)
}
// Set WM_NORMAL_HINTS so the window can't be resized.
err = icccm.WmNormalHintsSet(im.X, win.Id, &icccm.NormalHints{
Flags: icccm.SizeHintPMinSize | icccm.SizeHintPMaxSize,
MinWidth: uint(w),
MinHeight: uint(h),
MaxWidth: uint(w),
MaxHeight: uint(h),
})
if err != nil { // not a fatal error
xgbutil.Logger.Printf("Could not set WM_NORMAL_HINTS: %s", err)
}
// Set _NET_WM_NAME so it looks nice.
err = ewmh.WmNameSet(im.X, win.Id, name)
if err != nil { // not a fatal error
xgbutil.Logger.Printf("Could not set _NET_WM_NAME: %s", err)
}
// Paint our image before mapping.
im.XSurfaceSet(win.Id)
im.XDraw()
im.XPaint(win.Id)
// Now we can map, since we've set all our properties.
// (The initial map is when the window manager starts managing.)
win.Map()
return win
} | [
"func",
"(",
"im",
"*",
"Image",
")",
"XShowExtra",
"(",
"name",
"string",
",",
"quit",
"bool",
")",
"*",
"xwindow",
".",
"Window",
"{",
"if",
"len",
"(",
"name",
")",
"==",
"0",
"{",
"name",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"w",
",",
"h",
"... | // XShowName is just like XShow, except it sets the name of the window to the
// name provided, and will quit the current event loop if 'quit' is true when
// the window is closed.
// If name is empty and quit is false, then the behavior is precisely the same
// as XShow. | [
"XShowName",
"is",
"just",
"like",
"XShow",
"except",
"it",
"sets",
"the",
"name",
"of",
"the",
"window",
"to",
"the",
"name",
"provided",
"and",
"will",
"quit",
"the",
"current",
"event",
"loop",
"if",
"quit",
"is",
"true",
"when",
"the",
"window",
"is"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/xsurface.go#L230-L293 |
2,522 | BurntSushi/xgbutil | _examples/graceful-window-close/main.go | newWindow | func newWindow(X *xgbutil.XUtil) {
counter++
win, err := xwindow.Generate(X)
if err != nil {
log.Fatal(err)
}
// Get a random background color, create the window (ask to receive button
// release events while we're at it) and map the window.
bgColor := rand.Intn(0xffffff + 1)
win.Create(X.RootWin(), 0, 0, 200, 200,
xproto.CwBackPixel|xproto.CwEventMask,
uint32(bgColor), xproto.EventMaskButtonRelease)
// WMGracefulClose does all of the work for us. It sets the appropriate
// values for WM_PROTOCOLS, and listens for ClientMessages that implement
// the WM_DELETE_WINDOW protocol. When one is found, the provided callback
// is executed.
win.WMGracefulClose(
func(w *xwindow.Window) {
// Detach all event handlers.
// This should always be done when a window can no longer
// receive events.
xevent.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
// Exit if there are no more windows left.
counter--
if counter == 0 {
os.Exit(0)
}
})
// It's important that the map comes after setting WMGracefulClose, since
// the WM isn't obliged to watch updates to the WM_PROTOCOLS property.
win.Map()
// A mouse binding so that a left click will spawn a new window.
// Note that we don't issue a grab here. Typically, window managers will
// grab a button press on the client window (which usually activates the
// window), so that we'd end up competing with the window manager if we
// tried to grab it.
// Instead, we set a ButtonRelease mask when creating the window and attach
// a mouse binding *without* a grab.
err = mousebind.ButtonReleaseFun(
func(X *xgbutil.XUtil, ev xevent.ButtonReleaseEvent) {
newWindow(X)
}).Connect(X, win.Id, "1", false, false)
if err != nil {
log.Fatal(err)
}
} | go | func newWindow(X *xgbutil.XUtil) {
counter++
win, err := xwindow.Generate(X)
if err != nil {
log.Fatal(err)
}
// Get a random background color, create the window (ask to receive button
// release events while we're at it) and map the window.
bgColor := rand.Intn(0xffffff + 1)
win.Create(X.RootWin(), 0, 0, 200, 200,
xproto.CwBackPixel|xproto.CwEventMask,
uint32(bgColor), xproto.EventMaskButtonRelease)
// WMGracefulClose does all of the work for us. It sets the appropriate
// values for WM_PROTOCOLS, and listens for ClientMessages that implement
// the WM_DELETE_WINDOW protocol. When one is found, the provided callback
// is executed.
win.WMGracefulClose(
func(w *xwindow.Window) {
// Detach all event handlers.
// This should always be done when a window can no longer
// receive events.
xevent.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
// Exit if there are no more windows left.
counter--
if counter == 0 {
os.Exit(0)
}
})
// It's important that the map comes after setting WMGracefulClose, since
// the WM isn't obliged to watch updates to the WM_PROTOCOLS property.
win.Map()
// A mouse binding so that a left click will spawn a new window.
// Note that we don't issue a grab here. Typically, window managers will
// grab a button press on the client window (which usually activates the
// window), so that we'd end up competing with the window manager if we
// tried to grab it.
// Instead, we set a ButtonRelease mask when creating the window and attach
// a mouse binding *without* a grab.
err = mousebind.ButtonReleaseFun(
func(X *xgbutil.XUtil, ev xevent.ButtonReleaseEvent) {
newWindow(X)
}).Connect(X, win.Id, "1", false, false)
if err != nil {
log.Fatal(err)
}
} | [
"func",
"newWindow",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
")",
"{",
"counter",
"++",
"\n",
"win",
",",
"err",
":=",
"xwindow",
".",
"Generate",
"(",
"X",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"... | // newWindow creates a new window with a random background color. It sets the
// WM_PROTOCOLS property to contain the WM_DELETE_WINDOW atom. It also sets
// up a ClientMessage event handler so that we know when to destroy the window.
// We also set up a mouse binding so that clicking inside a window will
// create another one. | [
"newWindow",
"creates",
"a",
"new",
"window",
"with",
"a",
"random",
"background",
"color",
".",
"It",
"sets",
"the",
"WM_PROTOCOLS",
"property",
"to",
"contain",
"the",
"WM_DELETE_WINDOW",
"atom",
".",
"It",
"also",
"sets",
"up",
"a",
"ClientMessage",
"event"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/_examples/graceful-window-close/main.go#L48-L100 |
2,523 | BurntSushi/xgbutil | xgraphics/text.go | ftContext | func ftContext(font *truetype.Font, fontSize float64) *freetype.Context {
c := freetype.NewContext()
c.SetDPI(72)
c.SetFont(font)
c.SetFontSize(fontSize)
return c
} | go | func ftContext(font *truetype.Font, fontSize float64) *freetype.Context {
c := freetype.NewContext()
c.SetDPI(72)
c.SetFont(font)
c.SetFontSize(fontSize)
return c
} | [
"func",
"ftContext",
"(",
"font",
"*",
"truetype",
".",
"Font",
",",
"fontSize",
"float64",
")",
"*",
"freetype",
".",
"Context",
"{",
"c",
":=",
"freetype",
".",
"NewContext",
"(",
")",
"\n",
"c",
".",
"SetDPI",
"(",
"72",
")",
"\n",
"c",
".",
"Se... | // ftContext does the boiler plate to create a freetype context | [
"ftContext",
"does",
"the",
"boiler",
"plate",
"to",
"create",
"a",
"freetype",
"context"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/text.go#L73-L80 |
2,524 | BurntSushi/xgbutil | xgraphics/text.go | ParseFont | func ParseFont(fontReader io.Reader) (*truetype.Font, error) {
fontBytes, err := ioutil.ReadAll(fontReader)
if err != nil {
return nil, err
}
font, err := freetype.ParseFont(fontBytes)
if err != nil {
return nil, err
}
return font, nil
} | go | func ParseFont(fontReader io.Reader) (*truetype.Font, error) {
fontBytes, err := ioutil.ReadAll(fontReader)
if err != nil {
return nil, err
}
font, err := freetype.ParseFont(fontBytes)
if err != nil {
return nil, err
}
return font, nil
} | [
"func",
"ParseFont",
"(",
"fontReader",
"io",
".",
"Reader",
")",
"(",
"*",
"truetype",
".",
"Font",
",",
"error",
")",
"{",
"fontBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"fontReader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // ParseFont reads a font file and creates a freetype.Font type | [
"ParseFont",
"reads",
"a",
"font",
"file",
"and",
"creates",
"a",
"freetype",
".",
"Font",
"type"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/text.go#L83-L95 |
2,525 | BurntSushi/xgbutil | xgraphics/text.go | MustFont | func MustFont(font *truetype.Font, err error) *truetype.Font {
if err != nil {
panic(err)
}
if font == nil {
panic("font is nil")
}
return font
} | go | func MustFont(font *truetype.Font, err error) *truetype.Font {
if err != nil {
panic(err)
}
if font == nil {
panic("font is nil")
}
return font
} | [
"func",
"MustFont",
"(",
"font",
"*",
"truetype",
".",
"Font",
",",
"err",
"error",
")",
"*",
"truetype",
".",
"Font",
"{",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"font",
"==",
"nil",
"{",
"panic",
"(",
... | // MustFont panics if err is not nil or if the font is nil. | [
"MustFont",
"panics",
"if",
"err",
"is",
"not",
"nil",
"or",
"if",
"the",
"font",
"is",
"nil",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/text.go#L98-L106 |
2,526 | BurntSushi/xgbutil | motif/motif.go | Decor | func Decor(mh *Hints) bool {
if mh.Flags&HintDecorations > 0 {
noDecor := mh.Decoration == DecorationNone ||
(mh.Decoration&DecorationAll == 0 &&
mh.Decoration&DecorationTitle == 0 &&
mh.Decoration&DecorationResizeH == 0)
return !noDecor
}
return true
} | go | func Decor(mh *Hints) bool {
if mh.Flags&HintDecorations > 0 {
noDecor := mh.Decoration == DecorationNone ||
(mh.Decoration&DecorationAll == 0 &&
mh.Decoration&DecorationTitle == 0 &&
mh.Decoration&DecorationResizeH == 0)
return !noDecor
}
return true
} | [
"func",
"Decor",
"(",
"mh",
"*",
"Hints",
")",
"bool",
"{",
"if",
"mh",
".",
"Flags",
"&",
"HintDecorations",
">",
"0",
"{",
"noDecor",
":=",
"mh",
".",
"Decoration",
"==",
"DecorationNone",
"||",
"(",
"mh",
".",
"Decoration",
"&",
"DecorationAll",
"==... | // Decor checks a Hints value for whether or not the client has requested
// that the window manager paint decorations.
// That is, Decor returns false when the hints provided indicate no
// decorations and true otherwise. | [
"Decor",
"checks",
"a",
"Hints",
"value",
"for",
"whether",
"or",
"not",
"the",
"client",
"has",
"requested",
"that",
"the",
"window",
"manager",
"paint",
"decorations",
".",
"That",
"is",
"Decor",
"returns",
"false",
"when",
"the",
"hints",
"provided",
"ind... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/motif/motif.go#L80-L89 |
2,527 | BurntSushi/xgbutil | xwindow/icccm.go | WMTakeFocus | func (w *Window) WMTakeFocus(cb func(w *Window, tstamp xproto.Timestamp)) {
// Make sure the Input flag is set to true in WM_HINTS. We first
// must retrieve the current WM_HINTS, so we don't overwrite the flags.
curFlags := uint(0)
if hints, err := icccm.WmHintsGet(w.X, w.Id); err == nil {
curFlags = hints.Flags
}
icccm.WmHintsSet(w.X, w.Id, &icccm.Hints{
Flags: curFlags | icccm.HintInput,
Input: 1,
})
// Get the current protocols so we don't overwrite anything.
prots, _ := icccm.WmProtocolsGet(w.X, w.Id)
// If WM_TAKE_FOCUS isn't here, add it. Otherwise, move on.
wmfocus := false
for _, prot := range prots {
if prot == "WM_TAKE_FOCUS" {
wmfocus = true
break
}
}
if !wmfocus {
icccm.WmProtocolsSet(w.X, w.Id, append(prots, "WM_TAKE_FOCUS"))
}
// Attach a ClientMessage event handler. It will determine whether the
// ClientMessage is a 'focus' request, and if so, run the callback 'cb'
// provided.
xevent.ClientMessageFun(
func(X *xgbutil.XUtil, ev xevent.ClientMessageEvent) {
if icccm.IsFocusProtocol(X, ev) {
cb(w, xproto.Timestamp(ev.Data.Data32[1]))
}
}).Connect(w.X, w.Id)
} | go | func (w *Window) WMTakeFocus(cb func(w *Window, tstamp xproto.Timestamp)) {
// Make sure the Input flag is set to true in WM_HINTS. We first
// must retrieve the current WM_HINTS, so we don't overwrite the flags.
curFlags := uint(0)
if hints, err := icccm.WmHintsGet(w.X, w.Id); err == nil {
curFlags = hints.Flags
}
icccm.WmHintsSet(w.X, w.Id, &icccm.Hints{
Flags: curFlags | icccm.HintInput,
Input: 1,
})
// Get the current protocols so we don't overwrite anything.
prots, _ := icccm.WmProtocolsGet(w.X, w.Id)
// If WM_TAKE_FOCUS isn't here, add it. Otherwise, move on.
wmfocus := false
for _, prot := range prots {
if prot == "WM_TAKE_FOCUS" {
wmfocus = true
break
}
}
if !wmfocus {
icccm.WmProtocolsSet(w.X, w.Id, append(prots, "WM_TAKE_FOCUS"))
}
// Attach a ClientMessage event handler. It will determine whether the
// ClientMessage is a 'focus' request, and if so, run the callback 'cb'
// provided.
xevent.ClientMessageFun(
func(X *xgbutil.XUtil, ev xevent.ClientMessageEvent) {
if icccm.IsFocusProtocol(X, ev) {
cb(w, xproto.Timestamp(ev.Data.Data32[1]))
}
}).Connect(w.X, w.Id)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"WMTakeFocus",
"(",
"cb",
"func",
"(",
"w",
"*",
"Window",
",",
"tstamp",
"xproto",
".",
"Timestamp",
")",
")",
"{",
"// Make sure the Input flag is set to true in WM_HINTS. We first",
"// must retrieve the current WM_HINTS, so we d... | // WMTakeFocus will do all the necessary setup to support the WM_TAKE_FOCUS
// protocol using the "LocallyActive" input model described in Section 4.1.7
// of the ICCCM. Namely, listening to ClientMessage events and running the
// callback function provided when a WM_TAKE_FOCUS ClientMessage has been
// received.
//
// Typically, the callback function should include a call to SetInputFocus
// with the "Parent" InputFocus type, the sub-window id of the window that
// should have focus, and the 'tstamp' timestamp. | [
"WMTakeFocus",
"will",
"do",
"all",
"the",
"necessary",
"setup",
"to",
"support",
"the",
"WM_TAKE_FOCUS",
"protocol",
"using",
"the",
"LocallyActive",
"input",
"model",
"described",
"in",
"Section",
"4",
".",
"1",
".",
"7",
"of",
"the",
"ICCCM",
".",
"Namely... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/icccm.go#L56-L92 |
2,528 | BurntSushi/xgbutil | xwindow/xwindow.go | New | func New(xu *xgbutil.XUtil, win xproto.Window) *Window {
return &Window{
X: xu,
Id: win,
Geom: xrect.New(0, 0, 1, 1),
Destroyed: false,
}
} | go | func New(xu *xgbutil.XUtil, win xproto.Window) *Window {
return &Window{
X: xu,
Id: win,
Geom: xrect.New(0, 0, 1, 1),
Destroyed: false,
}
} | [
"func",
"New",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
")",
"*",
"Window",
"{",
"return",
"&",
"Window",
"{",
"X",
":",
"xu",
",",
"Id",
":",
"win",
",",
"Geom",
":",
"xrect",
".",
"New",
"(",
"0",
",",
"... | // New creates a new window value from a window id and an XUtil type.
// Geom is initialized to zero values. Use Window.Geometry to load it.
// Note that the geometry is the size of this particular window and nothing
// else. If you want the geometry of a client window including decorations,
// please use Window.DecorGeometry. | [
"New",
"creates",
"a",
"new",
"window",
"value",
"from",
"a",
"window",
"id",
"and",
"an",
"XUtil",
"type",
".",
"Geom",
"is",
"initialized",
"to",
"zero",
"values",
".",
"Use",
"Window",
".",
"Geometry",
"to",
"load",
"it",
".",
"Note",
"that",
"the",... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L31-L38 |
2,529 | BurntSushi/xgbutil | xwindow/xwindow.go | Must | func Must(win *Window, err error) *Window {
if err != nil {
panic(err)
}
if win == nil {
panic("win and err are nil")
}
return win
} | go | func Must(win *Window, err error) *Window {
if err != nil {
panic(err)
}
if win == nil {
panic("win and err are nil")
}
return win
} | [
"func",
"Must",
"(",
"win",
"*",
"Window",
",",
"err",
"error",
")",
"*",
"Window",
"{",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"win",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
... | // Must panics if err is non-nil or if win is nil. Otherwise, win is returned. | [
"Must",
"panics",
"if",
"err",
"is",
"non",
"-",
"nil",
"or",
"if",
"win",
"is",
"nil",
".",
"Otherwise",
"win",
"is",
"returned",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L71-L79 |
2,530 | BurntSushi/xgbutil | xwindow/xwindow.go | CreateChecked | func (w *Window) CreateChecked(parent xproto.Window, x, y, width, height,
valueMask int, valueList ...uint32) error {
s := w.X.Screen()
return xproto.CreateWindowChecked(w.X.Conn(),
s.RootDepth, w.Id, parent,
int16(x), int16(y), uint16(width), uint16(height), 0,
xproto.WindowClassInputOutput, s.RootVisual,
uint32(valueMask), valueList).Check()
} | go | func (w *Window) CreateChecked(parent xproto.Window, x, y, width, height,
valueMask int, valueList ...uint32) error {
s := w.X.Screen()
return xproto.CreateWindowChecked(w.X.Conn(),
s.RootDepth, w.Id, parent,
int16(x), int16(y), uint16(width), uint16(height), 0,
xproto.WindowClassInputOutput, s.RootVisual,
uint32(valueMask), valueList).Check()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"CreateChecked",
"(",
"parent",
"xproto",
".",
"Window",
",",
"x",
",",
"y",
",",
"width",
",",
"height",
",",
"valueMask",
"int",
",",
"valueList",
"...",
"uint32",
")",
"error",
"{",
"s",
":=",
"w",
".",
"X",... | // CreateChecked issues a CreateWindow checked request for Window.
// A checked request is a synchronous request. Meaning that if the request
// fails, you can get the error returned to you. However, it also forced your
// program to block for a round trip to the X server, so it is slower.
// See the docs for Create for more info. | [
"CreateChecked",
"issues",
"a",
"CreateWindow",
"checked",
"request",
"for",
"Window",
".",
"A",
"checked",
"request",
"is",
"a",
"synchronous",
"request",
".",
"Meaning",
"that",
"if",
"the",
"request",
"fails",
"you",
"can",
"get",
"the",
"error",
"returned"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L114-L123 |
2,531 | BurntSushi/xgbutil | xwindow/xwindow.go | Change | func (w *Window) Change(valueMask int, valueList ...uint32) {
xproto.ChangeWindowAttributes(w.X.Conn(), w.Id,
uint32(valueMask), valueList)
} | go | func (w *Window) Change(valueMask int, valueList ...uint32) {
xproto.ChangeWindowAttributes(w.X.Conn(), w.Id,
uint32(valueMask), valueList)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Change",
"(",
"valueMask",
"int",
",",
"valueList",
"...",
"uint32",
")",
"{",
"xproto",
".",
"ChangeWindowAttributes",
"(",
"w",
".",
"X",
".",
"Conn",
"(",
")",
",",
"w",
".",
"Id",
",",
"uint32",
"(",
"valu... | // Change issues a ChangeWindowAttributes request with the provided mask
// and value list. Please see Window.Create for an example on how to use
// the mask and value list. | [
"Change",
"issues",
"a",
"ChangeWindowAttributes",
"request",
"with",
"the",
"provided",
"mask",
"and",
"value",
"list",
".",
"Please",
"see",
"Window",
".",
"Create",
"for",
"an",
"example",
"on",
"how",
"to",
"use",
"the",
"mask",
"and",
"value",
"list",
... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L128-L131 |
2,532 | BurntSushi/xgbutil | xwindow/xwindow.go | Geometry | func (w *Window) Geometry() (xrect.Rect, error) {
geom, err := RawGeometry(w.X, xproto.Drawable(w.Id))
if err != nil {
return nil, err
}
w.Geom = geom
return geom, err
} | go | func (w *Window) Geometry() (xrect.Rect, error) {
geom, err := RawGeometry(w.X, xproto.Drawable(w.Id))
if err != nil {
return nil, err
}
w.Geom = geom
return geom, err
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Geometry",
"(",
")",
"(",
"xrect",
".",
"Rect",
",",
"error",
")",
"{",
"geom",
",",
"err",
":=",
"RawGeometry",
"(",
"w",
".",
"X",
",",
"xproto",
".",
"Drawable",
"(",
"w",
".",
"Id",
")",
")",
"\n",
"... | // Geometry retrieves an up-to-date version of the this window's geometry.
// It also loads the geometry into the Geom member of Window. | [
"Geometry",
"retrieves",
"an",
"up",
"-",
"to",
"-",
"date",
"version",
"of",
"the",
"this",
"window",
"s",
"geometry",
".",
"It",
"also",
"loads",
"the",
"geometry",
"into",
"the",
"Geom",
"member",
"of",
"Window",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L149-L156 |
2,533 | BurntSushi/xgbutil | xwindow/xwindow.go | RawGeometry | func RawGeometry(xu *xgbutil.XUtil, win xproto.Drawable) (xrect.Rect, error) {
xgeom, err := xproto.GetGeometry(xu.Conn(), win).Reply()
if err != nil {
return nil, err
}
return xrect.New(int(xgeom.X), int(xgeom.Y),
int(xgeom.Width), int(xgeom.Height)), nil
} | go | func RawGeometry(xu *xgbutil.XUtil, win xproto.Drawable) (xrect.Rect, error) {
xgeom, err := xproto.GetGeometry(xu.Conn(), win).Reply()
if err != nil {
return nil, err
}
return xrect.New(int(xgeom.X), int(xgeom.Y),
int(xgeom.Width), int(xgeom.Height)), nil
} | [
"func",
"RawGeometry",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Drawable",
")",
"(",
"xrect",
".",
"Rect",
",",
"error",
")",
"{",
"xgeom",
",",
"err",
":=",
"xproto",
".",
"GetGeometry",
"(",
"xu",
".",
"Conn",
"(",
")"... | // RawGeometry isn't smart. It just queries the window given for geometry. | [
"RawGeometry",
"isn",
"t",
"smart",
".",
"It",
"just",
"queries",
"the",
"window",
"given",
"for",
"geometry",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L159-L166 |
2,534 | BurntSushi/xgbutil | xwindow/xwindow.go | RootGeometry | func RootGeometry(xu *xgbutil.XUtil) xrect.Rect {
geom, err := RawGeometry(xu, xproto.Drawable(xu.RootWin()))
if err != nil {
panic(err)
}
return geom
} | go | func RootGeometry(xu *xgbutil.XUtil) xrect.Rect {
geom, err := RawGeometry(xu, xproto.Drawable(xu.RootWin()))
if err != nil {
panic(err)
}
return geom
} | [
"func",
"RootGeometry",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
")",
"xrect",
".",
"Rect",
"{",
"geom",
",",
"err",
":=",
"RawGeometry",
"(",
"xu",
",",
"xproto",
".",
"Drawable",
"(",
"xu",
".",
"RootWin",
"(",
")",
")",
")",
"\n",
"if",
"err",
... | // RootGeometry gets the geometry of the root window. It will panic on failure. | [
"RootGeometry",
"gets",
"the",
"geometry",
"of",
"the",
"root",
"window",
".",
"It",
"will",
"panic",
"on",
"failure",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L169-L175 |
2,535 | BurntSushi/xgbutil | xwindow/xwindow.go | Move | func (w *Window) Move(x, y int) {
w.Configure(xproto.ConfigWindowX|xproto.ConfigWindowY, x, y, 0, 0, 0, 0)
} | go | func (w *Window) Move(x, y int) {
w.Configure(xproto.ConfigWindowX|xproto.ConfigWindowY, x, y, 0, 0, 0, 0)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Move",
"(",
"x",
",",
"y",
"int",
")",
"{",
"w",
".",
"Configure",
"(",
"xproto",
".",
"ConfigWindowX",
"|",
"xproto",
".",
"ConfigWindowY",
",",
"x",
",",
"y",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
")... | // Move issues a ConfigureRequest for this window with the provided
// x and y positions.
// If you're trying to move a top-level window in a window manager that
// supports EWMH, please use WMMove instead. | [
"Move",
"issues",
"a",
"ConfigureRequest",
"for",
"this",
"window",
"with",
"the",
"provided",
"x",
"and",
"y",
"positions",
".",
"If",
"you",
"re",
"trying",
"to",
"move",
"a",
"top",
"-",
"level",
"window",
"in",
"a",
"window",
"manager",
"that",
"supp... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L253-L255 |
2,536 | BurntSushi/xgbutil | xwindow/xwindow.go | Resize | func (w *Window) Resize(width, height int) {
w.Configure(xproto.ConfigWindowWidth|xproto.ConfigWindowHeight, 0, 0,
width, height, 0, 0)
} | go | func (w *Window) Resize(width, height int) {
w.Configure(xproto.ConfigWindowWidth|xproto.ConfigWindowHeight, 0, 0,
width, height, 0, 0)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Resize",
"(",
"width",
",",
"height",
"int",
")",
"{",
"w",
".",
"Configure",
"(",
"xproto",
".",
"ConfigWindowWidth",
"|",
"xproto",
".",
"ConfigWindowHeight",
",",
"0",
",",
"0",
",",
"width",
",",
"height",
"... | // Resize issues a ConfigureRequest for this window with the provided
// width and height. Note that if width or height is 0, X will stomp
// all over you. Really hard. Don't do it.
// If you're trying to resize a top-level window in a window manager that
// supports EWMH, please use WMResize instead. | [
"Resize",
"issues",
"a",
"ConfigureRequest",
"for",
"this",
"window",
"with",
"the",
"provided",
"width",
"and",
"height",
".",
"Note",
"that",
"if",
"width",
"or",
"height",
"is",
"0",
"X",
"will",
"stomp",
"all",
"over",
"you",
".",
"Really",
"hard",
"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L262-L265 |
2,537 | BurntSushi/xgbutil | xwindow/xwindow.go | Map | func (w *Window) Map() {
if w == nil {
return
}
xproto.MapWindow(w.X.Conn(), w.Id)
} | go | func (w *Window) Map() {
if w == nil {
return
}
xproto.MapWindow(w.X.Conn(), w.Id)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Map",
"(",
")",
"{",
"if",
"w",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"xproto",
".",
"MapWindow",
"(",
"w",
".",
"X",
".",
"Conn",
"(",
")",
",",
"w",
".",
"Id",
")",
"\n",
"}"
] | // Map is a simple alias to map the window. | [
"Map",
"is",
"a",
"simple",
"alias",
"to",
"map",
"the",
"window",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L301-L307 |
2,538 | BurntSushi/xgbutil | xwindow/xwindow.go | Unmap | func (w *Window) Unmap() {
if w == nil {
return
}
xproto.UnmapWindow(w.X.Conn(), w.Id)
} | go | func (w *Window) Unmap() {
if w == nil {
return
}
xproto.UnmapWindow(w.X.Conn(), w.Id)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Unmap",
"(",
")",
"{",
"if",
"w",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"xproto",
".",
"UnmapWindow",
"(",
"w",
".",
"X",
".",
"Conn",
"(",
")",
",",
"w",
".",
"Id",
")",
"\n",
"}"
] | // Unmap is a simple alias to unmap the window. | [
"Unmap",
"is",
"a",
"simple",
"alias",
"to",
"unmap",
"the",
"window",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L310-L316 |
2,539 | BurntSushi/xgbutil | xwindow/xwindow.go | Detach | func (w *Window) Detach() {
keybind.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
xevent.Detach(w.X, w.Id)
} | go | func (w *Window) Detach() {
keybind.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
xevent.Detach(w.X, w.Id)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Detach",
"(",
")",
"{",
"keybind",
".",
"Detach",
"(",
"w",
".",
"X",
",",
"w",
".",
"Id",
")",
"\n",
"mousebind",
".",
"Detach",
"(",
"w",
".",
"X",
",",
"w",
".",
"Id",
")",
"\n",
"xevent",
".",
"Det... | // Detach will detach this window's event handlers from all xevent, keybind
// and mousebind callbacks. | [
"Detach",
"will",
"detach",
"this",
"window",
"s",
"event",
"handlers",
"from",
"all",
"xevent",
"keybind",
"and",
"mousebind",
"callbacks",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L335-L339 |
2,540 | BurntSushi/xgbutil | xwindow/xwindow.go | Focus | func (w *Window) Focus() {
mode := byte(xproto.InputFocusPointerRoot)
err := xproto.SetInputFocusChecked(w.X.Conn(), mode, w.Id, 0).Check()
if err != nil {
xgbutil.Logger.Println(err)
}
} | go | func (w *Window) Focus() {
mode := byte(xproto.InputFocusPointerRoot)
err := xproto.SetInputFocusChecked(w.X.Conn(), mode, w.Id, 0).Check()
if err != nil {
xgbutil.Logger.Println(err)
}
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Focus",
"(",
")",
"{",
"mode",
":=",
"byte",
"(",
"xproto",
".",
"InputFocusPointerRoot",
")",
"\n",
"err",
":=",
"xproto",
".",
"SetInputFocusChecked",
"(",
"w",
".",
"X",
".",
"Conn",
"(",
")",
",",
"mode",
... | // Focus tries to issue a SetInputFocus to get the focus.
// If you're trying to change the top-level active window, please use
// ewmh.ActiveWindowReq instead. | [
"Focus",
"tries",
"to",
"issue",
"a",
"SetInputFocus",
"to",
"get",
"the",
"focus",
".",
"If",
"you",
"re",
"trying",
"to",
"change",
"the",
"top",
"-",
"level",
"active",
"window",
"please",
"use",
"ewmh",
".",
"ActiveWindowReq",
"instead",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L344-L350 |
2,541 | BurntSushi/xgbutil | xwindow/xwindow.go | FocusParent | func (w *Window) FocusParent(tstamp xproto.Timestamp) {
mode := byte(xproto.InputFocusParent)
err := xproto.SetInputFocusChecked(w.X.Conn(), mode, w.Id, tstamp).Check()
if err != nil {
xgbutil.Logger.Println(err)
}
} | go | func (w *Window) FocusParent(tstamp xproto.Timestamp) {
mode := byte(xproto.InputFocusParent)
err := xproto.SetInputFocusChecked(w.X.Conn(), mode, w.Id, tstamp).Check()
if err != nil {
xgbutil.Logger.Println(err)
}
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"FocusParent",
"(",
"tstamp",
"xproto",
".",
"Timestamp",
")",
"{",
"mode",
":=",
"byte",
"(",
"xproto",
".",
"InputFocusParent",
")",
"\n",
"err",
":=",
"xproto",
".",
"SetInputFocusChecked",
"(",
"w",
".",
"X",
"... | // FocusParent is just like Focus, except it sets the "revert-to" mode to
// Parent. This should be used when setting focus to a sub-window. | [
"FocusParent",
"is",
"just",
"like",
"Focus",
"except",
"it",
"sets",
"the",
"revert",
"-",
"to",
"mode",
"to",
"Parent",
".",
"This",
"should",
"be",
"used",
"when",
"setting",
"focus",
"to",
"a",
"sub",
"-",
"window",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L354-L360 |
2,542 | BurntSushi/xgbutil | xwindow/xwindow.go | ClearAll | func (w *Window) ClearAll() {
xproto.ClearArea(w.X.Conn(), false, w.Id, 0, 0, 0, 0)
} | go | func (w *Window) ClearAll() {
xproto.ClearArea(w.X.Conn(), false, w.Id, 0, 0, 0, 0)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"ClearAll",
"(",
")",
"{",
"xproto",
".",
"ClearArea",
"(",
"w",
".",
"X",
".",
"Conn",
"(",
")",
",",
"false",
",",
"w",
".",
"Id",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"\n",
"}"
] | // ClearAll is the same as Clear, but does it for the entire background pixmap. | [
"ClearAll",
"is",
"the",
"same",
"as",
"Clear",
"but",
"does",
"it",
"for",
"the",
"entire",
"background",
"pixmap",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L381-L383 |
2,543 | BurntSushi/xgbutil | xwindow/xwindow.go | Parent | func (w *Window) Parent() (*Window, error) {
tree, err := xproto.QueryTree(w.X.Conn(), w.Id).Reply()
if err != nil {
return nil, fmt.Errorf("ParentWindow: Error retrieving parent window "+
"for %x: %s", w.Id, err)
}
return New(w.X, tree.Parent), nil
} | go | func (w *Window) Parent() (*Window, error) {
tree, err := xproto.QueryTree(w.X.Conn(), w.Id).Reply()
if err != nil {
return nil, fmt.Errorf("ParentWindow: Error retrieving parent window "+
"for %x: %s", w.Id, err)
}
return New(w.X, tree.Parent), nil
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Parent",
"(",
")",
"(",
"*",
"Window",
",",
"error",
")",
"{",
"tree",
",",
"err",
":=",
"xproto",
".",
"QueryTree",
"(",
"w",
".",
"X",
".",
"Conn",
"(",
")",
",",
"w",
".",
"Id",
")",
".",
"Reply",
"... | // Parent queries the QueryTree and finds the parent window. | [
"Parent",
"queries",
"the",
"QueryTree",
"and",
"finds",
"the",
"parent",
"window",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/xwindow.go#L386-L393 |
2,544 | BurntSushi/xgbutil | xgraphics/util.go | BlendBGRA | func BlendBGRA(dest, src BGRA) BGRA {
alpha := float64(src.A) / 255.0
return BGRA{
B: blend(dest.B, src.B, alpha),
G: blend(dest.G, src.G, alpha),
R: blend(dest.R, src.R, alpha),
A: 0xff,
}
} | go | func BlendBGRA(dest, src BGRA) BGRA {
alpha := float64(src.A) / 255.0
return BGRA{
B: blend(dest.B, src.B, alpha),
G: blend(dest.G, src.G, alpha),
R: blend(dest.R, src.R, alpha),
A: 0xff,
}
} | [
"func",
"BlendBGRA",
"(",
"dest",
",",
"src",
"BGRA",
")",
"BGRA",
"{",
"alpha",
":=",
"float64",
"(",
"src",
".",
"A",
")",
"/",
"255.0",
"\n",
"return",
"BGRA",
"{",
"B",
":",
"blend",
"(",
"dest",
".",
"B",
",",
"src",
".",
"B",
",",
"alpha"... | // Blend returns the blended alpha color for src and dest colors.
// This assumes that the destination has alpha = 1. | [
"Blend",
"returns",
"the",
"blended",
"alpha",
"color",
"for",
"src",
"and",
"dest",
"colors",
".",
"This",
"assumes",
"that",
"the",
"destination",
"has",
"alpha",
"=",
"1",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/util.go#L103-L111 |
2,545 | BurntSushi/xgbutil | xgraphics/util.go | FreePixmap | func FreePixmap(X *xgbutil.XUtil, pixid xproto.Pixmap) {
xproto.FreePixmap(X.Conn(), pixid)
} | go | func FreePixmap(X *xgbutil.XUtil, pixid xproto.Pixmap) {
xproto.FreePixmap(X.Conn(), pixid)
} | [
"func",
"FreePixmap",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"pixid",
"xproto",
".",
"Pixmap",
")",
"{",
"xproto",
".",
"FreePixmap",
"(",
"X",
".",
"Conn",
"(",
")",
",",
"pixid",
")",
"\n",
"}"
] | // FreePixmap is a convenience function for destroying a pixmap resource
// on the X server.
// If you're using an xgraphics.Image value, then its Destroy method will call
// this for you. | [
"FreePixmap",
"is",
"a",
"convenience",
"function",
"for",
"destroying",
"a",
"pixmap",
"resource",
"on",
"the",
"X",
"server",
".",
"If",
"you",
"re",
"using",
"an",
"xgraphics",
".",
"Image",
"value",
"then",
"its",
"Destroy",
"method",
"will",
"call",
"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/util.go#L124-L126 |
2,546 | BurntSushi/xgbutil | xgraphics/util.go | FindIcon | func FindIcon(X *xgbutil.XUtil, wid xproto.Window,
width, height int) (*Image, error) {
var ewmhErr, icccmErr error
// First try to get a EWMH style icon.
icon, ewmhErr := findIconEwmh(X, wid, width, height)
if ewmhErr != nil { // now look for an icccm-style icon
icon, icccmErr = findIconIcccm(X, wid)
if icccmErr != nil {
return nil, fmt.Errorf("Neither a EWMH-style or ICCCM-style icon "+
"could be found for window id %x because: %s *AND* %s",
wid, ewmhErr, icccmErr)
}
}
// We should have a valid xgraphics.Image if we're here.
// If the size doesn't match what's preferred, scale it.
if width != 0 && height != 0 {
if icon.Bounds().Dx() != width || icon.Bounds().Dy() != height {
icon = icon.Scale(width, height)
}
}
return icon, nil
} | go | func FindIcon(X *xgbutil.XUtil, wid xproto.Window,
width, height int) (*Image, error) {
var ewmhErr, icccmErr error
// First try to get a EWMH style icon.
icon, ewmhErr := findIconEwmh(X, wid, width, height)
if ewmhErr != nil { // now look for an icccm-style icon
icon, icccmErr = findIconIcccm(X, wid)
if icccmErr != nil {
return nil, fmt.Errorf("Neither a EWMH-style or ICCCM-style icon "+
"could be found for window id %x because: %s *AND* %s",
wid, ewmhErr, icccmErr)
}
}
// We should have a valid xgraphics.Image if we're here.
// If the size doesn't match what's preferred, scale it.
if width != 0 && height != 0 {
if icon.Bounds().Dx() != width || icon.Bounds().Dy() != height {
icon = icon.Scale(width, height)
}
}
return icon, nil
} | [
"func",
"FindIcon",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"wid",
"xproto",
".",
"Window",
",",
"width",
",",
"height",
"int",
")",
"(",
"*",
"Image",
",",
"error",
")",
"{",
"var",
"ewmhErr",
",",
"icccmErr",
"error",
"\n\n",
"// First try to ge... | // FindIcon takes a window id and attempts to return an xgraphics.Image of
// that window's icon.
// It will first try to look for an icon in _NET_WM_ICON that is closest to
// the size specified.
// If there are no icons in _NET_WM_ICON, then WM_HINTS will be checked for
// an icon.
// If an icon is found from either one and doesn't match the size
// specified, it will be scaled to that size.
// If the width and height are 0, then the largest icon will be returned with
// no scaling.
// If an icon is not found, an error is returned. | [
"FindIcon",
"takes",
"a",
"window",
"id",
"and",
"attempts",
"to",
"return",
"an",
"xgraphics",
".",
"Image",
"of",
"that",
"window",
"s",
"icon",
".",
"It",
"will",
"first",
"try",
"to",
"look",
"for",
"an",
"icon",
"in",
"_NET_WM_ICON",
"that",
"is",
... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/util.go#L139-L163 |
2,547 | BurntSushi/xgbutil | xgraphics/util.go | findIconEwmh | func findIconEwmh(X *xgbutil.XUtil, wid xproto.Window,
width, height int) (*Image, error) {
icons, err := ewmh.WmIconGet(X, wid)
if err != nil {
return nil, err
}
icon := FindBestEwmhIcon(width, height, icons)
if icon == nil {
return nil, fmt.Errorf("Could not find any _NET_WM_ICON icon.")
}
return NewEwmhIcon(X, icon), nil
} | go | func findIconEwmh(X *xgbutil.XUtil, wid xproto.Window,
width, height int) (*Image, error) {
icons, err := ewmh.WmIconGet(X, wid)
if err != nil {
return nil, err
}
icon := FindBestEwmhIcon(width, height, icons)
if icon == nil {
return nil, fmt.Errorf("Could not find any _NET_WM_ICON icon.")
}
return NewEwmhIcon(X, icon), nil
} | [
"func",
"findIconEwmh",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"wid",
"xproto",
".",
"Window",
",",
"width",
",",
"height",
"int",
")",
"(",
"*",
"Image",
",",
"error",
")",
"{",
"icons",
",",
"err",
":=",
"ewmh",
".",
"WmIconGet",
"(",
"X",
... | // findIconEwmh helps FindIcon by trying to return an ewmh-style icon that is
// closest to the preferred size specified. | [
"findIconEwmh",
"helps",
"FindIcon",
"by",
"trying",
"to",
"return",
"an",
"ewmh",
"-",
"style",
"icon",
"that",
"is",
"closest",
"to",
"the",
"preferred",
"size",
"specified",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/util.go#L167-L181 |
2,548 | BurntSushi/xgbutil | xgraphics/util.go | findIconIcccm | func findIconIcccm(X *xgbutil.XUtil, wid xproto.Window) (*Image, error) {
hints, err := icccm.WmHintsGet(X, wid)
if err != nil {
return nil, err
}
// Only continue if the WM_HINTS flags say an icon is specified and
// if at least one of icon pixmap or icon mask is non-zero.
if hints.Flags&icccm.HintIconPixmap == 0 ||
(hints.IconPixmap == 0 && hints.IconMask == 0) {
return nil, fmt.Errorf("No icon found in WM_HINTS.")
}
return NewIcccmIcon(X, hints.IconPixmap, hints.IconMask)
} | go | func findIconIcccm(X *xgbutil.XUtil, wid xproto.Window) (*Image, error) {
hints, err := icccm.WmHintsGet(X, wid)
if err != nil {
return nil, err
}
// Only continue if the WM_HINTS flags say an icon is specified and
// if at least one of icon pixmap or icon mask is non-zero.
if hints.Flags&icccm.HintIconPixmap == 0 ||
(hints.IconPixmap == 0 && hints.IconMask == 0) {
return nil, fmt.Errorf("No icon found in WM_HINTS.")
}
return NewIcccmIcon(X, hints.IconPixmap, hints.IconMask)
} | [
"func",
"findIconIcccm",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"wid",
"xproto",
".",
"Window",
")",
"(",
"*",
"Image",
",",
"error",
")",
"{",
"hints",
",",
"err",
":=",
"icccm",
".",
"WmHintsGet",
"(",
"X",
",",
"wid",
")",
"\n",
"if",
"e... | // findIconIcccm helps FindIcon by trying to return an icccm-style icon. | [
"findIconIcccm",
"helps",
"FindIcon",
"by",
"trying",
"to",
"return",
"an",
"icccm",
"-",
"style",
"icon",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/util.go#L184-L199 |
2,549 | BurntSushi/xgbutil | icccm/protocols.go | IsDeleteProtocol | func IsDeleteProtocol(X *xgbutil.XUtil, ev xevent.ClientMessageEvent) bool {
// Make sure the Format is 32. (Meaning that each data item is
// 32 bits.)
if ev.Format != 32 {
return false
}
// Check to make sure the Type atom is WM_PROTOCOLS.
typeName, err := xprop.AtomName(X, ev.Type)
if err != nil || typeName != "WM_PROTOCOLS" { // not what we want
return false
}
// Check to make sure the first data item is WM_DELETE_WINDOW.
protocolType, err := xprop.AtomName(X,
xproto.Atom(ev.Data.Data32[0]))
if err != nil || protocolType != "WM_DELETE_WINDOW" {
return false
}
return true
} | go | func IsDeleteProtocol(X *xgbutil.XUtil, ev xevent.ClientMessageEvent) bool {
// Make sure the Format is 32. (Meaning that each data item is
// 32 bits.)
if ev.Format != 32 {
return false
}
// Check to make sure the Type atom is WM_PROTOCOLS.
typeName, err := xprop.AtomName(X, ev.Type)
if err != nil || typeName != "WM_PROTOCOLS" { // not what we want
return false
}
// Check to make sure the first data item is WM_DELETE_WINDOW.
protocolType, err := xprop.AtomName(X,
xproto.Atom(ev.Data.Data32[0]))
if err != nil || protocolType != "WM_DELETE_WINDOW" {
return false
}
return true
} | [
"func",
"IsDeleteProtocol",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"ev",
"xevent",
".",
"ClientMessageEvent",
")",
"bool",
"{",
"// Make sure the Format is 32. (Meaning that each data item is",
"// 32 bits.)",
"if",
"ev",
".",
"Format",
"!=",
"32",
"{",
"retur... | // IsDeleteProtocol checks whether a ClientMessage event satisfies the
// WM_DELETE_WINDOW protocol. Namely, the format must be 32, the type must
// be the WM_PROTOCOLS atom, and the first data item must be the atom
// WM_DELETE_WINDOW.
//
// Note that if you're using the xwindow package, you should use the
// WMGracefulClose method instead of directly using IsDeleteProtocol. | [
"IsDeleteProtocol",
"checks",
"whether",
"a",
"ClientMessage",
"event",
"satisfies",
"the",
"WM_DELETE_WINDOW",
"protocol",
".",
"Namely",
"the",
"format",
"must",
"be",
"32",
"the",
"type",
"must",
"be",
"the",
"WM_PROTOCOLS",
"atom",
"and",
"the",
"first",
"da... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/icccm/protocols.go#L18-L39 |
2,550 | BurntSushi/xgbutil | keybind/callback.go | connect | func connect(xu *xgbutil.XUtil, callback xgbutil.CallbackKey,
evtype int, win xproto.Window, keyStr string, grab, reconnect bool) error {
// Get the mods/key first
mods, keycodes, err := ParseString(xu, keyStr)
if err != nil {
return err
}
// Only do the grab if we haven't yet on this window.
for _, keycode := range keycodes {
if grab && keyBindGrabs(xu, evtype, win, mods, keycode) == 0 {
if err := GrabChecked(xu, win, mods, keycode); err != nil {
// If a bad access, let's be nice and give a good error message.
switch err.(type) {
case xproto.AccessError:
return fmt.Errorf("Got a bad access error when trying to "+
"bind '%s'. This usually means another client has "+
"already grabbed this keybinding.", keyStr)
default:
return fmt.Errorf("Could not bind '%s' because: %s",
keyStr, err)
}
}
}
// If we've never grabbed anything on this window before, we need to
// make sure we can respond to it in the main event loop.
// Never do this if we're reconnecting.
if !reconnect {
var allCb xgbutil.Callback
if evtype == xevent.KeyPress {
allCb = xevent.KeyPressFun(runKeyPressCallbacks)
} else {
allCb = xevent.KeyReleaseFun(runKeyReleaseCallbacks)
}
// If this is the first Key{Press|Release}Event on this window,
// then we need to listen to Key{Press|Release} events in the main
// loop.
if !connectedKeyBind(xu, evtype, win) {
allCb.Connect(xu, win)
}
}
// Finally, attach the callback.
attachKeyBindCallback(xu, evtype, win, mods, keycode, callback)
}
// Keep track of all unique key connections.
if !reconnect {
addKeyString(xu, callback, evtype, win, keyStr, grab)
}
return nil
} | go | func connect(xu *xgbutil.XUtil, callback xgbutil.CallbackKey,
evtype int, win xproto.Window, keyStr string, grab, reconnect bool) error {
// Get the mods/key first
mods, keycodes, err := ParseString(xu, keyStr)
if err != nil {
return err
}
// Only do the grab if we haven't yet on this window.
for _, keycode := range keycodes {
if grab && keyBindGrabs(xu, evtype, win, mods, keycode) == 0 {
if err := GrabChecked(xu, win, mods, keycode); err != nil {
// If a bad access, let's be nice and give a good error message.
switch err.(type) {
case xproto.AccessError:
return fmt.Errorf("Got a bad access error when trying to "+
"bind '%s'. This usually means another client has "+
"already grabbed this keybinding.", keyStr)
default:
return fmt.Errorf("Could not bind '%s' because: %s",
keyStr, err)
}
}
}
// If we've never grabbed anything on this window before, we need to
// make sure we can respond to it in the main event loop.
// Never do this if we're reconnecting.
if !reconnect {
var allCb xgbutil.Callback
if evtype == xevent.KeyPress {
allCb = xevent.KeyPressFun(runKeyPressCallbacks)
} else {
allCb = xevent.KeyReleaseFun(runKeyReleaseCallbacks)
}
// If this is the first Key{Press|Release}Event on this window,
// then we need to listen to Key{Press|Release} events in the main
// loop.
if !connectedKeyBind(xu, evtype, win) {
allCb.Connect(xu, win)
}
}
// Finally, attach the callback.
attachKeyBindCallback(xu, evtype, win, mods, keycode, callback)
}
// Keep track of all unique key connections.
if !reconnect {
addKeyString(xu, callback, evtype, win, keyStr, grab)
}
return nil
} | [
"func",
"connect",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"callback",
"xgbutil",
".",
"CallbackKey",
",",
"evtype",
"int",
",",
"win",
"xproto",
".",
"Window",
",",
"keyStr",
"string",
",",
"grab",
",",
"reconnect",
"bool",
")",
"error",
"{",
"/... | // connect is essentially 'Connect' for either KeyPress or KeyRelease events.
// Namely, it parses the key string, issues a grab request if necessary,
// sets up the appropriate event handlers for the main event loop, and attaches
// the callback to the keybinding state. | [
"connect",
"is",
"essentially",
"Connect",
"for",
"either",
"KeyPress",
"or",
"KeyRelease",
"events",
".",
"Namely",
"it",
"parses",
"the",
"key",
"string",
"issues",
"a",
"grab",
"request",
"if",
"necessary",
"sets",
"up",
"the",
"appropriate",
"event",
"hand... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/callback.go#L16-L71 |
2,551 | BurntSushi/xgbutil | keybind/callback.go | runKeyPressCallbacks | func runKeyPressCallbacks(xu *xgbutil.XUtil, ev xevent.KeyPressEvent) {
mods, kc := DeduceKeyInfo(ev.State, ev.Detail)
runKeyBindCallbacks(xu, ev, xevent.KeyPress, ev.Event, mods, kc)
} | go | func runKeyPressCallbacks(xu *xgbutil.XUtil, ev xevent.KeyPressEvent) {
mods, kc := DeduceKeyInfo(ev.State, ev.Detail)
runKeyBindCallbacks(xu, ev, xevent.KeyPress, ev.Event, mods, kc)
} | [
"func",
"runKeyPressCallbacks",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"ev",
"xevent",
".",
"KeyPressEvent",
")",
"{",
"mods",
",",
"kc",
":=",
"DeduceKeyInfo",
"(",
"ev",
".",
"State",
",",
"ev",
".",
"Detail",
")",
"\n\n",
"runKeyBindCallbacks",
... | // runKeyPressCallbacks infers the window, keycode and modifiers from a
// KeyPressEvent and runs the corresponding callbacks. | [
"runKeyPressCallbacks",
"infers",
"the",
"window",
"keycode",
"and",
"modifiers",
"from",
"a",
"KeyPressEvent",
"and",
"runs",
"the",
"corresponding",
"callbacks",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/callback.go#L116-L120 |
2,552 | BurntSushi/xgbutil | keybind/callback.go | runKeyReleaseCallbacks | func runKeyReleaseCallbacks(xu *xgbutil.XUtil, ev xevent.KeyReleaseEvent) {
mods, kc := DeduceKeyInfo(ev.State, ev.Detail)
runKeyBindCallbacks(xu, ev, xevent.KeyRelease, ev.Event, mods, kc)
} | go | func runKeyReleaseCallbacks(xu *xgbutil.XUtil, ev xevent.KeyReleaseEvent) {
mods, kc := DeduceKeyInfo(ev.State, ev.Detail)
runKeyBindCallbacks(xu, ev, xevent.KeyRelease, ev.Event, mods, kc)
} | [
"func",
"runKeyReleaseCallbacks",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"ev",
"xevent",
".",
"KeyReleaseEvent",
")",
"{",
"mods",
",",
"kc",
":=",
"DeduceKeyInfo",
"(",
"ev",
".",
"State",
",",
"ev",
".",
"Detail",
")",
"\n\n",
"runKeyBindCallbacks... | // runKeyReleaseCallbacks infers the window, keycode and modifiers from a
// KeyPressEvent and runs the corresponding callbacks. | [
"runKeyReleaseCallbacks",
"infers",
"the",
"window",
"keycode",
"and",
"modifiers",
"from",
"a",
"KeyPressEvent",
"and",
"runs",
"the",
"corresponding",
"callbacks",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/callback.go#L124-L128 |
2,553 | BurntSushi/xgbutil | keybind/callback.go | Detach | func Detach(xu *xgbutil.XUtil, win xproto.Window) {
detach(xu, xevent.KeyPress, win)
detach(xu, xevent.KeyRelease, win)
} | go | func Detach(xu *xgbutil.XUtil, win xproto.Window) {
detach(xu, xevent.KeyPress, win)
detach(xu, xevent.KeyRelease, win)
} | [
"func",
"Detach",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
")",
"{",
"detach",
"(",
"xu",
",",
"xevent",
".",
"KeyPress",
",",
"win",
")",
"\n",
"detach",
"(",
"xu",
",",
"xevent",
".",
"KeyRelease",
",",
"win",... | // Detach removes all handlers for all key events for the provided window id.
// This should be called whenever a window is no longer receiving events to make
// sure the garbage collector can release memory used to store the handler info. | [
"Detach",
"removes",
"all",
"handlers",
"for",
"all",
"key",
"events",
"for",
"the",
"provided",
"window",
"id",
".",
"This",
"should",
"be",
"called",
"whenever",
"a",
"window",
"is",
"no",
"longer",
"receiving",
"events",
"to",
"make",
"sure",
"the",
"ga... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/callback.go#L133-L136 |
2,554 | BurntSushi/xgbutil | _examples/window-gradient/main.go | paintGradient | func paintGradient(X *xgbutil.XUtil, wid xproto.Window, width, height int,
start, end color.RGBA) {
ximg := xgraphics.New(X, image.Rect(0, 0, width, height))
// Now calculate the increment step between each RGB channel in
// the start and end colors.
rinc := (0xff * (int(end.R) - int(start.R))) / width
ginc := (0xff * (int(end.G) - int(start.G))) / width
binc := (0xff * (int(end.B) - int(start.B))) / width
// Now apply the increment to each "column" in the image.
// Using 'ForExp' allows us to bypass the creation of a color.BGRA value
// for each pixel in the image.
ximg.ForExp(func(x, y int) (uint8, uint8, uint8, uint8) {
return uint8(int(start.B) + (binc*x)/0xff),
uint8(int(start.G) + (ginc*x)/0xff),
uint8(int(start.R) + (rinc*x)/0xff),
0xff
})
// Set the surface to paint on for ximg.
// (This simply sets the background pixmap of the window to the pixmap
// used by ximg.)
ximg.XSurfaceSet(wid)
// XDraw will draw the contents of ximg to its corresponding pixmap.
ximg.XDraw()
// XPaint will "clear" the window provided so that it shows the updated
// pixmap.
ximg.XPaint(wid)
// Since we will not reuse ximg, we must destroy its pixmap.
ximg.Destroy()
} | go | func paintGradient(X *xgbutil.XUtil, wid xproto.Window, width, height int,
start, end color.RGBA) {
ximg := xgraphics.New(X, image.Rect(0, 0, width, height))
// Now calculate the increment step between each RGB channel in
// the start and end colors.
rinc := (0xff * (int(end.R) - int(start.R))) / width
ginc := (0xff * (int(end.G) - int(start.G))) / width
binc := (0xff * (int(end.B) - int(start.B))) / width
// Now apply the increment to each "column" in the image.
// Using 'ForExp' allows us to bypass the creation of a color.BGRA value
// for each pixel in the image.
ximg.ForExp(func(x, y int) (uint8, uint8, uint8, uint8) {
return uint8(int(start.B) + (binc*x)/0xff),
uint8(int(start.G) + (ginc*x)/0xff),
uint8(int(start.R) + (rinc*x)/0xff),
0xff
})
// Set the surface to paint on for ximg.
// (This simply sets the background pixmap of the window to the pixmap
// used by ximg.)
ximg.XSurfaceSet(wid)
// XDraw will draw the contents of ximg to its corresponding pixmap.
ximg.XDraw()
// XPaint will "clear" the window provided so that it shows the updated
// pixmap.
ximg.XPaint(wid)
// Since we will not reuse ximg, we must destroy its pixmap.
ximg.Destroy()
} | [
"func",
"paintGradient",
"(",
"X",
"*",
"xgbutil",
".",
"XUtil",
",",
"wid",
"xproto",
".",
"Window",
",",
"width",
",",
"height",
"int",
",",
"start",
",",
"end",
"color",
".",
"RGBA",
")",
"{",
"ximg",
":=",
"xgraphics",
".",
"New",
"(",
"X",
","... | // paintGradient creates a new xgraphics.Image value and draws a gradient
// starting at color 'start' and ending at color 'end'.
//
// Since xgraphics.Image values use pixmaps and pixmaps cannot be resized,
// a new pixmap must be allocated for each resize event. | [
"paintGradient",
"creates",
"a",
"new",
"xgraphics",
".",
"Image",
"value",
"and",
"draws",
"a",
"gradient",
"starting",
"at",
"color",
"start",
"and",
"ending",
"at",
"color",
"end",
".",
"Since",
"xgraphics",
".",
"Image",
"values",
"use",
"pixmaps",
"and"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/_examples/window-gradient/main.go#L95-L130 |
2,555 | BurntSushi/xgbutil | ewmh/ewmh.go | ClientEvent | func ClientEvent(xu *xgbutil.XUtil, window xproto.Window, messageType string,
data ...interface{}) error {
mstype, err := xprop.Atm(xu, messageType)
if err != nil {
return err
}
evMask := (xproto.EventMaskSubstructureNotify |
xproto.EventMaskSubstructureRedirect)
cm, err := xevent.NewClientMessage(32, window, mstype, data...)
if err != nil {
return err
}
return xevent.SendRootEvent(xu, cm, uint32(evMask))
} | go | func ClientEvent(xu *xgbutil.XUtil, window xproto.Window, messageType string,
data ...interface{}) error {
mstype, err := xprop.Atm(xu, messageType)
if err != nil {
return err
}
evMask := (xproto.EventMaskSubstructureNotify |
xproto.EventMaskSubstructureRedirect)
cm, err := xevent.NewClientMessage(32, window, mstype, data...)
if err != nil {
return err
}
return xevent.SendRootEvent(xu, cm, uint32(evMask))
} | [
"func",
"ClientEvent",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"window",
"xproto",
".",
"Window",
",",
"messageType",
"string",
",",
"data",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"mstype",
",",
"err",
":=",
"xprop",
".",
"Atm",
"(",
... | // ClientEvent is a convenience function that sends ClientMessage events
// to the root window as specified by the EWMH spec. | [
"ClientEvent",
"is",
"a",
"convenience",
"function",
"that",
"sends",
"ClientMessage",
"events",
"to",
"the",
"root",
"window",
"as",
"specified",
"by",
"the",
"EWMH",
"spec",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L13-L29 |
2,556 | BurntSushi/xgbutil | ewmh/ewmh.go | ActiveWindowReqExtra | func ActiveWindowReqExtra(xu *xgbutil.XUtil, win xproto.Window, source int,
time xproto.Timestamp, currentActive xproto.Window) error {
return ClientEvent(xu, win, "_NET_ACTIVE_WINDOW", source, int(time),
int(currentActive))
} | go | func ActiveWindowReqExtra(xu *xgbutil.XUtil, win xproto.Window, source int,
time xproto.Timestamp, currentActive xproto.Window) error {
return ClientEvent(xu, win, "_NET_ACTIVE_WINDOW", source, int(time),
int(currentActive))
} | [
"func",
"ActiveWindowReqExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"source",
"int",
",",
"time",
"xproto",
".",
"Timestamp",
",",
"currentActive",
"xproto",
".",
"Window",
")",
"error",
"{",
"return",
"Client... | // _NET_ACTIVE_WINDOW req extra | [
"_NET_ACTIVE_WINDOW",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L49-L54 |
2,557 | BurntSushi/xgbutil | ewmh/ewmh.go | CurrentDesktopReqExtra | func CurrentDesktopReqExtra(xu *xgbutil.XUtil, desk int,
time xproto.Timestamp) error {
return ClientEvent(xu, xu.RootWin(), "_NET_CURRENT_DESKTOP", desk,
int(time))
} | go | func CurrentDesktopReqExtra(xu *xgbutil.XUtil, desk int,
time xproto.Timestamp) error {
return ClientEvent(xu, xu.RootWin(), "_NET_CURRENT_DESKTOP", desk,
int(time))
} | [
"func",
"CurrentDesktopReqExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"desk",
"int",
",",
"time",
"xproto",
".",
"Timestamp",
")",
"error",
"{",
"return",
"ClientEvent",
"(",
"xu",
",",
"xu",
".",
"RootWin",
"(",
")",
",",
"\"",
"\"",
",",
... | // _NET_CURRENT_DESKTOP req extra | [
"_NET_CURRENT_DESKTOP",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L110-L115 |
2,558 | BurntSushi/xgbutil | ewmh/ewmh.go | MoveresizeWindow | func MoveresizeWindow(xu *xgbutil.XUtil, win xproto.Window,
x, y, w, h int) error {
return MoveresizeWindowExtra(xu, win, x, y, w, h, xproto.GravityBitForget,
2, true, true)
} | go | func MoveresizeWindow(xu *xgbutil.XUtil, win xproto.Window,
x, y, w, h int) error {
return MoveresizeWindowExtra(xu, win, x, y, w, h, xproto.GravityBitForget,
2, true, true)
} | [
"func",
"MoveresizeWindow",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
"int",
")",
"error",
"{",
"return",
"MoveresizeWindowExtra",
"(",
"xu",
",",
"win",
",",
"x",
",",
"y"... | // _NET_MOVERESIZE_WINDOW req
// If 'w' or 'h' are 0, then they are not sent.
// If you need to resize a window without moving it, use the ReqExtra variant,
// or Resize. | [
"_NET_MOVERESIZE_WINDOW",
"req",
"If",
"w",
"or",
"h",
"are",
"0",
"then",
"they",
"are",
"not",
"sent",
".",
"If",
"you",
"need",
"to",
"resize",
"a",
"window",
"without",
"moving",
"it",
"use",
"the",
"ReqExtra",
"variant",
"or",
"Resize",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L306-L311 |
2,559 | BurntSushi/xgbutil | ewmh/ewmh.go | ResizeWindow | func ResizeWindow(xu *xgbutil.XUtil, win xproto.Window, w, h int) error {
return MoveresizeWindowExtra(xu, win, 0, 0, w, h, xproto.GravityBitForget,
2, false, false)
} | go | func ResizeWindow(xu *xgbutil.XUtil, win xproto.Window, w, h int) error {
return MoveresizeWindowExtra(xu, win, 0, 0, w, h, xproto.GravityBitForget,
2, false, false)
} | [
"func",
"ResizeWindow",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"w",
",",
"h",
"int",
")",
"error",
"{",
"return",
"MoveresizeWindowExtra",
"(",
"xu",
",",
"win",
",",
"0",
",",
"0",
",",
"w",
",",
"h",
... | // _NET_MOVERESIZE_WINDOW req resize only | [
"_NET_MOVERESIZE_WINDOW",
"req",
"resize",
"only"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L314-L317 |
2,560 | BurntSushi/xgbutil | ewmh/ewmh.go | MoveWindow | func MoveWindow(xu *xgbutil.XUtil, win xproto.Window, x, y int) error {
return MoveresizeWindowExtra(xu, win, x, y, 0, 0, xproto.GravityBitForget,
2, true, true)
} | go | func MoveWindow(xu *xgbutil.XUtil, win xproto.Window, x, y int) error {
return MoveresizeWindowExtra(xu, win, x, y, 0, 0, xproto.GravityBitForget,
2, true, true)
} | [
"func",
"MoveWindow",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"x",
",",
"y",
"int",
")",
"error",
"{",
"return",
"MoveresizeWindowExtra",
"(",
"xu",
",",
"win",
",",
"x",
",",
"y",
",",
"0",
",",
"0",
",... | // _NET_MOVERESIZE_WINDOW req move only | [
"_NET_MOVERESIZE_WINDOW",
"req",
"move",
"only"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L320-L323 |
2,561 | BurntSushi/xgbutil | ewmh/ewmh.go | MoveresizeWindowExtra | func MoveresizeWindowExtra(xu *xgbutil.XUtil, win xproto.Window, x, y, w, h,
gravity, source int, usex, usey bool) error {
flags := gravity
flags |= source << 12
if usex {
flags |= 1 << 8
}
if usey {
flags |= 1 << 9
}
if w > 0 {
flags |= 1 << 10
}
if h > 0 {
flags |= 1 << 11
}
return ClientEvent(xu, win, "_NET_MOVERESIZE_WINDOW", flags, x, y, w, h)
} | go | func MoveresizeWindowExtra(xu *xgbutil.XUtil, win xproto.Window, x, y, w, h,
gravity, source int, usex, usey bool) error {
flags := gravity
flags |= source << 12
if usex {
flags |= 1 << 8
}
if usey {
flags |= 1 << 9
}
if w > 0 {
flags |= 1 << 10
}
if h > 0 {
flags |= 1 << 11
}
return ClientEvent(xu, win, "_NET_MOVERESIZE_WINDOW", flags, x, y, w, h)
} | [
"func",
"MoveresizeWindowExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"gravity",
",",
"source",
"int",
",",
"usex",
",",
"usey",
"bool",
")",
"error",
"{",
"flags... | // _NET_MOVERESIZE_WINDOW req extra
// If 'w' or 'h' are 0, then they are not sent.
// To not set 'x' or 'y', 'usex' or 'usey' need to be set to false. | [
"_NET_MOVERESIZE_WINDOW",
"req",
"extra",
"If",
"w",
"or",
"h",
"are",
"0",
"then",
"they",
"are",
"not",
"sent",
".",
"To",
"not",
"set",
"x",
"or",
"y",
"usex",
"or",
"usey",
"need",
"to",
"be",
"set",
"to",
"false",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L328-L347 |
2,562 | BurntSushi/xgbutil | ewmh/ewmh.go | RestackWindow | func RestackWindow(xu *xgbutil.XUtil, win xproto.Window) error {
return RestackWindowExtra(xu, win, xproto.StackModeAbove, 0, 2)
} | go | func RestackWindow(xu *xgbutil.XUtil, win xproto.Window) error {
return RestackWindowExtra(xu, win, xproto.StackModeAbove, 0, 2)
} | [
"func",
"RestackWindow",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
")",
"error",
"{",
"return",
"RestackWindowExtra",
"(",
"xu",
",",
"win",
",",
"xproto",
".",
"StackModeAbove",
",",
"0",
",",
"2",
")",
"\n",
"}"
] | // _NET_RESTACK_WINDOW req
// The shortcut here is to just raise the window to the top of the window stack. | [
"_NET_RESTACK_WINDOW",
"req",
"The",
"shortcut",
"here",
"is",
"to",
"just",
"raise",
"the",
"window",
"to",
"the",
"top",
"of",
"the",
"window",
"stack",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L373-L375 |
2,563 | BurntSushi/xgbutil | ewmh/ewmh.go | RestackWindowExtra | func RestackWindowExtra(xu *xgbutil.XUtil, win xproto.Window, stackMode int,
sibling xproto.Window, source int) error {
return ClientEvent(xu, win, "_NET_RESTACK_WINDOW", source, int(sibling),
stackMode)
} | go | func RestackWindowExtra(xu *xgbutil.XUtil, win xproto.Window, stackMode int,
sibling xproto.Window, source int) error {
return ClientEvent(xu, win, "_NET_RESTACK_WINDOW", source, int(sibling),
stackMode)
} | [
"func",
"RestackWindowExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"stackMode",
"int",
",",
"sibling",
"xproto",
".",
"Window",
",",
"source",
"int",
")",
"error",
"{",
"return",
"ClientEvent",
"(",
"xu",
","... | // _NET_RESTACK_WINDOW req extra | [
"_NET_RESTACK_WINDOW",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L378-L383 |
2,564 | BurntSushi/xgbutil | ewmh/ewmh.go | SupportedSet | func SupportedSet(xu *xgbutil.XUtil, atomNames []string) error {
atoms, err := xprop.StrToAtoms(xu, atomNames)
if err != nil {
return err
}
return xprop.ChangeProp32(xu, xu.RootWin(), "_NET_SUPPORTED", "ATOM",
atoms...)
} | go | func SupportedSet(xu *xgbutil.XUtil, atomNames []string) error {
atoms, err := xprop.StrToAtoms(xu, atomNames)
if err != nil {
return err
}
return xprop.ChangeProp32(xu, xu.RootWin(), "_NET_SUPPORTED", "ATOM",
atoms...)
} | [
"func",
"SupportedSet",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"atomNames",
"[",
"]",
"string",
")",
"error",
"{",
"atoms",
",",
"err",
":=",
"xprop",
".",
"StrToAtoms",
"(",
"xu",
",",
"atomNames",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // _NET_SUPPORTED set
// This will create any atoms in the argument if they don't already exist. | [
"_NET_SUPPORTED",
"set",
"This",
"will",
"create",
"any",
"atoms",
"in",
"the",
"argument",
"if",
"they",
"don",
"t",
"already",
"exist",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L431-L439 |
2,565 | BurntSushi/xgbutil | ewmh/ewmh.go | WmDesktopReqExtra | func WmDesktopReqExtra(xu *xgbutil.XUtil, win xproto.Window, desk uint,
source int) error {
return ClientEvent(xu, win, "_NET_WM_DESKTOP", desk, source)
} | go | func WmDesktopReqExtra(xu *xgbutil.XUtil, win xproto.Window, desk uint,
source int) error {
return ClientEvent(xu, win, "_NET_WM_DESKTOP", desk, source)
} | [
"func",
"WmDesktopReqExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"desk",
"uint",
",",
"source",
"int",
")",
"error",
"{",
"return",
"ClientEvent",
"(",
"xu",
",",
"win",
",",
"\"",
"\"",
",",
"desk",
","... | // _NET_WM_DESKTOP req extra | [
"_NET_WM_DESKTOP",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L523-L527 |
2,566 | BurntSushi/xgbutil | ewmh/ewmh.go | WmFullscreenMonitorsReqExtra | func WmFullscreenMonitorsReqExtra(xu *xgbutil.XUtil, win xproto.Window,
edges *WmFullscreenMonitors, source int) error {
return ClientEvent(xu, win, "_NET_WM_FULLSCREEN_MONITORS",
edges.Top, edges.Bottom, edges.Left, edges.Right, source)
} | go | func WmFullscreenMonitorsReqExtra(xu *xgbutil.XUtil, win xproto.Window,
edges *WmFullscreenMonitors, source int) error {
return ClientEvent(xu, win, "_NET_WM_FULLSCREEN_MONITORS",
edges.Top, edges.Bottom, edges.Left, edges.Right, source)
} | [
"func",
"WmFullscreenMonitorsReqExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"edges",
"*",
"WmFullscreenMonitors",
",",
"source",
"int",
")",
"error",
"{",
"return",
"ClientEvent",
"(",
"xu",
",",
"win",
",",
"... | // _NET_WM_FULLSCREEN_MONITORS req extra | [
"_NET_WM_FULLSCREEN_MONITORS",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L579-L584 |
2,567 | BurntSushi/xgbutil | ewmh/ewmh.go | WmMoveresizeExtra | func WmMoveresizeExtra(xu *xgbutil.XUtil, win xproto.Window, direction,
xRoot, yRoot, button, source int) error {
return ClientEvent(xu, win, "_NET_WM_MOVERESIZE",
xRoot, yRoot, direction, button, source)
} | go | func WmMoveresizeExtra(xu *xgbutil.XUtil, win xproto.Window, direction,
xRoot, yRoot, button, source int) error {
return ClientEvent(xu, win, "_NET_WM_MOVERESIZE",
xRoot, yRoot, direction, button, source)
} | [
"func",
"WmMoveresizeExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"direction",
",",
"xRoot",
",",
"yRoot",
",",
"button",
",",
"source",
"int",
")",
"error",
"{",
"return",
"ClientEvent",
"(",
"xu",
",",
"w... | // _NET_WM_MOVERESIZE req extra | [
"_NET_WM_MOVERESIZE",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L734-L739 |
2,568 | BurntSushi/xgbutil | ewmh/ewmh.go | WmPingExtra | func WmPingExtra(xu *xgbutil.XUtil, win xproto.Window, response bool,
time xproto.Timestamp) error {
pingAtom, err := xprop.Atm(xu, "_NET_WM_PING")
if err != nil {
return err
}
var evWindow xproto.Window
if response {
evWindow = xu.RootWin()
} else {
evWindow = win
}
return ClientEvent(xu, evWindow, "WM_PROTOCOLS", int(pingAtom), int(time),
int(win))
} | go | func WmPingExtra(xu *xgbutil.XUtil, win xproto.Window, response bool,
time xproto.Timestamp) error {
pingAtom, err := xprop.Atm(xu, "_NET_WM_PING")
if err != nil {
return err
}
var evWindow xproto.Window
if response {
evWindow = xu.RootWin()
} else {
evWindow = win
}
return ClientEvent(xu, evWindow, "WM_PROTOCOLS", int(pingAtom), int(time),
int(win))
} | [
"func",
"WmPingExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"response",
"bool",
",",
"time",
"xproto",
".",
"Timestamp",
")",
"error",
"{",
"pingAtom",
",",
"err",
":=",
"xprop",
".",
"Atm",
"(",
"xu",
",... | // _NET_WM_PING req extra | [
"_NET_WM_PING",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L817-L834 |
2,569 | BurntSushi/xgbutil | ewmh/ewmh.go | WmStateReqExtra | func WmStateReqExtra(xu *xgbutil.XUtil, win xproto.Window, action int,
first string, second string, source int) (err error) {
var atom1, atom2 xproto.Atom
atom1, err = xprop.Atom(xu, first, false)
if err != nil {
return err
}
if len(second) > 0 {
atom2, err = xprop.Atom(xu, second, false)
if err != nil {
return err
}
} else {
atom2 = 0
}
return ClientEvent(xu, win, "_NET_WM_STATE", action, int(atom1), int(atom2),
source)
} | go | func WmStateReqExtra(xu *xgbutil.XUtil, win xproto.Window, action int,
first string, second string, source int) (err error) {
var atom1, atom2 xproto.Atom
atom1, err = xprop.Atom(xu, first, false)
if err != nil {
return err
}
if len(second) > 0 {
atom2, err = xprop.Atom(xu, second, false)
if err != nil {
return err
}
} else {
atom2 = 0
}
return ClientEvent(xu, win, "_NET_WM_STATE", action, int(atom1), int(atom2),
source)
} | [
"func",
"WmStateReqExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"action",
"int",
",",
"first",
"string",
",",
"second",
"string",
",",
"source",
"int",
")",
"(",
"err",
"error",
")",
"{",
"var",
"atom1",
... | // _NET_WM_STATE req extra | [
"_NET_WM_STATE",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L870-L891 |
2,570 | BurntSushi/xgbutil | ewmh/ewmh.go | WmSyncRequestExtra | func WmSyncRequestExtra(xu *xgbutil.XUtil, win xproto.Window, reqNum uint64,
time xproto.Timestamp) error {
syncReq, err := xprop.Atm(xu, "_NET_WM_SYNC_REQUEST")
if err != nil {
return err
}
high := int(reqNum >> 32)
low := int(reqNum<<32 ^ reqNum)
return ClientEvent(xu, win, "WM_PROTOCOLS", int(syncReq), int(time),
low, high)
} | go | func WmSyncRequestExtra(xu *xgbutil.XUtil, win xproto.Window, reqNum uint64,
time xproto.Timestamp) error {
syncReq, err := xprop.Atm(xu, "_NET_WM_SYNC_REQUEST")
if err != nil {
return err
}
high := int(reqNum >> 32)
low := int(reqNum<<32 ^ reqNum)
return ClientEvent(xu, win, "WM_PROTOCOLS", int(syncReq), int(time),
low, high)
} | [
"func",
"WmSyncRequestExtra",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"reqNum",
"uint64",
",",
"time",
"xproto",
".",
"Timestamp",
")",
"error",
"{",
"syncReq",
",",
"err",
":=",
"xprop",
".",
"Atm",
"(",
"xu"... | // _NET_WM_SYNC_REQUEST req extra | [
"_NET_WM_SYNC_REQUEST",
"req",
"extra"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L987-L1000 |
2,571 | BurntSushi/xgbutil | ewmh/ewmh.go | WmSyncRequestCounter | func WmSyncRequestCounter(xu *xgbutil.XUtil, win xproto.Window) (uint, error) {
return xprop.PropValNum(xprop.GetProperty(xu, win,
"_NET_WM_SYNC_REQUEST_COUNTER"))
} | go | func WmSyncRequestCounter(xu *xgbutil.XUtil, win xproto.Window) (uint, error) {
return xprop.PropValNum(xprop.GetProperty(xu, win,
"_NET_WM_SYNC_REQUEST_COUNTER"))
} | [
"func",
"WmSyncRequestCounter",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
")",
"(",
"uint",
",",
"error",
")",
"{",
"return",
"xprop",
".",
"PropValNum",
"(",
"xprop",
".",
"GetProperty",
"(",
"xu",
",",
"win",
",",
... | // _NET_WM_SYNC_REQUEST_COUNTER get
// I'm pretty sure this needs 64 bit integers, but I'm not quite sure
// how to go about that yet. Any ideas? | [
"_NET_WM_SYNC_REQUEST_COUNTER",
"get",
"I",
"m",
"pretty",
"sure",
"this",
"needs",
"64",
"bit",
"integers",
"but",
"I",
"m",
"not",
"quite",
"sure",
"how",
"to",
"go",
"about",
"that",
"yet",
".",
"Any",
"ideas?"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L1005-L1008 |
2,572 | BurntSushi/xgbutil | ewmh/ewmh.go | WmSyncRequestCounterSet | func WmSyncRequestCounterSet(xu *xgbutil.XUtil, win xproto.Window,
counter uint) error {
return xprop.ChangeProp32(xu, win, "_NET_WM_SYNC_REQUEST_COUNTER",
"CARDINAL", counter)
} | go | func WmSyncRequestCounterSet(xu *xgbutil.XUtil, win xproto.Window,
counter uint) error {
return xprop.ChangeProp32(xu, win, "_NET_WM_SYNC_REQUEST_COUNTER",
"CARDINAL", counter)
} | [
"func",
"WmSyncRequestCounterSet",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"counter",
"uint",
")",
"error",
"{",
"return",
"xprop",
".",
"ChangeProp32",
"(",
"xu",
",",
"win",
",",
"\"",
"\"",
",",
"\"",
"\"",... | // _NET_WM_SYNC_REQUEST_COUNTER set
// I'm pretty sure this needs 64 bit integers, but I'm not quite sure
// how to go about that yet. Any ideas? | [
"_NET_WM_SYNC_REQUEST_COUNTER",
"set",
"I",
"m",
"pretty",
"sure",
"this",
"needs",
"64",
"bit",
"integers",
"but",
"I",
"m",
"not",
"quite",
"sure",
"how",
"to",
"go",
"about",
"that",
"yet",
".",
"Any",
"ideas?"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L1013-L1018 |
2,573 | BurntSushi/xgbutil | ewmh/ewmh.go | WmWindowTypeSet | func WmWindowTypeSet(xu *xgbutil.XUtil, win xproto.Window,
atomNames []string) error {
atoms, err := xprop.StrToAtoms(xu, atomNames)
if err != nil {
return err
}
return xprop.ChangeProp32(xu, win, "_NET_WM_WINDOW_TYPE", "ATOM", atoms...)
} | go | func WmWindowTypeSet(xu *xgbutil.XUtil, win xproto.Window,
atomNames []string) error {
atoms, err := xprop.StrToAtoms(xu, atomNames)
if err != nil {
return err
}
return xprop.ChangeProp32(xu, win, "_NET_WM_WINDOW_TYPE", "ATOM", atoms...)
} | [
"func",
"WmWindowTypeSet",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"atomNames",
"[",
"]",
"string",
")",
"error",
"{",
"atoms",
",",
"err",
":=",
"xprop",
".",
"StrToAtoms",
"(",
"xu",
",",
"atomNames",
")",
... | // _NET_WM_WINDOW_TYPE set
// This will create any atoms used in 'atomNames' if they don't already exist. | [
"_NET_WM_WINDOW_TYPE",
"set",
"This",
"will",
"create",
"any",
"atoms",
"used",
"in",
"atomNames",
"if",
"they",
"don",
"t",
"already",
"exist",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/ewmh.go#L1107-L1115 |
2,574 | BurntSushi/xgbutil | xprop/atom.go | Atom | func Atom(xu *xgbutil.XUtil, name string,
onlyIfExists bool) (xproto.Atom, error) {
// Check the cache first
if aid, ok := atomGet(xu, name); ok {
return aid, nil
}
reply, err := xproto.InternAtom(xu.Conn(), onlyIfExists,
uint16(len(name)), name).Reply()
if err != nil {
return 0, fmt.Errorf("Atom: Error interning atom '%s': %s", name, err)
}
// If we're here, it means we didn't have this atom cached. So cache it!
cacheAtom(xu, name, reply.Atom)
return reply.Atom, nil
} | go | func Atom(xu *xgbutil.XUtil, name string,
onlyIfExists bool) (xproto.Atom, error) {
// Check the cache first
if aid, ok := atomGet(xu, name); ok {
return aid, nil
}
reply, err := xproto.InternAtom(xu.Conn(), onlyIfExists,
uint16(len(name)), name).Reply()
if err != nil {
return 0, fmt.Errorf("Atom: Error interning atom '%s': %s", name, err)
}
// If we're here, it means we didn't have this atom cached. So cache it!
cacheAtom(xu, name, reply.Atom)
return reply.Atom, nil
} | [
"func",
"Atom",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"name",
"string",
",",
"onlyIfExists",
"bool",
")",
"(",
"xproto",
".",
"Atom",
",",
"error",
")",
"{",
"// Check the cache first",
"if",
"aid",
",",
"ok",
":=",
"atomGet",
"(",
"xu",
",",
... | // Atom interns an atom and panics if there is any error. | [
"Atom",
"interns",
"an",
"atom",
"and",
"panics",
"if",
"there",
"is",
"any",
"error",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/atom.go#L36-L54 |
2,575 | BurntSushi/xgbutil | xprop/atom.go | AtomName | func AtomName(xu *xgbutil.XUtil, aid xproto.Atom) (string, error) {
// Check the cache first
if atomName, ok := atomNameGet(xu, aid); ok {
return string(atomName), nil
}
reply, err := xproto.GetAtomName(xu.Conn(), aid).Reply()
if err != nil {
return "", fmt.Errorf("AtomName: Error fetching name for ATOM "+
"id '%d': %s", aid, err)
}
// If we're here, it means we didn't have ths ATOM id cached. So cache it.
atomName := string(reply.Name)
cacheAtom(xu, atomName, aid)
return atomName, nil
} | go | func AtomName(xu *xgbutil.XUtil, aid xproto.Atom) (string, error) {
// Check the cache first
if atomName, ok := atomNameGet(xu, aid); ok {
return string(atomName), nil
}
reply, err := xproto.GetAtomName(xu.Conn(), aid).Reply()
if err != nil {
return "", fmt.Errorf("AtomName: Error fetching name for ATOM "+
"id '%d': %s", aid, err)
}
// If we're here, it means we didn't have ths ATOM id cached. So cache it.
atomName := string(reply.Name)
cacheAtom(xu, atomName, aid)
return atomName, nil
} | [
"func",
"AtomName",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"aid",
"xproto",
".",
"Atom",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Check the cache first",
"if",
"atomName",
",",
"ok",
":=",
"atomNameGet",
"(",
"xu",
",",
"aid",
")",
";",
... | // AtomName fetches a string representation of an ATOM given its integer id. | [
"AtomName",
"fetches",
"a",
"string",
"representation",
"of",
"an",
"ATOM",
"given",
"its",
"integer",
"id",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/atom.go#L57-L74 |
2,576 | BurntSushi/xgbutil | xprop/atom.go | atomGet | func atomGet(xu *xgbutil.XUtil, name string) (xproto.Atom, bool) {
xu.AtomsLck.RLock()
defer xu.AtomsLck.RUnlock()
aid, ok := xu.Atoms[name]
return aid, ok
} | go | func atomGet(xu *xgbutil.XUtil, name string) (xproto.Atom, bool) {
xu.AtomsLck.RLock()
defer xu.AtomsLck.RUnlock()
aid, ok := xu.Atoms[name]
return aid, ok
} | [
"func",
"atomGet",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"name",
"string",
")",
"(",
"xproto",
".",
"Atom",
",",
"bool",
")",
"{",
"xu",
".",
"AtomsLck",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xu",
".",
"AtomsLck",
".",
"RUnlock",
"(",
"... | // atomGet retrieves an atom identifier from a cache if it exists. | [
"atomGet",
"retrieves",
"an",
"atom",
"identifier",
"from",
"a",
"cache",
"if",
"it",
"exists",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/atom.go#L77-L83 |
2,577 | BurntSushi/xgbutil | xprop/atom.go | atomNameGet | func atomNameGet(xu *xgbutil.XUtil, aid xproto.Atom) (string, bool) {
xu.AtomNamesLck.RLock()
defer xu.AtomNamesLck.RUnlock()
name, ok := xu.AtomNames[aid]
return name, ok
} | go | func atomNameGet(xu *xgbutil.XUtil, aid xproto.Atom) (string, bool) {
xu.AtomNamesLck.RLock()
defer xu.AtomNamesLck.RUnlock()
name, ok := xu.AtomNames[aid]
return name, ok
} | [
"func",
"atomNameGet",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"aid",
"xproto",
".",
"Atom",
")",
"(",
"string",
",",
"bool",
")",
"{",
"xu",
".",
"AtomNamesLck",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xu",
".",
"AtomNamesLck",
".",
"RUnlock",... | // atomNameGet retrieves an atom name from a cache if it exists. | [
"atomNameGet",
"retrieves",
"an",
"atom",
"name",
"from",
"a",
"cache",
"if",
"it",
"exists",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/atom.go#L86-L92 |
2,578 | BurntSushi/xgbutil | xprop/atom.go | cacheAtom | func cacheAtom(xu *xgbutil.XUtil, name string, aid xproto.Atom) {
xu.AtomsLck.Lock()
xu.AtomNamesLck.Lock()
defer xu.AtomsLck.Unlock()
defer xu.AtomNamesLck.Unlock()
xu.Atoms[name] = aid
xu.AtomNames[aid] = name
} | go | func cacheAtom(xu *xgbutil.XUtil, name string, aid xproto.Atom) {
xu.AtomsLck.Lock()
xu.AtomNamesLck.Lock()
defer xu.AtomsLck.Unlock()
defer xu.AtomNamesLck.Unlock()
xu.Atoms[name] = aid
xu.AtomNames[aid] = name
} | [
"func",
"cacheAtom",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"name",
"string",
",",
"aid",
"xproto",
".",
"Atom",
")",
"{",
"xu",
".",
"AtomsLck",
".",
"Lock",
"(",
")",
"\n",
"xu",
".",
"AtomNamesLck",
".",
"Lock",
"(",
")",
"\n",
"defer",
... | // cacheAtom puts an atom into the cache. | [
"cacheAtom",
"puts",
"an",
"atom",
"into",
"the",
"cache",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/atom.go#L95-L103 |
2,579 | BurntSushi/xgbutil | xevent/types_manual.go | NewClientMessage | func NewClientMessage(Format byte, Window xproto.Window, Type xproto.Atom,
data ...interface{}) (*ClientMessageEvent, error) {
// Create the client data list first
var clientData xproto.ClientMessageDataUnion
// Don't support formats 8 or 16 yet. They aren't used in EWMH anyway.
switch Format {
case 8:
buf := make([]byte, 20)
for i := 0; i < 20; i++ {
if i >= len(data) {
break
}
buf[i] = data[i].(byte)
}
clientData = xproto.ClientMessageDataUnionData8New(buf)
case 16:
buf := make([]uint16, 10)
for i := 0; i < 10; i++ {
if i >= len(data) {
break
}
buf[i] = uint16(data[i].(int16))
}
clientData = xproto.ClientMessageDataUnionData16New(buf)
case 32:
buf := make([]uint32, 5)
for i := 0; i < 5; i++ {
if i >= len(data) {
break
}
buf[i] = uint32(data[i].(int))
}
clientData = xproto.ClientMessageDataUnionData32New(buf)
default:
return nil, fmt.Errorf("NewClientMessage: Unsupported format '%d'.",
Format)
}
return &ClientMessageEvent{&xproto.ClientMessageEvent{
Format: Format,
Window: Window,
Type: Type,
Data: clientData,
}}, nil
} | go | func NewClientMessage(Format byte, Window xproto.Window, Type xproto.Atom,
data ...interface{}) (*ClientMessageEvent, error) {
// Create the client data list first
var clientData xproto.ClientMessageDataUnion
// Don't support formats 8 or 16 yet. They aren't used in EWMH anyway.
switch Format {
case 8:
buf := make([]byte, 20)
for i := 0; i < 20; i++ {
if i >= len(data) {
break
}
buf[i] = data[i].(byte)
}
clientData = xproto.ClientMessageDataUnionData8New(buf)
case 16:
buf := make([]uint16, 10)
for i := 0; i < 10; i++ {
if i >= len(data) {
break
}
buf[i] = uint16(data[i].(int16))
}
clientData = xproto.ClientMessageDataUnionData16New(buf)
case 32:
buf := make([]uint32, 5)
for i := 0; i < 5; i++ {
if i >= len(data) {
break
}
buf[i] = uint32(data[i].(int))
}
clientData = xproto.ClientMessageDataUnionData32New(buf)
default:
return nil, fmt.Errorf("NewClientMessage: Unsupported format '%d'.",
Format)
}
return &ClientMessageEvent{&xproto.ClientMessageEvent{
Format: Format,
Window: Window,
Type: Type,
Data: clientData,
}}, nil
} | [
"func",
"NewClientMessage",
"(",
"Format",
"byte",
",",
"Window",
"xproto",
".",
"Window",
",",
"Type",
"xproto",
".",
"Atom",
",",
"data",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"ClientMessageEvent",
",",
"error",
")",
"{",
"// Create the client data ... | // NewClientMessage takes all arguments required to build a ClientMessageEvent
// struct and hides the messy details.
// The variadic parameters coincide with the "data" part of a client message.
// The type of the variadic parameters depends upon the value of Format.
// If Format is 8, 'data' should have type byte.
// If Format is 16, 'data' should have type int16.
// If Format is 32, 'data' should have type int.
// Any other value of Format returns an error. | [
"NewClientMessage",
"takes",
"all",
"arguments",
"required",
"to",
"build",
"a",
"ClientMessageEvent",
"struct",
"and",
"hides",
"the",
"messy",
"details",
".",
"The",
"variadic",
"parameters",
"coincide",
"with",
"the",
"data",
"part",
"of",
"a",
"client",
"mes... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xevent/types_manual.go#L24-L70 |
2,580 | BurntSushi/xgbutil | xevent/types_manual.go | NewConfigureNotify | func NewConfigureNotify(Event, Window, AboveSibling xproto.Window,
X, Y, Width, Height int, BorderWidth uint16,
OverrideRedirect bool) *ConfigureNotifyEvent {
return &ConfigureNotifyEvent{&xproto.ConfigureNotifyEvent{
Event: Event, Window: Window, AboveSibling: AboveSibling,
X: int16(X), Y: int16(Y), Width: uint16(Width), Height: uint16(Height),
BorderWidth: BorderWidth, OverrideRedirect: OverrideRedirect,
}}
} | go | func NewConfigureNotify(Event, Window, AboveSibling xproto.Window,
X, Y, Width, Height int, BorderWidth uint16,
OverrideRedirect bool) *ConfigureNotifyEvent {
return &ConfigureNotifyEvent{&xproto.ConfigureNotifyEvent{
Event: Event, Window: Window, AboveSibling: AboveSibling,
X: int16(X), Y: int16(Y), Width: uint16(Width), Height: uint16(Height),
BorderWidth: BorderWidth, OverrideRedirect: OverrideRedirect,
}}
} | [
"func",
"NewConfigureNotify",
"(",
"Event",
",",
"Window",
",",
"AboveSibling",
"xproto",
".",
"Window",
",",
"X",
",",
"Y",
",",
"Width",
",",
"Height",
"int",
",",
"BorderWidth",
"uint16",
",",
"OverrideRedirect",
"bool",
")",
"*",
"ConfigureNotifyEvent",
... | // NewConfigureNotify takes all arguments required to build a
// ConfigureNotifyEvent struct and returns a ConfigureNotifyEvent value. | [
"NewConfigureNotify",
"takes",
"all",
"arguments",
"required",
"to",
"build",
"a",
"ConfigureNotifyEvent",
"struct",
"and",
"returns",
"a",
"ConfigureNotifyEvent",
"value",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xevent/types_manual.go#L81-L90 |
2,581 | BurntSushi/xgbutil | ewmh/winman.go | GetEwmhWM | func GetEwmhWM(xu *xgbutil.XUtil) (string, error) {
childCheck, err := SupportingWmCheckGet(xu, xu.RootWin())
if err != nil {
return "", fmt.Errorf("GetEwmhWM: Failed because: %s", err)
}
childCheck2, err := SupportingWmCheckGet(xu, childCheck)
if err != nil {
return "", fmt.Errorf("GetEwmhWM: Failed because: %s", err)
}
if childCheck != childCheck2 {
return "", fmt.Errorf(
"GetEwmhWM: _NET_SUPPORTING_WM_CHECK value on the root window "+
"(%x) does not match _NET_SUPPORTING_WM_CHECK value "+
"on the child window (%x).", childCheck, childCheck2)
}
return WmNameGet(xu, childCheck)
} | go | func GetEwmhWM(xu *xgbutil.XUtil) (string, error) {
childCheck, err := SupportingWmCheckGet(xu, xu.RootWin())
if err != nil {
return "", fmt.Errorf("GetEwmhWM: Failed because: %s", err)
}
childCheck2, err := SupportingWmCheckGet(xu, childCheck)
if err != nil {
return "", fmt.Errorf("GetEwmhWM: Failed because: %s", err)
}
if childCheck != childCheck2 {
return "", fmt.Errorf(
"GetEwmhWM: _NET_SUPPORTING_WM_CHECK value on the root window "+
"(%x) does not match _NET_SUPPORTING_WM_CHECK value "+
"on the child window (%x).", childCheck, childCheck2)
}
return WmNameGet(xu, childCheck)
} | [
"func",
"GetEwmhWM",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
")",
"(",
"string",
",",
"error",
")",
"{",
"childCheck",
",",
"err",
":=",
"SupportingWmCheckGet",
"(",
"xu",
",",
"xu",
".",
"RootWin",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"... | // GetEwmhWM uses the EWMH spec to find if a conforming window manager
// is currently running or not. If it is, then its name will be returned.
// Otherwise, an error will be returned explaining why one couldn't be found. | [
"GetEwmhWM",
"uses",
"the",
"EWMH",
"spec",
"to",
"find",
"if",
"a",
"conforming",
"window",
"manager",
"is",
"currently",
"running",
"or",
"not",
".",
"If",
"it",
"is",
"then",
"its",
"name",
"will",
"be",
"returned",
".",
"Otherwise",
"an",
"error",
"w... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/ewmh/winman.go#L12-L31 |
2,582 | BurntSushi/xgbutil | xevent/xevent.go | DequeueAt | func DequeueAt(xu *xgbutil.XUtil, i int) {
xu.EvqueueLck.Lock()
defer xu.EvqueueLck.Unlock()
xu.Evqueue = append(xu.Evqueue[:i], xu.Evqueue[i+1:]...)
} | go | func DequeueAt(xu *xgbutil.XUtil, i int) {
xu.EvqueueLck.Lock()
defer xu.EvqueueLck.Unlock()
xu.Evqueue = append(xu.Evqueue[:i], xu.Evqueue[i+1:]...)
} | [
"func",
"DequeueAt",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"i",
"int",
")",
"{",
"xu",
".",
"EvqueueLck",
".",
"Lock",
"(",
")",
"\n",
"defer",
"xu",
".",
"EvqueueLck",
".",
"Unlock",
"(",
")",
"\n\n",
"xu",
".",
"Evqueue",
"=",
"append",
... | // DequeueAt removes a particular item from the queue.
// This is primarily useful when attempting to compress events. | [
"DequeueAt",
"removes",
"a",
"particular",
"item",
"from",
"the",
"queue",
".",
"This",
"is",
"primarily",
"useful",
"when",
"attempting",
"to",
"compress",
"events",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xevent/xevent.go#L67-L72 |
2,583 | BurntSushi/xgbutil | xevent/xevent.go | Empty | func Empty(xu *xgbutil.XUtil) bool {
xu.EvqueueLck.RLock()
defer xu.EvqueueLck.RUnlock()
return len(xu.Evqueue) == 0
} | go | func Empty(xu *xgbutil.XUtil) bool {
xu.EvqueueLck.RLock()
defer xu.EvqueueLck.RUnlock()
return len(xu.Evqueue) == 0
} | [
"func",
"Empty",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
")",
"bool",
"{",
"xu",
".",
"EvqueueLck",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xu",
".",
"EvqueueLck",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"len",
"(",
"xu",
".",
"Evqueue",
")",
... | // Empty returns whether the event queue is empty or not. | [
"Empty",
"returns",
"whether",
"the",
"event",
"queue",
"is",
"empty",
"or",
"not",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xevent/xevent.go#L75-L80 |
2,584 | BurntSushi/xgbutil | xevent/xevent.go | SendRootEvent | func SendRootEvent(xu *xgbutil.XUtil, ev xgb.Event, evMask uint32) error {
return xproto.SendEventChecked(xu.Conn(), false, xu.RootWin(), evMask,
string(ev.Bytes())).Check()
} | go | func SendRootEvent(xu *xgbutil.XUtil, ev xgb.Event, evMask uint32) error {
return xproto.SendEventChecked(xu.Conn(), false, xu.RootWin(), evMask,
string(ev.Bytes())).Check()
} | [
"func",
"SendRootEvent",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"ev",
"xgb",
".",
"Event",
",",
"evMask",
"uint32",
")",
"error",
"{",
"return",
"xproto",
".",
"SendEventChecked",
"(",
"xu",
".",
"Conn",
"(",
")",
",",
"false",
",",
"xu",
".",... | // SendRootEvent takes a type implementing the xgb.Event interface, converts it
// to raw X bytes, and sends it to the root window using the SendEvent request. | [
"SendRootEvent",
"takes",
"a",
"type",
"implementing",
"the",
"xgb",
".",
"Event",
"interface",
"converts",
"it",
"to",
"raw",
"X",
"bytes",
"and",
"sends",
"it",
"to",
"the",
"root",
"window",
"using",
"the",
"SendEvent",
"request",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xevent/xevent.go#L229-L232 |
2,585 | BurntSushi/xgbutil | xevent/xevent.go | ReplayPointer | func ReplayPointer(xu *xgbutil.XUtil) {
xproto.AllowEvents(xu.Conn(), xproto.AllowReplayPointer, 0)
} | go | func ReplayPointer(xu *xgbutil.XUtil) {
xproto.AllowEvents(xu.Conn(), xproto.AllowReplayPointer, 0)
} | [
"func",
"ReplayPointer",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
")",
"{",
"xproto",
".",
"AllowEvents",
"(",
"xu",
".",
"Conn",
"(",
")",
",",
"xproto",
".",
"AllowReplayPointer",
",",
"0",
")",
"\n",
"}"
] | // ReplayPointer is a quick alias to AllowEvents with 'ReplayPointer' mode. | [
"ReplayPointer",
"is",
"a",
"quick",
"alias",
"to",
"AllowEvents",
"with",
"ReplayPointer",
"mode",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xevent/xevent.go#L235-L237 |
2,586 | BurntSushi/xgbutil | mousebind/drag.go | dragGrab | func dragGrab(xu *xgbutil.XUtil, grabwin xproto.Window, win xproto.Window,
cursor xproto.Cursor) bool {
status, err := GrabPointer(xu, grabwin, xu.RootWin(), cursor)
if err != nil {
xgbutil.Logger.Printf("Mouse dragging was unsuccessful because: %v",
err)
return false
}
if !status {
xgbutil.Logger.Println("Mouse dragging was unsuccessful because " +
"we could not establish a pointer grab.")
return false
}
mouseDragSet(xu, true)
return true
} | go | func dragGrab(xu *xgbutil.XUtil, grabwin xproto.Window, win xproto.Window,
cursor xproto.Cursor) bool {
status, err := GrabPointer(xu, grabwin, xu.RootWin(), cursor)
if err != nil {
xgbutil.Logger.Printf("Mouse dragging was unsuccessful because: %v",
err)
return false
}
if !status {
xgbutil.Logger.Println("Mouse dragging was unsuccessful because " +
"we could not establish a pointer grab.")
return false
}
mouseDragSet(xu, true)
return true
} | [
"func",
"dragGrab",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"grabwin",
"xproto",
".",
"Window",
",",
"win",
"xproto",
".",
"Window",
",",
"cursor",
"xproto",
".",
"Cursor",
")",
"bool",
"{",
"status",
",",
"err",
":=",
"GrabPointer",
"(",
"xu",
... | // dragGrab is a shortcut for grabbing the pointer for a drag. | [
"dragGrab",
"is",
"a",
"shortcut",
"for",
"grabbing",
"the",
"pointer",
"for",
"a",
"drag",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/drag.go#L37-L54 |
2,587 | BurntSushi/xgbutil | mousebind/drag.go | dragStep | func dragStep(xu *xgbutil.XUtil, ev xevent.MotionNotifyEvent) {
// If for whatever reason we don't have any *piece* of a grab,
// we've gotta back out.
if !mouseDrag(xu) || mouseDragStep(xu) == nil || mouseDragEnd(xu) == nil {
dragUngrab(xu)
mouseDragStepSet(xu, nil)
mouseDragEndSet(xu, nil)
return
}
// The most recent MotionNotify event that we'll end up returning.
laste := ev
// We force a round trip request so that we make sure to read all
// available events.
xu.Sync()
xevent.Read(xu, false)
// Compress MotionNotify events.
for i, ee := range xevent.Peek(xu) {
if ee.Err != nil { // This is an error, skip it.
continue
}
// Use type assertion to make sure this is a MotionNotify event.
if mn, ok := ee.Event.(xproto.MotionNotifyEvent); ok {
// Now make sure all appropriate fields are equivalent.
if ev.Event == mn.Event && ev.Child == mn.Child &&
ev.Detail == mn.Detail && ev.State == mn.State &&
ev.Root == mn.Root && ev.SameScreen == mn.SameScreen {
// Set the most recent/valid motion notify event.
laste = xevent.MotionNotifyEvent{&mn}
// We cheat and use the stack semantics of defer to dequeue
// most recent motion notify events first, so that the indices
// don't become invalid. (If we dequeued oldest first, we'd
// have to account for all future events shifting to the left
// by one.)
defer func(i int) { xevent.DequeueAt(xu, i) }(i)
}
}
}
xu.TimeSet(laste.Time)
// now actually run the step
mouseDragStep(xu)(xu, int(laste.RootX), int(laste.RootY),
int(laste.EventX), int(laste.EventY))
} | go | func dragStep(xu *xgbutil.XUtil, ev xevent.MotionNotifyEvent) {
// If for whatever reason we don't have any *piece* of a grab,
// we've gotta back out.
if !mouseDrag(xu) || mouseDragStep(xu) == nil || mouseDragEnd(xu) == nil {
dragUngrab(xu)
mouseDragStepSet(xu, nil)
mouseDragEndSet(xu, nil)
return
}
// The most recent MotionNotify event that we'll end up returning.
laste := ev
// We force a round trip request so that we make sure to read all
// available events.
xu.Sync()
xevent.Read(xu, false)
// Compress MotionNotify events.
for i, ee := range xevent.Peek(xu) {
if ee.Err != nil { // This is an error, skip it.
continue
}
// Use type assertion to make sure this is a MotionNotify event.
if mn, ok := ee.Event.(xproto.MotionNotifyEvent); ok {
// Now make sure all appropriate fields are equivalent.
if ev.Event == mn.Event && ev.Child == mn.Child &&
ev.Detail == mn.Detail && ev.State == mn.State &&
ev.Root == mn.Root && ev.SameScreen == mn.SameScreen {
// Set the most recent/valid motion notify event.
laste = xevent.MotionNotifyEvent{&mn}
// We cheat and use the stack semantics of defer to dequeue
// most recent motion notify events first, so that the indices
// don't become invalid. (If we dequeued oldest first, we'd
// have to account for all future events shifting to the left
// by one.)
defer func(i int) { xevent.DequeueAt(xu, i) }(i)
}
}
}
xu.TimeSet(laste.Time)
// now actually run the step
mouseDragStep(xu)(xu, int(laste.RootX), int(laste.RootY),
int(laste.EventX), int(laste.EventY))
} | [
"func",
"dragStep",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"ev",
"xevent",
".",
"MotionNotifyEvent",
")",
"{",
"// If for whatever reason we don't have any *piece* of a grab,",
"// we've gotta back out.",
"if",
"!",
"mouseDrag",
"(",
"xu",
")",
"||",
"mouseDrag... | // dragStep executes the "step" function registered for the current drag.
// It also compresses the MotionNotify events. | [
"dragStep",
"executes",
"the",
"step",
"function",
"registered",
"for",
"the",
"current",
"drag",
".",
"It",
"also",
"compresses",
"the",
"MotionNotify",
"events",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/drag.go#L98-L146 |
2,588 | BurntSushi/xgbutil | mousebind/drag.go | DragEnd | func DragEnd(xu *xgbutil.XUtil, ev xevent.ButtonReleaseEvent) {
if mouseDragEnd(xu) != nil {
mouseDragEnd(xu)(xu, int(ev.RootX), int(ev.RootY),
int(ev.EventX), int(ev.EventY))
}
dragUngrab(xu)
mouseDragStepSet(xu, nil)
mouseDragEndSet(xu, nil)
} | go | func DragEnd(xu *xgbutil.XUtil, ev xevent.ButtonReleaseEvent) {
if mouseDragEnd(xu) != nil {
mouseDragEnd(xu)(xu, int(ev.RootX), int(ev.RootY),
int(ev.EventX), int(ev.EventY))
}
dragUngrab(xu)
mouseDragStepSet(xu, nil)
mouseDragEndSet(xu, nil)
} | [
"func",
"DragEnd",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"ev",
"xevent",
".",
"ButtonReleaseEvent",
")",
"{",
"if",
"mouseDragEnd",
"(",
"xu",
")",
"!=",
"nil",
"{",
"mouseDragEnd",
"(",
"xu",
")",
"(",
"xu",
",",
"int",
"(",
"ev",
".",
"Ro... | // DragEnd executes the "end" function registered for the current drag.
// This must be called at some point if DragStart has been called. | [
"DragEnd",
"executes",
"the",
"end",
"function",
"registered",
"for",
"the",
"current",
"drag",
".",
"This",
"must",
"be",
"called",
"at",
"some",
"point",
"if",
"DragStart",
"has",
"been",
"called",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/drag.go#L150-L159 |
2,589 | BurntSushi/xgbutil | xevent/eventloop.go | Read | func Read(xu *xgbutil.XUtil, block bool) {
if block {
ev, err := xu.Conn().WaitForEvent()
if ev == nil && err == nil {
xgbutil.Logger.Fatal("BUG: Could not read an event or an error.")
}
Enqueue(xu, ev, err)
}
// Clean up anything that's in the queue
for {
ev, err := xu.Conn().PollForEvent()
// No events left...
if ev == nil && err == nil {
break
}
// We're good, queue it up
Enqueue(xu, ev, err)
}
} | go | func Read(xu *xgbutil.XUtil, block bool) {
if block {
ev, err := xu.Conn().WaitForEvent()
if ev == nil && err == nil {
xgbutil.Logger.Fatal("BUG: Could not read an event or an error.")
}
Enqueue(xu, ev, err)
}
// Clean up anything that's in the queue
for {
ev, err := xu.Conn().PollForEvent()
// No events left...
if ev == nil && err == nil {
break
}
// We're good, queue it up
Enqueue(xu, ev, err)
}
} | [
"func",
"Read",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"block",
"bool",
")",
"{",
"if",
"block",
"{",
"ev",
",",
"err",
":=",
"xu",
".",
"Conn",
"(",
")",
".",
"WaitForEvent",
"(",
")",
"\n",
"if",
"ev",
"==",
"nil",
"&&",
"err",
"==",
... | // Read reads one or more events and queues them in XUtil.
// If 'block' is True, then call 'WaitForEvent' before sucking up
// all events that have been queued by XGB. | [
"Read",
"reads",
"one",
"or",
"more",
"events",
"and",
"queues",
"them",
"in",
"XUtil",
".",
"If",
"block",
"is",
"True",
"then",
"call",
"WaitForEvent",
"before",
"sucking",
"up",
"all",
"events",
"that",
"have",
"been",
"queued",
"by",
"XGB",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xevent/eventloop.go#L23-L44 |
2,590 | BurntSushi/xgbutil | xevent/eventloop.go | mainEventLoop | func mainEventLoop(xu *xgbutil.XUtil,
pingBefore, pingAfter, pingQuit chan struct{}) {
for {
if Quitting(xu) {
if pingQuit != nil {
pingQuit <- struct{}{}
}
break
}
// Gobble up as many events as possible (into the queue).
// If there are no events, we block.
Read(xu, true)
// Now process every event/error in the queue.
processEventQueue(xu, pingBefore, pingAfter)
}
} | go | func mainEventLoop(xu *xgbutil.XUtil,
pingBefore, pingAfter, pingQuit chan struct{}) {
for {
if Quitting(xu) {
if pingQuit != nil {
pingQuit <- struct{}{}
}
break
}
// Gobble up as many events as possible (into the queue).
// If there are no events, we block.
Read(xu, true)
// Now process every event/error in the queue.
processEventQueue(xu, pingBefore, pingAfter)
}
} | [
"func",
"mainEventLoop",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"pingBefore",
",",
"pingAfter",
",",
"pingQuit",
"chan",
"struct",
"{",
"}",
")",
"{",
"for",
"{",
"if",
"Quitting",
"(",
"xu",
")",
"{",
"if",
"pingQuit",
"!=",
"nil",
"{",
"ping... | // mainEventLoop runs the main event loop with an optional ping channel. | [
"mainEventLoop",
"runs",
"the",
"main",
"event",
"loop",
"with",
"an",
"optional",
"ping",
"channel",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xevent/eventloop.go#L93-L110 |
2,591 | BurntSushi/xgbutil | mousebind/callback.go | connect | func connect(xu *xgbutil.XUtil, callback xgbutil.CallbackMouse, evtype int,
win xproto.Window, buttonStr string, sync bool, grab bool) error {
// Get the mods/button first
mods, button, err := ParseString(xu, buttonStr)
if err != nil {
return err
}
// Only do the grab if we haven't yet on this window.
// And if we WANT a grab...
if grab && mouseBindGrabs(xu, evtype, win, mods, button) == 0 {
err := GrabChecked(xu, win, mods, button, sync)
if err != nil {
// If a bad access, let's be nice and give a good error message.
switch err.(type) {
case xproto.AccessError:
return fmt.Errorf("Got a bad access error when trying to bind "+
"'%s'. This usually means another client has already "+
"grabbed this mouse binding.", buttonStr)
default:
return fmt.Errorf("Could not bind '%s' because: %s",
buttonStr, err)
}
}
}
// If we've never grabbed anything on this window before, we need to
// make sure we can respond to it in the main event loop.
var allCb xgbutil.Callback
if evtype == xevent.ButtonPress {
allCb = xevent.ButtonPressFun(runButtonPressCallbacks)
} else {
allCb = xevent.ButtonReleaseFun(runButtonReleaseCallbacks)
}
// If this is the first Button{Press|Release}Event on this window,
// then we need to listen to Button{Press|Release} events in the main loop.
if !connectedMouseBind(xu, evtype, win) {
allCb.Connect(xu, win)
}
// Finally, attach the callback.
attachMouseBindCallback(xu, evtype, win, mods, button, callback)
return nil
} | go | func connect(xu *xgbutil.XUtil, callback xgbutil.CallbackMouse, evtype int,
win xproto.Window, buttonStr string, sync bool, grab bool) error {
// Get the mods/button first
mods, button, err := ParseString(xu, buttonStr)
if err != nil {
return err
}
// Only do the grab if we haven't yet on this window.
// And if we WANT a grab...
if grab && mouseBindGrabs(xu, evtype, win, mods, button) == 0 {
err := GrabChecked(xu, win, mods, button, sync)
if err != nil {
// If a bad access, let's be nice and give a good error message.
switch err.(type) {
case xproto.AccessError:
return fmt.Errorf("Got a bad access error when trying to bind "+
"'%s'. This usually means another client has already "+
"grabbed this mouse binding.", buttonStr)
default:
return fmt.Errorf("Could not bind '%s' because: %s",
buttonStr, err)
}
}
}
// If we've never grabbed anything on this window before, we need to
// make sure we can respond to it in the main event loop.
var allCb xgbutil.Callback
if evtype == xevent.ButtonPress {
allCb = xevent.ButtonPressFun(runButtonPressCallbacks)
} else {
allCb = xevent.ButtonReleaseFun(runButtonReleaseCallbacks)
}
// If this is the first Button{Press|Release}Event on this window,
// then we need to listen to Button{Press|Release} events in the main loop.
if !connectedMouseBind(xu, evtype, win) {
allCb.Connect(xu, win)
}
// Finally, attach the callback.
attachMouseBindCallback(xu, evtype, win, mods, button, callback)
return nil
} | [
"func",
"connect",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"callback",
"xgbutil",
".",
"CallbackMouse",
",",
"evtype",
"int",
",",
"win",
"xproto",
".",
"Window",
",",
"buttonStr",
"string",
",",
"sync",
"bool",
",",
"grab",
"bool",
")",
"error",
... | // connect is essentially 'Connect' for either ButtonPress or
// ButtonRelease events. | [
"connect",
"is",
"essentially",
"Connect",
"for",
"either",
"ButtonPress",
"or",
"ButtonRelease",
"events",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/callback.go#L14-L60 |
2,592 | BurntSushi/xgbutil | mousebind/callback.go | runButtonPressCallbacks | func runButtonPressCallbacks(xu *xgbutil.XUtil, ev xevent.ButtonPressEvent) {
mods, button := DeduceButtonInfo(ev.State, ev.Detail)
runMouseBindCallbacks(xu, ev, xevent.ButtonPress, ev.Event, mods, button)
} | go | func runButtonPressCallbacks(xu *xgbutil.XUtil, ev xevent.ButtonPressEvent) {
mods, button := DeduceButtonInfo(ev.State, ev.Detail)
runMouseBindCallbacks(xu, ev, xevent.ButtonPress, ev.Event, mods, button)
} | [
"func",
"runButtonPressCallbacks",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"ev",
"xevent",
".",
"ButtonPressEvent",
")",
"{",
"mods",
",",
"button",
":=",
"DeduceButtonInfo",
"(",
"ev",
".",
"State",
",",
"ev",
".",
"Detail",
")",
"\n\n",
"runMouseBi... | // runButtonPressCallbacks infers the window, button and modifiers from a
// ButtonPressEvent and runs the corresponding callbacks. | [
"runButtonPressCallbacks",
"infers",
"the",
"window",
"button",
"and",
"modifiers",
"from",
"a",
"ButtonPressEvent",
"and",
"runs",
"the",
"corresponding",
"callbacks",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/callback.go#L131-L135 |
2,593 | BurntSushi/xgbutil | mousebind/callback.go | runButtonReleaseCallbacks | func runButtonReleaseCallbacks(xu *xgbutil.XUtil,
ev xevent.ButtonReleaseEvent) {
mods, button := DeduceButtonInfo(ev.State, ev.Detail)
runMouseBindCallbacks(xu, ev, xevent.ButtonRelease, ev.Event, mods, button)
} | go | func runButtonReleaseCallbacks(xu *xgbutil.XUtil,
ev xevent.ButtonReleaseEvent) {
mods, button := DeduceButtonInfo(ev.State, ev.Detail)
runMouseBindCallbacks(xu, ev, xevent.ButtonRelease, ev.Event, mods, button)
} | [
"func",
"runButtonReleaseCallbacks",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"ev",
"xevent",
".",
"ButtonReleaseEvent",
")",
"{",
"mods",
",",
"button",
":=",
"DeduceButtonInfo",
"(",
"ev",
".",
"State",
",",
"ev",
".",
"Detail",
")",
"\n\n",
"runMou... | // runButtonReleaseCallbacks infers the window, keycode and modifiers from a
// ButtonPressEvent and runs the corresponding callbacks. | [
"runButtonReleaseCallbacks",
"infers",
"the",
"window",
"keycode",
"and",
"modifiers",
"from",
"a",
"ButtonPressEvent",
"and",
"runs",
"the",
"corresponding",
"callbacks",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/callback.go#L139-L145 |
2,594 | BurntSushi/xgbutil | mousebind/callback.go | Detach | func Detach(xu *xgbutil.XUtil, win xproto.Window) {
detach(xu, xevent.ButtonPress, win)
detach(xu, xevent.ButtonRelease, win)
} | go | func Detach(xu *xgbutil.XUtil, win xproto.Window) {
detach(xu, xevent.ButtonPress, win)
detach(xu, xevent.ButtonRelease, win)
} | [
"func",
"Detach",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
")",
"{",
"detach",
"(",
"xu",
",",
"xevent",
".",
"ButtonPress",
",",
"win",
")",
"\n",
"detach",
"(",
"xu",
",",
"xevent",
".",
"ButtonRelease",
",",
... | // Detach removes all handlers for all mouse events for the provided window id.
// This should be called whenever a window is no longer receiving events to make
// sure the garbage collector can release memory used to store the handler info. | [
"Detach",
"removes",
"all",
"handlers",
"for",
"all",
"mouse",
"events",
"for",
"the",
"provided",
"window",
"id",
".",
"This",
"should",
"be",
"called",
"whenever",
"a",
"window",
"is",
"no",
"longer",
"receiving",
"events",
"to",
"make",
"sure",
"the",
"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/callback.go#L150-L153 |
2,595 | BurntSushi/xgbutil | xwindow/ewmh.go | WMMove | func (w *Window) WMMove(x, y int) error {
return ewmh.MoveWindow(w.X, w.Id, x, y)
} | go | func (w *Window) WMMove(x, y int) error {
return ewmh.MoveWindow(w.X, w.Id, x, y)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"WMMove",
"(",
"x",
",",
"y",
"int",
")",
"error",
"{",
"return",
"ewmh",
".",
"MoveWindow",
"(",
"w",
".",
"X",
",",
"w",
".",
"Id",
",",
"x",
",",
"y",
")",
"\n",
"}"
] | // WMMove changes the position of a window without touching the size.
// This should be used when moving a top-level client window with
// reparenting winow managers that support EWMH. | [
"WMMove",
"changes",
"the",
"position",
"of",
"a",
"window",
"without",
"touching",
"the",
"size",
".",
"This",
"should",
"be",
"used",
"when",
"moving",
"a",
"top",
"-",
"level",
"client",
"window",
"with",
"reparenting",
"winow",
"managers",
"that",
"suppo... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/ewmh.go#L54-L56 |
2,596 | BurntSushi/xgbutil | xwindow/ewmh.go | WMResize | func (w *Window) WMResize(width, height int) error {
neww, newh, err := adjustSize(w.X, w.Id, width, height)
if err != nil {
return err
}
return ewmh.ResizeWindow(w.X, w.Id, neww, newh)
} | go | func (w *Window) WMResize(width, height int) error {
neww, newh, err := adjustSize(w.X, w.Id, width, height)
if err != nil {
return err
}
return ewmh.ResizeWindow(w.X, w.Id, neww, newh)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"WMResize",
"(",
"width",
",",
"height",
"int",
")",
"error",
"{",
"neww",
",",
"newh",
",",
"err",
":=",
"adjustSize",
"(",
"w",
".",
"X",
",",
"w",
".",
"Id",
",",
"width",
",",
"height",
")",
"\n",
"if",... | // WMResize changes the size of a window without touching the position.
// This should be used when resizing a top-level client window with
// reparenting window managers that support EWMH. | [
"WMResize",
"changes",
"the",
"size",
"of",
"a",
"window",
"without",
"touching",
"the",
"position",
".",
"This",
"should",
"be",
"used",
"when",
"resizing",
"a",
"top",
"-",
"level",
"client",
"window",
"with",
"reparenting",
"window",
"managers",
"that",
"... | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xwindow/ewmh.go#L61-L67 |
2,597 | BurntSushi/xgbutil | icccm/icccm.go | WmNormalHintsSet | func WmNormalHintsSet(xu *xgbutil.XUtil, win xproto.Window,
nh *NormalHints) error {
raw := []uint{
nh.Flags,
uint(nh.X), uint(nh.Y), nh.Width, nh.Height,
nh.MinWidth, nh.MinHeight,
nh.MaxWidth, nh.MaxHeight,
nh.WidthInc, nh.HeightInc,
nh.MinAspectNum, nh.MinAspectDen,
nh.MaxAspectNum, nh.MaxAspectDen,
nh.BaseWidth, nh.BaseHeight,
nh.WinGravity,
}
return xprop.ChangeProp32(xu, win, "WM_NORMAL_HINTS", "WM_SIZE_HINTS",
raw...)
} | go | func WmNormalHintsSet(xu *xgbutil.XUtil, win xproto.Window,
nh *NormalHints) error {
raw := []uint{
nh.Flags,
uint(nh.X), uint(nh.Y), nh.Width, nh.Height,
nh.MinWidth, nh.MinHeight,
nh.MaxWidth, nh.MaxHeight,
nh.WidthInc, nh.HeightInc,
nh.MinAspectNum, nh.MinAspectDen,
nh.MaxAspectNum, nh.MaxAspectDen,
nh.BaseWidth, nh.BaseHeight,
nh.WinGravity,
}
return xprop.ChangeProp32(xu, win, "WM_NORMAL_HINTS", "WM_SIZE_HINTS",
raw...)
} | [
"func",
"WmNormalHintsSet",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"nh",
"*",
"NormalHints",
")",
"error",
"{",
"raw",
":=",
"[",
"]",
"uint",
"{",
"nh",
".",
"Flags",
",",
"uint",
"(",
"nh",
".",
"X",
... | // WM_NORMAL_HINTS set
// Make sure to set the flags in the NormalHints struct correctly! | [
"WM_NORMAL_HINTS",
"set",
"Make",
"sure",
"to",
"set",
"the",
"flags",
"in",
"the",
"NormalHints",
"struct",
"correctly!"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/icccm/icccm.go#L122-L138 |
2,598 | BurntSushi/xgbutil | icccm/icccm.go | WmHintsSet | func WmHintsSet(xu *xgbutil.XUtil, win xproto.Window, hints *Hints) error {
raw := []uint{
hints.Flags, hints.Input, hints.InitialState,
uint(hints.IconPixmap), uint(hints.IconWindow),
uint(hints.IconX), uint(hints.IconY),
uint(hints.IconMask),
uint(hints.WindowGroup),
}
return xprop.ChangeProp32(xu, win, "WM_HINTS", "WM_HINTS", raw...)
} | go | func WmHintsSet(xu *xgbutil.XUtil, win xproto.Window, hints *Hints) error {
raw := []uint{
hints.Flags, hints.Input, hints.InitialState,
uint(hints.IconPixmap), uint(hints.IconWindow),
uint(hints.IconX), uint(hints.IconY),
uint(hints.IconMask),
uint(hints.WindowGroup),
}
return xprop.ChangeProp32(xu, win, "WM_HINTS", "WM_HINTS", raw...)
} | [
"func",
"WmHintsSet",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"hints",
"*",
"Hints",
")",
"error",
"{",
"raw",
":=",
"[",
"]",
"uint",
"{",
"hints",
".",
"Flags",
",",
"hints",
".",
"Input",
",",
"hints",
... | // WM_HINTS set
// Make sure to set the flags in the Hints struct correctly! | [
"WM_HINTS",
"set",
"Make",
"sure",
"to",
"set",
"the",
"flags",
"in",
"the",
"Hints",
"struct",
"correctly!"
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/icccm/icccm.go#L181-L190 |
2,599 | BurntSushi/xgbutil | xprop/xprop.go | GetProperty | func GetProperty(xu *xgbutil.XUtil, win xproto.Window, atom string) (
*xproto.GetPropertyReply, error) {
atomId, err := Atm(xu, atom)
if err != nil {
return nil, err
}
reply, err := xproto.GetProperty(xu.Conn(), false, win, atomId,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
return nil, fmt.Errorf("GetProperty: Error retrieving property '%s' "+
"on window %x: %s", atom, win, err)
}
if reply.Format == 0 {
return nil, fmt.Errorf("GetProperty: No such property '%s' on "+
"window %x.", atom, win)
}
return reply, nil
} | go | func GetProperty(xu *xgbutil.XUtil, win xproto.Window, atom string) (
*xproto.GetPropertyReply, error) {
atomId, err := Atm(xu, atom)
if err != nil {
return nil, err
}
reply, err := xproto.GetProperty(xu.Conn(), false, win, atomId,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
return nil, fmt.Errorf("GetProperty: Error retrieving property '%s' "+
"on window %x: %s", atom, win, err)
}
if reply.Format == 0 {
return nil, fmt.Errorf("GetProperty: No such property '%s' on "+
"window %x.", atom, win)
}
return reply, nil
} | [
"func",
"GetProperty",
"(",
"xu",
"*",
"xgbutil",
".",
"XUtil",
",",
"win",
"xproto",
".",
"Window",
",",
"atom",
"string",
")",
"(",
"*",
"xproto",
".",
"GetPropertyReply",
",",
"error",
")",
"{",
"atomId",
",",
"err",
":=",
"Atm",
"(",
"xu",
",",
... | // GetProperty abstracts the messiness of calling xgb.GetProperty. | [
"GetProperty",
"abstracts",
"the",
"messiness",
"of",
"calling",
"xgb",
".",
"GetProperty",
"."
] | f7c97cef3b4e6c88280a5a7091c3314e815ca243 | https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L13-L35 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.