mirror of
https://github.com/hyprwm/hyprwayland-scanner.git
synced 2026-05-05 00:47:58 +02:00
Compare commits
No commits in common. "main" and "v0.3.10" have entirely different histories.
9 changed files with 231 additions and 450 deletions
22
.github/workflows/nix.yml
vendored
22
.github/workflows/nix.yml
vendored
|
|
@ -1,11 +1,21 @@
|
|||
name: Build
|
||||
|
||||
on: [push, pull_request, workflow_dispatch]
|
||||
|
||||
jobs:
|
||||
nix:
|
||||
if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork)
|
||||
uses: hyprwm/actions/.github/workflows/nix.yml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
command: nix build --print-build-logs --keep-going
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: cachix/install-nix-action@v25
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
|
||||
# not needed (yet)
|
||||
# - uses: cachix/cachix-action@v12
|
||||
# with:
|
||||
# name: hyprland
|
||||
# authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
||||
|
||||
- name: Build
|
||||
run: nix build -L
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
cmake_minimum_required(VERSION 3.19)
|
||||
|
||||
file(READ "${CMAKE_SOURCE_DIR}/VERSION" VER_RAW)
|
||||
string(STRIP ${VER_RAW} VERSION)
|
||||
set(VERSION 0.3.10)
|
||||
|
||||
project(
|
||||
hyprwayland-scanner
|
||||
DESCRIPTION "A hyprland version of wayland-scanner in and for C++"
|
||||
VERSION ${VERSION})
|
||||
project(hyprwayland-scanner
|
||||
DESCRIPTION "A hyprland version of wayland-scanner in and for C++"
|
||||
VERSION ${VERSION}
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
|
@ -16,17 +15,18 @@ set(PREFIX ${CMAKE_INSTALL_PREFIX})
|
|||
set(CMAKE_MESSAGE_LOG_LEVEL "STATUS")
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||
message(STATUS "Configuring hyprwayland-scanner in Debug with CMake")
|
||||
add_compile_definitions(HYPRLAND_DEBUG)
|
||||
message(STATUS "Configuring hyprwayland-scanner in Debug with CMake")
|
||||
add_compile_definitions(HYPRLAND_DEBUG)
|
||||
else()
|
||||
add_compile_options(-O3)
|
||||
message(STATUS "Configuring hyprwayland-scanner in Release with CMake")
|
||||
add_compile_options(-O3)
|
||||
message(STATUS "Configuring hyprwayland-scanner in Release with CMake")
|
||||
endif()
|
||||
|
||||
|
||||
# configure
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value
|
||||
-Wno-missing-field-initializers -Wno-narrowing)
|
||||
-Wno-missing-field-initializers -Wno-narrowing)
|
||||
|
||||
add_compile_definitions(SCANNER_VERSION="${VERSION}")
|
||||
|
||||
|
|
@ -41,29 +41,25 @@ pkg_check_modules(deps REQUIRED IMPORTED_TARGET pugixml)
|
|||
|
||||
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
|
||||
add_executable(hyprwayland-scanner ${SRCFILES})
|
||||
find_library(librt rt)
|
||||
if("${librt}" MATCHES "librt-NOTFOUND")
|
||||
unset(LIBRT)
|
||||
else()
|
||||
set(LIBRT rt)
|
||||
endif()
|
||||
target_link_libraries(hyprwayland-scanner PRIVATE ${LIBRT} Threads::Threads
|
||||
PkgConfig::deps)
|
||||
target_link_libraries(hyprwayland-scanner PRIVATE rt Threads::Threads PkgConfig::deps)
|
||||
|
||||
configure_package_config_file(
|
||||
hyprwayland-scanner-config.cmake.in hyprwayland-scanner-config.cmake
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/hyprwayland-scanner"
|
||||
PATH_VARS CMAKE_INSTALL_BINDIR)
|
||||
hyprwayland-scanner-config.cmake.in
|
||||
hyprwayland-scanner-config.cmake
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/hyprwayland-scanner"
|
||||
PATH_VARS CMAKE_INSTALL_BINDIR
|
||||
)
|
||||
write_basic_package_version_file(
|
||||
"hyprwayland-scanner-config-version.cmake"
|
||||
VERSION "${VERSION}"
|
||||
ARCH_INDEPENDENT
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
"hyprwayland-scanner-config-version.cmake"
|
||||
VERSION "${VERSION}"
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
# Installation
|
||||
install(TARGETS hyprwayland-scanner)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/hyprwayland-scanner.pc
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/hyprwayland-scanner-config.cmake
|
||||
${CMAKE_BINARY_DIR}/hyprwayland-scanner-config-version.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hyprwayland-scanner)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/hyprwayland-scanner.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
install(FILES
|
||||
${CMAKE_BINARY_DIR}/hyprwayland-scanner-config.cmake
|
||||
${CMAKE_BINARY_DIR}/hyprwayland-scanner-config-version.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hyprwayland-scanner
|
||||
)
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -1,20 +1,12 @@
|
|||
# hyprwayland-scanner
|
||||
A Hyprland implementation of wayland-scanner, in and for C++.
|
||||
|
||||
hw-s automatically generates properly RAII-ready, modern C++ bindings for Wayland protocols, for
|
||||
either servers or clients.
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
hyprwayland-scanner '/path/to/proto' '/path/to/output/directory'
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
- `--client` -> generate client code
|
||||
- `--wayland-enums` -> use wayland enum naming (snake instead of camel)
|
||||
|
||||
## Dependencies
|
||||
|
||||
Requires a compiler with C++23 support.
|
||||
|
|
@ -34,3 +26,7 @@ cmake --build build -j `nproc`
|
|||
```sh
|
||||
sudo cmake --install build
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] Support for generating client headers
|
||||
1
VERSION
1
VERSION
|
|
@ -1 +0,0 @@
|
|||
0.4.6
|
||||
6
flake.lock
generated
6
flake.lock
generated
|
|
@ -2,11 +2,11 @@
|
|||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1748929857,
|
||||
"narHash": "sha256-lcZQ8RhsmhsK8u7LIFsJhsLh/pzR9yZ8yqpTzyGdj+Q=",
|
||||
"lastModified": 1713537308,
|
||||
"narHash": "sha256-XtTSSIB2DA6tOv+l0FhvfDMiyCmhoRbNB+0SeInZkbk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c2a03962b8e24e669fb37b7df10e7c79531ff1a4",
|
||||
"rev": "5c24cf2f0a12ad855f444c30b2421d044120c66f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
67
flake.nix
67
flake.nix
|
|
@ -6,40 +6,39 @@
|
|||
systems.url = "github:nix-systems/default-linux";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
systems,
|
||||
}:
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
eachSystem = lib.genAttrs (import systems);
|
||||
pkgsFor = eachSystem (
|
||||
system:
|
||||
import nixpkgs {
|
||||
localSystem.system = system;
|
||||
overlays = with self.overlays; [ hyprwayland-scanner ];
|
||||
}
|
||||
);
|
||||
pkgsCrossFor = eachSystem (
|
||||
system: crossSystem:
|
||||
import nixpkgs {
|
||||
localSystem = system;
|
||||
crossSystem = crossSystem;
|
||||
overlays = with self.overlays; [ hyprwayland-scanner ];
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overlays = import ./nix/overlays.nix { inherit lib self; };
|
||||
|
||||
packages = eachSystem (system: {
|
||||
default = self.packages.${system}.hyprwayland-scanner;
|
||||
inherit (pkgsFor.${system}) hyprwayland-scanner;
|
||||
hyprwayland-scanner-cross = (pkgsCrossFor.${system} "aarch64-linux").hyprwayland-scanner;
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
systems,
|
||||
}: let
|
||||
inherit (nixpkgs) lib;
|
||||
eachSystem = lib.genAttrs (import systems);
|
||||
pkgsFor = eachSystem (system:
|
||||
import nixpkgs {
|
||||
localSystem.system = system;
|
||||
overlays = with self.overlays; [hyprwayland-scanner];
|
||||
});
|
||||
|
||||
formatter = eachSystem (system: pkgsFor.${system}.nixfmt-tree);
|
||||
mkDate = longDate: (lib.concatStringsSep "-" [
|
||||
(builtins.substring 0 4 longDate)
|
||||
(builtins.substring 4 2 longDate)
|
||||
(builtins.substring 6 2 longDate)
|
||||
]);
|
||||
in {
|
||||
overlays = {
|
||||
default = self.overlays.hyprwayland-scanner;
|
||||
hyprwayland-scanner = final: prev: {
|
||||
hyprwayland-scanner = final.callPackage ./nix/default.nix {
|
||||
stdenv = final.gcc13Stdenv;
|
||||
version = "0.1.0" + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
packages = eachSystem (system: {
|
||||
default = self.packages.${system}.hyprwayland-scanner;
|
||||
inherit (pkgsFor.${system}) hyprwayland-scanner;
|
||||
});
|
||||
|
||||
formatter = eachSystem (system: pkgsFor.${system}.alejandra);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,6 @@ stdenv.mkDerivation {
|
|||
nativeBuildInputs = [
|
||||
cmake
|
||||
pkg-config
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
pugixml
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
{
|
||||
lib,
|
||||
self,
|
||||
...
|
||||
}:
|
||||
let
|
||||
|
||||
mkDate =
|
||||
longDate:
|
||||
(lib.concatStringsSep "-" [
|
||||
(builtins.substring 0 4 longDate)
|
||||
(builtins.substring 4 2 longDate)
|
||||
(builtins.substring 6 2 longDate)
|
||||
]);
|
||||
|
||||
version = lib.removeSuffix "\n" (builtins.readFile ../VERSION);
|
||||
in
|
||||
{
|
||||
default = self.overlays.hyprwayland-scanner;
|
||||
|
||||
hyprwayland-scanner = final: prev: {
|
||||
hyprwayland-scanner = final.callPackage ./default.nix {
|
||||
stdenv = final.gcc15Stdenv;
|
||||
version =
|
||||
version
|
||||
+ "+date="
|
||||
+ (mkDate (self.lastModifiedDate or "19700101"))
|
||||
+ "_"
|
||||
+ (self.shortRev or "dirty");
|
||||
};
|
||||
};
|
||||
}
|
||||
480
src/main.cpp
480
src/main.cpp
|
|
@ -2,36 +2,39 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <format>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <filesystem>
|
||||
|
||||
bool waylandEnums = false;
|
||||
bool clientCode = false;
|
||||
bool noInterfaces = false;
|
||||
|
||||
struct SRequestArgument {
|
||||
std::string wlType;
|
||||
std::string interface;
|
||||
std::string enumName;
|
||||
std::string name;
|
||||
bool newType = false;
|
||||
bool allowNull = false;
|
||||
};
|
||||
|
||||
struct SWaylandFunction {
|
||||
struct SRequest {
|
||||
std::vector<SRequestArgument> args;
|
||||
std::string name;
|
||||
std::string since;
|
||||
};
|
||||
|
||||
struct SEvent {
|
||||
std::vector<SRequestArgument> args;
|
||||
std::string name;
|
||||
std::string since;
|
||||
std::string newIdType = ""; // client only
|
||||
bool destructor = false;
|
||||
};
|
||||
|
||||
struct SInterface {
|
||||
std::vector<SWaylandFunction> requests;
|
||||
std::vector<SWaylandFunction> events;
|
||||
std::string name;
|
||||
int version = 1;
|
||||
std::vector<SRequest> requests;
|
||||
std::vector<SEvent> events;
|
||||
std::string name;
|
||||
int version = 1;
|
||||
};
|
||||
|
||||
struct SEnum {
|
||||
|
|
@ -45,10 +48,6 @@ struct {
|
|||
std::vector<SEnum> enums;
|
||||
} XMLDATA;
|
||||
|
||||
const char* resourceName() {
|
||||
return clientCode ? "wl_proxy" : "wl_resource";
|
||||
}
|
||||
|
||||
std::string sanitize(const std::string& in) {
|
||||
if (in == "namespace")
|
||||
return "namespace_";
|
||||
|
|
@ -109,24 +108,19 @@ std::string WPTypeToCType(const SRequestArgument& arg, bool event /* events pass
|
|||
return "uint32_t";
|
||||
|
||||
// enum
|
||||
if (!arg.enumName.empty()) {
|
||||
if (!arg.enumName.empty())
|
||||
for (auto& e : XMLDATA.enums) {
|
||||
if (e.nameOriginal == arg.enumName)
|
||||
return e.name;
|
||||
}
|
||||
return "uint32_t";
|
||||
}
|
||||
|
||||
if (!event && clientCode && arg.wlType == "new_id")
|
||||
return "wl_proxy*";
|
||||
|
||||
// iface
|
||||
if (!arg.interface.empty() && event) {
|
||||
for (auto& i : XMLDATA.ifaces) {
|
||||
if (i.name == arg.interface)
|
||||
return camelize((clientCode ? "CC_" : "C_") + arg.interface + "*");
|
||||
return camelize("C_" + arg.interface + "*");
|
||||
}
|
||||
return std::string{resourceName()} + "*";
|
||||
return "wl_resource*";
|
||||
}
|
||||
|
||||
return "uint32_t";
|
||||
|
|
@ -135,10 +129,10 @@ std::string WPTypeToCType(const SRequestArgument& arg, bool event /* events pass
|
|||
if (!arg.interface.empty() && event && !ignoreTypes) {
|
||||
for (auto& i : XMLDATA.ifaces) {
|
||||
if (i.name == arg.interface)
|
||||
return camelize((clientCode ? "CC_" : "C_") + arg.interface + "*");
|
||||
return camelize("C_" + arg.interface + "*");
|
||||
}
|
||||
}
|
||||
return std::string{resourceName()} + "*";
|
||||
return "wl_resource*";
|
||||
}
|
||||
if (arg.wlType == "int" || arg.wlType == "fd")
|
||||
return "int32_t";
|
||||
|
|
@ -193,17 +187,12 @@ void parseXML(pugi::xml_document& doc) {
|
|||
}
|
||||
|
||||
for (auto& rq : iface.children("request")) {
|
||||
SWaylandFunction srq;
|
||||
srq.name = rq.attribute("name").as_string();
|
||||
srq.since = rq.attribute("since").as_string();
|
||||
srq.destructor = rq.attribute("type").as_string() == std::string{"destructor"};
|
||||
SRequest srq;
|
||||
srq.name = rq.attribute("name").as_string();
|
||||
srq.since = rq.attribute("since").as_string();
|
||||
|
||||
for (auto& arg : rq.children("arg")) {
|
||||
SRequestArgument sargm;
|
||||
if (arg.attribute("type").as_string() == std::string{"new_id"} && clientCode)
|
||||
srq.newIdType = arg.attribute("interface").as_string();
|
||||
|
||||
sargm.newType = arg.attribute("type").as_string() == std::string{"new_id"} && clientCode;
|
||||
sargm.name = sanitize(arg.attribute("name").as_string());
|
||||
sargm.wlType = arg.attribute("type").as_string();
|
||||
sargm.interface = arg.attribute("interface").as_string();
|
||||
|
|
@ -217,10 +206,9 @@ void parseXML(pugi::xml_document& doc) {
|
|||
}
|
||||
|
||||
for (auto& ev : iface.children("event")) {
|
||||
SWaylandFunction sev;
|
||||
sev.name = ev.attribute("name").as_string();
|
||||
sev.since = ev.attribute("since").as_string();
|
||||
sev.destructor = ev.attribute("type").as_string() == std::string{"destructor"};
|
||||
SEvent sev;
|
||||
sev.name = ev.attribute("name").as_string();
|
||||
sev.since = ev.attribute("since").as_string();
|
||||
|
||||
for (auto& arg : ev.children("arg")) {
|
||||
SRequestArgument sargm;
|
||||
|
|
@ -243,20 +231,19 @@ void parseXML(pugi::xml_document& doc) {
|
|||
void parseHeader() {
|
||||
|
||||
// add some boilerplate
|
||||
HEADER +=
|
||||
std::format(R"#(#pragma once
|
||||
HEADER += R"#(#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
{}
|
||||
#include <wayland-server.h>
|
||||
|
||||
#define F std::function
|
||||
|
||||
{}
|
||||
struct wl_client;
|
||||
struct wl_resource;
|
||||
|
||||
)#",
|
||||
(clientCode ? "#include <wayland-client.h>" : "#include <wayland-server.h>"), (clientCode ? "struct wl_proxy;" : "struct wl_client;\nstruct wl_resource;"));
|
||||
)#";
|
||||
|
||||
// parse all enums
|
||||
if (!waylandEnums) {
|
||||
|
|
@ -271,13 +258,13 @@ void parseHeader() {
|
|||
|
||||
// fw declare all classes
|
||||
for (auto& iface : XMLDATA.ifaces) {
|
||||
const auto IFACE_CLASS_NAME_CAMEL = camelize((clientCode ? "CC_" : "C_") + iface.name);
|
||||
const auto IFACE_CLASS_NAME_CAMEL = camelize("C_" + iface.name);
|
||||
HEADER += std::format("\nclass {};", IFACE_CLASS_NAME_CAMEL);
|
||||
|
||||
for (auto& rq : iface.requests) {
|
||||
for (auto& arg : rq.args) {
|
||||
if (!arg.interface.empty()) {
|
||||
HEADER += std::format("\nclass {};", camelize((clientCode ? "CC_" : "C_") + arg.interface));
|
||||
HEADER += std::format("\nclass {};", camelize("C_" + arg.interface));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -285,7 +272,7 @@ void parseHeader() {
|
|||
for (auto& rq : iface.events) {
|
||||
for (auto& arg : rq.args) {
|
||||
if (!arg.interface.empty()) {
|
||||
HEADER += std::format("\nclass {};", camelize((clientCode ? "CC_" : "C_") + arg.interface));
|
||||
HEADER += std::format("\nclass {};", camelize("C_" + arg.interface));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -304,35 +291,18 @@ void parseHeader() {
|
|||
|
||||
for (auto& iface : XMLDATA.ifaces) {
|
||||
const auto IFACE_NAME_CAMEL = camelize(iface.name);
|
||||
const auto IFACE_CLASS_NAME_CAMEL = camelize((clientCode ? "CC_" : "C_") + iface.name);
|
||||
|
||||
if (!clientCode) {
|
||||
HEADER += std::format(R"#(
|
||||
struct {}DestroyWrapper {{
|
||||
wl_listener listener;
|
||||
{}* parent = nullptr;
|
||||
}};
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL);
|
||||
}
|
||||
const auto IFACE_CLASS_NAME_CAMEL = camelize("C_" + iface.name);
|
||||
|
||||
// begin the class
|
||||
HEADER +=
|
||||
std::format(R"#(
|
||||
|
||||
HEADER += std::format(R"#(
|
||||
class {} {{
|
||||
public:
|
||||
{}({});
|
||||
{}(wl_client* client, uint32_t version, uint32_t id);
|
||||
~{}();
|
||||
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL, (clientCode ? "wl_proxy*" : "wl_client* client, uint32_t version, uint32_t id"), IFACE_CLASS_NAME_CAMEL);
|
||||
|
||||
if (!clientCode) {
|
||||
HEADER += std::format(R"#(
|
||||
// set a listener for when this resource is _being_ destroyed
|
||||
void setOnDestroy(F<void({}*)> &&handler) {{
|
||||
onDestroy = std::move(handler);
|
||||
void setOnDestroy(F<void({}*)> handler) {{
|
||||
onDestroy = handler;
|
||||
}}
|
||||
|
||||
// set the data for this resource
|
||||
|
|
@ -344,7 +314,7 @@ class {} {{
|
|||
void* data() {{
|
||||
return pData;
|
||||
}}
|
||||
|
||||
|
||||
// get the raw wl_resource ptr
|
||||
wl_resource* resource() {{
|
||||
return pResource;
|
||||
|
|
@ -369,64 +339,33 @@ class {} {{
|
|||
int version() {{
|
||||
return wl_resource_get_version(pResource);
|
||||
}}
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL);
|
||||
} else {
|
||||
HEADER += R"#(
|
||||
// set the data for this resource
|
||||
void setData(void* data) {{
|
||||
pData = data;
|
||||
}}
|
||||
|
||||
// get the data for this resource
|
||||
void* data() {{
|
||||
return pData;
|
||||
}}
|
||||
|
||||
// get the raw wl_resource (wl_proxy) ptr
|
||||
wl_proxy* resource() {{
|
||||
return pResource;
|
||||
}}
|
||||
|
||||
// get the raw wl_proxy ptr
|
||||
wl_proxy* proxy() {{
|
||||
return pResource;
|
||||
}}
|
||||
|
||||
// get the resource version
|
||||
int version() {{
|
||||
return wl_proxy_get_version(pResource);
|
||||
}}
|
||||
)#";
|
||||
}
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL);
|
||||
|
||||
// add all setters for requests
|
||||
HEADER += "\n // --------------- Requests --------------- //\n\n";
|
||||
|
||||
for (auto& rq : (clientCode ? iface.events : iface.requests)) {
|
||||
for (auto& rq : iface.requests) {
|
||||
|
||||
std::string args = ", ";
|
||||
for (auto& arg : rq.args) {
|
||||
if (arg.newType)
|
||||
continue;
|
||||
args += WPTypeToCType(arg, false) + ", ";
|
||||
}
|
||||
|
||||
args.pop_back();
|
||||
args.pop_back();
|
||||
|
||||
HEADER += std::format(" void {}(F<void({}*{})> &&handler);\n", camelize("set_" + rq.name), IFACE_CLASS_NAME_CAMEL, args);
|
||||
HEADER += std::format(" void {}(F<void({}*{})> handler);\n", camelize("set_" + rq.name), IFACE_CLASS_NAME_CAMEL, args);
|
||||
}
|
||||
|
||||
// start events
|
||||
|
||||
HEADER += "\n // --------------- Events --------------- //\n\n";
|
||||
|
||||
for (auto& ev : (!clientCode ? iface.events : iface.requests)) {
|
||||
for (auto& ev : iface.events) {
|
||||
std::string args = "";
|
||||
for (auto& arg : ev.args) {
|
||||
if (arg.newType)
|
||||
continue;
|
||||
args += WPTypeToCType(arg, true) + ", ";
|
||||
}
|
||||
|
||||
|
|
@ -435,26 +374,22 @@ class {} {{
|
|||
args.pop_back();
|
||||
}
|
||||
|
||||
HEADER += std::format(" {} {}({});\n", ev.newIdType.empty() ? "void" : "wl_proxy*", camelize("send_" + ev.name), args);
|
||||
HEADER += std::format(" void {}({});\n", camelize("send_" + ev.name), args);
|
||||
}
|
||||
|
||||
// dangerous ones
|
||||
if (!clientCode) {
|
||||
for (auto& ev : (!clientCode ? iface.events : iface.requests)) {
|
||||
std::string args = "";
|
||||
for (auto& arg : ev.args) {
|
||||
if (arg.newType)
|
||||
continue;
|
||||
args += WPTypeToCType(arg, true, true) + ", ";
|
||||
}
|
||||
|
||||
if (!args.empty()) {
|
||||
args.pop_back();
|
||||
args.pop_back();
|
||||
}
|
||||
|
||||
HEADER += std::format(" void {}({});\n", camelize("send_" + ev.name + "_raw"), args);
|
||||
for (auto& ev : iface.events) {
|
||||
std::string args = "";
|
||||
for (auto& arg : ev.args) {
|
||||
args += WPTypeToCType(arg, true, true) + ", ";
|
||||
}
|
||||
|
||||
if (!args.empty()) {
|
||||
args.pop_back();
|
||||
args.pop_back();
|
||||
}
|
||||
|
||||
HEADER += std::format(" void {}({});\n", camelize("send_" + ev.name + "_raw"), args);
|
||||
}
|
||||
|
||||
// end events
|
||||
|
|
@ -465,12 +400,10 @@ class {} {{
|
|||
// start requests storage
|
||||
HEADER += " struct {\n";
|
||||
|
||||
for (auto& rq : (clientCode ? iface.events : iface.requests)) {
|
||||
for (auto& rq : iface.requests) {
|
||||
|
||||
std::string args = ", ";
|
||||
for (auto& arg : rq.args) {
|
||||
if (arg.newType)
|
||||
continue;
|
||||
args += WPTypeToCType(arg, false) + ", ";
|
||||
}
|
||||
|
||||
|
|
@ -486,26 +419,17 @@ class {} {{
|
|||
HEADER += " } requests;\n";
|
||||
|
||||
// constant resource stuff
|
||||
if (!clientCode) {
|
||||
HEADER += std::format(R"#(
|
||||
HEADER += std::format(R"#(
|
||||
void onDestroyCalled();
|
||||
|
||||
F<void({}*)> onDestroy;
|
||||
|
||||
wl_resource* pResource = nullptr;
|
||||
|
||||
{}DestroyWrapper resourceDestroyListener;
|
||||
wl_listener resourceDestroyListener;
|
||||
|
||||
void* pData = nullptr;)#",
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL);
|
||||
} else {
|
||||
HEADER += R"#(
|
||||
wl_proxy* pResource = nullptr;
|
||||
|
||||
bool destroyed = false;
|
||||
|
||||
void* pData = nullptr;)#";
|
||||
}
|
||||
IFACE_CLASS_NAME_CAMEL);
|
||||
|
||||
HEADER += "\n};\n\n";
|
||||
}
|
||||
|
|
@ -514,8 +438,6 @@ class {} {{
|
|||
}
|
||||
|
||||
void parseSource() {
|
||||
std::string DUMMY_TYPE_TABLE_NAME = PROTO_DATA.name + "_dummyTypes";
|
||||
|
||||
SOURCE += std::format(R"#(#define private public
|
||||
#define HYPRWAYLAND_SCANNER_NO_INTERFACES
|
||||
#include "{}.hpp"
|
||||
|
|
@ -527,10 +449,9 @@ void parseSource() {
|
|||
// reference interfaces
|
||||
|
||||
// dummy
|
||||
SOURCE += std::format(R"#(
|
||||
static const wl_interface* {}[] = {{ nullptr }};
|
||||
)#",
|
||||
DUMMY_TYPE_TABLE_NAME);
|
||||
SOURCE += R"#(
|
||||
static const wl_interface* dummyTypes[] = { nullptr };
|
||||
)#";
|
||||
|
||||
SOURCE += R"#(
|
||||
// Reference all other interfaces.
|
||||
|
|
@ -589,16 +510,14 @@ static const wl_interface* {}[] = {{ nullptr }};
|
|||
const auto IFACE_WL_NAME = iface.name + "_interface";
|
||||
const auto IFACE_NAME = iface.name;
|
||||
const auto IFACE_NAME_CAMEL = camelize(iface.name);
|
||||
const auto IFACE_CLASS_NAME_CAMEL = camelize((clientCode ? "CC_" : "C_") + iface.name);
|
||||
const auto IFACE_CLASS_NAME_CAMEL = camelize("C_" + iface.name);
|
||||
|
||||
// create handlers
|
||||
for (auto& rq : (clientCode ? iface.events : iface.requests)) {
|
||||
for (auto& rq : iface.requests) {
|
||||
const auto REQUEST_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_" + rq.name);
|
||||
|
||||
std::string argsC = ", ";
|
||||
for (auto& arg : rq.args) {
|
||||
if (arg.newType)
|
||||
continue;
|
||||
argsC += WPTypeToCType(arg, false) + " " + arg.name + ", ";
|
||||
}
|
||||
|
||||
|
|
@ -615,38 +534,24 @@ static const wl_interface* {}[] = {{ nullptr }};
|
|||
argsN.pop_back();
|
||||
}
|
||||
|
||||
if (!clientCode) {
|
||||
SOURCE += std::format(R"#(
|
||||
SOURCE += std::format(R"#(
|
||||
static void {}(wl_client* client, wl_resource* resource{}) {{
|
||||
const auto PO = ({}*)wl_resource_get_user_data(resource);
|
||||
if (PO && PO->requests.{})
|
||||
PO->requests.{}(PO{});
|
||||
}}
|
||||
)#",
|
||||
REQUEST_NAME, argsC, IFACE_CLASS_NAME_CAMEL, camelize(rq.name), camelize(rq.name), argsN);
|
||||
} else {
|
||||
SOURCE += std::format(R"#(
|
||||
static void {}(void* data, void* resource{}) {{
|
||||
const auto PO = ({}*)data;
|
||||
if (PO && PO->requests.{})
|
||||
PO->requests.{}(PO{});
|
||||
}}
|
||||
)#",
|
||||
REQUEST_NAME, argsC, IFACE_CLASS_NAME_CAMEL, camelize(rq.name), camelize(rq.name), argsN);
|
||||
}
|
||||
REQUEST_NAME, argsC, IFACE_CLASS_NAME_CAMEL, camelize(rq.name), camelize(rq.name), argsN);
|
||||
}
|
||||
|
||||
// destroy handler
|
||||
if (!clientCode) {
|
||||
SOURCE += std::format(R"#(
|
||||
SOURCE += std::format(R"#(
|
||||
static void _{}__DestroyListener(wl_listener* l, void* d) {{
|
||||
{}DestroyWrapper *wrap = wl_container_of(l, wrap, listener);
|
||||
{}* pResource = wrap->parent;
|
||||
{}* pResource = wl_container_of(l, pResource, resourceDestroyListener);
|
||||
pResource->onDestroyCalled();
|
||||
}}
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL);
|
||||
}
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL);
|
||||
|
||||
// create vtable
|
||||
|
||||
|
|
@ -657,27 +562,21 @@ static const void* {}[] = {{
|
|||
)#",
|
||||
IFACE_VTABLE_NAME);
|
||||
|
||||
for (auto& rq : (clientCode ? iface.events : iface.requests)) {
|
||||
for (auto& rq : iface.requests) {
|
||||
const auto REQUEST_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_" + rq.name);
|
||||
SOURCE += std::format(" (void*){},\n", REQUEST_NAME);
|
||||
}
|
||||
|
||||
if ((clientCode ? iface.events : iface.requests).empty()) {
|
||||
SOURCE += " nullptr,\n";
|
||||
}
|
||||
|
||||
SOURCE += "};\n";
|
||||
|
||||
// create events
|
||||
|
||||
int evid = 0;
|
||||
for (auto& ev : (!clientCode ? iface.events : iface.requests)) {
|
||||
for (auto& ev : iface.events) {
|
||||
const auto EVENT_NAME = camelize("send_" + ev.name);
|
||||
|
||||
std::string argsC = "";
|
||||
for (auto& arg : ev.args) {
|
||||
if (arg.newType)
|
||||
continue;
|
||||
argsC += WPTypeToCType(arg, true) + " " + arg.name + ", ";
|
||||
}
|
||||
|
||||
|
|
@ -688,85 +587,60 @@ static const void* {}[] = {{
|
|||
|
||||
std::string argsN = ", ";
|
||||
for (auto& arg : ev.args) {
|
||||
if (arg.newType)
|
||||
argsN += "nullptr, ";
|
||||
else if (!WPTypeToCType(arg, true).starts_with("C"))
|
||||
if (!WPTypeToCType(arg, true).starts_with("C"))
|
||||
argsN += arg.name + ", ";
|
||||
else
|
||||
argsN += (arg.name + " ? " + arg.name + "->pResource : nullptr, ");
|
||||
argsN += arg.name + "->pResource, ";
|
||||
}
|
||||
|
||||
argsN.pop_back();
|
||||
argsN.pop_back();
|
||||
|
||||
if (!clientCode) {
|
||||
SOURCE += std::format(R"#(
|
||||
SOURCE += std::format(R"#(
|
||||
void {}::{}({}) {{
|
||||
if (!pResource)
|
||||
return;
|
||||
wl_resource_post_event(pResource, {}{});
|
||||
}}
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, EVENT_NAME, argsC, evid, argsN);
|
||||
} else {
|
||||
std::string retType = ev.newIdType.empty() ? "void" : "wl_proxy";
|
||||
std::string ptrRetType = ev.newIdType.empty() ? "void" : "wl_proxy*";
|
||||
std::string flags = ev.destructor ? "1" : "0";
|
||||
SOURCE += std::format(R"#(
|
||||
{} {}::{}({}) {{
|
||||
if (!pResource)
|
||||
return{};{}
|
||||
|
||||
auto proxy = wl_proxy_marshal_flags(pResource, {}, {}, wl_proxy_get_version(pResource), {}{});{}
|
||||
}}
|
||||
)#",
|
||||
ptrRetType, IFACE_CLASS_NAME_CAMEL, EVENT_NAME, argsC, (ev.newIdType.empty() ? "" : " nullptr"),
|
||||
(ev.destructor ? "\n destroyed = true;" : ""), evid, (ev.newIdType.empty() ? "nullptr" : "&" + ev.newIdType + "_interface"), flags, argsN,
|
||||
(ev.newIdType.empty() ? "\n proxy;" : "\n\n return proxy;"));
|
||||
}
|
||||
IFACE_CLASS_NAME_CAMEL, EVENT_NAME, argsC, evid, argsN);
|
||||
|
||||
evid++;
|
||||
}
|
||||
|
||||
// dangerous
|
||||
if (!clientCode) {
|
||||
evid = 0;
|
||||
for (auto& ev : iface.events) {
|
||||
const auto EVENT_NAME = camelize("send_" + ev.name + "_raw");
|
||||
evid = 0;
|
||||
for (auto& ev : iface.events) {
|
||||
const auto EVENT_NAME = camelize("send_" + ev.name + "_raw");
|
||||
|
||||
std::string argsC = "";
|
||||
for (auto& arg : ev.args) {
|
||||
if (arg.newType)
|
||||
continue;
|
||||
argsC += WPTypeToCType(arg, true, true) + " " + arg.name + ", ";
|
||||
}
|
||||
std::string argsC = "";
|
||||
for (auto& arg : ev.args) {
|
||||
argsC += WPTypeToCType(arg, true, true) + " " + arg.name + ", ";
|
||||
}
|
||||
|
||||
if (!argsC.empty()) {
|
||||
argsC.pop_back();
|
||||
argsC.pop_back();
|
||||
}
|
||||
if (!argsC.empty()) {
|
||||
argsC.pop_back();
|
||||
argsC.pop_back();
|
||||
}
|
||||
|
||||
std::string argsN = ", ";
|
||||
for (auto& arg : ev.args) {
|
||||
if (arg.newType)
|
||||
continue;
|
||||
argsN += arg.name + ", ";
|
||||
}
|
||||
std::string argsN = ", ";
|
||||
for (auto& arg : ev.args) {
|
||||
argsN += arg.name + ", ";
|
||||
}
|
||||
|
||||
argsN.pop_back();
|
||||
argsN.pop_back();
|
||||
argsN.pop_back();
|
||||
argsN.pop_back();
|
||||
|
||||
SOURCE += std::format(R"#(
|
||||
SOURCE += std::format(R"#(
|
||||
void {}::{}({}) {{
|
||||
if (!pResource)
|
||||
return;
|
||||
wl_resource_post_event(pResource, {}{});
|
||||
}}
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, EVENT_NAME, argsC, evid, argsN);
|
||||
IFACE_CLASS_NAME_CAMEL, EVENT_NAME, argsC, evid, argsN);
|
||||
|
||||
evid++;
|
||||
}
|
||||
evid++;
|
||||
}
|
||||
|
||||
// wayland interfaces and stuff
|
||||
|
|
@ -780,12 +654,6 @@ void {}::{}({}) {{
|
|||
SOURCE += std::format("static const wl_interface* {}[] = {{\n", TYPE_TABLE_NAME);
|
||||
|
||||
for (auto& arg : rq.args) {
|
||||
if (arg.wlType == "new_id" && arg.interface.empty()) {
|
||||
// untyped new_id expands to (string, uint, new_id)
|
||||
SOURCE += " nullptr,\n nullptr,\n nullptr,\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg.interface.empty()) {
|
||||
SOURCE += " nullptr,\n";
|
||||
continue;
|
||||
|
|
@ -804,12 +672,6 @@ void {}::{}({}) {{
|
|||
SOURCE += std::format("static const wl_interface* {}[] = {{\n", TYPE_TABLE_NAME);
|
||||
|
||||
for (auto& arg : ev.args) {
|
||||
if (arg.wlType == "new_id" && arg.interface.empty()) {
|
||||
// untyped new_id expands to (string, uint, new_id)
|
||||
SOURCE += " nullptr,\n nullptr,\n nullptr,\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg.interface.empty()) {
|
||||
SOURCE += " nullptr,\n";
|
||||
continue;
|
||||
|
|
@ -825,72 +687,66 @@ void {}::{}({}) {{
|
|||
const auto MESSAGE_NAME_EVENTS = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_events");
|
||||
|
||||
// message
|
||||
if (!noInterfaces) {
|
||||
if (iface.requests.size() > 0) {
|
||||
SOURCE += std::format(R"#(
|
||||
static const wl_message {}[] = {{
|
||||
)#",
|
||||
MESSAGE_NAME_REQUESTS);
|
||||
for (auto& rq : iface.requests) {
|
||||
// create type table
|
||||
const auto TYPE_TABLE_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_" + rq.name + "_types");
|
||||
|
||||
SOURCE += std::format(" {{ .name = \"{}\", .signature = \"{}\", .types = {}}},\n", rq.name, argsToShort(rq.args, rq.since),
|
||||
rq.args.empty() ? std::format("{} + 0", DUMMY_TYPE_TABLE_NAME) : TYPE_TABLE_NAME + " + 0");
|
||||
}
|
||||
|
||||
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(" {{ .name = \"{}\", .signature = \"{}\", .types = {}}},\n", ev.name, argsToShort(ev.args, ev.since),
|
||||
ev.args.empty() ? std::format("{} + 0", DUMMY_TYPE_TABLE_NAME) : TYPE_TABLE_NAME + " + 0");
|
||||
}
|
||||
|
||||
SOURCE += "};\n";
|
||||
}
|
||||
|
||||
// iface
|
||||
if (iface.requests.size() > 0) {
|
||||
SOURCE += std::format(R"#(
|
||||
const wl_interface {} = {{
|
||||
.name = "{}", .version = {},
|
||||
.method_count = {}, .methods = {},
|
||||
.event_count = {}, .events = {},
|
||||
}};
|
||||
static const wl_message {}[] = {{
|
||||
)#",
|
||||
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"));
|
||||
MESSAGE_NAME_REQUESTS);
|
||||
for (auto& rq : iface.requests) {
|
||||
// create type table
|
||||
const auto TYPE_TABLE_NAME = camelize(std::string{"_"} + "C_" + IFACE_NAME + "_" + rq.name + "_types");
|
||||
|
||||
SOURCE += std::format(" {{ \"{}\", \"{}\", {}}},\n", rq.name, argsToShort(rq.args, rq.since), rq.args.empty() ? "dummyTypes + 0" : TYPE_TABLE_NAME + " + 0");
|
||||
}
|
||||
|
||||
SOURCE += "};\n";
|
||||
}
|
||||
|
||||
// protocol body
|
||||
if (!clientCode) {
|
||||
if (iface.events.size() > 0) {
|
||||
SOURCE += std::format(R"#(
|
||||
{}::{}(wl_client* client, uint32_t version, uint32_t id) :
|
||||
pResource(wl_resource_create(client, &{}, version, id)) {{
|
||||
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.since), 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
|
||||
SOURCE += std::format(R"#(
|
||||
{}::{}(wl_client* client, uint32_t version, uint32_t id) {{
|
||||
pResource = wl_resource_create(client, &{}, version, id);
|
||||
|
||||
if (!pResource)
|
||||
return;
|
||||
|
||||
wl_resource_set_user_data(pResource, this);
|
||||
wl_list_init(&resourceDestroyListener.listener.link);
|
||||
resourceDestroyListener.listener.notify = _{}__DestroyListener;
|
||||
resourceDestroyListener.parent = this;
|
||||
wl_resource_add_destroy_listener(pResource, &resourceDestroyListener.listener);
|
||||
wl_list_init(&resourceDestroyListener.link);
|
||||
resourceDestroyListener.notify = _{}__DestroyListener;
|
||||
wl_resource_add_destroy_listener(pResource, &resourceDestroyListener);
|
||||
|
||||
wl_resource_set_implementation(pResource, {}, this, nullptr);
|
||||
}}
|
||||
|
||||
{}::~{}() {{
|
||||
wl_list_remove(&resourceDestroyListener.listener.link);
|
||||
wl_list_init(&resourceDestroyListener.listener.link);
|
||||
wl_list_remove(&resourceDestroyListener.link);
|
||||
wl_list_init(&resourceDestroyListener.link);
|
||||
|
||||
// if we still own the wayland resource,
|
||||
// it means we need to destroy it.
|
||||
|
|
@ -902,8 +758,8 @@ const wl_interface {} = {{
|
|||
|
||||
void {}::onDestroyCalled() {{
|
||||
wl_resource_set_user_data(pResource, nullptr);
|
||||
wl_list_remove(&resourceDestroyListener.listener.link);
|
||||
wl_list_init(&resourceDestroyListener.listener.link);
|
||||
wl_list_remove(&resourceDestroyListener.link);
|
||||
wl_list_init(&resourceDestroyListener.link);
|
||||
|
||||
// set the resource to nullptr,
|
||||
// as it will be freed. If the consumer does not destroy this resource
|
||||
|
|
@ -914,40 +770,10 @@ void {}::onDestroyCalled() {{
|
|||
onDestroy(this);
|
||||
}}
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL, IFACE_NAME + "_interface", IFACE_CLASS_NAME_CAMEL, IFACE_VTABLE_NAME, IFACE_CLASS_NAME_CAMEL,
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL);
|
||||
} else {
|
||||
std::string DTOR_FUNC = "";
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL, IFACE_NAME + "_interface", IFACE_CLASS_NAME_CAMEL, IFACE_VTABLE_NAME, IFACE_CLASS_NAME_CAMEL,
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL);
|
||||
|
||||
for (auto& rq : iface.requests) {
|
||||
if (!rq.destructor)
|
||||
continue;
|
||||
|
||||
DTOR_FUNC = camelize("send_" + rq.name) + "()";
|
||||
break;
|
||||
}
|
||||
|
||||
if (DTOR_FUNC.empty())
|
||||
DTOR_FUNC = "wl_proxy_destroy(pResource)";
|
||||
|
||||
SOURCE += std::format(R"#(
|
||||
{}::{}(wl_proxy* resource) : pResource(resource) {{
|
||||
|
||||
if (!pResource)
|
||||
return;
|
||||
|
||||
wl_proxy_add_listener(pResource, (void (**)(void))&{}, this);
|
||||
}}
|
||||
|
||||
{}::~{}() {{
|
||||
if (!destroyed)
|
||||
{};
|
||||
}}
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL, IFACE_VTABLE_NAME, IFACE_CLASS_NAME_CAMEL, IFACE_CLASS_NAME_CAMEL, DTOR_FUNC);
|
||||
}
|
||||
|
||||
for (auto& rq : (clientCode ? iface.events : iface.requests)) {
|
||||
for (auto& rq : iface.requests) {
|
||||
std::string args = ", ";
|
||||
for (auto& arg : rq.args) {
|
||||
args += WPTypeToCType(arg, false) + ", ";
|
||||
|
|
@ -957,8 +783,8 @@ void {}::onDestroyCalled() {{
|
|||
args.pop_back();
|
||||
|
||||
SOURCE += std::format(R"#(
|
||||
void {}::{}(F<void({}*{})> &&handler) {{
|
||||
requests.{} = std::move(handler);
|
||||
void {}::{}(F<void({}*{})> handler) {{
|
||||
requests.{} = handler;
|
||||
}}
|
||||
)#",
|
||||
IFACE_CLASS_NAME_CAMEL, camelize("set_" + rq.name), IFACE_CLASS_NAME_CAMEL, args, camelize(rq.name));
|
||||
|
|
@ -982,16 +808,6 @@ int main(int argc, char** argv, char** envp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (curarg == "-c" || curarg == "--client") {
|
||||
clientCode = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (curarg == "--no-interfaces") {
|
||||
noInterfaces = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (curarg == "--wayland-enums") {
|
||||
waylandEnums = true;
|
||||
continue;
|
||||
|
|
@ -1077,4 +893,4 @@ int main(int argc, char** argv, char** envp) {
|
|||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue