Remove status and datetime modules

This commit is contained in:
Alex Kotov 2021-11-14 23:01:33 +05:00
parent e4b0adecb7
commit 77616c75b2
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
9 changed files with 10 additions and 269 deletions

View file

@ -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}

View file

@ -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);

View file

@ -8,7 +8,7 @@ enum {
NetSupported, NetWMName, NetWMState, NetWMCheck, NetSystemTray,
NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz,
NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDialog,
NetClientList, NetStatusUpdate, NetLast,
NetClientList, NetLast,
};
/* Xembed atoms */

View file

@ -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}

View file

@ -1,81 +0,0 @@
#include "datetime.h"
#include "atoms.h"
#include "status.h"
#include <pthread.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
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;
}

View file

@ -1,11 +0,0 @@
#ifndef _DATETIME_H
#define _DATETIME_H
#include <stdbool.h>
#define DATETIME_BUFFER_SIZE 32
bool datetime_start();
void datetime_stop();
#endif // _DATETIME_H

43
dwm.c
View file

@ -42,10 +42,8 @@
#include <X11/Xft/Xft.h>
#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;

120
status.c
View file

@ -1,120 +0,0 @@
#include "status.h"
#include "atoms.h"
#include "datetime.h"
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#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);
}

View file

@ -1,15 +0,0 @@
#ifndef _STATUS_H
#define _STATUS_H
#include <stdbool.h>
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