2 Commits

Author SHA1 Message Date
Pijus Kamandulis fe338401d6 Move rainbow-ui into a separate thread 2021-03-03 22:50:30 +02:00
Pijus Kamandulis e4988ef755 Initial rainbow implementation 2021-03-03 02:29:39 +02:00
5 changed files with 68 additions and 3 deletions
+2 -1
View File
@@ -17,7 +17,8 @@ static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb"; static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee"; static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577"; static const char col_cyan[] = "#005577";
static const unsigned int baralpha = 0xd0; static const useconds_t rainbowrate = 100000;
static const unsigned int baralpha = 0xd0;
static const unsigned int borderalpha = OPAQUE; static const unsigned int borderalpha = OPAQUE;
static const char *colors[][3] = { static const char *colors[][3] = {
/* fg bg border */ /* fg bg border */
+1
View File
@@ -17,6 +17,7 @@ static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb"; static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee"; static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577"; static const char col_cyan[] = "#005577";
static const useconds_t rainbowrate = 100000;
static const unsigned int baralpha = 0xd0; static const unsigned int baralpha = 0xd0;
static const unsigned int borderalpha = OPAQUE; static const unsigned int borderalpha = OPAQUE;
static const char *colors[][3] = { static const char *colors[][3] = {
+1 -1
View File
@@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2
# includes and libs # includes and libs
INCS = -I${X11INC} -I${FREETYPEINC} INCS = -I${X11INC} -I${FREETYPEINC}
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender -lpthread
# flags # flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
+24 -1
View File
@@ -22,6 +22,7 @@
*/ */
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include <pthread.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
@@ -42,6 +43,7 @@
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
#include "drw.h" #include "drw.h"
#include "rainbow.c"
#include "util.h" #include "util.h"
/* macros */ /* macros */
@@ -214,6 +216,7 @@ static Client *nexttiled(Client *c);
static void pop(Client *); static void pop(Client *);
static void propertynotify(XEvent *e); static void propertynotify(XEvent *e);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static void* rainbowthread(void *arg);
static Monitor *recttomon(int x, int y, int w, int h); static Monitor *recttomon(int x, int y, int w, int h);
static void removesystrayicon(Client *i); static void removesystrayicon(Client *i);
static void resize(Client *c, int x, int y, int w, int h, int interact); static void resize(Client *c, int x, int y, int w, int h, int interact);
@@ -298,7 +301,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[ResizeRequest] = resizerequest, [ResizeRequest] = resizerequest,
[UnmapNotify] = unmapnotify [UnmapNotify] = unmapnotify
}; };
static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast]; static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast], rainbowatom;
static int running = 1; static int running = 1;
static Cur *cursor[CurLast]; static Cur *cursor[CurLast];
static Clr **scheme; static Clr **scheme;
@@ -612,6 +615,11 @@ clientmessage(XEvent *e)
} }
return; return;
} }
if (cme->message_type == rainbowatom) {
runrainbow(&scheme[SchemeSel][ColBg]);
drawbars();
return;
}
if (!c) if (!c)
return; return;
if (cme->message_type == netatom[NetWMState]) { if (cme->message_type == netatom[NetWMState]) {
@@ -1393,6 +1401,16 @@ quit(const Arg *arg)
running = 0; running = 0;
} }
void *
rainbowthread(void *arg) {
while (1) {
usleep(rainbowrate);
sendevent(0, rainbowatom, StructureNotifyMask, CurrentTime, 0, 0, 0, 0);
XSync(dpy, False);
}
return NULL;
}
Monitor * Monitor *
recttomon(int x, int y, int w, int h) recttomon(int x, int y, int w, int h)
{ {
@@ -1766,6 +1784,7 @@ setup(void)
bh = drw->fonts->h + 2; bh = drw->fonts->h + 2;
updategeom(); updategeom();
/* init atoms */ /* init atoms */
rainbowatom = XInternAtom(dpy, "RAINBOW_ATOM", False);
utf8string = XInternAtom(dpy, "UTF8_STRING", False); utf8string = XInternAtom(dpy, "UTF8_STRING", False);
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
@@ -1800,6 +1819,9 @@ setup(void)
/* init bars */ /* init bars */
updatebars(); updatebars();
updatestatus(); updatestatus();
/* init rainbow */
pthread_t thread;
pthread_create(&thread, NULL, &rainbowthread, NULL);
/* supporting window for NetWMCheck */ /* supporting window for NetWMCheck */
wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32, XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
@@ -2559,6 +2581,7 @@ zoom(const Arg *arg)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
XInitThreads();
if (argc == 2 && !strcmp("-v", argv[1])) if (argc == 2 && !strcmp("-v", argv[1]))
die("dwm-"VERSION); die("dwm-"VERSION);
else if (argc != 1) else if (argc != 1)
+40
View File
@@ -0,0 +1,40 @@
static int rainbowcurrentcolor = 0;
static const int rainbowcolorrange = 100;
static unsigned int rainbowgetcolor(double ratio);
static void runrainbow(Clr *color);
unsigned int
rainbowgetcolor(double ratio)
{
/* we want to normalize ratio so that it fits in to 6 regions */
/* where each region is 256 units long */
int normalized = (int) (ratio * 256 * 6);
/* find the distance to the start of the closest region */
int x = normalized % 256;
int red = 0, grn = 0, blu = 0;
switch(normalized / 256)
{
case 0: red = 255; grn = x; blu = 0; break;//red
case 1: red = 255 - x; grn = 255; blu = 0; break;//yellow
case 2: red = 0; grn = 255; blu = x; break;//green
case 3: red = 0; grn = 255 - x; blu = 255; break;//cyan
case 4: red = x; grn = 0; blu = 255; break;//blue
case 5: red = 255; grn = 0; blu = 255 - x; break;//magenta
}
return red + (grn << 8) + (blu << 16);
}
void
runrainbow(Clr *color) {
rainbowcurrentcolor++;
if (rainbowcurrentcolor > rainbowcolorrange)
rainbowcurrentcolor = 1;
unsigned int newColor =
rainbowgetcolor((double) (rainbowcurrentcolor) / rainbowcolorrange);
if (newColor > 0)
color->pixel = newColor;
}