core: fix missing interfaces

This commit is contained in:
Vaxry 2024-04-21 21:13:44 +01:00
parent 6c4c47329f
commit 7c9c8adfe7

View file

@ -217,6 +217,8 @@ struct wl_resource;
HEADER += "};\n\n"; HEADER += "};\n\n";
} }
HEADER += "\n#ifndef HYPRWAYLAND_SCANNER_NO_INTERFACES\n";
for (auto& iface : XMLDATA.ifaces) { for (auto& iface : XMLDATA.ifaces) {
const auto IFACE_WL_NAME = iface.name + "_interface"; const auto IFACE_WL_NAME = iface.name + "_interface";
const auto IFACE_WL_NAME_CAMEL = camelize(iface.name + "_interface"); const auto IFACE_WL_NAME_CAMEL = camelize(iface.name + "_interface");
@ -224,6 +226,8 @@ struct wl_resource;
HEADER += std::format("extern const wl_interface {};\n", IFACE_WL_NAME, IFACE_WL_NAME_CAMEL, IFACE_WL_NAME); HEADER += std::format("extern const wl_interface {};\n", IFACE_WL_NAME, IFACE_WL_NAME_CAMEL, IFACE_WL_NAME);
} }
HEADER += "\n#endif\n";
for (auto& iface : XMLDATA.ifaces) { for (auto& iface : XMLDATA.ifaces) {
const auto IFACE_NAME_CAMEL = camelize(iface.name); const auto IFACE_NAME_CAMEL = camelize(iface.name);
const auto IFACE_CLASS_NAME_CAMEL = camelize("C_" + iface.name); const auto IFACE_CLASS_NAME_CAMEL = camelize("C_" + iface.name);
@ -339,6 +343,7 @@ class {} {{
void parseSource() { void parseSource() {
SOURCE += std::format(R"#(#define private public SOURCE += std::format(R"#(#define private public
#define HYPRWAYLAND_SCANNER_NO_INTERFACES
#include "{}.hpp" #include "{}.hpp"
#undef private #undef private
#define F std::function #define F std::function
@ -364,13 +369,12 @@ static const wl_interface* dummyTypes[] = { nullptr };
for (auto& iface : XMLDATA.ifaces) { for (auto& iface : XMLDATA.ifaces) {
const auto IFACE_WL_NAME = iface.name + "_interface"; const auto IFACE_WL_NAME = iface.name + "_interface";
const auto IFACE_WL_NAME_CAMEL = camelize(iface.name + "_interface"); const auto IFACE_WL_NAME_CAMEL = camelize(iface.name + "_interface");
if (std::find(declaredIfaces.begin(), declaredIfaces.end(), IFACE_WL_NAME) == declaredIfaces.end()) {
SOURCE += std::format("extern const wl_interface {};\n", IFACE_WL_NAME, IFACE_WL_NAME_CAMEL, IFACE_WL_NAME);
declaredIfaces.push_back(IFACE_WL_NAME); declaredIfaces.push_back(IFACE_WL_NAME);
SOURCE += std::format("extern const wl_interface {};\n", IFACE_WL_NAME, IFACE_WL_NAME_CAMEL, IFACE_WL_NAME);
} }
for (auto& iface : XMLDATA.ifaces) {
// do all referenced too // do all referenced too
for (auto& rq : iface.requests) { for (auto& rq : iface.requests) {
for (auto& arg : rq.args) { for (auto& arg : rq.args) {
@ -407,6 +411,7 @@ static const wl_interface* dummyTypes[] = { nullptr };
for (auto& iface : XMLDATA.ifaces) { for (auto& iface : XMLDATA.ifaces) {
const auto IFACE_WL_NAME = iface.name + "_interface";
const auto IFACE_NAME = iface.name; const auto IFACE_NAME = iface.name;
const auto IFACE_NAME_CAMEL = camelize(iface.name); const auto IFACE_NAME_CAMEL = camelize(iface.name);
const auto IFACE_CLASS_NAME_CAMEL = camelize("C_" + iface.name); const auto IFACE_CLASS_NAME_CAMEL = camelize("C_" + iface.name);
@ -523,14 +528,34 @@ void {}::{}({}) {{
SOURCE += "};\n"; SOURCE += "};\n";
} }
for (auto& ev : iface.events) {
if (ev.args.empty())
continue;
const auto MESSAGE_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_message"); const auto TYPE_TABLE_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_" + ev.name + "_types");
SOURCE += std::format("static const wl_interface* {}[] = {{\n", TYPE_TABLE_NAME);
for (auto& arg : ev.args) {
if (arg.interface.empty()) {
SOURCE += " nullptr,\n";
continue;
}
SOURCE += std::format(" &{}_interface,\n", arg.interface);
}
SOURCE += "};\n";
}
const auto MESSAGE_NAME_REQUESTS = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_requests");
const auto MESSAGE_NAME_EVENTS = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_events");
// message // message
if (iface.requests.size() > 0) {
SOURCE += std::format(R"#( SOURCE += std::format(R"#(
static const wl_message {}[] = {{ static const wl_message {}[] = {{
)#", )#",
MESSAGE_NAME); MESSAGE_NAME_REQUESTS);
for (auto& rq : iface.requests) { for (auto& rq : iface.requests) {
// create type table // create type table
const auto TYPE_TABLE_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_" + rq.name + "_types"); const auto TYPE_TABLE_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_" + rq.name + "_types");
@ -539,6 +564,33 @@ static const wl_message {}[] = {{
} }
SOURCE += "};\n"; SOURCE += "};\n";
}
if (iface.events.size() > 0) {
SOURCE += std::format(R"#(
static const wl_message {}[] = {{
)#",
MESSAGE_NAME_EVENTS);
for (auto& ev : iface.events) {
// create type table
const auto TYPE_TABLE_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_" + ev.name + "_types");
SOURCE += std::format(" {{ \"{}\", \"{}\", {}}},\n", ev.name, argsToShort(ev.args), ev.args.empty() ? "dummyTypes + 0" : TYPE_TABLE_NAME + " + 0");
}
SOURCE += "};\n";
}
// iface
SOURCE += std::format(R"#(
const wl_interface {} = {{
"{}", {},
{}, {},
{}, {},
}};
)#",
IFACE_WL_NAME, iface.name, iface.version, iface.requests.size(), (iface.requests.size() > 0 ? MESSAGE_NAME_REQUESTS : "nullptr"), iface.events.size(),
(iface.events.size() > 0 ? MESSAGE_NAME_EVENTS : "nullptr"));
// protocol body // protocol body
SOURCE += std::format(R"#( SOURCE += std::format(R"#(