From 4d1dac524e01798919754102e9d316c2da3a7984 Mon Sep 17 00:00:00 2001 From: night0721 Date: Tue, 5 Nov 2024 00:20:43 +0000 Subject: [PATCH] Use Luft as alternative for libnotify, update CFLAGS --- Makefile | 27 +++++++++++++-------------- include/config.h | 6 ++++-- include/zen/notification.h | 7 +++++++ luft.h | 6 ++++++ src/zen/notification.c | 10 +++++++++- src/zen/zen.c | 2 ++ zsm.1 | 0 7 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 luft.h create mode 100644 zsm.1 diff --git a/Makefile b/Makefile index 9412f79..06fd187 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ .POSIX: .SUFFIXES: -CC = cc VERSION = 1.0 SERVER = zmr CLIENT = zen @@ -11,24 +10,24 @@ PREFIX ?= /usr/local BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/share/man/man1 -# Flags -LDFLAGS = $(shell pkg-config --libs libsodium libnotify ncurses sqlite3) -CFLAGS = -O3 -mtune=native -march=native -pipe -s -std=c99 -Wno-pointer-sign -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 $(shell pkg-config --cflags libsodium libnotify ncurses sqlite3) -lpthread +LDFLAGS != pkg-config --libs libsodium libnotify ncurses sqlite3 +INCFLAGS != pkg-config --cflags libsodium libnotify ncurses sqlite3 +CFLAGS = -Os -mtune=native -march=native -pipe -g -std=c99 -Wno-pointer-sign -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 $(INCFLAGS) -lpthread -lluft -L. -SERVERSRC = src/zmr/*.c -CLIENTSRC = src/zen/*.c -LIBSRC = src/lib/*.c -INCLUDE = -Iinclude/ +SERVERSRC != find src/zmr -name "*.c" +CLIENTSRC != find src/zen -name "*.c" +LIBSRC != find src/lib -name "*.c" +INCLUDE = include all: $(SERVER) $(CLIENT) $(SERVER): $(SERVERSRC) $(LIBSRC) mkdir -p bin - $(CC) $(SERVERSRC) $(LIBSRC) $(INCLUDE) -o bin/$@ $(CFLAGS) $(LDFLAGS) + $(CC) $(SERVERSRC) $(LIBSRC) -I$(INCLUDE) -I. -o bin/$@ $(CFLAGS) $(LDFLAGS) $(CLIENT): $(CLIENTSRC) $(LIBSRC) mkdir -p bin - $(CC) $(CLIENTSRC) $(LIBSRC) $(INCLUDE) -o bin/$@ $(CFLAGS) $(LDFLAGS) + $(CC) $(CLIENTSRC) $(LIBSRC) -I$(INCLUDE) -I. -o bin/$@ $(CFLAGS) $(LDFLAGS) dist: mkdir -p $(TARGET)-$(VERSION) @@ -48,11 +47,11 @@ install: $(TARGET) chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE) uninstall: - $(RM) $(DESTDIR)$(BINDIR)/$(SERVER) - $(RM) $(DESTDIR)$(BINDIR)/$(CLIENT) - $(RM) $(DESTDIR)$(MANDIR)/$(MANPAGE) + rm $(DESTDIR)$(BINDIR)/$(SERVER) + rm $(DESTDIR)$(BINDIR)/$(CLIENT) + rm $(DESTDIR)$(MANDIR)/$(MANPAGE) clean: - $(RM) $(SERVER) $(CLIENT) + rm $(SERVER) $(CLIENT) .PHONY: all dist install uninstall clean diff --git a/include/config.h b/include/config.h index b9b2cc4..ded26c8 100644 --- a/include/config.h +++ b/include/config.h @@ -4,8 +4,10 @@ #define MAX_CLIENTS_PER_THREAD 1024 /* Client */ -#define DOMAIN "127.0.0.1" -/* #define USERNAME "night" */ +#define DOMAIN "zsm.night0721.xyz" +#define USERNAME "night" + +#define USE_LUFT /* UI */ #define PANEL_HEIGHT 1 diff --git a/include/zen/notification.h b/include/zen/notification.h index 448404e..1a7af5d 100644 --- a/include/zen/notification.h +++ b/include/zen/notification.h @@ -2,7 +2,14 @@ #define NOTIFICATION_H #include + +#include "config.h" + +#ifdef USE_LUFT +#include "luft.h" +#else #include +#endif void send_notification(uint8_t *author, uint8_t *content); diff --git a/luft.h b/luft.h new file mode 100644 index 0000000..d324468 --- /dev/null +++ b/luft.h @@ -0,0 +1,6 @@ +#ifndef LUFT_H_ +#define LUFT_H_ + +void render_notification(char **texts, int num_of_lines); + +#endif diff --git a/src/zen/notification.c b/src/zen/notification.c index 484e517..f267dd3 100644 --- a/src/zen/notification.c +++ b/src/zen/notification.c @@ -1,9 +1,16 @@ #include "util.h" #include "zen/notification.h" +#include "config.h" void send_notification(uint8_t *author, uint8_t *content) { - NotifyNotification *notification = notify_notification_new((char *) author, +#ifdef USE_LUFT + char *texts[3]; + texts[0] = author; + texts[1] = content; + render_notification(texts, 2); +#else + NotifyNotification *notification = notify_notification_new((char *) author, (char *) content, "dialog-information"); if (notification == NULL) { write_log(LOG_ERROR, "Cannot create notification"); @@ -12,4 +19,5 @@ void send_notification(uint8_t *author, uint8_t *content) write_log(LOG_ERROR, "Cannot show notifcation"); } g_object_unref(G_OBJECT(notification)); +#endif } diff --git a/src/zen/zen.c b/src/zen/zen.c index 7c8c017..e50523c 100644 --- a/src/zen/zen.c +++ b/src/zen/zen.c @@ -142,9 +142,11 @@ int main() } /* Init libnotify with app name */ +#ifndef USE_LUFT if (notify_init("zen") < 0) { error(1, "Error initializing libnotify"); } +#endif int sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { diff --git a/zsm.1 b/zsm.1 new file mode 100644 index 0000000..e69de29