mirror of
https://github.com/hyprwm/hyprwayland-scanner.git
synced 2024-11-25 22:16:00 +01:00
core: fix new_id types in events
This commit is contained in:
parent
a0263ab9fc
commit
066c24549f
1 changed files with 42 additions and 28 deletions
66
src/main.cpp
66
src/main.cpp
|
@ -70,16 +70,36 @@ std::string argsToShort(std::vector<SRequestArgument>& args) {
|
||||||
return shortt;
|
return shortt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WPTypeToCType(const SRequestArgument& arg) {
|
std::string camelize(std::string snake) {
|
||||||
|
std::string result = "";
|
||||||
|
for (size_t i = 0; i < snake.length(); ++i) {
|
||||||
|
if (snake[i] == '_' && i != 0 && i + 1 < snake.length() && snake[i + 1] != '_') {
|
||||||
|
result += ::toupper(snake[i + 1]);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result += snake[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string WPTypeToCType(const SRequestArgument& arg, bool event /* events pass iface ptrs, requests ids */) {
|
||||||
if (arg.wlType == "uint" || arg.wlType == "new_id") {
|
if (arg.wlType == "uint" || arg.wlType == "new_id") {
|
||||||
if (arg.enumName.empty())
|
if (arg.enumName.empty() && arg.interface.empty())
|
||||||
return "uint32_t";
|
return "uint32_t";
|
||||||
|
|
||||||
// enum!
|
// enum
|
||||||
for (auto& e : XMLDATA.enums) {
|
if (!arg.enumName.empty())
|
||||||
if (e.nameOriginal == arg.enumName)
|
for (auto& e : XMLDATA.enums) {
|
||||||
return e.name;
|
if (e.nameOriginal == arg.enumName)
|
||||||
}
|
return e.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// iface
|
||||||
|
if (!arg.interface.empty() && event)
|
||||||
|
return camelize("C_" + arg.interface + "*");
|
||||||
|
|
||||||
return "uint32_t";
|
return "uint32_t";
|
||||||
}
|
}
|
||||||
|
@ -100,21 +120,6 @@ std::string WPTypeToCType(const SRequestArgument& arg) {
|
||||||
std::string HEADER;
|
std::string HEADER;
|
||||||
std::string SOURCE;
|
std::string SOURCE;
|
||||||
|
|
||||||
std::string camelize(std::string snake) {
|
|
||||||
std::string result = "";
|
|
||||||
for (size_t i = 0; i < snake.length(); ++i) {
|
|
||||||
if (snake[i] == '_' && i != 0 && i + 1 < snake.length() && snake[i + 1] != '_') {
|
|
||||||
result += ::toupper(snake[i + 1]);
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
result += snake[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string nameOriginal;
|
std::string nameOriginal;
|
||||||
|
@ -162,7 +167,7 @@ void parseXML(pugi::xml_document& doc) {
|
||||||
sargm.wlType = arg.attribute("type").as_string();
|
sargm.wlType = arg.attribute("type").as_string();
|
||||||
sargm.interface = arg.attribute("interface").as_string();
|
sargm.interface = arg.attribute("interface").as_string();
|
||||||
sargm.enumName = arg.attribute("enum").as_string();
|
sargm.enumName = arg.attribute("enum").as_string();
|
||||||
sargm.CType = WPTypeToCType(sargm);
|
sargm.CType = WPTypeToCType(sargm, false);
|
||||||
|
|
||||||
srq.args.push_back(sargm);
|
srq.args.push_back(sargm);
|
||||||
}
|
}
|
||||||
|
@ -180,7 +185,7 @@ void parseXML(pugi::xml_document& doc) {
|
||||||
sargm.interface = arg.attribute("interface").as_string();
|
sargm.interface = arg.attribute("interface").as_string();
|
||||||
sargm.wlType = arg.attribute("type").as_string();
|
sargm.wlType = arg.attribute("type").as_string();
|
||||||
sargm.enumName = arg.attribute("enum").as_string();
|
sargm.enumName = arg.attribute("enum").as_string();
|
||||||
sargm.CType = WPTypeToCType(sargm);
|
sargm.CType = WPTypeToCType(sargm, true);
|
||||||
|
|
||||||
sev.args.push_back(sargm);
|
sev.args.push_back(sargm);
|
||||||
}
|
}
|
||||||
|
@ -217,7 +222,13 @@ struct wl_resource;
|
||||||
HEADER += "};\n\n";
|
HEADER += "};\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
HEADER += "\n#ifndef HYPRWAYLAND_SCANNER_NO_INTERFACES\n";
|
// fw declare all classes
|
||||||
|
for (auto& iface : XMLDATA.ifaces) {
|
||||||
|
const auto IFACE_CLASS_NAME_CAMEL = camelize("C_" + iface.name);
|
||||||
|
HEADER += std::format("\nclass {};", IFACE_CLASS_NAME_CAMEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
HEADER += "\n\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";
|
||||||
|
@ -491,7 +502,10 @@ static const void* {}[] = {{
|
||||||
|
|
||||||
std::string argsN = ", ";
|
std::string argsN = ", ";
|
||||||
for (auto& arg : ev.args) {
|
for (auto& arg : ev.args) {
|
||||||
argsN += arg.name + ", ";
|
if (arg.interface.empty())
|
||||||
|
argsN += arg.name + ", ";
|
||||||
|
else
|
||||||
|
argsN += arg.name + "->pResource, ";
|
||||||
}
|
}
|
||||||
|
|
||||||
argsN.pop_back();
|
argsN.pop_back();
|
||||||
|
|
Loading…
Reference in a new issue