Commit edef67e308b9c5d968c60c80458f65900d0ec5a0 Parent: b94c9a32a76ed858193b4a2b2109dd9b33141de4 Author: mcol <mcol@posteo.net> Date: 2021-02-14 19:53:20 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-02-14 19:53:20 +0000 add skeleton for wimptool client interface
src/wimptool.c Added
@@ -0,0 +1,52 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/socket.h> +#include <sys/un.h> + +#define SOCKET_PATH "/tmp/wimpy-sock-%s" + + +void usage() { + printf("Usage: wimptool <command> <arguments>\n"); +} + + +int main(int argc, char *argv[]) { + if (argc < 2) { + usage(); + return EXIT_FAILURE; + } + + char *display = getenv("WAYLAND_DISPLAY"); + if (!display) { + printf("WAYLAND_DISPLAY not set.\n"); + return EXIT_FAILURE; + } + + int sock; + if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + printf("Failed to create socket.\n"); + return EXIT_FAILURE; + } + + struct sockaddr_un addr; + snprintf(addr.sun_path, sizeof(addr.sun_path), SOCKET_PATH, display); + addr.sun_family = AF_UNIX; + + if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + printf("Failed to connect to wimp.\n"); + return EXIT_FAILURE; + } + + char buffer[BUFSIZ] = {0}; + for (int i = 1; i < argc; i++) { + strcat(buffer, argv[i]); + } + + if (send(sock, buffer, strlen(buffer), 0) == -1) { + printf("Failed to send message to wimp.\n"); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +}
Makefile Modified
@@ -1,5 +1,4 @@ -OUT = wimp -SOURCES = $(wildcard src/*.c) +SOURCES = $(filter-out src/wimptool.c, $(wildcard src/*.c)) OBJECTS = $(SOURCES:.c=.o) CFLAGS += -g -I. -DWLR_USE_UNSTABLE -Wall -Wextra -pedantic -Wno-unused-parameter LDFLAGS += $(shell pkg-config --cflags --libs wlroots) \ @@ -10,15 +9,20 @@ $(shell pkg-config --cflags --libs pixman-1) \ -lm +all: wimp wimptool + PREFIX ?= /usr/local BINPREFIX ?= $(PREFIX)/bin -${OUT}: xdg-shell-protocol wlr-layer-shell-unstable-v1-protocol ${OBJECTS} - @$(CC) -o ${OUT} $(OBJECTS) $(LDFLAGS) +wimp: xdg-shell-protocol wlr-layer-shell-unstable-v1-protocol ${OBJECTS} + @$(CC) -o wimp $(OBJECTS) $(LDFLAGS) %.o: %.c %.h @$(CC) $(CFLAGS) -c -o $@ $< ${LDFLAGS} +wimptool: src/wimptool.c + @$(CC) $(CFLAGS) -o $@ $< + WAYLAND_PROTOCOLS=$(shell pkg-config --variable=pkgdatadir wayland-protocols) WAYLAND_SCANNER=$(shell pkg-config --variable=wayland_scanner wayland-scanner) @@ -31,14 +35,13 @@ @$(WAYLAND_SCANNER) private-code protocols/wlr-layer-shell-unstable-v1.xml $@.c clean: - rm -f ${OUT} *-protocol.h *-protocol.c ${OBJECTS} + rm -f wimp wimptool *-protocol.h *-protocol.c ${OBJECTS} install: mkdir -p "$(DESTDIR)$(BINPREFIX)" - cp -pf "$(OUT)" "$(DESTDIR)$(BINPREFIX)" + cp -pf "wimp" "$(DESTDIR)$(BINPREFIX)" uninstall: - rm -f "$(DESTDIR)$(BINPREFIX)/$(OUT)" + rm -f "$(DESTDIR)$(BINPREFIX)/wimp" -.DEFAULT_GOAL=${OUT} -.PHONY: clean +.PHONY: all clean install uninstall
.gitignore Modified
@@ -1,4 +1,5 @@ wimp +wimptool src/*.o *-protocol.c *-protocol.h