commit e99d13ae697dbf43287789b6c4eaf3442428c3ea
parent d7a9eda640d4b4d96f6158266099d3c3fe8e5673
Author: sewn <sewn@disroot.org>
Date: Sun, 1 Mar 2026 03:41:13 +0300
switch to meson
convert_font: print debugging lines on debug mode only
example: fix API usage
evdev: assume devices are always set
Diffstat:
19 files changed, 252 insertions(+), 634 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,323 +0,0 @@
-# bmake-compatible build for swc (avoids GNU make-specific functions/macros).
-
-.include "config.mk"
-
-.MAIN: build
-
-.if !defined(PREFIX)
-PREFIX=/usr/local
-.endif
-.if !defined(BINDIR)
-BINDIR=${PREFIX}/bin
-.endif
-.if !defined(LIBDIR)
-LIBDIR=${PREFIX}/lib
-.endif
-.if !defined(INCLUDEDIR)
-INCLUDEDIR=${PREFIX}/include
-.endif
-.if !defined(DATADIR)
-DATADIR=${PREFIX}/share
-.endif
-.if !defined(PKGCONFIGDIR)
-PKGCONFIGDIR=${LIBDIR}/pkgconfig
-.endif
-
-.if !defined(OBJCOPY)
-OBJCOPY=objcopy
-.endif
-.if !defined(PKG_CONFIG)
-PKG_CONFIG=pkg-config
-.endif
-.if !defined(WAYLAND_SCANNER)
-WAYLAND_SCANNER=wayland-scanner
-.endif
-.if !defined(CC)
-CC=cc
-.endif
-.if !defined(AR)
-AR=ar
-.endif
-
-UNAME!= uname
-
-.if !defined(INPUT_BACKEND)
-. if ${UNAME} == "NetBSD"
-INPUT_BACKEND=wscons
-. else
-INPUT_BACKEND=libinput
-. endif
-.endif
-
-VERSION_MAJOR=0
-VERSION_MINOR=0
-VERSION=${VERSION_MAJOR}.${VERSION_MINOR}
-
-PACKAGES=libdrm pixman-1 wayland-server wayland-protocols wld xkbcommon
-
-.if ${INPUT_BACKEND} == "libinput"
-PACKAGES+= libinput
-.if defined(ENABLE_LIBUDEV) && ${ENABLE_LIBUDEV} == 1
-PACKAGES+= libudev
-.endif
-.endif
-
-.if defined(ENABLE_XWAYLAND) && ${ENABLE_XWAYLAND} == 1
-PACKAGES+= xcb xcb-composite xcb-ewmh xcb-icccm
-.endif
-
-PKG_CFLAGS!= ${PKG_CONFIG} --cflags ${PACKAGES}
-PKG_LIBS!= ${PKG_CONFIG} --libs ${PACKAGES}
-WAYLAND_CLIENT_CFLAGS!= ${PKG_CONFIG} --cflags wayland-client
-WAYLAND_CLIENT_LIBS!= ${PKG_CONFIG} --libs wayland-client
-WAYLAND_PROTOCOLS_DATADIR!= ${PKG_CONFIG} --variable=pkgdatadir wayland-protocols
-
-CPPFLAGS+= -D_GNU_SOURCE
-CFLAGS+= -fvisibility=hidden -std=c11 ${PKG_CFLAGS}
-CFLAGS+= -Werror=implicit-function-declaration -Werror=implicit-int -Werror=pointer-sign -Werror=pointer-arith -Wall -Wno-missing-braces
-
-.if defined(ENABLE_DEBUG) && ${ENABLE_DEBUG} == 1
-CPPFLAGS+= -DENABLE_DEBUG=1
-CFLAGS+= -g
-.endif
-
-.if defined(ENABLE_LIBUDEV) && ${ENABLE_LIBUDEV} == 1
-CPPFLAGS+= -DENABLE_LIBUDEV
-.endif
-.if defined(ENABLE_XWAYLAND) && ${ENABLE_XWAYLAND} == 1
-CPPFLAGS+= -DENABLE_XWAYLAND
-.endif
-
-.if defined(EVDEV_KBD_DEVICE)
-CPPFLAGS+= -DEVDEV_KBD_DEVICE=\\\"${EVDEV_KBD_DEVICE}\\\"
-.endif
-.if defined(EVDEV_POINTER_DEVICE)
-CPPFLAGS+= -DEVDEV_POINTER_DEVICE=\\\"${EVDEV_POINTER_DEVICE}\\\"
-.endif
-
-PROTO_EXTENSIONS= \
- protocol/server-decoration.xml \
- protocol/swc.xml \
- protocol/swc_snap.xml \
- protocol/swc_select.xml \
- protocol/swc_wallpaper.xml \
- protocol/wayland-drm.xml \
- ${WAYLAND_PROTOCOLS_DATADIR}/stable/xdg-shell/xdg-shell.xml \
- ${WAYLAND_PROTOCOLS_DATADIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml \
- ${WAYLAND_PROTOCOLS_DATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml
-
-.for xml in ${PROTO_EXTENSIONS}
-_base=${xml:T:R}
-protocol/${_base}-protocol.c: ${xml} \
- protocol/${_base}-server-protocol.h \
- protocol/${_base}-client-protocol.h
- @echo " GEN $@"
- @${WAYLAND_SCANNER} code ${xml} ${.TARGET}
-
-protocol/${_base}-server-protocol.h: ${xml}
- @echo " GEN $@"
- @${WAYLAND_SCANNER} server-header ${xml} ${.TARGET}
-
-protocol/${_base}-client-protocol.h: ${xml}
- @echo " GEN $@"
- @${WAYLAND_SCANNER} client-header ${xml} ${.TARGET}
-.endfor
-
-PROTO_GEN_C= \
- protocol/linux-dmabuf-unstable-v1-protocol.c \
- protocol/server-decoration-protocol.c \
- protocol/swc-protocol.c \
- protocol/swc_snap-protocol.c \
- protocol/swc_select-protocol.c \
- protocol/swc_wallpaper-protocol.c \
- protocol/wayland-drm-protocol.c \
- protocol/xdg-decoration-unstable-v1-protocol.c \
- protocol/xdg-shell-protocol.c
-
-PROTO_GEN_H= \
- protocol/linux-dmabuf-unstable-v1-server-protocol.h \
- protocol/linux-dmabuf-unstable-v1-client-protocol.h \
- protocol/server-decoration-server-protocol.h \
- protocol/server-decoration-client-protocol.h \
- protocol/swc-server-protocol.h \
- protocol/swc-client-protocol.h \
- protocol/swc_snap-server-protocol.h \
- protocol/swc_snap-client-protocol.h \
- protocol/swc_select-server-protocol.h \
- protocol/swc_select-client-protocol.h \
- protocol/swc_wallpaper-server-protocol.h \
- protocol/swc_wallpaper-client-protocol.h \
- protocol/wayland-drm-server-protocol.h \
- protocol/wayland-drm-client-protocol.h \
- protocol/xdg-decoration-unstable-v1-server-protocol.h \
- protocol/xdg-decoration-unstable-v1-client-protocol.h \
- protocol/xdg-shell-server-protocol.h \
- protocol/xdg-shell-client-protocol.h
-
-cursor/cursor_data.h: cursor/cursor.pcf cursor/convert_font
- @echo " GEN $@"
- @cursor/convert_font cursor/cursor.pcf ${.TARGET} 2>/dev/null
-
-cursor/convert_font: cursor/convert_font.o
- @echo " CCLD $@"
- @${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
-
-cursor/convert_font.o: cursor/convert_font.c
- @echo " CC $@"
- @${CC} ${CPPFLAGS} ${CFLAGS} -I . -c -o ${.TARGET} ${.ALLSRC}
-
-LAUNCH_DEVMAJOR=launch/devmajor-linux.c
-.if ${UNAME} == "NetBSD"
-LAUNCH_DEVMAJOR=launch/devmajor-netbsd.c
-.elif ${UNAME} == "OpenBSD"
-LAUNCH_DEVMAJOR=launch/devmajor-openbsd.c
-.endif
-
-launch/swc-launch: launch/launch.o launch/protocol.o launch/${LAUNCH_DEVMAJOR:T:R}.o
- @echo " CCLD $@"
- @${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} ${PKG_LIBS}
-
-.for f in launch/launch.c launch/protocol.c ${LAUNCH_DEVMAJOR}
-launch/${f:T:R}.o: ${f}
- @echo " CC $@"
- @${CC} ${CPPFLAGS} ${CFLAGS} -I . -c -o ${.TARGET} ${.ALLSRC}
-.endfor
-
-SWC_SOURCES= \
- libswc/bindings.c \
- libswc/compositor.c \
- libswc/data.c \
- libswc/data_device.c \
- libswc/data_device_manager.c \
- libswc/dmabuf.c \
- libswc/drm.c \
- libswc/input.c \
- libswc/kde_decoration.c \
- libswc/keyboard.c \
- libswc/launch.c \
- libswc/mode.c \
- libswc/output.c \
- libswc/panel.c \
- libswc/panel_manager.c \
- libswc/plane.c \
- libswc/pointer.c \
- libswc/primary_plane.c \
- libswc/region.c \
- libswc/screen.c \
- libswc/shell.c \
- libswc/shell_surface.c \
- libswc/shm.c \
- libswc/snap.c \
- libswc/subcompositor.c \
- libswc/subsurface.c \
- libswc/surface.c \
- libswc/select.c \
- libswc/swc.c \
- libswc/util.c \
- libswc/view.c \
- libswc/wallpaper.c \
- libswc/wayland_buffer.c \
- libswc/window.c \
- libswc/xdg_decoration.c \
- libswc/xdg_shell.c \
- protocol/linux-dmabuf-unstable-v1-protocol.c \
- protocol/server-decoration-protocol.c \
- protocol/swc-protocol.c \
- protocol/swc_snap-protocol.c \
- protocol/swc_select-protocol.c \
- protocol/swc_wallpaper-protocol.c \
- protocol/wayland-drm-protocol.c \
- protocol/xdg-decoration-unstable-v1-protocol.c \
- protocol/xdg-shell-protocol.c
-
-.if ${INPUT_BACKEND} == "wscons"
-SWC_SOURCES+= libswc/seat-ws.c
-.elif ${INPUT_BACKEND} == "evdev"
-SWC_SOURCES+= libswc/seat-evdev.c
-.elif ${INPUT_BACKEND} == "libinput"
-SWC_SOURCES+= libswc/seat.c
-.else
-.error Unknown INPUT_BACKEND '${INPUT_BACKEND}'. Use libinput, evdev, or wscons.
-.endif
-
-.if defined(ENABLE_XWAYLAND) && ${ENABLE_XWAYLAND} == 1
-SWC_SOURCES+= libswc/xserver.c libswc/xwm.c
-.endif
-
-SWC_OBJECTS=${SWC_SOURCES:S/.c/.o/}
-SWC_OBJECTS+= launch/protocol.o
-
-.for src in ${SWC_SOURCES}
-${src:R}.o: ${src} ${PROTO_GEN_H} cursor/cursor_data.h
- @echo " CC $@"
- @${CC} ${CPPFLAGS} ${CFLAGS} -I . -I protocol -c -o ${.TARGET} ${.IMPSRC}
-.endfor
-
-libswc/libswc-internal.o: ${SWC_OBJECTS}
- @echo " CCLD $@"
- @${CC} -nostdlib -r -o ${.TARGET} ${.ALLSRC}
-
-libswc/libswc.o: libswc/libswc-internal.o
- @echo " OBJCOPY $@"
-.if ${UNAME} == "OpenBSD"
- @cp ${.ALLSRC} ${.TARGET}
-.else
- @${OBJCOPY} --localize-hidden ${.ALLSRC} ${.TARGET}
-.endif
-
-libswc/libswc.a: libswc/libswc.o
- @echo " AR $@"
- @${AR} cru ${.TARGET} ${.ALLSRC}
-
-EXTRA_CAPTURE_TOOLS= \
- extra/swcsnap
-
-.for ex in ${EXTRA_CAPTURE_TOOLS}
-${ex:R}.o: ${ex}.c protocol/swc_snap-client-protocol.h
- @echo " CC $@"
- @${CC} ${CPPFLAGS} ${CFLAGS} ${WAYLAND_CLIENT_CFLAGS} -I . -I protocol \
- -c -o ${.TARGET} ${.IMPSRC}
-.endfor
-
-extra/swcsnap: extra/swcsnap.o protocol/swc_snap-protocol.o
- @echo " CCLD $@"
- @${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} ${WAYLAND_CLIENT_LIBS}
-
-swc.pc: swc.pc.in
- @echo " GEN $@"
- @sed -e 's:@VERSION@:${VERSION}:' \
- -e 's:@PREFIX@:${PREFIX}:' \
- -e 's:@LIBDIR@:${LIBDIR}:' \
- -e 's:@INCLUDEDIR@:${INCLUDEDIR}:' \
- -e 's:@DATADIR@:${DATADIR}:' \
- -e 's:@REQUIRES@:wayland-server:' \
- -e 's:@REQUIRES_PRIVATE@::' \
- ${.ALLSRC} > ${.TARGET}
-
-.PHONY: all build clean install
-all: build
-build: libswc/libswc.a launch/swc-launch cursor/cursor_data.h swc.pc
-build: ${EXTRA_CAPTURE_TOOLS}
-
-install: build
- install -d ${DESTDIR}${BINDIR}
- install -d ${DESTDIR}${LIBDIR}
- install -d ${DESTDIR}${INCLUDEDIR}
- install -d ${DESTDIR}${DATADIR}/swc
- install -d ${DESTDIR}${PKGCONFIGDIR}
- install -m 4755 launch/swc-launch ${DESTDIR}${BINDIR}/
- install -m 755 extra/swcsnap ${DESTDIR}${BINDIR}/
- install -m 644 libswc/libswc.a ${DESTDIR}${LIBDIR}/
- install -m 644 libswc/swc.h ${DESTDIR}${INCLUDEDIR}/
- install -m 644 ${PROTO_GEN_H} ${DESTDIR}${INCLUDEDIR}/
- install -m 644 protocol/swc.xml protocol/swc_snap.xml protocol/swc_wallpaper.xml ${DESTDIR}${DATADIR}/swc/
- install -m 644 swc.pc ${DESTDIR}${PKGCONFIGDIR}/
-
-clean:
- rm -f swc.pc \
- ${PROTO_GEN_C} ${PROTO_GEN_H} \
- cursor/cursor_data.h cursor/convert_font cursor/convert_font.o \
- launch/*.o launch/swc-launch \
- libswc/*.o libswc/libswc-internal.o libswc/libswc.o libswc/libswc.a \
- protocol/*.o \
- extra/swcsnap.o extra/swcsnap
diff --git a/common.mk b/common.mk
@@ -1,28 +0,0 @@
-# swc: common.mk
-
-.PHONY: build-$(dir)
-build-$(dir): $($(dir)_TARGETS)
-
-.PHONY: install-$(dir)
-install-$(dir):
-
-.deps/$(dir):
- @mkdir -p "$@"
-
-$(dir)/%: dir := $(dir)
-
-$(dir)/%.o: $(dir)/%.c | .deps/$(dir)
- $(compile) $($(dir)_CFLAGS) $($(dir)_PACKAGE_CFLAGS)
-
-$(dir)/%.lo: $(dir)/%.c | .deps/$(dir)
- $(compile) -fPIC $($(dir)_CFLAGS) $($(dir)_PACKAGE_CFLAGS)
-
-ifeq ($(origin $(dir)_PACKAGE_CFLAGS),undefined)
- $(dir)_PACKAGE_CFLAGS := $(call pkgconfig,$($(dir)_PACKAGES),cflags,CFLAGS)
-endif
-ifeq ($(origin $(dir)_PACKAGE_LIBS),undefined)
- $(dir)_PACKAGE_LIBS := $(call pkgconfig,$($(dir)_PACKAGES),libs,LIBS)
-endif
-
-CLEAN_FILES += $($(dir)_TARGETS)
-
diff --git a/config.mk b/config.mk
@@ -1,24 +0,0 @@
-# swc: config.mk
-
-# The commented out options are defaults
-
-PREFIX = /usr
-# BINDIR = $(PREFIX)/bin
-# LIBDIR = $(PREFIX)/lib
-# INCLUDEDIR = $(PREFIX)/include
-# DATADIR = $(PREFIX)/share
-# PKGCONFIGDIR = $(LIBDIR)/pkgconfig
-
-# OBJCOPY = objcopy
-# PKG_CONFIG = pkg-config
-# WAYLAND_SCANNER = wayland-scanner
-
-ENABLE_DEBUG = 1
-ENABLE_STATIC = 1
-ENABLE_SHARED = 0
-ENABLE_LIBUDEV = 1
-ENABLE_XWAYLAND = 1
-
-#INPUT_BACKEND = libinput
-# available: libinput, evdev, wscons
-# default: libinput on linux, wscons on NetBSD
diff --git a/cursor/convert_font.c b/cursor/convert_font.c
@@ -129,7 +129,9 @@ struct bitmaps {
static void
handle_compressed_metrics(int32_t count, struct compressed_metrics *m)
{
+#if ENABLE_DEBUG
fprintf(stderr, "metrics count: %d\n", count);
+#endif
extracted_font.count = count;
extracted_font.glyphs = calloc(count, sizeof(struct glyph));
@@ -154,15 +156,21 @@ static void
handle_metrics(void *metricbuf)
{
struct metrics *metrics = metricbuf;
+#if ENABLE_DEBUG
fprintf(stderr, "metric format: %x\n", metrics->format);
+#endif
if ((metrics->format & PCF_FORMAT_MASK) == PCF_DEFAULT_FORMAT) {
+#if ENABLE_DEBUG
fprintf(stderr, "todo...\n");
+#endif
} else if ((metrics->format & PCF_FORMAT_MASK) == PCF_COMPRESSED_METRICS) {
handle_compressed_metrics(metrics->compressed.count,
&metrics->compressed.compressed_metrics[0]);
} else {
+#if ENABLE_DEBUG
fprintf(stderr, "incompatible format\n");
+#endif
abort();
}
}
@@ -170,13 +178,17 @@ handle_metrics(void *metricbuf)
static void
handle_glyph_names(struct glyph_names *names)
{
+#if ENABLE_DEBUG
fprintf(stderr, "glyph count %d\n", names->glyph_count);
+#endif
if (names->glyph_count != extracted_font.count) {
abort();
}
+#if ENABLE_DEBUG
fprintf(stderr, "glyph names format %x\n", names->format);
+#endif
char *names_start = ((char *)names) + sizeof(struct glyph_names) +
(names->glyph_count + 1) * sizeof(int32_t);
@@ -194,16 +206,21 @@ handle_glyph_names(struct glyph_names *names)
static void
handle_bitmaps(struct bitmaps *bitmaps)
{
+#if ENABLE_DEBUG
fprintf(stderr, "bitmaps count %d\n", bitmaps->glyph_count);
+#endif
if (bitmaps->glyph_count != extracted_font.count) {
abort();
}
-
+#if ENABLE_DEBUG
fprintf(stderr, "format %x\n", bitmaps->format);
+#endif
if (bitmaps->format != 2) {
+#if ENABLE_DEBUG
fprintf(stderr, "format not yet supported\n");
+#endif
abort();
}
@@ -223,11 +240,15 @@ static void
handle_pcf(void *fontbuf)
{
struct pcf_header *header = fontbuf;
+#if ENABLE_DEBUG
fprintf(stderr, "tablecount %d\n", header->table_count);
+#endif
for (unsigned i = 0; i < header->table_count; ++i) {
struct toc_entry *entry = &header->tables[i];
+#if ENABLE_DEBUG
fprintf(stderr, "type: %d\n", entry->type);
+#endif
if (entry->type == PCF_METRICS) {
handle_metrics((void *)((uintptr_t)fontbuf + entry->offset));
} else if (entry->type == PCF_GLYPH_NAMES) {
@@ -472,13 +493,17 @@ output_interesting_cursors(FILE *file)
find_cursor_and_mask(interesting_cursors[i].source_name, &cursor,
&mask);
if (!cursor) {
+#if ENABLE_DEBUG
fprintf(stderr, "no cursor for %s\n",
interesting_cursors[i].source_name);
+#endif
abort();
}
if (!mask) {
+#if ENABLE_DEBUG
fprintf(stderr, "no mask for %s\n",
interesting_cursors[i].source_name);
+#endif
abort();
}
reconstruct_glyph(cursor, mask, interesting_cursors[i].target_name,
@@ -492,7 +517,9 @@ int
main(int argc, char *argv[])
{
if (argc != 3) {
+#if ENABLE_DEBUG
fprintf(stderr, "Usage: %s input.pcf output.h\n", argv[0]);
+#endif
return EXIT_FAILURE;
}
diff --git a/cursor/local.mk b/cursor/local.mk
@@ -1,15 +0,0 @@
-# swc: cursor/local.mk
-
-dir := cursor
-
-$(dir)_TARGETS := $(dir)/convert_font $(dir)/cursor_data.h
-
-$(dir)/convert_font: $(dir)/convert_font.o
- $(link)
-
-$(dir)/cursor_data.h: $(dir)/cursor.pcf $(dir)/convert_font
- $(Q_GEN)cursor/convert_font $< $@ 2>/dev/null
-
-CLEAN_FILES += $(dir)/convert_font.o
-
-include common.mk
diff --git a/cursor/meson.build b/cursor/meson.build
@@ -0,0 +1,7 @@
+tool = executable('convert_cont', 'convert_font.c')
+
+cursor = custom_target('cursor_data_h',
+ input: 'cursor.pcf',
+ output: 'cursor_data.h',
+ command: [tool, '@INPUT@', '@OUTPUT@']
+)
diff --git a/example/local.mk b/example/local.mk
@@ -1,16 +0,0 @@
-# swc: example/local.mk
-
-dir := example
-
-$(dir)_PACKAGES = wayland-server xkbcommon
-$(dir)_CFLAGS = -Ilibswc
-
-$(dir): $(dir)/wm
-
-$(dir)/wm: $(dir)/wm.o libswc/libswc.a
- $(link) $(example_PACKAGE_LIBS) $(libswc_PACKAGE_LIBS) -lm
-
-CLEAN_FILES += $(dir)/wm.o $(dir)/wm
-
-include common.mk
-
diff --git a/example/meson.build b/example/meson.build
@@ -0,0 +1,4 @@
+executable('wm',
+ 'wm.c',
+ dependencies: libswc,
+)
diff --git a/example/wm.c b/example/wm.c
@@ -115,11 +115,11 @@ focus(struct window *window)
{
if (focused_window) {
swc_window_set_border(focused_window->swc, border_color_normal,
- border_width);
+ border_width, 0, 0);
}
if (window) {
- swc_window_set_border(window->swc, border_color_active, border_width);
+ swc_window_set_border(window->swc, border_color_active, border_width, 0, 0);
swc_window_focus(window->swc);
} else {
swc_window_focus(NULL);
diff --git a/extra/meson.build b/extra/meson.build
@@ -0,0 +1,5 @@
+executable('swcsnap',
+ ['swcsnap.c', protos.get('swc_snap') ],
+ dependencies: libswc,
+ install: true,
+)
diff --git a/launch/local.mk b/launch/local.mk
@@ -1,24 +0,0 @@
-# swc: launch/local.mk
-
-dir := launch
-
-$(dir)_TARGETS := $(dir)/swc-launch
-$(dir)_PACKAGES := libdrm
-
-ifeq ($(shell uname),NetBSD)
- DEVMAJOR_OBJ=devmajor-netbsd.o
-else
- DEVMAJOR_OBJ=devmajor-linux.o
-endif
-
-$(dir)/swc-launch: $(dir)/$(DEVMAJOR_OBJ) $(dir)/launch.o $(dir)/protocol.o
- $(link) $(launch_PACKAGE_LIBS)
-
-install-$(dir): $(dir)/swc-launch | $(DESTDIR)$(BINDIR)
- install -m 4755 launch/swc-launch $(DESTDIR)$(BINDIR)
-
-CLEAN_FILES += $(dir)/launch.o
-CLEAN_FILES += $(dir)/$(DEVMAJOR_OBJ)
-
-include common.mk
-
diff --git a/launch/meson.build b/launch/meson.build
@@ -0,0 +1,7 @@
+launch_protocol = files('protocol.c')
+executable('swc-launch',
+ ['launch.c', launch_protocol, 'devmajor-@0@.c'.format(os)],
+ dependencies: requires_private[0], # libdrm
+ install: true,
+ install_mode: 'rwsr-xr-x',
+)
diff --git a/libswc/local.mk b/libswc/local.mk
@@ -1,157 +0,0 @@
-# swc: libswc/local.mk
-
-dir := libswc
-
-LIBSWC_LINK := libswc.so
-LIBSWC_SO := $(LIBSWC_LINK).$(VERSION_MAJOR)
-LIBSWC_LIB := $(LIBSWC_SO).$(VERSION_MINOR)
-
-ifneq ($(ENABLE_STATIC), 0)
-$(dir)_TARGETS += $(dir)/libswc.a
-endif
-
-ifneq ($(ENABLE_SHARED), 0)
-$(dir)_TARGETS += \
- $(dir)/$(LIBSWC_LIB) \
- $(dir)/$(LIBSWC_SO) \
- $(dir)/$(LIBSWC_LINK)
-endif
-
-$(dir)_PACKAGES := libdrm pixman-1 wayland-server wld xkbcommon
-$(dir)_CFLAGS += -Iprotocol
-
-SWC_SOURCES = \
- launch/protocol.c \
- libswc/bindings.c \
- libswc/compositor.c \
- libswc/data.c \
- libswc/data_device.c \
- libswc/data_device_manager.c \
- libswc/dmabuf.c \
- libswc/drm.c \
- libswc/input.c \
- libswc/kde_decoration.c \
- libswc/keyboard.c \
- libswc/launch.c \
- libswc/mode.c \
- libswc/output.c \
- libswc/panel.c \
- libswc/panel_manager.c \
- libswc/plane.c \
- libswc/pointer.c \
- libswc/primary_plane.c \
- libswc/region.c \
- libswc/screen.c \
- libswc/shell.c \
- libswc/shell_surface.c \
- libswc/shm.c \
- libswc/snap.c \
- libswc/subcompositor.c \
- libswc/subsurface.c \
- libswc/surface.c \
- libswc/swc.c \
- libswc/util.c \
- libswc/view.c \
- libswc/wallpaper.c \
- libswc/wayland_buffer.c \
- libswc/window.c \
- libswc/xdg_decoration.c \
- libswc/xdg_shell.c \
- protocol/linux-dmabuf-unstable-v1-protocol.c \
- protocol/server-decoration-protocol.c \
- protocol/swc-protocol.c \
- protocol/swc_snap-protocol.c \
- protocol/swc_wallpaper-protocol.c \
- protocol/wayland-drm-protocol.c \
- protocol/xdg-decoration-unstable-v1-protocol.c \
- protocol/xdg-shell-protocol.c
-
-ifeq ($(strip $(INPUT_BACKEND)),)
- ifeq ($(shell uname),NetBSD)
- INPUT_BACKEND = wscons
- else
- INPUT_BACKEND = libinput
- endif
-endif
-
-ifeq ($(INPUT_BACKEND),wscons)
- SWC_SOURCES += libswc/seat-ws.c
-else ifeq ($(INPUT_BACKEND),evdev)
- SWC_SOURCES += libswc/seat-evdev.c
- ifneq ($(EVDEV_KBD_DEVICE),)
- $(dir)_CFLAGS += -DEVDEV_KBD_DEVICE=\"$(EVDEV_KBD_DEVICE)\"
- endif
- ifneq ($(EVDEV_POINTER_DEVICE),)
- $(dir)_CFLAGS += -DEVDEV_POINTER_DEVICE=\"$(EVDEV_POINTER_DEVICE)\"
- endif
-else ifeq ($(INPUT_BACKEND),libinput)
- SWC_SOURCES += libswc/seat.c
- $(dir)_PACKAGES += libinput
- ifeq ($(ENABLE_LIBUDEV),1)
- $(dir)_CFLAGS += -DENABLE_LIBUDEV
- $(dir)_PACKAGES += libudev
- endif
-else
- $(error Unknown INPUT_BACKEND '$(INPUT_BACKEND)'. Use libinput, evdev, or wscons.)
-endif
-
-ifeq ($(ENABLE_XWAYLAND),1)
-$(dir)_CFLAGS += -DENABLE_XWAYLAND
-$(dir)_PACKAGES += xcb xcb-composite xcb-ewmh xcb-icccm
-
-SWC_SOURCES += \
- libswc/xserver.c \
- libswc/xwm.c
-endif
-
-SWC_STATIC_OBJECTS = $(SWC_SOURCES:%.c=%.o)
-SWC_SHARED_OBJECTS = $(SWC_SOURCES:%.c=%.lo)
-
-# Explicitly state dependencies on generated files
-objects = $(foreach obj,$(1),$(dir)/$(obj).o $(dir)/$(obj).lo)
-$(call objects,compositor panel_manager panel screen): protocol/swc-server-protocol.h
-$(call objects,dmabuf): protocol/linux-dmabuf-unstable-v1-server-protocol.h
-$(call objects,drm drm_buffer): protocol/wayland-drm-server-protocol.h
-$(call objects,kde_decoration): protocol/server-decoration-server-protocol.h
-$(call objects,snap): protocol/swc_snap-server-protocol.h
-$(call objects,wallpaper): protocol/swc_wallpaper-server-protocol.h
-$(call objects,xdg_decoration): protocol/xdg-decoration-unstable-v1-server-protocol.h
-$(call objects,xdg_shell): protocol/xdg-shell-server-protocol.h
-$(call objects,pointer): cursor/cursor_data.h
-
-$(dir)/libswc-internal.o: $(SWC_STATIC_OBJECTS)
- $(link) -nostdlib -r
-
-$(dir)/libswc.o: $(dir)/libswc-internal.o
- $(Q_OBJCOPY)$(OBJCOPY) --localize-hidden $< $@
-
-$(dir)/libswc.a: $(dir)/libswc.o
- $(Q_AR)$(AR) cru $@ $^
-
-$(dir)/$(LIBSWC_LIB): $(SWC_SHARED_OBJECTS)
- $(link) -shared -Wl,-soname,$(LIBSWC_SO) -Wl,-no-undefined $(libswc_PACKAGE_LIBS)
-
-$(dir)/$(LIBSWC_SO): $(dir)/$(LIBSWC_LIB)
- $(Q_SYM)ln -sf $(notdir $<) $@
-
-$(dir)/$(LIBSWC_LINK): $(dir)/$(LIBSWC_SO)
- $(Q_SYM)ln -sf $(notdir $<) $@
-
-.PHONY: install-libswc.a
-install-libswc.a: $(dir)/libswc.a | $(DESTDIR)$(LIBDIR)
- install -m 644 $< $(DESTDIR)$(LIBDIR)
-
-.PHONY: install-$(LIBSWC_LIB)
-install-$(LIBSWC_LIB): $(dir)/$(LIBSWC_LIB) | $(DESTDIR)$(LIBDIR)
- install -m 755 $< $(DESTDIR)$(LIBDIR)
-
-.PHONY: install-$(LIBSWC_SO) install-$(LIBSWC_LINK)
-install-$(LIBSWC_SO) install-$(LIBSWC_LINK): install-$(LIBSWC_LIB)
- ln -sf $(LIBSWC_LIB) $(DESTDIR)$(LIBDIR)/${@:install-%=%}
-
-install-$(dir): $($(dir)_TARGETS:$(dir)/%=install-%) | $(DESTDIR)$(INCLUDEDIR)
- install -m 644 libswc/swc.h $(DESTDIR)$(INCLUDEDIR)
-
-CLEAN_FILES += $(SWC_SHARED_OBJECTS) $(SWC_STATIC_OBJECTS)
-
-include common.mk
diff --git a/libswc/meson.build b/libswc/meson.build
@@ -0,0 +1,73 @@
+install_headers('swc.h')
+
+libswc_src = files(
+ 'bindings.c',
+ 'compositor.c',
+ 'data.c',
+ 'data_device.c',
+ 'data_device_manager.c',
+ 'dmabuf.c',
+ 'drm.c',
+ 'input.c',
+ 'kde_decoration.c',
+ 'keyboard.c',
+ 'launch.c',
+ 'mode.c',
+ 'output.c',
+ 'panel.c',
+ 'panel_manager.c',
+ 'plane.c',
+ 'pointer.c',
+ 'primary_plane.c',
+ 'region.c',
+ 'screen.c',
+ 'select.c',
+ 'snap.c',
+ 'shell.c',
+ 'shell_surface.c',
+ 'shm.c',
+ 'subcompositor.c',
+ 'subsurface.c',
+ 'surface.c',
+ 'swc.c',
+ 'util.c',
+ 'view.c',
+ 'wallpaper.c',
+ 'wayland_buffer.c',
+ 'window.c',
+ 'xdg_decoration.c',
+ 'xdg_shell.c',
+
+ input_backend == 'libinput' ? 'seat.c' : [],
+ input_backend == 'wscons' ? 'seat-ws.c' : [],
+ input_backend == 'evdev' ? 'seat-evdev.c' : [],
+
+ xwayland.found() ? ['xserver.c', 'xwm.c'] : [],
+)
+libswc_src += [cursor, launch_protocol]
+
+foreach proto, proto_src : protos
+ libswc_src += proto_src
+endforeach
+
+libswc_lib = library(
+ 'swc',
+ libswc_src,
+ dependencies: requires + requires_private,
+ install: true,
+ include_directories: include_directories('..'),
+)
+
+# Allows other meson projects to use libswc
+libswc = declare_dependency(
+ link_with: libswc_lib,
+ dependencies: requires + requires_private,
+)
+
+pkg.generate(
+ libswc_lib,
+ name: 'swc',
+ description: 'A library for making a simple Wayland compositor',
+ requires: requires,
+ requires_private: requires_private,
+)
diff --git a/libswc/seat-evdev.c b/libswc/seat-evdev.c
@@ -25,14 +25,6 @@
#include <linux/input.h>
-#ifndef EVDEV_KBD_DEVICE
-#define EVDEV_KBD_DEVICE "/dev/input/event0"
-#endif
-
-#ifndef EVDEV_POINTER_DEVICE
-#define EVDEV_POINTER_DEVICE "/dev/input/event1"
-#endif
-
struct seat {
struct swc_seat base;
diff --git a/meson.build b/meson.build
@@ -0,0 +1,98 @@
+project('swc', 'c',
+ version: '0.0',
+ meson_version: '>=1.1',
+ license: 'MIT',
+ default_options: [
+ 'c_std=c11',
+ 'warning_level=1',
+ 'default_library=both',
+ ],
+)
+
+cc = meson.get_compiler('c')
+os = host_machine.system()
+pkg = import('pkgconfig')
+wl = import('wayland')
+
+add_project_arguments(cc.get_supported_arguments([
+ '-fvisibility=hidden',
+
+ '-Werror=implicit-function-declaration',
+ '-Werror=implicit-int',
+ '-Werror=pointer-sign',
+ '-Werror=pointer-arith',
+ '-Wno-missing-braces',
+]) + [
+ '-D_GNU_SOURCE', # Required for mkostemp
+ get_option('buildtype').startswith('debug') ? '-DENABLE_DEBUG=1' : [],
+], language: 'c')
+
+requires = [
+ dependency('wayland-server', version: '>=1.6.0'),
+]
+requires_private = [
+ dependency('libdrm'),
+ dependency('pixman-1'),
+ dependency('wayland-protocols'),
+ dependency('wld'),
+ dependency('xkbcommon'),
+]
+
+xwayland = dependency('xwayland', required: get_option('xwayland'))
+xwayland_deps = [
+ 'xcb',
+ 'xcb-composite',
+ 'xcb-ewmh',
+ 'xcb-icccm',
+]
+if xwayland.found()
+ add_project_arguments('-DENABLE_XWAYLAND', language: 'c')
+ requires_private += xwayland
+ foreach dep : xwayland_deps
+ requires_private += dependency(dep, required: xwayland.found())
+ endforeach
+endif
+
+input_backend = get_option('input')
+libinput = dependency('libinput', version: '>=0.4', required: input_backend == 'libinput')
+
+if input_backend == 'auto'
+ if os == 'linux'
+ input_backend = libinput.found() ? 'libinput' : 'evdev'
+ elif os == 'netbsd'
+ input_backend = 'wscons'
+ else
+ error('Failed to determine input backend for ' + os)
+ endif
+endif
+
+if input_backend == 'libinput'
+ udev = dependency('libudev', required: get_option('udev'))
+ if udev.found()
+ add_project_arguments('-DENABLE_LIBUDEV', language: 'c')
+ endif
+ requires_private += [libinput, udev]
+elif input_backend == 'evdev'
+ add_project_arguments([
+ '-DEVDEV_KBD_DEVICE="@0@"'.format(get_option('evdev-keyboard')),
+ '-DEVDEV_POINTER_DEVICE="@0@"'.format(get_option('evdev-pointer')),
+ ], language: 'c')
+endif
+
+subdir('protocol')
+subdir('cursor')
+subdir('launch')
+subdir('libswc')
+
+if get_option('extra')
+ subdir('extra')
+endif
+
+if get_option('example')
+ subdir('example')
+endif
+
+summary({
+ 'Xwayland support': xwayland.found(),
+ 'Input backend': input_backend,
+}, bool_yn: true)
diff --git a/meson.options b/meson.options
@@ -0,0 +1,7 @@
+option('xwayland', type: 'feature', value: 'auto', description: 'Automatic Xwayland handling')
+option('input', type: 'combo', value: 'auto', choices: ['auto', 'libinput', 'evdev', 'wscons'], description: 'Input backend to use')
+option('udev', type: 'feature', value: 'auto', description: 'libinput libudev support')
+option('evdev-keyboard', type: 'string', value: '/dev/input/event0', description: 'evdev keyboard device to use')
+option('evdev-pointer', type: 'string', value: '/dev/input/event1', description: 'evdev pointer device to use')
+option('extra', type: 'boolean', value: true, description: 'Build swc utility applications')
+option('example', type: 'boolean', value: false, description: 'Build swc example compositor')
diff --git a/protocol/local.mk b/protocol/local.mk
@@ -1,36 +0,0 @@
-# swc: protocol/local.mk
-
-dir := protocol
-wayland_protocols := $(call pkgconfig,wayland-protocols,variable=pkgdatadir,DATADIR)
-
-PROTOCOL_EXTENSIONS = \
- $(dir)/server-decoration.xml\
- $(dir)/swc.xml \
- $(dir)/swc_snap.xml \
- $(dir)/swc_wallpaper.xml \
- $(dir)/wayland-drm.xml \
- $(wayland_protocols)/stable/xdg-shell/xdg-shell.xml \
- $(wayland_protocols)/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml \
- $(wayland_protocols)/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml
-
-$(dir)_PACKAGES := wayland-server
-
-.for ext in ${PROTOCOL_EXTENSIONS}
-proto_base := ${ext:T:R}
-
-${dir}/${proto_base}-protocol.c: ${ext}
- ${Q_GEN}${WAYLAND_SCANNER} server-header ${ext} ${dir}/${proto_base}-server-protocol.h
- ${Q_GEN}${WAYLAND_SCANNER} client-header ${ext} ${dir}/${proto_base}-client-protocol.h
- ${Q_GEN}${WAYLAND_SCANNER} code ${ext} ${.TARGET}
-
-CLEAN_FILES += ${dir}/${proto_base}-protocol.c \
- ${dir}/${proto_base}-server-protocol.h \
- ${dir}/${proto_base}-client-protocol.h
-.endfor
-
-install-$(dir): | $(DESTDIR)$(DATADIR)/swc
- install -m 644 protocol/swc.xml $(DESTDIR)$(DATADIR)/swc
- install -m 644 protocol/swc_snap.xml $(DESTDIR)$(DATADIR)/swc
- install -m 644 protocol/swc_wallpaper.xml $(DESTDIR)$(DATADIR)/swc
-
-include common.mk
diff --git a/protocol/meson.build b/protocol/meson.build
@@ -0,0 +1,21 @@
+fs = import('fs')
+
+# Allow easy lookup for protocol for utility applications
+protos = {}
+foreach proto : [
+ 'server-decoration.xml',
+ 'swc.xml',
+ 'swc_snap.xml',
+ 'swc_select.xml',
+ 'swc_wallpaper.xml',
+ 'wayland-drm.xml',
+ wl.find_protocol('xdg-shell', state: 'stable'),
+ wl.find_protocol('linux-dmabuf', state: 'unstable', version: 1),
+ wl.find_protocol('xdg-decoration', state: 'unstable', version: 1),
+]
+ protocols = wl.scan_xml(proto,
+ public: true,
+ client: true,
+ server: true)
+ protos += {fs.stem(fs.name(proto)): protocols}
+endforeach