Warning, /plasma/kwin/src/wayland/DESIGN.md is written in an unsupported language. File is not indexed.

0001 # History
0002 
0003 We started out with one method of generting classes. We then ported to a new approach of using QtWaylandScanner to reduce a lot of boiler plate.
0004 
0005 New classes should use the new approach.
0006 
0007 # New Approach
0008 
0009 A public facing PIMPL class which should inherit from QObject.
0010 A private class that should inherit from QtWaylandServer::interface_name which is auto-generated. This will manage individual resources, handle callbacks and QString conversions.
0011 
0012 Class Names should map to the interface name in UpperCamelCase.
0013 Where a V1 exists in the interface name, this should be mirrored in the file and class name.
0014 
0015 An implementation should handle all versions of a given interface, but not different interfaces which represent different versions.
0016 
0017 (i.e zxdg_output_manager_v1 versions 1 2 and 3 would be wrapped in one class XdgOutputManagerV1Interface. A zxdg_output_manager_v2 protocol would be exposed as a new public class XdgOutputManagerV2Interface)
0018 
0019 # Implementations
0020 
0021 There are 3 modes of operation happening within the exported classes
0022 
0023 The generated classes can behave in all these modes, it is up to our implementation to use the correct methods.
0024 
0025 ## Globals
0026 e.g BlurManager
0027 
0028 This represents an object listed by the Display class.
0029 Use the interface_name::(wl_display*, int version) constructor within the private class to create an instance.
0030 
0031 
0032 ## Server-managed multicasting resources
0033 e.g XdgOutput
0034 
0035 This is where one QObject represents multiple Resources.
0036 
0037 Use the method
0038 ```cpp
0039 QtWaylandServer::interface_name::add(client, id, version)
0040 ```
0041 
0042 to create a a new Resource instance managed by this object.
0043 
0044 Use the event method with the wl_resource* overload to send events.
0045 
0046 ```cpp
0047 for (auto resource : resourceMap())
0048 {
0049     send_some_method(resource->handle, arg1, arg2);
0050 }
0051 ```
0052 
0053 methods to send requests to all clients.
0054 
0055 ## Client-owned Resources:
0056 
0057 e.g BlurInterface
0058 
0059 This is where one instance of our public class represents a single resource. Typically the lifespan of the exported class matches our resource.
0060 
0061 In the private class use the QtWaylandServer::interface_name(wl_resource*) constructor to create a wrapper bound to a specific resource.
0062 
0063 Use
0064 ```cpp
0065 send_some_method(arg1, args2)
0066 ```
0067 methods of the privateClass to send events to the resource set in the constructor
0068 
0069 
0070 ## Other hooks
0071 
0072 `_bind_resource` is called whenever a resource is bound. This exists for all generated classes in all the operating modes
0073 
0074 `_destroy_resource` is a hook called whenever a resource has been unbound.
0075 Note one should not call wl_resource_destroy in this hook.
0076 
0077 ## Resource destructors
0078 
0079 destructors (tagged with type="destructor" in the XML) are not handled specially in QtWayland it is up to the class implementation to implement the event handler and call 
0080 ```cpp
0081 wl_resource_destroy(resource->handle)
0082 ```
0083 in the relevant method
0084