X11 API partial cleanup

This commit is contained in:
2026-01-08 22:17:06 +01:00
parent 1e8e14ed67
commit 99f8ae059c
4 changed files with 1565 additions and 1425 deletions

1
packages/sciter/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/sciter-js-sdk

View File

@@ -71,8 +71,10 @@ pub fn build(b: *std.Build) void {
if (b.args) |args| { if (b.args) |args| {
run_cmd.addArgs(args); run_cmd.addArgs(args);
} }
// TODO It does not look like the cleanest solution, however, the build
// system code is too cryptic to come up with a better solution and the
// Internet is surprisingly silent about this very basic use case.
run_cmd.setCwd(.{ .cwd_relative = b.exe_dir }); run_cmd.setCwd(.{ .cwd_relative = b.exe_dir });
//run_cmd.setCwd(exe.getEmittedBinDirectory());
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);

View File

@@ -77,7 +77,7 @@ pub fn wWinMain(
std.posix.exit(1); std.posix.exit(1);
}; };
_ = sciter_api.SciterSetOption(0, 10, 1); _ = sciter_api.SciterSetOption(null, 10, 1);
sciter_api.SciterSetupDebugOutput(hwnd, null, &sciterDebugOutputProc); sciter_api.SciterSetupDebugOutput(hwnd, null, &sciterDebugOutputProc);
_ = sciter_api.SciterLoadHtml(hwnd, html, html.len, L("/")); _ = sciter_api.SciterLoadHtml(hwnd, html, html.len, L("/"));
_ = wam.ShowWindow(hwnd, @bitCast(nCmdShow)); _ = wam.ShowWindow(hwnd, @bitCast(nCmdShow));
@@ -140,53 +140,62 @@ pub fn main() void {
std.debug.print("Sciter API version is: 0x{X:0>8}\n", .{sciter_api.version}); std.debug.print("Sciter API version is: 0x{X:0>8}\n", .{sciter_api.version});
const display = x11.XOpenDisplay(null) orelse { const display = x11.Display.openDisplay(null) orelse {
_ = std.posix.write(std.posix.STDERR_FILENO, "Couldn't open connection to X server.\n") catch {}; _ = std.posix.write(std.posix.STDERR_FILENO, "Couldn't open connection to X server.\n") catch {};
std.posix.exit(1); std.posix.exit(1);
}; };
defer _ = x11.XCloseDisplay(display); defer _ = display.closeDisplay();
const window = x11.XCreateSimpleWindow( const screen = display.defaultScreen();
display,
x11.DefaultRootWindow(display), var attributes: x11.XSetWindowAttributes = .{
.background_pixel = display.blackPixel(screen),
.event_mask = .{
.exposure = true,
.key_press = true,
},
};
const window = display.createWindow(
display.rootWindow(screen),
0, 0,
0, 0,
720, 720,
480, 480,
0, 0,
x11.BlackPixel(display, x11.DefaultScreen(display)), display.defaultDepth(screen),
x11.BlackPixel(display, x11.DefaultScreen(display)), x11.InputOutput,
display.defaultVisual(screen),
.{
.background_pixel = true,
.event_mask = true,
},
&attributes,
); );
defer _ = x11.XDestroyWindow(display, window); defer _ = display.destroyWindow(window);
const event_mask = x11.KeyPressMask | _ = display.storeName(window, "Sciter Demo");
x11.KeyReleaseMask |
x11.ButtonPressMask |
x11.ButtonReleaseMask |
x11.EnterWindowMask |
x11.LeaveWindowMask |
x11.PointerMotionMask;
_ = x11.XSelectInput(display, window, event_mask);
_ = x11.XStoreName(display, window, "Sciter Demo"); const gc = display.createGC(@enumFromInt(@intFromEnum(window)), .{}, null);
_ = display.freeGC(gc);
const wm_delete_window = x11.XInternAtom(display, "WM_DELETE_WINDOW", x11.False); const wm_delete_window = display.internAtom("WM_DELETE_WINDOW", false);
_ = x11.XSetWMProtocols(display, window, @constCast(&wm_delete_window), 1); var protocols = [_]x11.Atom{wm_delete_window};
_ = display.setWMProtocols(window, &protocols);
_ = x11.XMapWindow(display, window); _ = display.mapWindow(window);
defer _ = x11.XUnmapWindow(display, window); defer _ = display.unmapWindow(window);
_ = sciter_api.SciterSetOption(0, 10, 1); _ = sciter_api.SciterSetOption(.null_handle, 10, 1);
sciter_api.SciterSetupDebugOutput(window, null, &sciterDebugOutputProc); sciter_api.SciterSetupDebugOutput(window, null, &sciterDebugOutputProc);
_ = sciter_api.SciterLoadHtml(window, html, html.len, L("/")); _ = sciter_api.SciterLoadHtml(window, html, html.len, L("/"));
var event: x11.XEvent = undefined;
var running = true; var running = true;
while (running) { while (running) {
_ = x11.XNextEvent(display, &event); const event = display.nextEvent();
switch (event.type) { switch (event.type) {
x11.ClientMessage => { x11.ClientMessage => {
const atom: x11.Atom = @bitCast(event.xclient.data.l[0]); const atom: x11.Atom = @enumFromInt(event.xclient.data.l[0]);
if (atom == wm_delete_window) { if (atom == wm_delete_window) {
running = false; running = false;
} }

File diff suppressed because it is too large Load Diff