diff options
| author | sinanmohd <sinan@firemail.cc> | 2023-09-28 10:27:39 +0530 | 
|---|---|---|
| committer | sinanmohd <sinan@firemail.cc> | 2023-09-28 16:17:21 +0530 | 
| commit | d605727d4bb3b7ae19dc0227d55030a7ebc73148 (patch) | |
| tree | b183df7104eedaf8628985933d52df16d23df278 | |
| parent | 3647b6c1140cb9e0cebeab19e53c0294f966b19b (diff) | |
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 12 | ||||
| -rw-r--r-- | flake.nix | 1 | ||||
| -rw-r--r-- | globals.c | 24 | ||||
| -rw-r--r-- | server.c | 43 | ||||
| -rw-r--r-- | util.h | 16 | 
6 files changed, 74 insertions, 23 deletions
@@ -1,2 +1,3 @@  globals +server  *.o @@ -1,9 +1,13 @@ -OBJECTS = globals.o  CC = gcc -globals: $(OBJECTS) -	$(CC) -o globals $(OBJECTS) -lwayland-client +all: server globals + +globals: globals.o util.o +	$(CC) -o globals globals.o -lwayland-client +server: server.o util.o +	$(CC) -o server server.o -lwayland-server +util.o: util.h  .PHONY: clean  clean: -	rm -rf globals *.o +	rm -rf globals server *.o @@ -22,6 +22,7 @@  	buildInputs = with pkgs; [ wayland ];  	shellHook = '' +	  [ -z $WAYLAND_DISPLAY ] && export WAYLAND_DISPLAY="wayland-1"  	  export PS1="\033[0;33m[ ]\033[0m $PS1"  	'';        }; @@ -1,8 +1,6 @@ -#include <stdio.h> -#include <stdint.h>  #include <wayland-client.h> +#include "util.h" -void plog(char *type, char *fmt, ...);  static void  registry_handle_global(void *data, struct wl_registry *registry,  		       uint32_t name, const char *interface, uint32_t version); @@ -20,7 +18,7 @@ static void  registry_handle_global(void *data, struct wl_registry *registry,  		       uint32_t name, const char *interface, uint32_t version)  { -	plog("info", "interface: %s, version: %d, name: %d", interface, +	plog(PLOG_INFO, "interface: %s, version: %d, name: %d", interface,  			version, name);  } @@ -28,19 +26,7 @@ static void  registry_handle_global_remove(void *data, struct wl_registry *registry,  			      uint32_t name)  { -	plog("info", "interface with name %d removed", name); -} - -void plog(char *type, char *fmt, ...) -{ -	va_list args; - -	va_start(args, fmt); -	fprintf(stderr, "%s",type); -	fprintf(stderr, ": "); -	vfprintf(stderr, fmt, args); -	putc('\n', stderr); -	va_end(args); +	plog(PLOG_INFO, "interface with name %d removed", name);  }  int main(void) @@ -50,10 +36,10 @@ int main(void)  	display = wl_display_connect(NULL);  	if (!display) { -		plog("eror", "Unable to connect to wayland display"); +		plog(PLOG_ERR, "Unable to connect to wayland display");  		return 1;  	} -	plog("info", "Running wayland display"); +	plog(PLOG_INFO, "Running wayland display");  	registry = wl_display_get_registry(display);  	wl_registry_add_listener(registry, ®istry_listener, NULL); diff --git a/server.c b/server.c new file mode 100644 index 0000000..79b5f75 --- /dev/null +++ b/server.c @@ -0,0 +1,43 @@ +#include <wayland-server.h> +#include "util.h" + + +static void +wl_output_handle_bind(struct wl_client *client, void *data, +                             uint32_t version, uint32_t id) +{ +	// TODO +} + +int main(void) +{ +	struct wl_display *display = wl_display_create(); +	if (!display) { +		plog(PLOG_ERR, "Unable to create wayland display"); +		return 1; +	} + +	const char *socket = wl_display_add_socket_auto(display); +	if (!socket) { +		plog(PLOG_ERR, "unbale to add socket to wayland display"); +		return 1; +	} + +	const struct wl_interface interface = { +		.name = "sneed", +		.version = 60, +		.method_count = 0, +		.methods = NULL, +		.event_count =0, +		.events = NULL, +	}; + +	wl_global_create(display, &interface, 51, NULL, wl_output_handle_bind); +	wl_global_create(display, &interface, 50, NULL, wl_output_handle_bind); + +	plog(PLOG_INFO, "Running wayland display on %s", socket); +	wl_display_run(display); + +	wl_display_destroy(display); +	return 0; +} @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdarg.h> + +enum plog { PLOG_INFO, PLOG_WARN, PLOG_ERR }; +static const char *msg[] = { "info", "warn", "eror"}; + +void plog(enum plog type, const char *fmt, ...) +{ +	va_list args; + +	va_start(args, fmt); +	fprintf(stderr, "%s: ",msg[type]); +	vfprintf(stderr, fmt, args); +	putc('\n', stderr); +	va_end(args); +}  | 
