tinywl: clean up build system, add LICENSE/README

This commit is contained in:
Isaac Freund 2020-11-03 11:24:29 +01:00
parent 928e54dd2f
commit e8f077cb98
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
10 changed files with 65 additions and 56 deletions

9
.gitmodules vendored Normal file
View file

@ -0,0 +1,9 @@
[submodule "tinywl/deps/zig-wayland"]
path = tinywl/deps/zig-wayland
url = https://github.com/ifreund/zig-wayland
[submodule "tinywl/deps/zig-xkbcommon"]
path = tinywl/deps/zig-xkbcommon
url = https://github.com/ifreund/zig-xkbcommon
[submodule "tinywl/deps/zig-pixman"]
path = tinywl/deps/zig-pixman
url = https://github.com/ifreund/zig-pixman

View file

@ -15,8 +15,15 @@ addition the following zig bindings are required:
- [zig-xkbcommon](https://github.com/ifreund/zig-xkbcommon)
- [zig-pixman](https://github.com/ifreund/zig-pixman)
## Usage
See [tinwyl.zig][./tinywl/] for an example compositor using zig-wlroots and an example
of how to integrate zig-wlroots and its dependencies into your build.zig.
See the C headers of wlroots for documentation.
## TODO
- [ ] Bind enough to port [tinwyl](https://github.com/swaywm/wlroots/tree/master/tinywl)
- [x] Bind enough to port [tinwyl](https://github.com/swaywm/wlroots/tree/master/tinywl)
- [ ] Bind enough to port [river](https://github.com/ifreund/river)
- [ ] Complete bindings

View file

@ -303,7 +303,9 @@ pub const Seat = extern struct {
pub const clientForWlClient = wlr_seat_client_for_wl_client;
extern fn wlr_seat_set_capabilities(seat: *Seat, capabilities: u32) void;
pub const setCapabilities = wlr_seat_set_capabilities;
pub inline fn setCapabilities(seat: *Seat, capabilities: wl.Seat.Capability) void {
wlr_seat_set_capabilities(seat, @bitCast(u32, capabilities));
}
extern fn wlr_seat_set_name(seat: *Seat, name: [*:0]const u8) void;
pub const setName = wlr_seat_set_name;

12
tinywl/LICENSE Normal file
View file

@ -0,0 +1,12 @@
Copyright 2020 Isaac Freund
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

16
tinywl/README.md Normal file
View file

@ -0,0 +1,16 @@
# tinywl.zig
This is an implmentation of
[tinywl](https://github.com/swaywm/wlroots/tree/master/tinywl) in zig using
zig-wlroots.
## Building
First make sure the submodules are initialized and updated with
```
git submodule update --init
```
Then simply run `zig build` to build tinywl.zig.

View file

@ -1,24 +1,19 @@
const std = @import("std");
const Builder = std.build.Builder;
const Step = std.build.Step;
const Pkg = std.build.Pkg;
pub fn build(b: *Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep;
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const scan_protocols = ScanProtocolsStep.create(b);
const scanner = ScanProtocolsStep.create(b, "deps/zig-wayland");
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
const wayland = Pkg{ .name = "wayland", .path = "../../zig-wayland/wayland.zig" };
const xkbcommon = Pkg{ .name = "xkbcommon", .path = "../../zig-xkbcommon/src/xkbcommon.zig" };
const pixman = Pkg{ .name = "pixman", .path = "../../zig-pixman/pixman.zig" };
const wayland = scanner.getPkg();
const xkbcommon = Pkg{ .name = "xkbcommon", .path = "deps/zig-xkbcommon/src/xkbcommon.zig" };
const pixman = Pkg{ .name = "pixman", .path = "deps/zig-pixman/pixman.zig" };
const wlroots = Pkg{
.name = "wlroots",
.path = "../src/wlroots.zig",
@ -33,8 +28,9 @@ pub fn build(b: *Builder) void {
exe.addPackage(wayland);
exe.linkSystemLibrary("wayland-server");
exe.step.dependOn(&scan_protocols.step);
exe.addCSourceFile("xdg_shell.c", &[_][]const u8{"-std=c99"});
exe.step.dependOn(&scanner.step);
// TODO: remove when https://github.com/ziglang/zig/issues/131 is implemented
scanner.addCSource(exe);
exe.addPackage(xkbcommon);
exe.linkSystemLibrary("xkbcommon");
@ -48,41 +44,6 @@ pub fn build(b: *Builder) void {
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
const run_step = b.step("run", "Run the compositor");
run_step.dependOn(&run_cmd.step);
}
const ScanProtocolsStep = struct {
builder: *Builder,
step: Step,
fn create(builder: *Builder) *ScanProtocolsStep {
const self = builder.allocator.create(ScanProtocolsStep) catch @panic("out of memory");
self.* = init(builder);
return self;
}
fn init(builder: *Builder) ScanProtocolsStep {
return ScanProtocolsStep{
.builder = builder,
.step = Step.init(.Custom, "Scan Protocols", builder.allocator, make),
};
}
fn make(step: *Step) !void {
const self = @fieldParentPtr(ScanProtocolsStep, "step", step);
const protocol_dir = std.fmt.trim(try self.builder.exec(
&[_][]const u8{ "pkg-config", "--variable=pkgdatadir", "wayland-protocols" },
));
const xml_path = try std.fs.path.join(self.builder.allocator, &[_][]const u8{ protocol_dir, "stable/xdg-shell/xdg-shell.xml" });
// Extension is .xml, so slice off the last 4 characters
const basename = std.fs.path.basename(xml_path);
const basename_no_ext = basename[0..(basename.len - 4)];
_ = try self.builder.exec(
&[_][]const u8{ "wayland-scanner", "private-code", xml_path, "xdg_shell.c" },
);
}
};

@ -0,0 +1 @@
Subproject commit 7847fd1bae7021cdb572e77eac93676c551fd1eb

@ -0,0 +1 @@
Subproject commit 931b6f767b5c25280df1252982322d6eb1580aca

@ -0,0 +1 @@
Subproject commit 21a9b30e9f23884e72a34643190a892925dd369c

View file

@ -232,9 +232,8 @@ const Server = struct {
else => {},
}
var caps: u32 = @enumToInt(wl.Seat.Capability.pointer);
if (server.keyboards.len > 0)
caps |= @as(u32, @enumToInt(wl.Seat.Capability.keyboard));
var caps = wl.Seat.Capability{ .pointer = true };
if (server.keyboards.len > 0) caps.keyboard = true;
server.seat.setCapabilities(caps);
}