private void RegistryGlobalCallback(void *data, wl_registry *registry, uint name, byte *ifaceUtf8, uint version)
        {
            // TODO we should only bind with the required version
            // TODO we should expose interface names in Utf8 format so we can do a direct compare without marshalling
            var iface = Util.Utf8ToString(ifaceUtf8);

            LogDebug($"Registry global announce for type '{iface}' v{version}.");

            // we store and expose all globals so users can bind whatever they want
            var global = new WaylandGlobal(iface, name, version);

            Globals.Add(global);
            _globalsDirty = true;

            switch (iface)
            {
            case WaylandBindings.wl_shell_name:
                _wlShellAvailable = true;
                break;

            case WaylandBindings.wl_output_name:
                LogDebug($"Binding WlOutput.");
                var output = _wlRegistry.Bind <wl_output>(name, WlOutput.Interface, version);
                AddDisplay(output);
                LogInfo($"Display connected with id {name}.");
                break;

            case WaylandBindings.wl_compositor_name:
                LogDebug($"Binding WlCompositor.");
                _wlCompositor = _wlRegistry.Bind <wl_compositor>(name, WlCompositor.Interface, version);
                break;

            case WaylandBindings.wl_seat_name:
                LogDebug($"Binding WlSeat.");
                _wlSeat = _wlRegistry.Bind <wl_seat>(name, WlSeat.Interface, version);
                _wlSeat.SetListener(SeatCapabilitiesCallback, SeatNameCallback);
                break;

            case XdgShellBindings.xdg_wm_base_name:
                LogDebug($"Binding XdgWmBase.");
                _xdgWmBase = _wlRegistry.Bind <xdg_wm_base>(name, XdgWmBase.Interface, version);
                _xdgWmBase.SetListener(XdgWmBasePingCallback);
                break;

            case XdgDecorationUnstableV1Bindings.zxdg_decoration_manager_v1_name:
                _xdgDecorationManager = _wlRegistry.Bind <zxdg_decoration_manager_v1>(name, ZxdgDecorationManagerV1.Interface, version);
                break;

            case ViewporterBindings.wp_viewporter_name:
                _wpViewporter = _wlRegistry.Bind <wp_viewporter>(name, WpViewporter.Interface, version);
                break;
            }
        }
示例#2
0
        public unsafe T Bind <T>(IBindFactory <T> factory, string iface, int?version) where T : WlProxy
        {
            var glob = GetGlobals().FirstOrDefault(g => g.Interface == iface);

            if (glob == null)
            {
                throw new NotSupportedException($"Unable to find {iface} in the registry");
            }

            version ??= factory.GetInterface()->Version;
            if (version > factory.GetInterface()->Version)
            {
                throw new ArgumentException($"Version {version} is not supported");
            }

            if (glob.Version < version)
            {
                throw new NotSupportedException(
                          $"Compositor doesn't support {version} of {iface}, only {glob.Version} is supported");
            }

            return(_registry.Bind(glob.Name, factory, version.Value));
        }