// Code generated by wlbgen. DO NOT EDIT. // Protocol: input_method_unstable_v2 // Source: input-method-unstable-v2.xml // Upstream protocol copyright and license: // Copyright © 2008-2011 Kristian Høgsberg // Copyright © 2010-2011 Intel Corporation // Copyright © 2012-2013 Collabora, Ltd. // Copyright © 2012, 2013 Intel Corporation // Copyright © 2015, 2016 Jan Arne Petersen // Copyright © 2017, 2018 Red Hat, Inc. // Copyright © 2018 Purism SPC // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice (including the next // paragraph) shall be included in all copies or substantial portions of the // Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. package inputmethod import ( "sync" cross_wl_seat "github.com/bnema/go-wayland-bindings/client/wayland" cross_wl_surface "github.com/bnema/go-wayland-bindings/client/wayland" "github.com/bnema/wlturbo/wl" ) // ERROR_ROLE is the error role value. const ERROR_ROLE = 0 // InputMethodInterface is the protocol interface name. const InputMethodInterface = "zwp_input_method_v2" // InputMethod is the generated binding for zwp_input_method_v2 version 1. type InputMethod struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onActivate []func() onDeactivate []func() onSurroundingText []func(text string, cursor uint32, anchor uint32) onTextChangeCause []func(cause uint32) onContentType []func(hint uint32, purpose uint32) onDone []func() onUnavailable []func() } // NewInputMethod returns an unbound InputMethod. func NewInputMethod(ctx *wl.Context) *InputMethod { obj := &InputMethod{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Send the commit string text for insertion to the application. Inserts a string at current cursor position (see commit event sequence). The string to commit could be either just a single character after a key press or the result of some composing. The argument text is a buffer containing the string to insert. There is a maximum length of wayland messages, so text can not be longer than 4000 bytes. Values set with this event are double-buffered. They must be applied and reset to initial on the next zwp_text_input_v3.commit request. The initial value of text is an empty string. func (o *InputMethod) CommitString(text string) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_input_method_v2.commit_string"}, wl.ArgString(text)); err != nil { return err } return nil } // Send the pre-edit string text to the application text input. Place a new composing text (pre-edit) at the current cursor position. Any previously set composing text must be removed. Any previously existing selected text must be removed. The cursor is moved to a new position within the preedit string. The argument text is a buffer containing the preedit string. There is a maximum length of wayland messages, so text can not be longer than 4000 bytes. The arguments cursor_begin and cursor_end are counted in bytes relative to the beginning of the submitted string buffer. Cursor should be hidden by the text input when both are equal to -1. cursor_begin indicates the beginning of the cursor. cursor_end indicates the end of the cursor. It may be equal or different than cursor_begin. Values set with this event are double-buffered. They must be applied on the next zwp_input_method_v2.commit event. The initial value of text is an empty string. The initial value of cursor_begin, and cursor_end are both 0. func (o *InputMethod) SetPreeditString(text string, cursorBegin int32, cursorEnd int32) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_input_method_v2.set_preedit_string"}, wl.ArgString(text), wl.ArgInt(cursorBegin), wl.ArgInt(cursorEnd)); err != nil { return err } return nil } // Remove the surrounding text. before_length and after_length are the number of bytes before and after the current cursor index (excluding the preedit text) to delete. If any preedit text is present, it is replaced with the cursor for the purpose of this event. In effect before_length is counted from the beginning of preedit text, and after_length from its end (see commit event sequence). Values set with this event are double-buffered. They must be applied and reset to initial on the next zwp_input_method_v2.commit request. The initial values of both before_length and after_length are 0. func (o *InputMethod) DeleteSurroundingText(beforeLength uint32, afterLength uint32) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "zwp_input_method_v2.delete_surrounding_text"}, wl.ArgUint(beforeLength), wl.ArgUint(afterLength)); err != nil { return err } return nil } // Apply state changes from commit_string, set_preedit_string and delete_surrounding_text requests. The state relating to these events is double-buffered, and each one modifies the pending state. This request replaces the current state with the pending state. The connected text input is expected to proceed by evaluating the changes in the following order: 1. Replace existing preedit string with the cursor. 2. Delete requested surrounding text. 3. Insert commit string with the cursor at its end. 4. Calculate surrounding text to send. 5. Insert new preedit text in cursor position. 6. Place cursor inside preedit text. The serial number reflects the last state of the zwp_input_method_v2 object known to the client. The value of the serial argument must be equal to the number of done events already issued by that object. When the compositor receives a commit request with a serial different than the number of past done events, it must proceed as normal, except it should not change the current state of the zwp_input_method_v2 object. func (o *InputMethod) Commit(serial uint32) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 3, Name: "zwp_input_method_v2.commit"}, wl.ArgUint(serial)); err != nil { return err } return nil } // Creates a new zwp_input_popup_surface_v2 object wrapping a given surface. The surface gets assigned the "input_popup" role. If the surface already has an assigned role, the compositor must issue a protocol error. func (o *InputMethod) GetInputPopupSurface(surface *cross_wl_surface.Surface) (*InputPopupSurface, error) { var arg1 wl.Object if surface != nil { arg1 = surface } child := &InputPopupSurface{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 4, Name: "zwp_input_method_v2.get_input_popup_surface", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil { return nil, err } return child, nil } // Allow an input method to receive hardware keyboard input and process key events to generate text events (with pre-edit) over the wire. This allows input methods which compose multiple key events for inputting text like it is done for CJK languages. The compositor should send all keyboard events on the seat to the grab holder via the returned wl_keyboard object. Nevertheless, the compositor may decide not to forward any particular event. The compositor must not further process any event after it has been forwarded to the grab holder. Releasing the resulting wl_keyboard object releases the grab. func (o *InputMethod) GrabKeyboard() (*InputMethodKeyboardGrab, error) { child := &InputMethodKeyboardGrab{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 5, Name: "zwp_input_method_v2.grab_keyboard", Child: child}, wl.ArgObject(child)); err != nil { return nil, err } return child, nil } // Destroys the zwp_text_input_v2 object and any associated child objects, i.e. zwp_input_popup_surface_v2 and zwp_input_method_keyboard_grab_v2. func (o *InputMethod) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 6, Name: "zwp_input_method_v2.destroy", Destructor: true}); err != nil { return err } return nil } // OnActivate registers a handler for the activate event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethod) OnActivate(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onActivate = append(o.onActivate, handler) } // handlersForActivate returns the handlers registered for activate, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethod) handlersForActivate() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onActivate } // OnDeactivate registers a handler for the deactivate event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethod) OnDeactivate(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDeactivate = append(o.onDeactivate, handler) } // handlersForDeactivate returns the handlers registered for deactivate, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethod) handlersForDeactivate() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDeactivate } // OnSurroundingText registers a handler for the surrounding_text event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethod) OnSurroundingText(handler func(text string, cursor uint32, anchor uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onSurroundingText = append(o.onSurroundingText, handler) } // handlersForSurroundingText returns the handlers registered for surrounding_text, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethod) handlersForSurroundingText() []func(text string, cursor uint32, anchor uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onSurroundingText } // OnTextChangeCause registers a handler for the text_change_cause event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethod) OnTextChangeCause(handler func(cause uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onTextChangeCause = append(o.onTextChangeCause, handler) } // handlersForTextChangeCause returns the handlers registered for text_change_cause, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethod) handlersForTextChangeCause() []func(cause uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onTextChangeCause } // OnContentType registers a handler for the content_type event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethod) OnContentType(handler func(hint uint32, purpose uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onContentType = append(o.onContentType, handler) } // handlersForContentType returns the handlers registered for content_type, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethod) handlersForContentType() []func(hint uint32, purpose uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onContentType } // OnDone registers a handler for the done event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethod) OnDone(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDone = append(o.onDone, handler) } // handlersForDone returns the handlers registered for done, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethod) handlersForDone() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDone } // OnUnavailable registers a handler for the unavailable event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethod) OnUnavailable(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onUnavailable = append(o.onUnavailable, handler) } // handlersForUnavailable returns the handlers registered for unavailable, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethod) handlersForUnavailable() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onUnavailable } // EventSignature returns the declared event argument types in wire order. func (o *InputMethod) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "", true case 1: return "", true case 2: return "string,uint,uint,", true case 3: return "uint,", true case 4: return "uint,uint,", true case 5: return "", true case 6: return "", true default: return "", false } } // Dispatch decodes one event on zwp_input_method_v2 and calls the registered handlers. func (o *InputMethod) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // activate for i, handler := range o.handlersForActivate() { _ = i handler() } case 1: // deactivate for i, handler := range o.handlersForDeactivate() { _ = i handler() } case 2: // surrounding_text text := event.String() cursor := event.Uint32() anchor := event.Uint32() for i, handler := range o.handlersForSurroundingText() { _ = i handler(text, cursor, anchor) } case 3: // text_change_cause cause := event.Uint32() for i, handler := range o.handlersForTextChangeCause() { _ = i handler(cause) } case 4: // content_type hint := event.Uint32() purpose := event.Uint32() for i, handler := range o.handlersForContentType() { _ = i handler(hint, purpose) } case 5: // done for i, handler := range o.handlersForDone() { _ = i handler() } case 6: // unavailable for i, handler := range o.handlersForUnavailable() { _ = i handler() } default: } } // InputPopupSurfaceInterface is the protocol interface name. const InputPopupSurfaceInterface = "zwp_input_popup_surface_v2" // InputPopupSurface is the generated binding for zwp_input_popup_surface_v2 version 1. type InputPopupSurface struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onTextInputRectangle []func(x int32, y int32, width int32, height int32) } // NewInputPopupSurface returns an unbound InputPopupSurface. func NewInputPopupSurface(ctx *wl.Context) *InputPopupSurface { obj := &InputPopupSurface{} obj.SetContext(ctx) ctx.Register(obj) return obj } func (o *InputPopupSurface) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_input_popup_surface_v2.destroy", Destructor: true}); err != nil { return err } return nil } // OnTextInputRectangle registers a handler for the text_input_rectangle event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputPopupSurface) OnTextInputRectangle(handler func(x int32, y int32, width int32, height int32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onTextInputRectangle = append(o.onTextInputRectangle, handler) } // handlersForTextInputRectangle returns the handlers registered for text_input_rectangle, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputPopupSurface) handlersForTextInputRectangle() []func(x int32, y int32, width int32, height int32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onTextInputRectangle } // EventSignature returns the declared event argument types in wire order. func (o *InputPopupSurface) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "int,int,int,int,", true default: return "", false } } // Dispatch decodes one event on zwp_input_popup_surface_v2 and calls the registered handlers. func (o *InputPopupSurface) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // text_input_rectangle x := event.Int32() y := event.Int32() width := event.Int32() height := event.Int32() for i, handler := range o.handlersForTextInputRectangle() { _ = i handler(x, y, width, height) } default: } } // InputMethodKeyboardGrabInterface is the protocol interface name. const InputMethodKeyboardGrabInterface = "zwp_input_method_keyboard_grab_v2" // InputMethodKeyboardGrab is the generated binding for zwp_input_method_keyboard_grab_v2 version 1. type InputMethodKeyboardGrab struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onKeymap []func(format uint32, fd *wl.OwnedFD, size uint32) onKey []func(serial uint32, time uint32, key uint32, state uint32) onModifiers []func(serial uint32, modsDepressed uint32, modsLatched uint32, modsLocked uint32, group uint32) onRepeatInfo []func(rate int32, delay int32) } // NewInputMethodKeyboardGrab returns an unbound InputMethodKeyboardGrab. func NewInputMethodKeyboardGrab(ctx *wl.Context) *InputMethodKeyboardGrab { obj := &InputMethodKeyboardGrab{} obj.SetContext(ctx) ctx.Register(obj) return obj } // release the grab object func (o *InputMethodKeyboardGrab) Release() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_input_method_keyboard_grab_v2.release", Destructor: true}); err != nil { return err } return nil } // OnKeymap registers a handler for the keymap event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethodKeyboardGrab) OnKeymap(handler func(format uint32, fd *wl.OwnedFD, size uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onKeymap = append(o.onKeymap, handler) } // handlersForKeymap returns the handlers registered for keymap, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethodKeyboardGrab) handlersForKeymap() []func(format uint32, fd *wl.OwnedFD, size uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onKeymap } // OnKey registers a handler for the key event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethodKeyboardGrab) OnKey(handler func(serial uint32, time uint32, key uint32, state uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onKey = append(o.onKey, handler) } // handlersForKey returns the handlers registered for key, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethodKeyboardGrab) handlersForKey() []func(serial uint32, time uint32, key uint32, state uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onKey } // OnModifiers registers a handler for the modifiers event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethodKeyboardGrab) OnModifiers(handler func(serial uint32, modsDepressed uint32, modsLatched uint32, modsLocked uint32, group uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onModifiers = append(o.onModifiers, handler) } // handlersForModifiers returns the handlers registered for modifiers, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethodKeyboardGrab) handlersForModifiers() []func(serial uint32, modsDepressed uint32, modsLatched uint32, modsLocked uint32, group uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onModifiers } // OnRepeatInfo registers a handler for the repeat_info event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *InputMethodKeyboardGrab) OnRepeatInfo(handler func(rate int32, delay int32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onRepeatInfo = append(o.onRepeatInfo, handler) } // handlersForRepeatInfo returns the handlers registered for repeat_info, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *InputMethodKeyboardGrab) handlersForRepeatInfo() []func(rate int32, delay int32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onRepeatInfo } // EventSignature returns the declared event argument types in wire order. func (o *InputMethodKeyboardGrab) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "uint,fd,uint,", true case 1: return "uint,uint,uint,uint,", true case 2: return "uint,uint,uint,uint,uint,", true case 3: return "int,int,", true default: return "", false } } // Dispatch decodes one event on zwp_input_method_keyboard_grab_v2 and calls the registered handlers. func (o *InputMethodKeyboardGrab) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // keymap format := event.Uint32() fd := event.FD() size := event.Uint32() ownedfd := fd defer ownedfd.Close() for i, handler := range o.handlersForKeymap() { if i > 0 { fd = nil } handler(format, fd, size) } case 1: // key serial := event.Uint32() time := event.Uint32() key := event.Uint32() state := event.Uint32() for i, handler := range o.handlersForKey() { _ = i handler(serial, time, key, state) } case 2: // modifiers serial := event.Uint32() modsDepressed := event.Uint32() modsLatched := event.Uint32() modsLocked := event.Uint32() group := event.Uint32() for i, handler := range o.handlersForModifiers() { _ = i handler(serial, modsDepressed, modsLatched, modsLocked, group) } case 3: // repeat_info rate := event.Int32() delay := event.Int32() for i, handler := range o.handlersForRepeatInfo() { _ = i handler(rate, delay) } default: } } // InputMethodManagerInterface is the protocol interface name. const InputMethodManagerInterface = "zwp_input_method_manager_v2" // InputMethodManager is the generated binding for zwp_input_method_manager_v2 version 1. type InputMethodManager struct { wl.BaseProxy } // NewInputMethodManager returns an unbound InputMethodManager. func NewInputMethodManager(ctx *wl.Context) *InputMethodManager { obj := &InputMethodManager{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Request a new input zwp_input_method_v2 object associated with a given seat. func (o *InputMethodManager) GetInputMethod(seat *cross_wl_seat.Seat) (*InputMethod, error) { var arg0 wl.Object if seat != nil { arg0 = seat } child := &InputMethod{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_input_method_manager_v2.get_input_method", Child: child}, wl.ArgObject(arg0), wl.ArgObject(child)); err != nil { return nil, err } return child, nil } // Destroys the zwp_input_method_manager_v2 object. The zwp_input_method_v2 objects originating from it remain valid. func (o *InputMethodManager) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_input_method_manager_v2.destroy", Destructor: true}); err != nil { return err } return nil } // EventSignature returns the declared event argument types in wire order. func (o *InputMethodManager) EventSignature(opcode uint16) (string, bool) { switch opcode { default: return "", false } } // Dispatch decodes one event on zwp_input_method_manager_v2 and calls the registered handlers. func (o *InputMethodManager) Dispatch(event *wl.Event) { switch event.Opcode { default: } }