Cleanup extensions

This commit is contained in:
Oskari Alaranta 2026-02-12 02:38:08 +02:00
parent 6124525439
commit 24baab2e84
8 changed files with 66 additions and 49 deletions

View File

@ -3073,6 +3073,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
continue;
reply.present = xTrue;
reply.major_opcode = extension.major_opcode;
reply.first_event = extension.event_base;
reply.first_error = extension.error_base;
break;
}

View File

@ -2,6 +2,7 @@ set(SOURCES
main.cpp
Base.cpp
Extensions.cpp
ExtBigReg.cpp
ExtRANDR.cpp
Keymap.cpp
)

41
xbanan/ExtBigReg.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "Extensions.h"
#include "Utils.h"
#include <X11/X.h>
#include <X11/extensions/bigreqsproto.h>
BAN::ErrorOr<void> extension_bigrequests(Client& client_info, BAN::ConstByteSpan packet)
{
switch (packet[1])
{
case X_BigReqEnable:
{
xGenericReply reply {
.type = X_Reply,
.sequenceNumber = client_info.sequence,
.length = 0,
.data00 = (16 << 20) / 4, // 16 MiB
};
TRY(encode(client_info.output_buffer, reply));
client_info.has_bigrequests = true;
dprintln("client enabled big requests");
break;
}
default:
dwarnln("invalid BIG-REQUESTS minor opcode {}", packet[1]);
return BAN::Error::from_errno(EINVAL);
}
return {};
}
static struct BigRegInstaller
{
BigRegInstaller()
{
install_extension(XBigReqExtensionName, XBigReqNumberEvents, XBigReqNumberErrors, extension_bigrequests);
}
} installer;

View File

@ -1,5 +1,4 @@
#include "Extensions.h"
#include "ExtRANDR.h"
#include "Utils.h"
#include <X11/X.h>
@ -7,15 +6,7 @@
#include <time.h>
static struct RANDRInstaller
{
RANDRInstaller()
{
install_extension(RANDR_NAME, extension_randr);
}
} installer;
BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpan packet)
static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpan packet)
{
static CARD32 crtc_id = 5;
static CARD32 output_id = 6;
@ -479,3 +470,11 @@ BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpan packe
return {};
}
static struct RANDRInstaller
{
RANDRInstaller()
{
install_extension(RANDR_NAME, RRNumberEvents, RRNumberErrors, extension_randr);
}
} installer;

View File

@ -1,5 +0,0 @@
#pragma once
#include "Definitions.h"
BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpan packet);

View File

@ -1,14 +1,23 @@
#include "Extensions.h"
#include <X11/X.h>
static uint8_t g_extension_opcode { 128 };
static uint8_t g_extension_event_base { LASTEvent };
static uint8_t g_extension_error_base { FirstExtensionError };
BAN::Array<Extension, 128> g_extensions;
void install_extension(BAN::StringView name, BAN::ErrorOr<void> (*handler)(Client&, BAN::ConstByteSpan))
void install_extension(BAN::StringView name, uint8_t event_count, uint8_t error_count, BAN::ErrorOr<void> (*handler)(Client&, BAN::ConstByteSpan))
{
g_extensions[g_extension_opcode - 128] = {
.name = name,
.major_opcode = g_extension_opcode,
.event_base = g_extension_event_base,
.error_base = g_extension_error_base,
.handler = handler,
};
g_extension_opcode++;
g_extension_event_base += event_count;
g_extension_error_base += error_count;
}

View File

@ -8,10 +8,11 @@ struct Extension
{
BAN::StringView name;
uint8_t major_opcode;
uint8_t opcode_count;
uint8_t event_base;
uint8_t error_base;
BAN::ErrorOr<void> (*handler)(Client&, BAN::ConstByteSpan);
};
void install_extension(BAN::StringView name, BAN::ErrorOr<void> (*handler)(Client&, BAN::ConstByteSpan));
void install_extension(BAN::StringView name, uint8_t event_count, uint8_t error_count, BAN::ErrorOr<void> (*handler)(Client&, BAN::ConstByteSpan));
extern BAN::Array<Extension, 128> g_extensions;

View File

@ -1,6 +1,5 @@
#include "Base.h"
#include "Definitions.h"
#include "Extensions.h"
#include "Keymap.h"
#include "Utils.h"
@ -95,34 +94,6 @@ ATOM g_atom_value = XA_LAST_PREDEFINED + 1;
int g_epoll_fd;
BAN::HashMap<int, EpollThingy> g_epoll_thingies;
BAN::ErrorOr<void> extension_bigrequests(Client& client_info, BAN::ConstByteSpan packet)
{
switch (packet[1])
{
case 0:
{
xGenericReply reply {
.type = X_Reply,
.sequenceNumber = client_info.sequence,
.length = 0,
.data00 = (16 << 20) / 4, // 16 MiB
};
TRY(encode(client_info.output_buffer, reply));
client_info.has_bigrequests = true;
dprintln("client enabled big requests");
break;
}
default:
dwarnln("invalid BIG-REQUESTS minor opcode {}", packet[1]);
return BAN::Error::from_errno(EINVAL);
}
return {};
}
int main()
{
for (int sig = 1; sig < NSIG; sig++)
@ -269,8 +240,6 @@ int main()
MUST(initialize_keymap());
install_extension("BIG-REQUESTS"_sv, extension_bigrequests);
printf("xbanan started\n");
const auto close_client =