Update datetime
This commit is contained in:
parent
8416d8f8ff
commit
8e18605139
1
atoms.c
1
atoms.c
|
@ -26,6 +26,7 @@ AtomValues atoms_create(Display *const dpy)
|
||||||
atom_values->netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
|
atom_values->netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
|
||||||
atom_values->netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
|
atom_values->netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
|
||||||
atom_values->netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
|
atom_values->netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
|
||||||
|
atom_values->netatom[NetDateTime] = XInternAtom(dpy, "_NET_DATE_TIME", False);
|
||||||
|
|
||||||
atom_values->xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
|
atom_values->xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
|
||||||
atom_values->xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False);
|
atom_values->xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False);
|
||||||
|
|
2
atoms.h
2
atoms.h
|
@ -8,7 +8,7 @@ enum {
|
||||||
NetSupported, NetWMName, NetWMState, NetWMCheck, NetSystemTray,
|
NetSupported, NetWMName, NetWMState, NetWMCheck, NetSystemTray,
|
||||||
NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz,
|
NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz,
|
||||||
NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDialog,
|
NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDialog,
|
||||||
NetClientList, NetLast,
|
NetClientList, NetDateTime, NetLast,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Xembed atoms */
|
/* Xembed atoms */
|
||||||
|
|
37
datetime.c
37
datetime.c
|
@ -1,10 +1,12 @@
|
||||||
#include "datetime.h"
|
#include "datetime.h"
|
||||||
|
|
||||||
|
#include "atoms.h"
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#define BUFFER_SIZE 32
|
#define BUFFER_SIZE 32
|
||||||
|
|
||||||
|
@ -12,20 +14,33 @@ static void *run(void *vargp);
|
||||||
|
|
||||||
static const char *const default_text = "date & time";
|
static const char *const default_text = "date & time";
|
||||||
|
|
||||||
|
static Display *display = None;
|
||||||
|
static AtomValues atom_values = NULL;
|
||||||
static bool running = true;
|
static bool running = true;
|
||||||
static pthread_t thread;
|
static pthread_t thread;
|
||||||
static pthread_mutex_t mutex;
|
static pthread_mutex_t mutex;
|
||||||
static char buffer[BUFFER_SIZE];
|
static char buffer[BUFFER_SIZE];
|
||||||
|
|
||||||
void datetime_start()
|
bool datetime_start()
|
||||||
{
|
{
|
||||||
strcpy(buffer, default_text);
|
strcpy(buffer, default_text);
|
||||||
|
|
||||||
|
if ((display = XOpenDisplay(NULL)) == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
atom_values = atoms_create(display);
|
||||||
|
|
||||||
pthread_create(&thread, NULL, run, NULL);
|
pthread_create(&thread, NULL, run, NULL);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void datetime_stop()
|
void datetime_stop()
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
|
atoms_destroy(atom_values);
|
||||||
|
XCloseDisplay(display);
|
||||||
pthread_join(thread, NULL);
|
pthread_join(thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +56,24 @@ void *run(void *vargp)
|
||||||
strftime(buffer, sizeof(buffer), "%a, %e %b %Y, %H:%M:%S", time_info);
|
strftime(buffer, sizeof(buffer), "%a, %e %b %Y, %H:%M:%S", time_info);
|
||||||
datetime_unlock();
|
datetime_unlock();
|
||||||
|
|
||||||
|
XEvent event;
|
||||||
|
memset(&event, 0, sizeof(event));
|
||||||
|
event.xclient.type = ClientMessage;
|
||||||
|
event.xclient.serial = 0;
|
||||||
|
event.xclient.send_event = True;
|
||||||
|
event.xclient.display = display; // TODO: was undefined in xclimsg
|
||||||
|
event.xclient.window = DefaultRootWindow(display);
|
||||||
|
event.xclient.message_type = atom_values->netatom[NetDateTime];
|
||||||
|
event.xclient.format = 32;
|
||||||
|
XSendEvent(
|
||||||
|
display,
|
||||||
|
event.xclient.window,
|
||||||
|
False,
|
||||||
|
SubstructureRedirectMask | SubstructureNotifyMask,
|
||||||
|
&event
|
||||||
|
);
|
||||||
|
XFlush(display);
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef _DATETIME_H
|
#ifndef _DATETIME_H
|
||||||
#define _DATETIME_H
|
#define _DATETIME_H
|
||||||
|
|
||||||
void datetime_start();
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool datetime_start();
|
||||||
void datetime_stop();
|
void datetime_stop();
|
||||||
|
|
||||||
void datetime_lock();
|
void datetime_lock();
|
||||||
|
|
9
dwm.c
9
dwm.c
|
@ -601,6 +601,12 @@ clientmessage(XEvent *e)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cme->message_type == atom_values->netatom[NetDateTime]) {
|
||||||
|
updatestatus(); // TODO: maybe we need some filtering
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!c)
|
if (!c)
|
||||||
return;
|
return;
|
||||||
if (cme->message_type == atom_values->netatom[NetWMState]) {
|
if (cme->message_type == atom_values->netatom[NetWMState]) {
|
||||||
|
@ -2476,7 +2482,8 @@ main(int argc, char *argv[])
|
||||||
if (!(dpy = XOpenDisplay(NULL)))
|
if (!(dpy = XOpenDisplay(NULL)))
|
||||||
die("dwm: cannot open display");
|
die("dwm: cannot open display");
|
||||||
checkotherwm();
|
checkotherwm();
|
||||||
datetime_start();
|
if (!datetime_start())
|
||||||
|
die("dwm: cannot start datetime service");
|
||||||
setup();
|
setup();
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (pledge("stdio rpath proc exec", NULL) == -1)
|
if (pledge("stdio rpath proc exec", NULL) == -1)
|
||||||
|
|
Loading…
Reference in New Issue