github.com/BurntSushi/xgb@v0.0.0-20210121224620-deaf085860bc/xevie/xevie.go (about)

     1  // Package xevie is the X client API for the XEVIE extension.
     2  package xevie
     3  
     4  // This file is automatically generated from xevie.xml. Edit at your peril!
     5  
     6  import (
     7  	"github.com/BurntSushi/xgb"
     8  
     9  	"github.com/BurntSushi/xgb/xproto"
    10  )
    11  
    12  // Init must be called before using the XEVIE extension.
    13  func Init(c *xgb.Conn) error {
    14  	reply, err := xproto.QueryExtension(c, 5, "XEVIE").Reply()
    15  	switch {
    16  	case err != nil:
    17  		return err
    18  	case !reply.Present:
    19  		return xgb.Errorf("No extension named XEVIE could be found on on the server.")
    20  	}
    21  
    22  	c.ExtLock.Lock()
    23  	c.Extensions["XEVIE"] = reply.MajorOpcode
    24  	c.ExtLock.Unlock()
    25  	for evNum, fun := range xgb.NewExtEventFuncs["XEVIE"] {
    26  		xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
    27  	}
    28  	for errNum, fun := range xgb.NewExtErrorFuncs["XEVIE"] {
    29  		xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
    30  	}
    31  	return nil
    32  }
    33  
    34  func init() {
    35  	xgb.NewExtEventFuncs["XEVIE"] = make(map[int]xgb.NewEventFun)
    36  	xgb.NewExtErrorFuncs["XEVIE"] = make(map[int]xgb.NewErrorFun)
    37  }
    38  
    39  const (
    40  	DatatypeUnmodified = 0
    41  	DatatypeModified   = 1
    42  )
    43  
    44  type Event struct {
    45  	// padding: 32 bytes
    46  }
    47  
    48  // EventRead reads a byte slice into a Event value.
    49  func EventRead(buf []byte, v *Event) int {
    50  	b := 0
    51  
    52  	b += 32 // padding
    53  
    54  	return b
    55  }
    56  
    57  // EventReadList reads a byte slice into a list of Event values.
    58  func EventReadList(buf []byte, dest []Event) int {
    59  	b := 0
    60  	for i := 0; i < len(dest); i++ {
    61  		dest[i] = Event{}
    62  		b += EventRead(buf[b:], &dest[i])
    63  	}
    64  	return xgb.Pad(b)
    65  }
    66  
    67  // Bytes writes a Event value to a byte slice.
    68  func (v Event) Bytes() []byte {
    69  	buf := make([]byte, 32)
    70  	b := 0
    71  
    72  	b += 32 // padding
    73  
    74  	return buf[:b]
    75  }
    76  
    77  // EventListBytes writes a list of Event values to a byte slice.
    78  func EventListBytes(buf []byte, list []Event) int {
    79  	b := 0
    80  	var structBytes []byte
    81  	for _, item := range list {
    82  		structBytes = item.Bytes()
    83  		copy(buf[b:], structBytes)
    84  		b += len(structBytes)
    85  	}
    86  	return xgb.Pad(b)
    87  }
    88  
    89  // Skipping definition for base type 'Bool'
    90  
    91  // Skipping definition for base type 'Byte'
    92  
    93  // Skipping definition for base type 'Card8'
    94  
    95  // Skipping definition for base type 'Char'
    96  
    97  // Skipping definition for base type 'Void'
    98  
    99  // Skipping definition for base type 'Double'
   100  
   101  // Skipping definition for base type 'Float'
   102  
   103  // Skipping definition for base type 'Int16'
   104  
   105  // Skipping definition for base type 'Int32'
   106  
   107  // Skipping definition for base type 'Int8'
   108  
   109  // Skipping definition for base type 'Card16'
   110  
   111  // Skipping definition for base type 'Card32'
   112  
   113  // EndCookie is a cookie used only for End requests.
   114  type EndCookie struct {
   115  	*xgb.Cookie
   116  }
   117  
   118  // End sends a checked request.
   119  // If an error occurs, it will be returned with the reply by calling EndCookie.Reply()
   120  func End(c *xgb.Conn, Cmap uint32) EndCookie {
   121  	c.ExtLock.RLock()
   122  	defer c.ExtLock.RUnlock()
   123  	if _, ok := c.Extensions["XEVIE"]; !ok {
   124  		panic("Cannot issue request 'End' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   125  	}
   126  	cookie := c.NewCookie(true, true)
   127  	c.NewRequest(endRequest(c, Cmap), cookie)
   128  	return EndCookie{cookie}
   129  }
   130  
   131  // EndUnchecked sends an unchecked request.
   132  // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
   133  func EndUnchecked(c *xgb.Conn, Cmap uint32) EndCookie {
   134  	c.ExtLock.RLock()
   135  	defer c.ExtLock.RUnlock()
   136  	if _, ok := c.Extensions["XEVIE"]; !ok {
   137  		panic("Cannot issue request 'End' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   138  	}
   139  	cookie := c.NewCookie(false, true)
   140  	c.NewRequest(endRequest(c, Cmap), cookie)
   141  	return EndCookie{cookie}
   142  }
   143  
   144  // EndReply represents the data returned from a End request.
   145  type EndReply struct {
   146  	Sequence uint16 // sequence number of the request for this reply
   147  	Length   uint32 // number of bytes in this reply
   148  	// padding: 1 bytes
   149  	// padding: 24 bytes
   150  }
   151  
   152  // Reply blocks and returns the reply data for a End request.
   153  func (cook EndCookie) Reply() (*EndReply, error) {
   154  	buf, err := cook.Cookie.Reply()
   155  	if err != nil {
   156  		return nil, err
   157  	}
   158  	if buf == nil {
   159  		return nil, nil
   160  	}
   161  	return endReply(buf), nil
   162  }
   163  
   164  // endReply reads a byte slice into a EndReply value.
   165  func endReply(buf []byte) *EndReply {
   166  	v := new(EndReply)
   167  	b := 1 // skip reply determinant
   168  
   169  	b += 1 // padding
   170  
   171  	v.Sequence = xgb.Get16(buf[b:])
   172  	b += 2
   173  
   174  	v.Length = xgb.Get32(buf[b:]) // 4-byte units
   175  	b += 4
   176  
   177  	b += 24 // padding
   178  
   179  	return v
   180  }
   181  
   182  // Write request to wire for End
   183  // endRequest writes a End request to a byte slice.
   184  func endRequest(c *xgb.Conn, Cmap uint32) []byte {
   185  	size := 8
   186  	b := 0
   187  	buf := make([]byte, size)
   188  
   189  	c.ExtLock.RLock()
   190  	buf[b] = c.Extensions["XEVIE"]
   191  	c.ExtLock.RUnlock()
   192  	b += 1
   193  
   194  	buf[b] = 2 // request opcode
   195  	b += 1
   196  
   197  	xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
   198  	b += 2
   199  
   200  	xgb.Put32(buf[b:], Cmap)
   201  	b += 4
   202  
   203  	return buf
   204  }
   205  
   206  // QueryVersionCookie is a cookie used only for QueryVersion requests.
   207  type QueryVersionCookie struct {
   208  	*xgb.Cookie
   209  }
   210  
   211  // QueryVersion sends a checked request.
   212  // If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply()
   213  func QueryVersion(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) QueryVersionCookie {
   214  	c.ExtLock.RLock()
   215  	defer c.ExtLock.RUnlock()
   216  	if _, ok := c.Extensions["XEVIE"]; !ok {
   217  		panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   218  	}
   219  	cookie := c.NewCookie(true, true)
   220  	c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie)
   221  	return QueryVersionCookie{cookie}
   222  }
   223  
   224  // QueryVersionUnchecked sends an unchecked request.
   225  // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
   226  func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) QueryVersionCookie {
   227  	c.ExtLock.RLock()
   228  	defer c.ExtLock.RUnlock()
   229  	if _, ok := c.Extensions["XEVIE"]; !ok {
   230  		panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   231  	}
   232  	cookie := c.NewCookie(false, true)
   233  	c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie)
   234  	return QueryVersionCookie{cookie}
   235  }
   236  
   237  // QueryVersionReply represents the data returned from a QueryVersion request.
   238  type QueryVersionReply struct {
   239  	Sequence uint16 // sequence number of the request for this reply
   240  	Length   uint32 // number of bytes in this reply
   241  	// padding: 1 bytes
   242  	ServerMajorVersion uint16
   243  	ServerMinorVersion uint16
   244  	// padding: 20 bytes
   245  }
   246  
   247  // Reply blocks and returns the reply data for a QueryVersion request.
   248  func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
   249  	buf, err := cook.Cookie.Reply()
   250  	if err != nil {
   251  		return nil, err
   252  	}
   253  	if buf == nil {
   254  		return nil, nil
   255  	}
   256  	return queryVersionReply(buf), nil
   257  }
   258  
   259  // queryVersionReply reads a byte slice into a QueryVersionReply value.
   260  func queryVersionReply(buf []byte) *QueryVersionReply {
   261  	v := new(QueryVersionReply)
   262  	b := 1 // skip reply determinant
   263  
   264  	b += 1 // padding
   265  
   266  	v.Sequence = xgb.Get16(buf[b:])
   267  	b += 2
   268  
   269  	v.Length = xgb.Get32(buf[b:]) // 4-byte units
   270  	b += 4
   271  
   272  	v.ServerMajorVersion = xgb.Get16(buf[b:])
   273  	b += 2
   274  
   275  	v.ServerMinorVersion = xgb.Get16(buf[b:])
   276  	b += 2
   277  
   278  	b += 20 // padding
   279  
   280  	return v
   281  }
   282  
   283  // Write request to wire for QueryVersion
   284  // queryVersionRequest writes a QueryVersion request to a byte slice.
   285  func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) []byte {
   286  	size := 8
   287  	b := 0
   288  	buf := make([]byte, size)
   289  
   290  	c.ExtLock.RLock()
   291  	buf[b] = c.Extensions["XEVIE"]
   292  	c.ExtLock.RUnlock()
   293  	b += 1
   294  
   295  	buf[b] = 0 // request opcode
   296  	b += 1
   297  
   298  	xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
   299  	b += 2
   300  
   301  	xgb.Put16(buf[b:], ClientMajorVersion)
   302  	b += 2
   303  
   304  	xgb.Put16(buf[b:], ClientMinorVersion)
   305  	b += 2
   306  
   307  	return buf
   308  }
   309  
   310  // SelectInputCookie is a cookie used only for SelectInput requests.
   311  type SelectInputCookie struct {
   312  	*xgb.Cookie
   313  }
   314  
   315  // SelectInput sends a checked request.
   316  // If an error occurs, it will be returned with the reply by calling SelectInputCookie.Reply()
   317  func SelectInput(c *xgb.Conn, EventMask uint32) SelectInputCookie {
   318  	c.ExtLock.RLock()
   319  	defer c.ExtLock.RUnlock()
   320  	if _, ok := c.Extensions["XEVIE"]; !ok {
   321  		panic("Cannot issue request 'SelectInput' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   322  	}
   323  	cookie := c.NewCookie(true, true)
   324  	c.NewRequest(selectInputRequest(c, EventMask), cookie)
   325  	return SelectInputCookie{cookie}
   326  }
   327  
   328  // SelectInputUnchecked sends an unchecked request.
   329  // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
   330  func SelectInputUnchecked(c *xgb.Conn, EventMask uint32) SelectInputCookie {
   331  	c.ExtLock.RLock()
   332  	defer c.ExtLock.RUnlock()
   333  	if _, ok := c.Extensions["XEVIE"]; !ok {
   334  		panic("Cannot issue request 'SelectInput' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   335  	}
   336  	cookie := c.NewCookie(false, true)
   337  	c.NewRequest(selectInputRequest(c, EventMask), cookie)
   338  	return SelectInputCookie{cookie}
   339  }
   340  
   341  // SelectInputReply represents the data returned from a SelectInput request.
   342  type SelectInputReply struct {
   343  	Sequence uint16 // sequence number of the request for this reply
   344  	Length   uint32 // number of bytes in this reply
   345  	// padding: 1 bytes
   346  	// padding: 24 bytes
   347  }
   348  
   349  // Reply blocks and returns the reply data for a SelectInput request.
   350  func (cook SelectInputCookie) Reply() (*SelectInputReply, error) {
   351  	buf, err := cook.Cookie.Reply()
   352  	if err != nil {
   353  		return nil, err
   354  	}
   355  	if buf == nil {
   356  		return nil, nil
   357  	}
   358  	return selectInputReply(buf), nil
   359  }
   360  
   361  // selectInputReply reads a byte slice into a SelectInputReply value.
   362  func selectInputReply(buf []byte) *SelectInputReply {
   363  	v := new(SelectInputReply)
   364  	b := 1 // skip reply determinant
   365  
   366  	b += 1 // padding
   367  
   368  	v.Sequence = xgb.Get16(buf[b:])
   369  	b += 2
   370  
   371  	v.Length = xgb.Get32(buf[b:]) // 4-byte units
   372  	b += 4
   373  
   374  	b += 24 // padding
   375  
   376  	return v
   377  }
   378  
   379  // Write request to wire for SelectInput
   380  // selectInputRequest writes a SelectInput request to a byte slice.
   381  func selectInputRequest(c *xgb.Conn, EventMask uint32) []byte {
   382  	size := 8
   383  	b := 0
   384  	buf := make([]byte, size)
   385  
   386  	c.ExtLock.RLock()
   387  	buf[b] = c.Extensions["XEVIE"]
   388  	c.ExtLock.RUnlock()
   389  	b += 1
   390  
   391  	buf[b] = 4 // request opcode
   392  	b += 1
   393  
   394  	xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
   395  	b += 2
   396  
   397  	xgb.Put32(buf[b:], EventMask)
   398  	b += 4
   399  
   400  	return buf
   401  }
   402  
   403  // SendCookie is a cookie used only for Send requests.
   404  type SendCookie struct {
   405  	*xgb.Cookie
   406  }
   407  
   408  // Send sends a checked request.
   409  // If an error occurs, it will be returned with the reply by calling SendCookie.Reply()
   410  func Send(c *xgb.Conn, Event Event, DataType uint32) SendCookie {
   411  	c.ExtLock.RLock()
   412  	defer c.ExtLock.RUnlock()
   413  	if _, ok := c.Extensions["XEVIE"]; !ok {
   414  		panic("Cannot issue request 'Send' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   415  	}
   416  	cookie := c.NewCookie(true, true)
   417  	c.NewRequest(sendRequest(c, Event, DataType), cookie)
   418  	return SendCookie{cookie}
   419  }
   420  
   421  // SendUnchecked sends an unchecked request.
   422  // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
   423  func SendUnchecked(c *xgb.Conn, Event Event, DataType uint32) SendCookie {
   424  	c.ExtLock.RLock()
   425  	defer c.ExtLock.RUnlock()
   426  	if _, ok := c.Extensions["XEVIE"]; !ok {
   427  		panic("Cannot issue request 'Send' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   428  	}
   429  	cookie := c.NewCookie(false, true)
   430  	c.NewRequest(sendRequest(c, Event, DataType), cookie)
   431  	return SendCookie{cookie}
   432  }
   433  
   434  // SendReply represents the data returned from a Send request.
   435  type SendReply struct {
   436  	Sequence uint16 // sequence number of the request for this reply
   437  	Length   uint32 // number of bytes in this reply
   438  	// padding: 1 bytes
   439  	// padding: 24 bytes
   440  }
   441  
   442  // Reply blocks and returns the reply data for a Send request.
   443  func (cook SendCookie) Reply() (*SendReply, error) {
   444  	buf, err := cook.Cookie.Reply()
   445  	if err != nil {
   446  		return nil, err
   447  	}
   448  	if buf == nil {
   449  		return nil, nil
   450  	}
   451  	return sendReply(buf), nil
   452  }
   453  
   454  // sendReply reads a byte slice into a SendReply value.
   455  func sendReply(buf []byte) *SendReply {
   456  	v := new(SendReply)
   457  	b := 1 // skip reply determinant
   458  
   459  	b += 1 // padding
   460  
   461  	v.Sequence = xgb.Get16(buf[b:])
   462  	b += 2
   463  
   464  	v.Length = xgb.Get32(buf[b:]) // 4-byte units
   465  	b += 4
   466  
   467  	b += 24 // padding
   468  
   469  	return v
   470  }
   471  
   472  // Write request to wire for Send
   473  // sendRequest writes a Send request to a byte slice.
   474  func sendRequest(c *xgb.Conn, Event Event, DataType uint32) []byte {
   475  	size := 104
   476  	b := 0
   477  	buf := make([]byte, size)
   478  
   479  	c.ExtLock.RLock()
   480  	buf[b] = c.Extensions["XEVIE"]
   481  	c.ExtLock.RUnlock()
   482  	b += 1
   483  
   484  	buf[b] = 3 // request opcode
   485  	b += 1
   486  
   487  	xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
   488  	b += 2
   489  
   490  	{
   491  		structBytes := Event.Bytes()
   492  		copy(buf[b:], structBytes)
   493  		b += len(structBytes)
   494  	}
   495  
   496  	xgb.Put32(buf[b:], DataType)
   497  	b += 4
   498  
   499  	b += 64 // padding
   500  
   501  	return buf
   502  }
   503  
   504  // StartCookie is a cookie used only for Start requests.
   505  type StartCookie struct {
   506  	*xgb.Cookie
   507  }
   508  
   509  // Start sends a checked request.
   510  // If an error occurs, it will be returned with the reply by calling StartCookie.Reply()
   511  func Start(c *xgb.Conn, Screen uint32) StartCookie {
   512  	c.ExtLock.RLock()
   513  	defer c.ExtLock.RUnlock()
   514  	if _, ok := c.Extensions["XEVIE"]; !ok {
   515  		panic("Cannot issue request 'Start' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   516  	}
   517  	cookie := c.NewCookie(true, true)
   518  	c.NewRequest(startRequest(c, Screen), cookie)
   519  	return StartCookie{cookie}
   520  }
   521  
   522  // StartUnchecked sends an unchecked request.
   523  // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
   524  func StartUnchecked(c *xgb.Conn, Screen uint32) StartCookie {
   525  	c.ExtLock.RLock()
   526  	defer c.ExtLock.RUnlock()
   527  	if _, ok := c.Extensions["XEVIE"]; !ok {
   528  		panic("Cannot issue request 'Start' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.")
   529  	}
   530  	cookie := c.NewCookie(false, true)
   531  	c.NewRequest(startRequest(c, Screen), cookie)
   532  	return StartCookie{cookie}
   533  }
   534  
   535  // StartReply represents the data returned from a Start request.
   536  type StartReply struct {
   537  	Sequence uint16 // sequence number of the request for this reply
   538  	Length   uint32 // number of bytes in this reply
   539  	// padding: 1 bytes
   540  	// padding: 24 bytes
   541  }
   542  
   543  // Reply blocks and returns the reply data for a Start request.
   544  func (cook StartCookie) Reply() (*StartReply, error) {
   545  	buf, err := cook.Cookie.Reply()
   546  	if err != nil {
   547  		return nil, err
   548  	}
   549  	if buf == nil {
   550  		return nil, nil
   551  	}
   552  	return startReply(buf), nil
   553  }
   554  
   555  // startReply reads a byte slice into a StartReply value.
   556  func startReply(buf []byte) *StartReply {
   557  	v := new(StartReply)
   558  	b := 1 // skip reply determinant
   559  
   560  	b += 1 // padding
   561  
   562  	v.Sequence = xgb.Get16(buf[b:])
   563  	b += 2
   564  
   565  	v.Length = xgb.Get32(buf[b:]) // 4-byte units
   566  	b += 4
   567  
   568  	b += 24 // padding
   569  
   570  	return v
   571  }
   572  
   573  // Write request to wire for Start
   574  // startRequest writes a Start request to a byte slice.
   575  func startRequest(c *xgb.Conn, Screen uint32) []byte {
   576  	size := 8
   577  	b := 0
   578  	buf := make([]byte, size)
   579  
   580  	c.ExtLock.RLock()
   581  	buf[b] = c.Extensions["XEVIE"]
   582  	c.ExtLock.RUnlock()
   583  	b += 1
   584  
   585  	buf[b] = 1 // request opcode
   586  	b += 1
   587  
   588  	xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
   589  	b += 2
   590  
   591  	xgb.Put32(buf[b:], Screen)
   592  	b += 4
   593  
   594  	return buf
   595  }