Debian Codegraph @

xdg/shell.go

raw symbols SCIP
1 // package xdg acts as a client for the xdg_shell wayland protocol.
2
3 // generated by wl-scanner
4 // https://github.com/dkolbly/wl-scanner
5 // from: https://raw.githubusercontent.com/wayland-project/wayland-protocols/master/stable/xdg-shell/xdg-shell.xml
6 // on 2018-02-19 14:50:40 -0600
7 package xdg
8
9 import (
10 "context"
11 "sync"
12
13 "github.com/dkolbly/wl"
14 )
15
16 type WmBasePingEvent struct {
17 EventContext context.Context
18 Serial uint32
19 }
20
21 type WmBasePingHandler interface {
22 HandleWmBasePing(WmBasePingEvent)
23 }
24
25 func (p *WmBase) AddPingHandler(h WmBasePingHandler) {
26 if h != nil {
27 p.mu.Lock()
28 p.pingHandlers = append(p.pingHandlers, h)
29 p.mu.Unlock()
30 }
31 }
32
33 func (p *WmBase) RemovePingHandler(h WmBasePingHandler) {
34 p.mu.Lock()
35 defer p.mu.Unlock()
36
37 for i, e := range p.pingHandlers {
38 if e == h {
39 p.pingHandlers = append(p.pingHandlers[:i], p.pingHandlers[i+1:]...)
40 break
41 }
42 }
43 }
44
45 func (p *WmBase) Dispatch(ctx context.Context, event *wl.Event) {
46 switch event.Opcode {
47 case 0:
48 if len(p.pingHandlers) > 0 {
49 ev := WmBasePingEvent{}
50 ev.EventContext = ctx
51 ev.Serial = event.Uint32()
52 p.mu.RLock()
53 for _, h := range p.pingHandlers {
54 h.HandleWmBasePing(ev)
55 }
56 p.mu.RUnlock()
57 }
58 }
59 }
60
61 type WmBase struct {
62 wl.BaseProxy
63 mu sync.RWMutex
64 pingHandlers []WmBasePingHandler
65 }
66
67 func NewWmBase(ctx *wl.Context) *WmBase {
68 ret := new(WmBase)
69 ctx.Register(ret)
70 return ret
71 }
72
73 // Destroy will destroy xdg_wm_base.
74 //
75 //
76 // Destroy this xdg_wm_base object.
77 //
78 // Destroying a bound xdg_wm_base object while there are surfaces
79 // still alive created by this xdg_wm_base object instance is illegal
80 // and will result in a protocol error.
81 //
82 func (p *WmBase) Destroy() error {
83 return p.Context().SendRequest(p, 0)
84 }
85
86 // CreatePositioner will create a positioner object.
87 //
88 //
89 // Create a positioner object. A positioner object is used to position
90 // surfaces relative to some parent surface. See the interface description
91 // and xdg_surface.get_popup for details.
92 //
93 func (p *WmBase) CreatePositioner() (*Positioner, error) {
94 ret := NewPositioner(p.Context())
95 return ret, p.Context().SendRequest(p, 1, wl.Proxy(ret))
96 }
97
98 // GetXdgSurface will create a shell surface from a surface.
99 //
100 //
101 // This creates an xdg_surface for the given surface. While xdg_surface
102 // itself is not a role, the corresponding surface may only be assigned
103 // a role extending xdg_surface, such as xdg_toplevel or xdg_popup.
104 //
105 // This creates an xdg_surface for the given surface. An xdg_surface is
106 // used as basis to define a role to a given surface, such as xdg_toplevel
107 // or xdg_popup. It also manages functionality shared between xdg_surface
108 // based surface roles.
109 //
110 // See the documentation of xdg_surface for more details about what an
111 // xdg_surface is and how it is used.
112 //
113 func (p *WmBase) GetXdgSurface(surface *wl.Surface) (*Surface, error) {
114 ret := NewSurface(p.Context())
115 return ret, p.Context().SendRequest(p, 2, wl.Proxy(ret), surface)
116 }
117
118 // Pong will respond to a ping event.
119 //
120 //
121 // A client must respond to a ping event with a pong request or
122 // the client may be deemed unresponsive. See xdg_wm_base.ping.
123 //
124 func (p *WmBase) Pong(serial uint32) error {
125 return p.Context().SendRequest(p, 3, serial)
126 }
127
128 const (
129 WmBaseErrorRole = 0
130 WmBaseErrorDefunctSurfaces = 1
131 WmBaseErrorNotTheTopmostPopup = 2
132 WmBaseErrorInvalidPopupParent = 3
133 WmBaseErrorInvalidSurfaceState = 4
134 WmBaseErrorInvalidPositioner = 5
135 )
136
137 type Positioner struct {
138 wl.BaseProxy
139 }
140
141 func NewPositioner(ctx *wl.Context) *Positioner {
142 ret := new(Positioner)
143 ctx.Register(ret)
144 return ret
145 }
146
147 // Destroy will destroy the xdg_positioner object.
148 //
149 //
150 // Notify the compositor that the xdg_positioner will no longer be used.
151 //
152 func (p *Positioner) Destroy() error {
153 return p.Context().SendRequest(p, 0)
154 }
155
156 // SetSize will set the size of the to-be positioned rectangle.
157 //
158 //
159 // Set the size of the surface that is to be positioned with the positioner
160 // object. The size is in surface-local coordinates and corresponds to the
161 // window geometry. See xdg_surface.set_window_geometry.
162 //
163 // If a zero or negative size is set the invalid_input error is raised.
164 //
165 func (p *Positioner) SetSize(width int32, height int32) error {
166 return p.Context().SendRequest(p, 1, width, height)
167 }
168
169 // SetAnchorRect will set the anchor rectangle within the parent surface.
170 //
171 //
172 // Specify the anchor rectangle within the parent surface that the child
173 // surface will be placed relative to. The rectangle is relative to the
174 // window geometry as defined by xdg_surface.set_window_geometry of the
175 // parent surface.
176 //
177 // When the xdg_positioner object is used to position a child surface, the
178 // anchor rectangle may not extend outside the window geometry of the
179 // positioned child's parent surface.
180 //
181 // If a negative size is set the invalid_input error is raised.
182 //
183 func (p *Positioner) SetAnchorRect(x int32, y int32, width int32, height int32) error {
184 return p.Context().SendRequest(p, 2, x, y, width, height)
185 }
186
187 // SetAnchor will set anchor rectangle anchor.
188 //
189 //
190 // Defines the anchor point for the anchor rectangle. The specified anchor
191 // is used derive an anchor point that the child surface will be
192 // positioned relative to. If a corner anchor is set (e.g. 'top_left' or
193 // 'bottom_right'), the anchor point will be at the specified corner;
194 // otherwise, the derived anchor point will be centered on the specified
195 // edge, or in the center of the anchor rectangle if no edge is specified.
196 //
197 func (p *Positioner) SetAnchor(anchor uint32) error {
198 return p.Context().SendRequest(p, 3, anchor)
199 }
200
201 // SetGravity will set child surface gravity.
202 //
203 //
204 // Defines in what direction a surface should be positioned, relative to
205 // the anchor point of the parent surface. If a corner gravity is
206 // specified (e.g. 'bottom_right' or 'top_left'), then the child surface
207 // will be placed towards the specified gravity; otherwise, the child
208 // surface will be centered over the anchor point on any axis that had no
209 // gravity specified.
210 //
211 func (p *Positioner) SetGravity(gravity uint32) error {
212 return p.Context().SendRequest(p, 4, gravity)
213 }
214
215 // SetConstraintAdjustment will set the adjustment to be done when constrained.
216 //
217 //
218 // Specify how the window should be positioned if the originally intended
219 // position caused the surface to be constrained, meaning at least
220 // partially outside positioning boundaries set by the compositor. The
221 // adjustment is set by constructing a bitmask describing the adjustment to
222 // be made when the surface is constrained on that axis.
223 //
224 // If no bit for one axis is set, the compositor will assume that the child
225 // surface should not change its position on that axis when constrained.
226 //
227 // If more than one bit for one axis is set, the order of how adjustments
228 // are applied is specified in the corresponding adjustment descriptions.
229 //
230 // The default adjustment is none.
231 //
232 func (p *Positioner) SetConstraintAdjustment(constraint_adjustment uint32) error {
233 return p.Context().SendRequest(p, 5, constraint_adjustment)
234 }
235
236 // SetOffset will set surface position offset.
237 //
238 //
239 // Specify the surface position offset relative to the position of the
240 // anchor on the anchor rectangle and the anchor on the surface. For
241 // example if the anchor of the anchor rectangle is at (x, y), the surface
242 // has the gravity bottom|right, and the offset is (ox, oy), the calculated
243 // surface position will be (x + ox, y + oy). The offset position of the
244 // surface is the one used for constraint testing. See
245 // set_constraint_adjustment.
246 //
247 // An example use case is placing a popup menu on top of a user interface
248 // element, while aligning the user interface element of the parent surface
249 // with some user interface element placed somewhere in the popup surface.
250 //
251 func (p *Positioner) SetOffset(x int32, y int32) error {
252 return p.Context().SendRequest(p, 6, x, y)
253 }
254
255 const (
256 PositionerErrorInvalidInput = 0
257 )
258
259 const (
260 PositionerAnchorNone = 0
261 PositionerAnchorTop = 1
262 PositionerAnchorBottom = 2
263 PositionerAnchorLeft = 3
264 PositionerAnchorRight = 4
265 PositionerAnchorTopLeft = 5
266 PositionerAnchorBottomLeft = 6
267 PositionerAnchorTopRight = 7
268 PositionerAnchorBottomRight = 8
269 )
270
271 const (
272 PositionerGravityNone = 0
273 PositionerGravityTop = 1
274 PositionerGravityBottom = 2
275 PositionerGravityLeft = 3
276 PositionerGravityRight = 4
277 PositionerGravityTopLeft = 5
278 PositionerGravityBottomLeft = 6
279 PositionerGravityTopRight = 7
280 PositionerGravityBottomRight = 8
281 )
282
283 const (
284 PositionerConstraintAdjustmentNone = 0
285 PositionerConstraintAdjustmentSlideX = 1
286 PositionerConstraintAdjustmentSlideY = 2
287 PositionerConstraintAdjustmentFlipX = 4
288 PositionerConstraintAdjustmentFlipY = 8
289 PositionerConstraintAdjustmentResizeX = 16
290 PositionerConstraintAdjustmentResizeY = 32
291 )
292
293 type SurfaceConfigureEvent struct {
294 EventContext context.Context
295 Serial uint32
296 }
297
298 type SurfaceConfigureHandler interface {
299 HandleSurfaceConfigure(SurfaceConfigureEvent)
300 }
301
302 func (p *Surface) AddConfigureHandler(h SurfaceConfigureHandler) {
303 if h != nil {
304 p.mu.Lock()
305 p.configureHandlers = append(p.configureHandlers, h)
306 p.mu.Unlock()
307 }
308 }
309
310 func (p *Surface) RemoveConfigureHandler(h SurfaceConfigureHandler) {
311 p.mu.Lock()
312 defer p.mu.Unlock()
313
314 for i, e := range p.configureHandlers {
315 if e == h {
316 p.configureHandlers = append(p.configureHandlers[:i], p.configureHandlers[i+1:]...)
317 break
318 }
319 }
320 }
321
322 func (p *Surface) Dispatch(ctx context.Context, event *wl.Event) {
323 switch event.Opcode {
324 case 0:
325 if len(p.configureHandlers) > 0 {
326 ev := SurfaceConfigureEvent{}
327 ev.EventContext = ctx
328 ev.Serial = event.Uint32()
329 p.mu.RLock()
330 for _, h := range p.configureHandlers {
331 h.HandleSurfaceConfigure(ev)
332 }
333 p.mu.RUnlock()
334 }
335 }
336 }
337
338 type Surface struct {
339 wl.BaseProxy
340 mu sync.RWMutex
341 configureHandlers []SurfaceConfigureHandler
342 }
343
344 func NewSurface(ctx *wl.Context) *Surface {
345 ret := new(Surface)
346 ctx.Register(ret)
347 return ret
348 }
349
350 // Destroy will destroy the xdg_surface.
351 //
352 //
353 // Destroy the xdg_surface object. An xdg_surface must only be destroyed
354 // after its role object has been destroyed.
355 //
356 func (p *Surface) Destroy() error {
357 return p.Context().SendRequest(p, 0)
358 }
359
360 // GetToplevel will assign the xdg_toplevel surface role.
361 //
362 //
363 // This creates an xdg_toplevel object for the given xdg_surface and gives
364 // the associated wl_surface the xdg_toplevel role.
365 //
366 // See the documentation of xdg_toplevel for more details about what an
367 // xdg_toplevel is and how it is used.
368 //
369 func (p *Surface) GetToplevel() (*Toplevel, error) {
370 ret := NewToplevel(p.Context())
371 return ret, p.Context().SendRequest(p, 1, wl.Proxy(ret))
372 }
373
374 // GetPopup will assign the xdg_popup surface role.
375 //
376 //
377 // This creates an xdg_popup object for the given xdg_surface and gives
378 // the associated wl_surface the xdg_popup role.
379 //
380 // If null is passed as a parent, a parent surface must be specified using
381 // some other protocol, before committing the initial state.
382 //
383 // See the documentation of xdg_popup for more details about what an
384 // xdg_popup is and how it is used.
385 //
386 func (p *Surface) GetPopup(parent *Surface, positioner *Positioner) (*Popup, error) {
387 ret := NewPopup(p.Context())
388 return ret, p.Context().SendRequest(p, 2, wl.Proxy(ret), parent, positioner)
389 }
390
391 // SetWindowGeometry will set the new window geometry.
392 //
393 //
394 // The window geometry of a surface is its "visible bounds" from the
395 // user's perspective. Client-side decorations often have invisible
396 // portions like drop-shadows which should be ignored for the
397 // purposes of aligning, placing and constraining windows.
398 //
399 // The window geometry is double buffered, and will be applied at the
400 // time wl_surface.commit of the corresponding wl_surface is called.
401 //
402 // When maintaining a position, the compositor should treat the (x, y)
403 // coordinate of the window geometry as the top left corner of the window.
404 // A client changing the (x, y) window geometry coordinate should in
405 // general not alter the position of the window.
406 //
407 // Once the window geometry of the surface is set, it is not possible to
408 // unset it, and it will remain the same until set_window_geometry is
409 // called again, even if a new subsurface or buffer is attached.
410 //
411 // If never set, the value is the full bounds of the surface,
412 // including any subsurfaces. This updates dynamically on every
413 // commit. This unset is meant for extremely simple clients.
414 //
415 // The arguments are given in the surface-local coordinate space of
416 // the wl_surface associated with this xdg_surface.
417 //
418 // The width and height must be greater than zero. Setting an invalid size
419 // will raise an error. When applied, the effective window geometry will be
420 // the set window geometry clamped to the bounding rectangle of the
421 // combined geometry of the surface of the xdg_surface and the associated
422 // subsurfaces.
423 //
424 func (p *Surface) SetWindowGeometry(x int32, y int32, width int32, height int32) error {
425 return p.Context().SendRequest(p, 3, x, y, width, height)
426 }
427
428 // AckConfigure will ack a configure event.
429 //
430 //
431 // When a configure event is received, if a client commits the
432 // surface in response to the configure event, then the client
433 // must make an ack_configure request sometime before the commit
434 // request, passing along the serial of the configure event.
435 //
436 // For instance, for toplevel surfaces the compositor might use this
437 // information to move a surface to the top left only when the client has
438 // drawn itself for the maximized or fullscreen state.
439 //
440 // If the client receives multiple configure events before it
441 // can respond to one, it only has to ack the last configure event.
442 //
443 // A client is not required to commit immediately after sending
444 // an ack_configure request - it may even ack_configure several times
445 // before its next surface commit.
446 //
447 // A client may send multiple ack_configure requests before committing, but
448 // only the last request sent before a commit indicates which configure
449 // event the client really is responding to.
450 //
451 func (p *Surface) AckConfigure(serial uint32) error {
452 return p.Context().SendRequest(p, 4, serial)
453 }
454
455 const (
456 SurfaceErrorNotConstructed = 1
457 SurfaceErrorAlreadyConstructed = 2
458 SurfaceErrorUnconfiguredBuffer = 3
459 )
460
461 type ToplevelConfigureEvent struct {
462 EventContext context.Context
463 Width int32
464 Height int32
465 States []int32
466 }
467
468 type ToplevelConfigureHandler interface {
469 HandleToplevelConfigure(ToplevelConfigureEvent)
470 }
471
472 func (p *Toplevel) AddConfigureHandler(h ToplevelConfigureHandler) {
473 if h != nil {
474 p.mu.Lock()
475 p.configureHandlers = append(p.configureHandlers, h)
476 p.mu.Unlock()
477 }
478 }
479
480 func (p *Toplevel) RemoveConfigureHandler(h ToplevelConfigureHandler) {
481 p.mu.Lock()
482 defer p.mu.Unlock()
483
484 for i, e := range p.configureHandlers {
485 if e == h {
486 p.configureHandlers = append(p.configureHandlers[:i], p.configureHandlers[i+1:]...)
487 break
488 }
489 }
490 }
491
492 type ToplevelCloseEvent struct {
493 EventContext context.Context
494 }
495
496 type ToplevelCloseHandler interface {
497 HandleToplevelClose(ToplevelCloseEvent)
498 }
499
500 func (p *Toplevel) AddCloseHandler(h ToplevelCloseHandler) {
501 if h != nil {
502 p.mu.Lock()
503 p.closeHandlers = append(p.closeHandlers, h)
504 p.mu.Unlock()
505 }
506 }
507
508 func (p *Toplevel) RemoveCloseHandler(h ToplevelCloseHandler) {
509 p.mu.Lock()
510 defer p.mu.Unlock()
511
512 for i, e := range p.closeHandlers {
513 if e == h {
514 p.closeHandlers = append(p.closeHandlers[:i], p.closeHandlers[i+1:]...)
515 break
516 }
517 }
518 }
519
520 func (p *Toplevel) Dispatch(ctx context.Context, event *wl.Event) {
521 switch event.Opcode {
522 case 0:
523 if len(p.configureHandlers) > 0 {
524 ev := ToplevelConfigureEvent{}
525 ev.EventContext = ctx
526 ev.Width = event.Int32()
527 ev.Height = event.Int32()
528 ev.States = event.Array()
529 p.mu.RLock()
530 for _, h := range p.configureHandlers {
531 h.HandleToplevelConfigure(ev)
532 }
533 p.mu.RUnlock()
534 }
535 case 1:
536 if len(p.closeHandlers) > 0 {
537 ev := ToplevelCloseEvent{}
538 ev.EventContext = ctx
539 p.mu.RLock()
540 for _, h := range p.closeHandlers {
541 h.HandleToplevelClose(ev)
542 }
543 p.mu.RUnlock()
544 }
545 }
546 }
547
548 type Toplevel struct {
549 wl.BaseProxy
550 mu sync.RWMutex
551 configureHandlers []ToplevelConfigureHandler
552 closeHandlers []ToplevelCloseHandler
553 }
554
555 func NewToplevel(ctx *wl.Context) *Toplevel {
556 ret := new(Toplevel)
557 ctx.Register(ret)
558 return ret
559 }
560
561 // Destroy will destroy the xdg_toplevel.
562 //
563 //
564 // This request destroys the role surface and unmaps the surface;
565 // see "Unmapping" behavior in interface section for details.
566 //
567 func (p *Toplevel) Destroy() error {
568 return p.Context().SendRequest(p, 0)
569 }
570
571 // SetParent will set the parent of this surface.
572 //
573 //
574 // Set the "parent" of this surface. This surface should be stacked
575 // above the parent surface and all other ancestor surfaces.
576 //
577 // Parent windows should be set on dialogs, toolboxes, or other
578 // "auxiliary" surfaces, so that the parent is raised when the dialog
579 // is raised.
580 //
581 // Setting a null parent for a child window removes any parent-child
582 // relationship for the child. Setting a null parent for a window which
583 // currently has no parent is a no-op.
584 //
585 // If the parent is unmapped then its children are managed as
586 // though the parent of the now-unmapped parent has become the
587 // parent of this surface. If no parent exists for the now-unmapped
588 // parent then the children are managed as though they have no
589 // parent surface.
590 //
591 func (p *Toplevel) SetParent(parent *Toplevel) error {
592 return p.Context().SendRequest(p, 1, parent)
593 }
594
595 // SetTitle will set surface title.
596 //
597 //
598 // Set a short title for the surface.
599 //
600 // This string may be used to identify the surface in a task bar,
601 // window list, or other user interface elements provided by the
602 // compositor.
603 //
604 // The string must be encoded in UTF-8.
605 //
606 func (p *Toplevel) SetTitle(title string) error {
607 return p.Context().SendRequest(p, 2, title)
608 }
609
610 // SetAppId will set application ID.
611 //
612 //
613 // Set an application identifier for the surface.
614 //
615 // The app ID identifies the general class of applications to which
616 // the surface belongs. The compositor can use this to group multiple
617 // surfaces together, or to determine how to launch a new application.
618 //
619 // For D-Bus activatable applications, the app ID is used as the D-Bus
620 // service name.
621 //
622 // The compositor shell will try to group application surfaces together
623 // by their app ID. As a best practice, it is suggested to select app
624 // ID's that match the basename of the application's .desktop file.
625 // For example, "org.freedesktop.FooViewer" where the .desktop file is
626 // "org.freedesktop.FooViewer.desktop".
627 //
628 // See the desktop-entry specification [0] for more details on
629 // application identifiers and how they relate to well-known D-Bus
630 // names and .desktop files.
631 //
632 // [0] http://standards.freedesktop.org/desktop-entry-spec/
633 //
634 func (p *Toplevel) SetAppId(app_id string) error {
635 return p.Context().SendRequest(p, 3, app_id)
636 }
637
638 // ShowWindowMenu will show the window menu.
639 //
640 //
641 // Clients implementing client-side decorations might want to show
642 // a context menu when right-clicking on the decorations, giving the
643 // user a menu that they can use to maximize or minimize the window.
644 //
645 // This request asks the compositor to pop up such a window menu at
646 // the given position, relative to the local surface coordinates of
647 // the parent surface. There are no guarantees as to what menu items
648 // the window menu contains.
649 //
650 // This request must be used in response to some sort of user action
651 // like a button press, key press, or touch down event.
652 //
653 func (p *Toplevel) ShowWindowMenu(seat *wl.Seat, serial uint32, x int32, y int32) error {
654 return p.Context().SendRequest(p, 4, seat, serial, x, y)
655 }
656
657 // Move will start an interactive move.
658 //
659 //
660 // Start an interactive, user-driven move of the surface.
661 //
662 // This request must be used in response to some sort of user action
663 // like a button press, key press, or touch down event. The passed
664 // serial is used to determine the type of interactive move (touch,
665 // pointer, etc).
666 //
667 // The server may ignore move requests depending on the state of
668 // the surface (e.g. fullscreen or maximized), or if the passed serial
669 // is no longer valid.
670 //
671 // If triggered, the surface will lose the focus of the device
672 // (wl_pointer, wl_touch, etc) used for the move. It is up to the
673 // compositor to visually indicate that the move is taking place, such as
674 // updating a pointer cursor, during the move. There is no guarantee
675 // that the device focus will return when the move is completed.
676 //
677 func (p *Toplevel) Move(seat *wl.Seat, serial uint32) error {
678 return p.Context().SendRequest(p, 5, seat, serial)
679 }
680
681 // Resize will start an interactive resize.
682 //
683 //
684 // Start a user-driven, interactive resize of the surface.
685 //
686 // This request must be used in response to some sort of user action
687 // like a button press, key press, or touch down event. The passed
688 // serial is used to determine the type of interactive resize (touch,
689 // pointer, etc).
690 //
691 // The server may ignore resize requests depending on the state of
692 // the surface (e.g. fullscreen or maximized).
693 //
694 // If triggered, the client will receive configure events with the
695 // "resize" state enum value and the expected sizes. See the "resize"
696 // enum value for more details about what is required. The client
697 // must also acknowledge configure events using "ack_configure". After
698 // the resize is completed, the client will receive another "configure"
699 // event without the resize state.
700 //
701 // If triggered, the surface also will lose the focus of the device
702 // (wl_pointer, wl_touch, etc) used for the resize. It is up to the
703 // compositor to visually indicate that the resize is taking place,
704 // such as updating a pointer cursor, during the resize. There is no
705 // guarantee that the device focus will return when the resize is
706 // completed.
707 //
708 // The edges parameter specifies how the surface should be resized,
709 // and is one of the values of the resize_edge enum. The compositor
710 // may use this information to update the surface position for
711 // example when dragging the top left corner. The compositor may also
712 // use this information to adapt its behavior, e.g. choose an
713 // appropriate cursor image.
714 //
715 func (p *Toplevel) Resize(seat *wl.Seat, serial uint32, edges uint32) error {
716 return p.Context().SendRequest(p, 6, seat, serial, edges)
717 }
718
719 // SetMaxSize will set the maximum size.
720 //
721 //
722 // Set a maximum size for the window.
723 //
724 // The client can specify a maximum size so that the compositor does
725 // not try to configure the window beyond this size.
726 //
727 // The width and height arguments are in window geometry coordinates.
728 // See xdg_surface.set_window_geometry.
729 //
730 // Values set in this way are double-buffered. They will get applied
731 // on the next commit.
732 //
733 // The compositor can use this information to allow or disallow
734 // different states like maximize or fullscreen and draw accurate
735 // animations.
736 //
737 // Similarly, a tiling window manager may use this information to
738 // place and resize client windows in a more effective way.
739 //
740 // The client should not rely on the compositor to obey the maximum
741 // size. The compositor may decide to ignore the values set by the
742 // client and request a larger size.
743 //
744 // If never set, or a value of zero in the request, means that the
745 // client has no expected maximum size in the given dimension.
746 // As a result, a client wishing to reset the maximum size
747 // to an unspecified state can use zero for width and height in the
748 // request.
749 //
750 // Requesting a maximum size to be smaller than the minimum size of
751 // a surface is illegal and will result in a protocol error.
752 //
753 // The width and height must be greater than or equal to zero. Using
754 // strictly negative values for width and height will result in a
755 // protocol error.
756 //
757 func (p *Toplevel) SetMaxSize(width int32, height int32) error {
758 return p.Context().SendRequest(p, 7, width, height)
759 }
760
761 // SetMinSize will set the minimum size.
762 //
763 //
764 // Set a minimum size for the window.
765 //
766 // The client can specify a minimum size so that the compositor does
767 // not try to configure the window below this size.
768 //
769 // The width and height arguments are in window geometry coordinates.
770 // See xdg_surface.set_window_geometry.
771 //
772 // Values set in this way are double-buffered. They will get applied
773 // on the next commit.
774 //
775 // The compositor can use this information to allow or disallow
776 // different states like maximize or fullscreen and draw accurate
777 // animations.
778 //
779 // Similarly, a tiling window manager may use this information to
780 // place and resize client windows in a more effective way.
781 //
782 // The client should not rely on the compositor to obey the minimum
783 // size. The compositor may decide to ignore the values set by the
784 // client and request a smaller size.
785 //
786 // If never set, or a value of zero in the request, means that the
787 // client has no expected minimum size in the given dimension.
788 // As a result, a client wishing to reset the minimum size
789 // to an unspecified state can use zero for width and height in the
790 // request.
791 //
792 // Requesting a minimum size to be larger than the maximum size of
793 // a surface is illegal and will result in a protocol error.
794 //
795 // The width and height must be greater than or equal to zero. Using
796 // strictly negative values for width and height will result in a
797 // protocol error.
798 //
799 func (p *Toplevel) SetMinSize(width int32, height int32) error {
800 return p.Context().SendRequest(p, 8, width, height)
801 }
802
803 // SetMaximized will maximize the window.
804 //
805 //
806 // Maximize the surface.
807 //
808 // After requesting that the surface should be maximized, the compositor
809 // will respond by emitting a configure event with the "maximized" state
810 // and the required window geometry. The client should then update its
811 // content, drawing it in a maximized state, i.e. without shadow or other
812 // decoration outside of the window geometry. The client must also
813 // acknowledge the configure when committing the new content (see
814 // ack_configure).
815 //
816 // It is up to the compositor to decide how and where to maximize the
817 // surface, for example which output and what region of the screen should
818 // be used.
819 //
820 // If the surface was already maximized, the compositor will still emit
821 // a configure event with the "maximized" state.
822 //
823 // If the surface is in a fullscreen state, this request has no direct
824 // effect. It will alter the state the surface is returned to when
825 // unmaximized if not overridden by the compositor.
826 //
827 func (p *Toplevel) SetMaximized() error {
828 return p.Context().SendRequest(p, 9)
829 }
830
831 // UnsetMaximized will unmaximize the window.
832 //
833 //
834 // Unmaximize the surface.
835 //
836 // After requesting that the surface should be unmaximized, the compositor
837 // will respond by emitting a configure event without the "maximized"
838 // state. If available, the compositor will include the window geometry
839 // dimensions the window had prior to being maximized in the configure
840 // event. The client must then update its content, drawing it in a
841 // regular state, i.e. potentially with shadow, etc. The client must also
842 // acknowledge the configure when committing the new content (see
843 // ack_configure).
844 //
845 // It is up to the compositor to position the surface after it was
846 // unmaximized; usually the position the surface had before maximizing, if
847 // applicable.
848 //
849 // If the surface was already not maximized, the compositor will still
850 // emit a configure event without the "maximized" state.
851 //
852 // If the surface is in a fullscreen state, this request has no direct
853 // effect. It will alter the state the surface is returned to when
854 // unmaximized if not overridden by the compositor.
855 //
856 func (p *Toplevel) UnsetMaximized() error {
857 return p.Context().SendRequest(p, 10)
858 }
859
860 // SetFullscreen will set the window as fullscreen on an output.
861 //
862 //
863 // Make the surface fullscreen.
864 //
865 // After requesting that the surface should be fullscreened, the
866 // compositor will respond by emitting a configure event with the
867 // "fullscreen" state and the fullscreen window geometry. The client must
868 // also acknowledge the configure when committing the new content (see
869 // ack_configure).
870 //
871 // The output passed by the request indicates the client's preference as
872 // to which display it should be set fullscreen on. If this value is NULL,
873 // it's up to the compositor to choose which display will be used to map
874 // this surface.
875 //
876 // If the surface doesn't cover the whole output, the compositor will
877 // position the surface in the center of the output and compensate with
878 // with border fill covering the rest of the output. The content of the
879 // border fill is undefined, but should be assumed to be in some way that
880 // attempts to blend into the surrounding area (e.g. solid black).
881 //
882 // If the fullscreened surface is not opaque, the compositor must make
883 // sure that other screen content not part of the same surface tree (made
884 // up of subsurfaces, popups or similarly coupled surfaces) are not
885 // visible below the fullscreened surface.
886 //
887 func (p *Toplevel) SetFullscreen(output *wl.Output) error {
888 return p.Context().SendRequest(p, 11, output)
889 }
890
891 // UnsetFullscreen will unset the window as fullscreen.
892 //
893 //
894 // Make the surface no longer fullscreen.
895 //
896 // After requesting that the surface should be unfullscreened, the
897 // compositor will respond by emitting a configure event without the
898 // "fullscreen" state.
899 //
900 // Making a surface unfullscreen sets states for the surface based on the following:
901 // * the state(s) it may have had before becoming fullscreen
902 // * any state(s) decided by the compositor
903 // * any state(s) requested by the client while the surface was fullscreen
904 //
905 // The compositor may include the previous window geometry dimensions in
906 // the configure event, if applicable.
907 //
908 // The client must also acknowledge the configure when committing the new
909 // content (see ack_configure).
910 //
911 func (p *Toplevel) UnsetFullscreen() error {
912 return p.Context().SendRequest(p, 12)
913 }
914
915 // SetMinimized will set the window as minimized.
916 //
917 //
918 // Request that the compositor minimize your surface. There is no
919 // way to know if the surface is currently minimized, nor is there
920 // any way to unset minimization on this surface.
921 //
922 // If you are looking to throttle redrawing when minimized, please
923 // instead use the wl_surface.frame event for this, as this will
924 // also work with live previews on windows in Alt-Tab, Expose or
925 // similar compositor features.
926 //
927 func (p *Toplevel) SetMinimized() error {
928 return p.Context().SendRequest(p, 13)
929 }
930
931 const (
932 ToplevelResizeEdgeNone = 0
933 ToplevelResizeEdgeTop = 1
934 ToplevelResizeEdgeBottom = 2
935 ToplevelResizeEdgeLeft = 4
936 ToplevelResizeEdgeTopLeft = 5
937 ToplevelResizeEdgeBottomLeft = 6
938 ToplevelResizeEdgeRight = 8
939 ToplevelResizeEdgeTopRight = 9
940 ToplevelResizeEdgeBottomRight = 10
941 )
942
943 const (
944 ToplevelStateMaximized = 1
945 ToplevelStateFullscreen = 2
946 ToplevelStateResizing = 3
947 ToplevelStateActivated = 4
948 )
949
950 type PopupConfigureEvent struct {
951 EventContext context.Context
952 X int32
953 Y int32
954 Width int32
955 Height int32
956 }
957
958 type PopupConfigureHandler interface {
959 HandlePopupConfigure(PopupConfigureEvent)
960 }
961
962 func (p *Popup) AddConfigureHandler(h PopupConfigureHandler) {
963 if h != nil {
964 p.mu.Lock()
965 p.configureHandlers = append(p.configureHandlers, h)
966 p.mu.Unlock()
967 }
968 }
969
970 func (p *Popup) RemoveConfigureHandler(h PopupConfigureHandler) {
971 p.mu.Lock()
972 defer p.mu.Unlock()
973
974 for i, e := range p.configureHandlers {
975 if e == h {
976 p.configureHandlers = append(p.configureHandlers[:i], p.configureHandlers[i+1:]...)
977 break
978 }
979 }
980 }
981
982 type PopupPopupDoneEvent struct {
983 EventContext context.Context
984 }
985
986 type PopupPopupDoneHandler interface {
987 HandlePopupPopupDone(PopupPopupDoneEvent)
988 }
989
990 func (p *Popup) AddPopupDoneHandler(h PopupPopupDoneHandler) {
991 if h != nil {
992 p.mu.Lock()
993 p.popupDoneHandlers = append(p.popupDoneHandlers, h)
994 p.mu.Unlock()
995 }
996 }
997
998 func (p *Popup) RemovePopupDoneHandler(h PopupPopupDoneHandler) {
999 p.mu.Lock()
1000 defer p.mu.Unlock()
1001
1002 for i, e := range p.popupDoneHandlers {
1003 if e == h {
1004 p.popupDoneHandlers = append(p.popupDoneHandlers[:i], p.popupDoneHandlers[i+1:]...)
1005 break
1006 }
1007 }
1008 }
1009
1010 func (p *Popup) Dispatch(ctx context.Context, event *wl.Event) {
1011 switch event.Opcode {
1012 case 0:
1013 if len(p.configureHandlers) > 0 {
1014 ev := PopupConfigureEvent{}
1015 ev.EventContext = ctx
1016 ev.X = event.Int32()
1017 ev.Y = event.Int32()
1018 ev.Width = event.Int32()
1019 ev.Height = event.Int32()
1020 p.mu.RLock()
1021 for _, h := range p.configureHandlers {
1022 h.HandlePopupConfigure(ev)
1023 }
1024 p.mu.RUnlock()
1025 }
1026 case 1:
1027 if len(p.popupDoneHandlers) > 0 {
1028 ev := PopupPopupDoneEvent{}
1029 ev.EventContext = ctx
1030 p.mu.RLock()
1031 for _, h := range p.popupDoneHandlers {
1032 h.HandlePopupPopupDone(ev)
1033 }
1034 p.mu.RUnlock()
1035 }
1036 }
1037 }
1038
1039 type Popup struct {
1040 wl.BaseProxy
1041 mu sync.RWMutex
1042 configureHandlers []PopupConfigureHandler
1043 popupDoneHandlers []PopupPopupDoneHandler
1044 }
1045
1046 func NewPopup(ctx *wl.Context) *Popup {
1047 ret := new(Popup)
1048 ctx.Register(ret)
1049 return ret
1050 }
1051
1052 // Destroy will remove xdg_popup interface.
1053 //
1054 //
1055 // This destroys the popup. Explicitly destroying the xdg_popup
1056 // object will also dismiss the popup, and unmap the surface.
1057 //
1058 // If this xdg_popup is not the "topmost" popup, a protocol error
1059 // will be sent.
1060 //
1061 func (p *Popup) Destroy() error {
1062 return p.Context().SendRequest(p, 0)
1063 }
1064
1065 // Grab will make the popup take an explicit grab.
1066 //
1067 //
1068 // This request makes the created popup take an explicit grab. An explicit
1069 // grab will be dismissed when the user dismisses the popup, or when the
1070 // client destroys the xdg_popup. This can be done by the user clicking
1071 // outside the surface, using the keyboard, or even locking the screen
1072 // through closing the lid or a timeout.
1073 //
1074 // If the compositor denies the grab, the popup will be immediately
1075 // dismissed.
1076 //
1077 // This request must be used in response to some sort of user action like a
1078 // button press, key press, or touch down event. The serial number of the
1079 // event should be passed as 'serial'.
1080 //
1081 // The parent of a grabbing popup must either be an xdg_toplevel surface or
1082 // another xdg_popup with an explicit grab. If the parent is another
1083 // xdg_popup it means that the popups are nested, with this popup now being
1084 // the topmost popup.
1085 //
1086 // Nested popups must be destroyed in the reverse order they were created
1087 // in, e.g. the only popup you are allowed to destroy at all times is the
1088 // topmost one.
1089 //
1090 // When compositors choose to dismiss a popup, they may dismiss every
1091 // nested grabbing popup as well. When a compositor dismisses popups, it
1092 // will follow the same dismissing order as required from the client.
1093 //
1094 // The parent of a grabbing popup must either be another xdg_popup with an
1095 // active explicit grab, or an xdg_popup or xdg_toplevel, if there are no
1096 // explicit grabs already taken.
1097 //
1098 // If the topmost grabbing popup is destroyed, the grab will be returned to
1099 // the parent of the popup, if that parent previously had an explicit grab.
1100 //
1101 // If the parent is a grabbing popup which has already been dismissed, this
1102 // popup will be immediately dismissed. If the parent is a popup that did
1103 // not take an explicit grab, an error will be raised.
1104 //
1105 // During a popup grab, the client owning the grab will receive pointer
1106 // and touch events for all their surfaces as normal (similar to an
1107 // "owner-events" grab in X11 parlance), while the top most grabbing popup
1108 // will always have keyboard focus.
1109 //
1110 func (p *Popup) Grab(seat *wl.Seat, serial uint32) error {
1111 return p.Context().SendRequest(p, 1, seat, serial)
1112 }
1113
1114 const (
1115 PopupErrorInvalidGrab = 0
1116 )