Debian Codegraph @

xdg-unstable-v6/shell.go

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