From 77616c75b2dc282ec3e37ff01c9b6a5ad804cb47 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 14 Nov 2021 23:01:33 +0500 Subject: [PATCH] Remove status and datetime modules --- Makefile | 4 +- atoms.c | 1 - atoms.h | 2 +- config.mk | 2 +- datetime.c | 81 ------------------------------------ datetime.h | 11 ----- dwm.c | 43 +++---------------- status.c | 120 ----------------------------------------------------- status.h | 15 ------- 9 files changed, 10 insertions(+), 269 deletions(-) delete mode 100644 datetime.c delete mode 100644 datetime.h delete mode 100644 status.c delete mode 100644 status.h diff --git a/Makefile b/Makefile index 03014a0..e2dc69b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = atoms.c datetime.c drw.c dwm.c settings.c status.c tags.c util.c +SRC = atoms.c drw.c dwm.c settings.c tags.c util.c OBJ = ${SRC:.c=.o} all: options dwm @@ -17,7 +17,7 @@ options: %.o: %.c ${CC} -c $< -o $@ ${CFLAGS} -${OBJ}: atoms.h datetime.h drw.h config.def.h config.mk settings.h status.h tags.h util.h +${OBJ}: atoms.h drw.h config.def.h config.mk settings.h tags.h util.h dwm: ${OBJ} ${CC} -o $@ ${OBJ} ${LDFLAGS} diff --git a/atoms.c b/atoms.c index b593ebf..fed2407 100644 --- a/atoms.c +++ b/atoms.c @@ -26,7 +26,6 @@ Atoms atoms_create(Display *const dpy) atoms->netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); atoms->netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); atoms->netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); - atoms->netatom[NetStatusUpdate] = XInternAtom(dpy, "_NET_STATUS_UPDATE", False); atoms->xatom[Manager] = XInternAtom(dpy, "MANAGER", False); atoms->xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False); diff --git a/atoms.h b/atoms.h index 8b2b649..b83e2e8 100644 --- a/atoms.h +++ b/atoms.h @@ -8,7 +8,7 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz, NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDialog, - NetClientList, NetStatusUpdate, NetLast, + NetClientList, NetLast, }; /* Xembed atoms */ diff --git a/config.mk b/config.mk index 86e9131..df237cb 100644 --- a/config.mk +++ b/config.mk @@ -32,7 +32,7 @@ FREETYPEINC = /usr/include/freetype2 # includes and libs INCS = -I${X11INC} -I${FREETYPEINC} -LIBS = -L${X11LIB} -lX11 -lpthread ${XINERAMALIBS} ${FREETYPELIBS} +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} diff --git a/datetime.c b/datetime.c deleted file mode 100644 index 7de4b78..0000000 --- a/datetime.c +++ /dev/null @@ -1,81 +0,0 @@ -#include "datetime.h" - -#include "atoms.h" -#include "status.h" - -#include -#include -#include -#include - -static void datetime_lock(); -static void datetime_unlock(); -static void *run(void *vargp); - -static const char *const default_text = "date & time"; - -static pthread_mutex_t mutex; -static bool running = false; - -static pthread_t thread; -static bool thread_created = false; - -static char buffer[DATETIME_BUFFER_SIZE]; - -void datetime_lock() -{ - pthread_mutex_lock(&mutex); -} - -void datetime_unlock() -{ - pthread_mutex_unlock(&mutex); -} - -bool datetime_start() -{ - datetime_lock(); - - if (running) return false; - - running = true; - strcpy(buffer, default_text); - - thread_created = pthread_create(&thread, NULL, run, NULL) == 0; - - datetime_unlock(); - - return thread_created; -} - -void datetime_stop() -{ - datetime_lock(); - - if (!running) return; - - running = false; - if (thread_created) pthread_join(thread, NULL); - - datetime_unlock(); -} - -void *run(void *vargp) -{ - while (running) { - time_t raw_time; - time(&raw_time); - - const struct tm *const time_info = localtime(&raw_time); - - datetime_lock(); - strftime(buffer, sizeof(buffer), "%a, %e %b %Y, %H:%M:%S", time_info); - datetime_unlock(); - - status_set_datetime(buffer); - - sleep(1); - } - - return NULL; -} diff --git a/datetime.h b/datetime.h deleted file mode 100644 index 6a613ab..0000000 --- a/datetime.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _DATETIME_H -#define _DATETIME_H - -#include - -#define DATETIME_BUFFER_SIZE 32 - -bool datetime_start(); -void datetime_stop(); - -#endif // _DATETIME_H diff --git a/dwm.c b/dwm.c index ab1d502..cbaa5c2 100644 --- a/dwm.c +++ b/dwm.c @@ -42,10 +42,8 @@ #include #include "atoms.h" -#include "datetime.h" #include "drw.h" #include "settings.h" -#include "status.h" #include "tags.h" #include "util.h" @@ -255,7 +253,6 @@ static int updategeom(void); static void updatenumlockmask(void); static void updatesizehints(Client *c); static void updatestatus(void); -static void updatestatusexternal(void); static void updatesystray(void); static void updatesystrayicongeom(Client *i, int w, int h); static void updatesystrayiconstate(Client *i, XPropertyEvent *ev); @@ -692,11 +689,6 @@ clientmessage(XEvent *e) return; } - if (cme->message_type == atoms->netatom[NetStatusUpdate]) { - updatestatus(); // TODO: maybe we need some filtering - return; - } - if (!c) return; if (cme->message_type == atoms->netatom[NetWMState]) { @@ -1593,7 +1585,7 @@ propertynotify(XEvent *e) updatesystray(); } if ((ev->window == root) && (ev->atom == XA_WM_NAME)) - updatestatusexternal(); + updatestatus(); else if (ev->state == PropertyDelete) return; /* ignore */ else if ((c = wintoclient(ev->window))) { @@ -2002,6 +1994,7 @@ setup(void) updategeom(); /* init atoms */ atoms = atoms_create(dpy); + if (atoms == NULL) die("dwm: fatal: cannot allocate atoms"); /* init cursors */ cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); cursor[CurResize] = drw_cur_create(drw, XC_sizing); @@ -2014,7 +2007,7 @@ setup(void) updatesystray(); /* init bars */ updatebars(); - updatestatusexternal(); + updatestatus(); /* supporting window for NetWMCheck */ wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); XChangeProperty(dpy, wmcheckwin, atoms->netatom[NetWMCheck], XA_WINDOW, 32, @@ -2490,9 +2483,9 @@ updatesizehints(Client *c) void updatestatus(void) { - status_lock(); - sprintf(stext, "%s", status_get()); - status_unlock(); + if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) { + strcpy(stext, "dwm-"VERSION); + } for (Monitor *m = mons; m; m = m->next) { drawbar(m); @@ -2501,18 +2494,6 @@ updatestatus(void) updatesystray(); } -void -updatestatusexternal(void) -{ - char buffer[256]; - - if (!gettextprop(root, XA_WM_NAME, buffer, sizeof(buffer))) { - sprintf(buffer, "dwm-"VERSION); - } - - status_set_external(buffer); -} - void updatesystrayicongeom(Client *i, int w, int h) { @@ -2881,16 +2862,6 @@ main(int argc, char *argv[]) checkotherwm(); - if (!status_start()) { - status_stop(); - die("dwm: cannot start status service"); - } - - if (!datetime_start()) { - datetime_stop(); - die("dwm: cannot start datetime service"); - } - setup(); #ifdef __OpenBSD__ @@ -2902,8 +2873,6 @@ main(int argc, char *argv[]) scan(); run(); cleanup(); - datetime_stop(); - status_stop(); XCloseDisplay(dpy); return EXIT_SUCCESS; diff --git a/status.c b/status.c deleted file mode 100644 index 13f23dc..0000000 --- a/status.c +++ /dev/null @@ -1,120 +0,0 @@ -#include "status.h" - -#include "atoms.h" -#include "datetime.h" - -#include -#include -#include -#include - -#define EXTERNAL_BUFFER_SIZE 256 - -#define BUFFER_SIZE (EXTERNAL_BUFFER_SIZE + 3 + DATETIME_BUFFER_SIZE) - -static void update(); - -static pthread_mutex_t mutex; -static bool running = false; - -static Display *display = None; -static Atoms atoms = NULL; - -static char buffer[BUFFER_SIZE]; -static char external_buffer[EXTERNAL_BUFFER_SIZE]; -static char datetime_buffer[DATETIME_BUFFER_SIZE]; - -void status_lock() -{ - pthread_mutex_lock(&mutex); -} - -void status_unlock() -{ - pthread_mutex_unlock(&mutex); -} - -const char *status_get() -{ - return buffer; -} - -bool status_start() -{ - status_lock(); - - if (running) return false; - - running = true; - - memset(buffer, 0, sizeof(buffer)); - memset(external_buffer, 0, sizeof(external_buffer)); - memset(datetime_buffer, 0, sizeof(datetime_buffer)); - - if ((display = XOpenDisplay(NULL)) == NULL) return false; - if ((atoms = atoms_create(display)) == NULL) return false; - - status_unlock(); - - return true; -} - -void status_stop() -{ - status_lock(); - - if (!running) return; - - running = false; - if (atoms != NULL) atoms_destroy(atoms); - if (display != None) XCloseDisplay(display); - - status_unlock(); -} - -void status_set_external(const char *const text) -{ - status_lock(); - - strncpy(external_buffer, text, EXTERNAL_BUFFER_SIZE); - external_buffer[EXTERNAL_BUFFER_SIZE - 1] = '\0'; - update(); - - status_unlock(); -} - -void status_set_datetime(const char *const text) -{ - status_lock(); - - strncpy(datetime_buffer, text, DATETIME_BUFFER_SIZE); - datetime_buffer[DATETIME_BUFFER_SIZE - 1] = '\0'; - update(); - - status_unlock(); -} - -static void update() -{ - sprintf(buffer, "%s | %s", external_buffer, datetime_buffer); - - XEvent event; - memset(&event, 0, sizeof(event)); - event.xclient.type = ClientMessage; - event.xclient.serial = 0; - event.xclient.send_event = True; - event.xclient.display = display; - event.xclient.window = DefaultRootWindow(display); - event.xclient.message_type = atoms->netatom[NetStatusUpdate]; - event.xclient.format = 32; - - XSendEvent( - display, - event.xclient.window, - False, - SubstructureRedirectMask | SubstructureNotifyMask, - &event - ); - - XFlush(display); -} diff --git a/status.h b/status.h deleted file mode 100644 index 2bca139..0000000 --- a/status.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _STATUS_H -#define _STATUS_H - -#include - -bool status_start(); -void status_stop(); -void status_lock(); -void status_unlock(); -const char *status_get(); - -void status_set_external(const char *text); -void status_set_datetime(const char *text); - -#endif // _STATUS_H