diff options
| author | stkhan <personal@slickd.xyz> | 2022-03-18 08:09:07 -0800 |
|---|---|---|
| committer | stkhan <personal@slickd.xyz> | 2022-03-18 08:09:07 -0800 |
| commit | e20a439f0de08052fad50669fd005dee14d40cae (patch) | |
| tree | 8ffed60a1dce40ae64fd8f336a4d1b5d103683f1 | |
| parent | a33351c3345f7b8657e6415878a73b5fedb09d72 (diff) | |
Update dwm, added farbfeld, sent, and wmname plus more
| -rw-r--r-- | .gitignore | 30 | ||||
| -rw-r--r-- | Makefile | 26 | ||||
| -rw-r--r-- | README | 7 | ||||
| -rw-r--r-- | README.md | 14 | ||||
| -rwxr-xr-x | build.sh | 30 | ||||
| -rw-r--r-- | config.mk | 1 | ||||
| -rw-r--r-- | dmenu-5.0/Makefile | 1 | ||||
| -rw-r--r-- | dmenu-5.0/config.def.h.orig | 31 | ||||
| -rw-r--r-- | dmenu-5.0/config.mk | 1 | ||||
| -rwxr-xr-x | dmenu-5.0/dmenu | bin | 43416 -> 0 bytes | |||
| -rw-r--r-- | dmenu-5.0/dmenu.c.orig | 821 | ||||
| -rw-r--r-- | dmenu-5.0/dmenu.o | bin | 32096 -> 0 bytes | |||
| -rw-r--r-- | dmenu-5.0/drw.o | bin | 10584 -> 0 bytes | |||
| -rw-r--r-- | dmenu-5.0/patches/dmenu-alpha-20210605-1a13d04.diff (renamed from dmenu-5.0/dmenu-alpha-20210605-1a13d04.diff) | 0 | ||||
| -rwxr-xr-x | dmenu-5.0/stest | bin | 17080 -> 0 bytes | |||
| -rw-r--r-- | dmenu-5.0/stest.o | bin | 5296 -> 0 bytes | |||
| -rw-r--r-- | dmenu-5.0/util.o | bin | 2256 -> 0 bytes | |||
| -rw-r--r-- | dwm-6.2/colors.h | 40 | ||||
| -rw-r--r-- | dwm-6.2/config.h | 158 | ||||
| -rw-r--r-- | dwm-6.2/drw.c | 436 | ||||
| -rw-r--r-- | dwm-6.2/drw.h | 57 | ||||
| -rw-r--r-- | dwm-6.2/drw.o | bin | 10528 -> 0 bytes | |||
| -rwxr-xr-x | dwm-6.2/dwm | bin | 80352 -> 0 bytes | |||
| -rw-r--r-- | dwm-6.2/dwm.o | bin | 72496 -> 0 bytes | |||
| -rw-r--r-- | dwm-6.2/util.o | bin | 2256 -> 0 bytes | |||
| -rw-r--r-- | dwm-6.3/LICENSE (renamed from dwm-6.2/LICENSE) | 0 | ||||
| -rw-r--r-- | dwm-6.3/Makefile (renamed from dwm-6.2/Makefile) | 2 | ||||
| -rw-r--r-- | dwm-6.3/README (renamed from dwm-6.2/README) | 0 | ||||
| -rw-r--r-- | dwm-6.3/colors.h | 50 | ||||
| -rw-r--r-- | dwm-6.3/config.def.h (renamed from dwm-6.2/config.def.h) | 14 | ||||
| -rw-r--r-- | dwm-6.3/config.mk (renamed from dwm-6.2/config.mk) | 7 | ||||
| -rw-r--r-- | dwm-6.3/drw.c (renamed from dmenu-5.0/drw.c.orig) | 0 | ||||
| -rw-r--r-- | dwm-6.3/drw.h (renamed from dmenu-5.0/drw.h.orig) | 4 | ||||
| -rw-r--r-- | dwm-6.3/dwm.1 (renamed from dwm-6.2/dwm.1) | 2 | ||||
| -rw-r--r-- | dwm-6.3/dwm.c (renamed from dwm-6.2/dwm.c) | 170 | ||||
| -rw-r--r-- | dwm-6.3/dwm.png (renamed from dwm-6.2/dwm.png) | bin | 373 -> 373 bytes | |||
| -rw-r--r-- | dwm-6.3/patches/dwm-alpha-20201019-61bb8b2.diff (renamed from dwm-6.2/patches/dwm-alpha-20201019-61bb8b2.diff) | 0 | ||||
| -rw-r--r-- | dwm-6.3/patches/dwm-cool-autostart-6.2.diff (renamed from dwm-6.2/patches/dwm-cool-autostart-6.2.diff) | 0 | ||||
| -rw-r--r-- | dwm-6.3/patches/dwm-setstatus-6.2.diff | 49 | ||||
| -rw-r--r-- | dwm-6.3/patches/dwm-statuscmd-20210405-67d76bd.diff | 208 | ||||
| -rw-r--r-- | dwm-6.3/patches/dwm-vanitygaps-6.2.diff (renamed from dwm-6.2/patches/dwm-vanitygaps-6.2.diff) | 0 | ||||
| -rw-r--r-- | dwm-6.3/transient.c (renamed from dwm-6.2/transient.c) | 0 | ||||
| -rw-r--r-- | dwm-6.3/util.c (renamed from dwm-6.2/util.c) | 0 | ||||
| -rw-r--r-- | dwm-6.3/util.h (renamed from dwm-6.2/util.h) | 0 | ||||
| -rw-r--r-- | dwm-6.3/vanitygaps.c (renamed from dwm-6.2/vanitygaps.c) | 0 | ||||
| -rwxr-xr-x | dwm-6.3/wmbar (renamed from dwm-6.2/wmbar) | 4 | ||||
| -rwxr-xr-x | farbfeld/2ff | 38 | ||||
| -rw-r--r-- | farbfeld/2ff.1 | 45 | ||||
| -rw-r--r-- | farbfeld/FORMAT | 14 | ||||
| -rw-r--r-- | farbfeld/LICENSE | 24 | ||||
| -rw-r--r-- | farbfeld/Makefile | 68 | ||||
| -rw-r--r-- | farbfeld/README | 74 | ||||
| -rw-r--r-- | farbfeld/arg.h | 49 | ||||
| -rw-r--r-- | farbfeld/config.mk | 17 | ||||
| -rw-r--r-- | farbfeld/farbfeld.5 | 177 | ||||
| -rw-r--r-- | farbfeld/ff2jpg.1 | 54 | ||||
| -rw-r--r-- | farbfeld/ff2jpg.c | 114 | ||||
| -rw-r--r-- | farbfeld/ff2pam.1 | 38 | ||||
| -rw-r--r-- | farbfeld/ff2pam.c | 55 | ||||
| -rw-r--r-- | farbfeld/ff2png.1 | 38 | ||||
| -rw-r--r-- | farbfeld/ff2png.c | 77 | ||||
| -rw-r--r-- | farbfeld/ff2ppm.1 | 46 | ||||
| -rw-r--r-- | farbfeld/ff2ppm.c | 72 | ||||
| -rw-r--r-- | farbfeld/jpg2ff.1 | 38 | ||||
| -rw-r--r-- | farbfeld/jpg2ff.c | 90 | ||||
| -rw-r--r-- | farbfeld/png2ff.1 | 38 | ||||
| -rw-r--r-- | farbfeld/png2ff.c | 97 | ||||
| -rw-r--r-- | farbfeld/util.c | 242 | ||||
| -rw-r--r-- | farbfeld/util.h | 28 | ||||
| -rwxr-xr-x | install.sh | 14 | ||||
| -rw-r--r-- | scripts/Makefile | 6 | ||||
| -rwxr-xr-x | scripts/dmenumount | 7 | ||||
| -rwxr-xr-x | scripts/dmenuumount | 6 | ||||
| -rw-r--r-- | scripts/ip.c | 32 | ||||
| -rwxr-xr-x | scripts/mic_toggle | 2 | ||||
| -rwxr-xr-x | scripts/set_theme.sh | 9 | ||||
| -rwxr-xr-x | scripts/xrandrdmenu | 4 | ||||
| -rw-r--r-- | st-0.8.4/Makefile | 1 | ||||
| -rw-r--r-- | st-0.8.4/config.h | 2 | ||||
| -rw-r--r-- | st-0.8.4/config.mk | 1 | ||||
| -rwxr-xr-x | st-0.8.4/st | bin | 106440 -> 0 bytes | |||
| -rw-r--r-- | st-0.8.4/st.o | bin | 77144 -> 0 bytes | |||
| -rw-r--r-- | st-0.8.4/x.o | bin | 75712 -> 0 bytes | |||
| -rw-r--r-- | theme/blue_wave/blue_wave.png | bin | 0 -> 1157396 bytes | |||
| -rw-r--r-- | theme/blue_wave/colors.h | 50 | ||||
| -rw-r--r-- | theme/lake/colors.h | 50 | ||||
| -rw-r--r-- | theme/lake/lake.png | bin | 0 -> 6666092 bytes | |||
| -rw-r--r-- | theme/purple_mountain/colors.h | 2 | ||||
| -rw-r--r-- | theme/snowleopard/colors.h | 50 | ||||
| -rw-r--r-- | theme/snowleopard/snowleopard.png | bin | 0 -> 11338841 bytes | |||
| -rw-r--r-- | wmname/LICENSE | 21 | ||||
| -rw-r--r-- | wmname/Makefile | 51 | ||||
| -rw-r--r-- | wmname/README | 25 | ||||
| -rw-r--r-- | wmname/config.mk | 22 | ||||
| -rw-r--r-- | wmname/wmname.c | 53 |
95 files changed, 2472 insertions, 1632 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c303b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Object files +*.o +*.ko +*.obj +*.elf + +# Libraries +*.lib +*.a + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex +/sent + +# vim +*.swp +*~ + +config.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1e5785d --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +all: sarc + + +sarc: + ./scripts/set_theme.sh + make -C dwm-6.3 + make -C st-0.8.4 + make -C dmenu-5.0 + make -C farbfeld + make -C sent + make -C wmname +install: + make install -C dwm-6.3 + make install -C st-0.8.4 + make install -C dmenu-5.0 + make install -C scripts + make install -C farbfeld + make install -C sent + make install -C wmname +clean: + make clean -C dwm-6.3 + make clean -C st-0.8.4 + make clean -C dmenu-5.0 + make clean -C farbfeld + make clean -C sent + make clean -C wmname @@ -0,0 +1,7 @@ +sarc - my build of some suckless tools + +dwm - window manager +dmenu - a menu/launcher that can be used for other things +st - terminal +farbfeld - an image format +sent - simple presentation software diff --git a/README.md b/README.md deleted file mode 100644 index 88a5aa3..0000000 --- a/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# sarc 3.0 - -<img src="theme/purple_mountain/screenshot.png" width="500px"></img> - -## About -My patches dwm, st, dmenu, and more - -## Installation - -``` -git clone https://github.com/SkywalkerSW5/sarc -./build.sh -sudo ./install.sh -``` diff --git a/build.sh b/build.sh deleted file mode 100755 index b9962c4..0000000 --- a/build.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# A script to build sarc - -# Sets theme configuration -# To see available themes, do "ls theme/" - -echo "Welcome to the sarc installation!" -echo -echo "Choose a theme:" && ls theme/ -read theme - -cp theme/$theme/colors.h dwm-6.2/ -cp theme/$theme/$theme.png $HOME/.config/wallpaper.png - -# Compiles dwm, st, etc - -cd dwm-6.2 -make clean -make - -cd ../st-0.8.4/ -make clean -make - -cd ../dmenu-5.0/ -make clean -make -cd ../ - - diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..a67a797 --- /dev/null +++ b/config.mk @@ -0,0 +1 @@ +PREFIX=/usr/local diff --git a/dmenu-5.0/Makefile b/dmenu-5.0/Makefile index a03a95c..6b49acc 100644 --- a/dmenu-5.0/Makefile +++ b/dmenu-5.0/Makefile @@ -2,6 +2,7 @@ # See LICENSE file for copyright and license details. include config.mk +include ../config.mk SRC = drw.c dmenu.c stest.c util.c OBJ = $(SRC:.c=.o) diff --git a/dmenu-5.0/config.def.h.orig b/dmenu-5.0/config.def.h.orig deleted file mode 100644 index 697d511..0000000 --- a/dmenu-5.0/config.def.h.orig +++ /dev/null @@ -1,31 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -/* Default settings; can be overriden by command line. */ - -static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ -static const unsigned int alpha = 0xf0; -/* -fn option overrides fonts[0]; default X11 font or font set */ -static const char *fonts[] = { - "monospace:size=10" -}; -static const char *prompt = NULL; /* -p option; prompt to the left of input field */ -static const char *colors[SchemeLast][2] = { - /* fg bg */ - [SchemeNorm] = { "#bbbbbb", "#222222" }, - [SchemeSel] = { "#eeeeee", "#005577" }, - [SchemeOut] = { "#000000", "#00ffff" }, -}; - -static const unsigned int alphas[SchemeLast][2] = { - [SchemeNorm] = { OPAQUE, alpha }, - [SchemeSel] = { OPAQUE, alpha }, - [SchemeOut] = { OPAQUE, alpha }, -}; - -/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ -static unsigned int lines = 0; - -/* - * Characters not considered part of a word while deleting words - * for example: " /?\"&[]" - */ -static const char worddelimiters[] = " "; diff --git a/dmenu-5.0/config.mk b/dmenu-5.0/config.mk index 05d5a3e..57c4d69 100644 --- a/dmenu-5.0/config.mk +++ b/dmenu-5.0/config.mk @@ -2,7 +2,6 @@ VERSION = 5.0 # paths -PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man X11INC = /usr/X11R6/include diff --git a/dmenu-5.0/dmenu b/dmenu-5.0/dmenu Binary files differdeleted file mode 100755 index 3ceec6c..0000000 --- a/dmenu-5.0/dmenu +++ /dev/null diff --git a/dmenu-5.0/dmenu.c.orig b/dmenu-5.0/dmenu.c.orig deleted file mode 100644 index 3e56e1a..0000000 --- a/dmenu-5.0/dmenu.c.orig +++ /dev/null @@ -1,821 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <ctype.h> -#include <locale.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <strings.h> -#include <time.h> -#include <unistd.h> - -#include <X11/Xlib.h> -#include <X11/Xatom.h> -#include <X11/Xproto.h> -#include <X11/Xutil.h> -#ifdef XINERAMA -#include <X11/extensions/Xinerama.h> -#endif -#include <X11/Xft/Xft.h> - -#include "drw.h" -#include "util.h" - -/* macros */ -#define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ - * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) -#define LENGTH(X) (sizeof X / sizeof X[0]) -#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) - -#define OPAQUE 0xffU - -/* enums */ -enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ - -struct item { - char *text; - struct item *left, *right; - int out; -}; - -static char text[BUFSIZ] = ""; -static char *embed; -static int bh, mw, mh; -static int inputw = 0, promptw; -static int lrpad; /* sum of left and right padding */ -static size_t cursor; -static struct item *items = NULL; -static struct item *matches, *matchend; -static struct item *prev, *curr, *next, *sel; -static int mon = -1, screen; - -static Atom clip, utf8; -static Display *dpy; -static Window root, parentwin, win; -static XIC xic; - -static Drw *drw; -static Clr *scheme[SchemeLast]; - -static int useargb = 0; -static Visual *visual; -static int depth; -static Colormap cmap; - -#include "config.h" - -static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; -static char *(*fstrstr)(const char *, const char *) = strstr; -static void xinitvisual(); - -static void -appenditem(struct item *item, struct item **list, struct item **last) -{ - if (*last) - (*last)->right = item; - else - *list = item; - - item->left = *last; - item->right = NULL; - *last = item; -} - -static void -calcoffsets(void) -{ - int i, n; - - if (lines > 0) - n = lines * bh; - else - n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">")); - /* calculate which items will begin the next page and previous page */ - for (i = 0, next = curr; next; next = next->right) - if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n) - break; - for (i = 0, prev = curr; prev && prev->left; prev = prev->left) - if ((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n) - break; -} - -static void -cleanup(void) -{ - size_t i; - - XUngrabKey(dpy, AnyKey, AnyModifier, root); - for (i = 0; i < SchemeLast; i++) - free(scheme[i]); - drw_free(drw); - XSync(dpy, False); - XCloseDisplay(dpy); -} - -static char * -cistrstr(const char *s, const char *sub) -{ - size_t len; - - for (len = strlen(sub); *s; s++) - if (!strncasecmp(s, sub, len)) - return (char *)s; - return NULL; -} - -static int -drawitem(struct item *item, int x, int y, int w) -{ - if (item == sel) - drw_setscheme(drw, scheme[SchemeSel]); - else if (item->out) - drw_setscheme(drw, scheme[SchemeOut]); - else - drw_setscheme(drw, scheme[SchemeNorm]); - - return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); -} - -static void -drawmenu(void) -{ - unsigned int curpos; - struct item *item; - int x = 0, y = 0, w; - - drw_setscheme(drw, scheme[SchemeNorm]); - drw_rect(drw, 0, 0, mw, mh, 1, 1); - - if (prompt && *prompt) { - drw_setscheme(drw, scheme[SchemeSel]); - x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0); - } - /* draw input field */ - w = (lines > 0 || !matches) ? mw - x : inputw; - drw_setscheme(drw, scheme[SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); - - curpos = TEXTW(text) - TEXTW(&text[cursor]); - if ((curpos += lrpad / 2 - 1) < w) { - drw_setscheme(drw, scheme[SchemeNorm]); - drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); - } - - if (lines > 0) { - /* draw vertical list */ - for (item = curr; item != next; item = item->right) - drawitem(item, x, y += bh, mw - x); - } else if (matches) { - /* draw horizontal list */ - x += inputw; - w = TEXTW("<"); - if (curr->left) { - drw_setscheme(drw, scheme[SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0); - } - x += w; - for (item = curr; item != next; item = item->right) - x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">"))); - if (next) { - w = TEXTW(">"); - drw_setscheme(drw, scheme[SchemeNorm]); - drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0); - } - } - drw_map(drw, win, 0, 0, mw, mh); -} - -static void -grabfocus(void) -{ - struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 }; - Window focuswin; - int i, revertwin; - - for (i = 0; i < 100; ++i) { - XGetInputFocus(dpy, &focuswin, &revertwin); - if (focuswin == win) - return; - XSetInputFocus(dpy, win, RevertToParent, CurrentTime); - nanosleep(&ts, NULL); - } - die("cannot grab focus"); -} - -static void -grabkeyboard(void) -{ - struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 }; - int i; - - if (embed) - return; - /* try to grab keyboard, we may have to wait for another process to ungrab */ - for (i = 0; i < 1000; i++) { - if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, - GrabModeAsync, CurrentTime) == GrabSuccess) - return; - nanosleep(&ts, NULL); - } - die("cannot grab keyboard"); -} - -static void -match(void) -{ - static char **tokv = NULL; - static int tokn = 0; - - char buf[sizeof text], *s; - int i, tokc = 0; - size_t len, textsize; - struct item *item, *lprefix, *lsubstr, *prefixend, *substrend; - - strcpy(buf, text); - /* separate input text into tokens to be matched individually */ - for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) - if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) - die("cannot realloc %u bytes:", tokn * sizeof *tokv); - len = tokc ? strlen(tokv[0]) : 0; - - matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; - textsize = strlen(text) + 1; - for (item = items; item && item->text; item++) { - for (i = 0; i < tokc; i++) - if (!fstrstr(item->text, tokv[i])) - break; - if (i != tokc) /* not all tokens match */ - continue; - /* exact matches go first, then prefixes, then substrings */ - if (!tokc || !fstrncmp(text, item->text, textsize)) - appenditem(item, &matches, &matchend); - else if (!fstrncmp(tokv[0], item->text, len)) - appenditem(item, &lprefix, &prefixend); - else - appenditem(item, &lsubstr, &substrend); - } - if (lprefix) { - if (matches) { - matchend->right = lprefix; - lprefix->left = matchend; - } else - matches = lprefix; - matchend = prefixend; - } - if (lsubstr) { - if (matches) { - matchend->right = lsubstr; - lsubstr->left = matchend; - } else - matches = lsubstr; - matchend = substrend; - } - curr = sel = matches; - calcoffsets(); -} - -static void -insert(const char *str, ssize_t n) -{ - if (strlen(text) + n > sizeof text - 1) - return; - /* move existing text out of the way, insert new text, and update cursor */ - memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0)); - if (n > 0) - memcpy(&text[cursor], str, n); - cursor += n; - match(); -} - -static size_t -nextrune(int inc) -{ - ssize_t n; - - /* return location of next utf8 rune in the given direction (+1 or -1) */ - for (n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc) - ; - return n; -} - -static void -movewordedge(int dir) -{ - if (dir < 0) { /* move cursor to the start of the word*/ - while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) - cursor = nextrune(-1); - while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) - cursor = nextrune(-1); - } else { /* move cursor to the end of the word */ - while (text[cursor] && strchr(worddelimiters, text[cursor])) - cursor = nextrune(+1); - while (text[cursor] && !strchr(worddelimiters, text[cursor])) - cursor = nextrune(+1); - } -} - -static void -keypress(XKeyEvent *ev) -{ - char buf[32]; - int len; - KeySym ksym; - Status status; - - len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); - switch (status) { - default: /* XLookupNone, XBufferOverflow */ - return; - case XLookupChars: - goto insert; - case XLookupKeySym: - case XLookupBoth: - break; - } - - if (ev->state & ControlMask) { - switch(ksym) { - case XK_a: ksym = XK_Home; break; - case XK_b: ksym = XK_Left; break; - case XK_c: ksym = XK_Escape; break; - case XK_d: ksym = XK_Delete; break; - case XK_e: ksym = XK_End; break; - case XK_f: ksym = XK_Right; break; - case XK_g: ksym = XK_Escape; break; - case XK_h: ksym = XK_BackSpace; break; - case XK_i: ksym = XK_Tab; break; - case XK_j: /* fallthrough */ - case XK_J: /* fallthrough */ - case XK_m: /* fallthrough */ - case XK_M: ksym = XK_Return; ev->state &= ~ControlMask; break; - case XK_n: ksym = XK_Down; break; - case XK_p: ksym = XK_Up; break; - - case XK_k: /* delete right */ - text[cursor] = '\0'; - match(); - break; - case XK_u: /* delete left */ - insert(NULL, 0 - cursor); - break; - case XK_w: /* delete word */ - while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) - insert(NULL, nextrune(-1) - cursor); - while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) - insert(NULL, nextrune(-1) - cursor); - break; - case XK_y: /* paste selection */ - case XK_Y: - XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, - utf8, utf8, win, CurrentTime); - return; - case XK_Left: - movewordedge(-1); - goto draw; - case XK_Right: - movewordedge(+1); - goto draw; - case XK_Return: - case XK_KP_Enter: - break; - case XK_bracketleft: - cleanup(); - exit(1); - default: - return; - } - } else if (ev->state & Mod1Mask) { - switch(ksym) { - case XK_b: - movewordedge(-1); - goto draw; - case XK_f: - movewordedge(+1); - goto draw; - case XK_g: ksym = XK_Home; break; - case XK_G: ksym = XK_End; break; - case XK_h: ksym = XK_Up; break; - case XK_j: ksym = XK_Next; break; - case XK_k: ksym = XK_Prior; break; - case XK_l: ksym = XK_Down; break; - default: - return; - } - } - - switch(ksym) { - default: -insert: - if (!iscntrl(*buf)) - insert(buf, len); - break; - case XK_Delete: - if (text[cursor] == '\0') - return; - cursor = nextrune(+1); - /* fallthrough */ - case XK_BackSpace: - if (cursor == 0) - return; - insert(NULL, nextrune(-1) - cursor); - break; - case XK_End: - if (text[cursor] != '\0') { - cursor = strlen(text); - break; - } - if (next) { - /* jump to end of list and position items in reverse */ - curr = matchend; - calcoffsets(); - curr = prev; - calcoffsets(); - while (next && (curr = curr->right)) - calcoffsets(); - } - sel = matchend; - break; - case XK_Escape: - cleanup(); - exit(1); - case XK_Home: - if (sel == matches) { - cursor = 0; - break; - } - sel = curr = matches; - calcoffsets(); - break; - case XK_Left: - if (cursor > 0 && (!sel || !sel->left || lines > 0)) { - cursor = nextrune(-1); - break; - } - if (lines > 0) - return; - /* fallthrough */ - case XK_Up: - if (sel && sel->left && (sel = sel->left)->right == curr) { - curr = prev; - calcoffsets(); - } - break; - case XK_Next: - if (!next) - return; - sel = curr = next; - calcoffsets(); - break; - case XK_Prior: - if (!prev) - return; - sel = curr = prev; - calcoffsets(); - break; - case XK_Return: - case XK_KP_Enter: - puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); - if (!(ev->state & ControlMask)) { - cleanup(); - exit(0); - } - if (sel) - sel->out = 1; - break; - case XK_Right: - if (text[cursor] != '\0') { - cursor = nextrune(+1); - break; - } - if (lines > 0) - return; - /* fallthrough */ - case XK_Down: - if (sel && sel->right && (sel = sel->right) == next) { - curr = next; - calcoffsets(); - } - break; - case XK_Tab: - if (!sel) - return; - strncpy(text, sel->text, sizeof text - 1); - text[sizeof text - 1] = '\0'; - cursor = strlen(text); - match(); - break; - } - -draw: - drawmenu(); -} - -static void -paste(void) -{ - char *p, *q; - int di; - unsigned long dl; - Atom da; - - /* we have been given the current selection, now insert it into input */ - if (XGetWindowProperty(dpy, win, utf8, 0, (sizeof text / 4) + 1, False, - utf8, &da, &di, &dl, &dl, (unsigned char **)&p) - == Success && p) { - insert(p, (q = strchr(p, '\n')) ? q - p : (ssize_t)strlen(p)); - XFree(p); - } - drawmenu(); -} - -static void -readstdin(void) -{ - char buf[sizeof text], *p; - size_t i, imax = 0, size = 0; - unsigned int tmpmax = 0; - - /* read each line from stdin and add it to the item list */ - for (i = 0; fgets(buf, sizeof buf, stdin); i++) { - if (i + 1 >= size / sizeof *items) - if (!(items = realloc(items, (size += BUFSIZ)))) - die("cannot realloc %u bytes:", size); - if ((p = strchr(buf, '\n'))) - *p = '\0'; - if (!(items[i].text = strdup(buf))) - die("cannot strdup %u bytes:", strlen(buf) + 1); - items[i].out = 0; - drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL); - if (tmpmax > inputw) { - inputw = tmpmax; - imax = i; - } - } - if (items) - items[i].text = NULL; - inputw = items ? TEXTW(items[imax].text) : 0; - lines = MIN(lines, i); -} - -static void -run(void) -{ - XEvent ev; - - while (!XNextEvent(dpy, &ev)) { - if (XFilterEvent(&ev, win)) - continue; - switch(ev.type) { - case DestroyNotify: - if (ev.xdestroywindow.window != win) - break; - cleanup(); - exit(1); - case Expose: - if (ev.xexpose.count == 0) - drw_map(drw, win, 0, 0, mw, mh); - break; - case FocusIn: - /* regrab focus from parent window */ - if (ev.xfocus.window != win) - grabfocus(); - break; - case KeyPress: - keypress(&ev.xkey); - break; - case SelectionNotify: - if (ev.xselection.property == utf8) - paste(); - break; - case VisibilityNotify: - if (ev.xvisibility.state != VisibilityUnobscured) - XRaiseWindow(dpy, win); - break; - } - } -} - -static void -setup(void) -{ - int x, y, i, j; - unsigned int du; - XSetWindowAttributes swa; - XIM xim; - Window w, dw, *dws; - XWindowAttributes wa; - XClassHint ch = {"dmenu", "dmenu"}; -#ifdef XINERAMA - XineramaScreenInfo *info; - Window pw; - int a, di, n, area = 0; -#endif - /* init appearance */ - for (j = 0; j < SchemeLast; j++) - scheme[j] = drw_scm_create(drw, colors[j], alphas[i], 2); - - clip = XInternAtom(dpy, "CLIPBOARD", False); - utf8 = XInternAtom(dpy, "UTF8_STRING", False); - - /* calculate menu geometry */ - bh = drw->fonts->h + 2; - lines = MAX(lines, 0); - mh = (lines + 1) * bh; -#ifdef XINERAMA - i = 0; - if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { - XGetInputFocus(dpy, &w, &di); - if (mon >= 0 && mon < n) - i = mon; - else if (w != root && w != PointerRoot && w != None) { - /* find top-level window containing current input focus */ - do { - if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws) - XFree(dws); - } while (w != root && w != pw); - /* find xinerama screen with which the window intersects most */ - if (XGetWindowAttributes(dpy, pw, &wa)) - for (j = 0; j < n; j++) - if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { - area = a; - i = j; - } - } - /* no focused window is on screen, so use pointer location instead */ - if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) - for (i = 0; i < n; i++) - if (INTERSECT(x, y, 1, 1, info[i])) - break; - - x = info[i].x_org; - y = info[i].y_org + (topbar ? 0 : info[i].height - mh); - mw = info[i].width; - - XFree(info); - } else -#endif - { - if (!XGetWindowAttributes(dpy, parentwin, &wa)) - die("could not get embedding window attributes: 0x%lx", - parentwin); - x = 0; - y = topbar ? 0 : wa.height - mh; - mw = wa.width; - } - promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; - inputw = MIN(inputw, mw/3); - match(); - - /* create menu window */ - swa.override_redirect = True; - swa.background_pixel = 0; - swa.border_pixel = 0; - swa.colormap = cmap; - swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; - win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width, - depth, CopyFromParent, visual, - CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa); - XSetClassHint(dpy, win, &ch); - - - /* input methods */ - if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL) - die("XOpenIM failed: could not open input device"); - - xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - XNClientWindow, win, XNFocusWindow, win, NULL); - - XMapRaised(dpy, win); - if (embed) { - XSelectInput(dpy, parentwin, FocusChangeMask | SubstructureNotifyMask); - if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) { - for (i = 0; i < du && dws[i] != win; ++i) - XSelectInput(dpy, dws[i], FocusChangeMask); - XFree(dws); - } - grabfocus(); - } - drw_resize(drw, mw, mh); - drawmenu(); -} - -static void -usage(void) -{ - fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" - " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - XWindowAttributes wa; - int i, fast = 0; - - for (i = 1; i < argc; i++) - /* these options take no arguments */ - if (!strcmp(argv[i], "-v")) { /* prints version information */ - puts("dmenu-"VERSION); - exit(0); - } else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ - topbar = 0; - else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ - fast = 1; - else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ - fstrncmp = strncasecmp; - fstrstr = cistrstr; - } else if (i + 1 == argc) - usage(); - /* these options take one argument */ - else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ - lines = atoi(argv[++i]); - else if (!strcmp(argv[i], "-m")) - mon = atoi(argv[++i]); - else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ - prompt = argv[++i]; - else if (!strcmp(argv[i], "-fn")) /* font or font set */ - fonts[0] = argv[++i]; - else if (!strcmp(argv[i], "-nb")) /* normal background color */ - colors[SchemeNorm][ColBg] = argv[++i]; - else if (!strcmp(argv[i], "-nf")) /* normal foreground color */ - colors[SchemeNorm][ColFg] = argv[++i]; - else if (!strcmp(argv[i], "-sb")) /* selected background color */ - colors[SchemeSel][ColBg] = argv[++i]; - else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ - colors[SchemeSel][ColFg] = argv[++i]; - else if (!strcmp(argv[i], "-w")) /* embedding window id */ - embed = argv[++i]; - else - usage(); - - if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) - fputs("warning: no locale support\n", stderr); - if (!(dpy = XOpenDisplay(NULL))) - die("cannot open display"); - screen = DefaultScreen(dpy); - root = RootWindow(dpy, screen); - if (!embed || !(parentwin = strtol(embed, NULL, 0))) - parentwin = root; - if (!XGetWindowAttributes(dpy, parentwin, &wa)) - die("could not get embedding window attributes: 0x%lx", - parentwin); - xinitvisual(); - drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap); - if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) - die("no fonts could be loaded."); - lrpad = drw->fonts->h; - -#ifdef __OpenBSD__ - if (pledge("stdio rpath", NULL) == -1) - die("pledge"); -#endif - - if (fast && !isatty(0)) { - grabkeyboard(); - readstdin(); - } else { - readstdin(); - grabkeyboard(); - } - setup(); - run(); - - return 1; /* unreachable */ -} - - void -xinitvisual() -{ - XVisualInfo *infos; - XRenderPictFormat *fmt; - int nitems; - int i; - - XVisualInfo tpl = { - .screen = screen, - .depth = 32, - .class = TrueColor - }; - long masks = VisualScreenMask | VisualDepthMask | VisualClassMask; - - infos = XGetVisualInfo(dpy, masks, &tpl, &nitems); - visual = NULL; - for(i = 0; i < nitems; i ++) { - fmt = XRenderFindVisualFormat(dpy, infos[i].visual); - if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) { - visual = infos[i].visual; - depth = infos[i].depth; - cmap = XCreateColormap(dpy, root, visual, AllocNone); - useargb = 1; - break; - } - } - - XFree(infos); - - if (! visual) { - visual = DefaultVisual(dpy, screen); - depth = DefaultDepth(dpy, screen); - cmap = DefaultColormap(dpy, screen); - } -} diff --git a/dmenu-5.0/dmenu.o b/dmenu-5.0/dmenu.o Binary files differdeleted file mode 100644 index fb225c1..0000000 --- a/dmenu-5.0/dmenu.o +++ /dev/null diff --git a/dmenu-5.0/drw.o b/dmenu-5.0/drw.o Binary files differdeleted file mode 100644 index 57700fd..0000000 --- a/dmenu-5.0/drw.o +++ /dev/null diff --git a/dmenu-5.0/dmenu-alpha-20210605-1a13d04.diff b/dmenu-5.0/patches/dmenu-alpha-20210605-1a13d04.diff index 51679f7..51679f7 100644 --- a/dmenu-5.0/dmenu-alpha-20210605-1a13d04.diff +++ b/dmenu-5.0/patches/dmenu-alpha-20210605-1a13d04.diff diff --git a/dmenu-5.0/stest b/dmenu-5.0/stest Binary files differdeleted file mode 100755 index 63e0ea3..0000000 --- a/dmenu-5.0/stest +++ /dev/null diff --git a/dmenu-5.0/stest.o b/dmenu-5.0/stest.o Binary files differdeleted file mode 100644 index 4ffa357..0000000 --- a/dmenu-5.0/stest.o +++ /dev/null diff --git a/dmenu-5.0/util.o b/dmenu-5.0/util.o Binary files differdeleted file mode 100644 index 3b48c2f..0000000 --- a/dmenu-5.0/util.o +++ /dev/null diff --git a/dwm-6.2/colors.h b/dwm-6.2/colors.h deleted file mode 100644 index 8026ee1..0000000 --- a/dwm-6.2/colors.h +++ /dev/null @@ -1,40 +0,0 @@ -/* dwm color configuration */ -static const char col_gray1[] = "#222222"; -static const char col_gray2[] = "#444444"; -static const char col_gray3[] = "#bbbbbb"; -static const char col_gray4[] = "#eeeeee"; -static const char col_cyan[] = "#4B4E74"; - -/* st config */ - -float alpha = 0.6; /* some themes may have this lighter or stronger then others */ - -static const char *colorname[] = { - /* 8 normal colors */ - "#050704", /* black */ - "#d80e0e", /* red */ - "#06f115", /* green */ - "#d8ff00", /* yellow */ - "#0050d2", /* blue */ - "#802bee", /* magenta */ - "#23f0f2", /* cyan */ - "#cfcfcf", /* white */ - - /* 8 bright colors */ - "#cfcfcf", /* black */ - "#ff2857", /* red */ - "#79fc6a", /* green */ - "#d7ff62", /* yellow */ - "#698eff", /* blue */ - "#a461fb", /* magenta */ - "#91fff5", /* cyan */ - "#ffffff", /* white */ - - [255] = 0, - - /* special colors */ - "#cccccc", - "#555555", - "#000000", /* background */ - "#cfcfcf", /* foreground */ -}; diff --git a/dwm-6.2/config.h b/dwm-6.2/config.h deleted file mode 100644 index 7c82875..0000000 --- a/dwm-6.2/config.h +++ /dev/null @@ -1,158 +0,0 @@ -#include "colors.h" -/* appearance */ -static const unsigned int borderpx = 1; /* border pixel of windows */ -static const unsigned int snap = 32; /* snap pixel */ -static const unsigned int gappih = 4; /* horiz inner gap between windows */ -static const unsigned int gappiv = 4; /* vert inner gap between windows */ -static const unsigned int gappoh = 4; /* horiz outer gap between windows and screen edge */ -static const unsigned int gappov = 4; /* vert outer gap between windows and screen edge */ -static int smartgaps = 0; /* 1 means no outer gap when there is only one window */ -static const int showbar = 1; /* 0 means no bar */ -static const int topbar = 1; /* 0 means bottom bar */ -static const char *fonts[] = { "Source Code Pro:size=9" }; -static const char dmenufont[] = "Source Code Pro:size=9"; -static const char *colors[][3] = { - /* fg bg border */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, -}; - -static const char *const autostart[] = { - "picom", NULL, - "wmbar", NULL, - "dunst", NULL, - "fehbg", NULL, /* terminate */ - NULL -}; - -/* tagging */ -static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; - -static const Rule rules[] = { - /* xprop(1): - * WM_CLASS(STRING) = instance, class - * WM_NAME(STRING) = title - */ - /* class instance title tags mask isfloating monitor */ - { "Gimp", NULL, NULL, 0, 1, -1 }, - { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, -}; - -/* layout(s) */ -static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ -static const int nmaster = 1; /* number of clients in master area */ -static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ - -#define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */ -#include "vanitygaps.c" - -static const Layout layouts[] = { - /* symbol arrange function */ - { "[]=", tile }, /* first entry is default */ - { "[M]", monocle }, - { "[@]", spiral }, - { "[\\]", dwindle }, - { "H[]", deck }, - { "TTT", bstack }, - { "===", bstackhoriz }, - { "HHH", grid }, - { "###", nrowgrid }, - { "---", horizgrid }, - { ":::", gaplessgrid }, - { "|M|", centeredmaster }, - { ">M>", centeredfloatingmaster }, - { "><>", NULL }, /* no layout function means floating behavior */ - { NULL, NULL }, -}; - -/* key definitions */ -#define MODKEY Mod1Mask -#define TAGKEYS(KEY,TAG) \ - { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ - { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ - { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ - { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, - -/* helper for spawning shell commands in the pre dwm-5.0 fashion */ -#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } - -/* commands */ -static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; -static const char *termcmd[] = { "st", NULL }; - -static Key keys[] = { - /* modifier key function argument */ - { MODKEY, XK_d, spawn, {.v = dmenucmd } }, - { MODKEY, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, - { MODKEY, XK_k, focusstack, {.i = -1 } }, -/* { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_d, incnmaster, {.i = -1 } }, -*/ { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY|ShiftMask, XK_Return, zoom, {0} }, - { MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } }, - { MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } }, - { MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } }, - { MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } }, - { MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } }, - { MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } }, - { MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } }, - { MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } }, - { MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } }, - { MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } }, - { MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } }, - { MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } }, - { MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } }, - { MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } }, - { MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, - { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, - { MODKEY, XK_Tab, view, {0} }, - { MODKEY, XK_x, killclient, {0} }, - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XK_space, setlayout, {0} }, - { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, - { MODKEY, XK_0, view, {.ui = ~0 } }, - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, - { MODKEY, XK_comma, focusmon, {.i = -1 } }, - { MODKEY, XK_period, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_p, spawn, SHCMD("mic_toggle") }, - { MODKEY|ShiftMask, XK_u, spawn, SHCMD("vol_up") }, - { MODKEY|ShiftMask, XK_d, spawn, SHCMD("vol_down") }, - { MODKEY|ShiftMask, XK_m, spawn, SHCMD("mute") }, - { MODKEY|ShiftMask, XK_f, spawn, SHCMD("tabbed surf -e") }, - TAGKEYS( XK_1, 0) - TAGKEYS( XK_2, 1) - TAGKEYS( XK_3, 2) - TAGKEYS( XK_4, 3) - TAGKEYS( XK_5, 4) - TAGKEYS( XK_6, 5) - TAGKEYS( XK_7, 6) - TAGKEYS( XK_8, 7) - TAGKEYS( XK_9, 8) - { MODKEY|ShiftMask, XK_q, quit, {0} }, -}; - -/* button definitions */ -/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ -static Button buttons[] = { - /* click event mask button function argument */ - { ClkLtSymbol, 0, Button1, setlayout, {0} }, - { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, - { ClkWinTitle, 0, Button2, zoom, {0} }, - { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, - { ClkClientWin, MODKEY, Button1, movemouse, {0} }, - { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, - { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, - { ClkTagBar, 0, Button1, view, {0} }, - { ClkTagBar, 0, Button3, toggleview, {0} }, - { ClkTagBar, MODKEY, Button1, tag, {0} }, - { ClkTagBar, MODKEY, Button3, toggletag, {0} }, -}; - diff --git a/dwm-6.2/drw.c b/dwm-6.2/drw.c deleted file mode 100644 index 4cdbcbe..0000000 --- a/dwm-6.2/drw.c +++ /dev/null @@ -1,436 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xft/Xft.h> - -#include "drw.h" -#include "util.h" - -#define UTF_INVALID 0xFFFD -#define UTF_SIZ 4 - -static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; -static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; -static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; -static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; - -static long -utf8decodebyte(const char c, size_t *i) -{ - for (*i = 0; *i < (UTF_SIZ + 1); ++(*i)) - if (((unsigned char)c & utfmask[*i]) == utfbyte[*i]) - return (unsigned char)c & ~utfmask[*i]; - return 0; -} - -static size_t -utf8validate(long *u, size_t i) -{ - if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) - *u = UTF_INVALID; - for (i = 1; *u > utfmax[i]; ++i) - ; - return i; -} - -static size_t -utf8decode(const char *c, long *u, size_t clen) -{ - size_t i, j, len, type; - long udecoded; - - *u = UTF_INVALID; - if (!clen) - return 0; - udecoded = utf8decodebyte(c[0], &len); - if (!BETWEEN(len, 1, UTF_SIZ)) - return 1; - for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { - udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); - if (type) - return j; - } - if (j < len) - return 0; - *u = udecoded; - utf8validate(u, len); - - return len; -} - -Drw * -drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) -{ - Drw *drw = ecalloc(1, sizeof(Drw)); - - drw->dpy = dpy; - drw->screen = screen; - drw->root = root; - drw->w = w; - drw->h = h; - drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); - drw->gc = XCreateGC(dpy, root, 0, NULL); - XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); - - return drw; -} - -void -drw_resize(Drw *drw, unsigned int w, unsigned int h) -{ - if (!drw) - return; - - drw->w = w; - drw->h = h; - if (drw->drawable) - XFreePixmap(drw->dpy, drw->drawable); - drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); -} - -void -drw_free(Drw *drw) -{ - XFreePixmap(drw->dpy, drw->drawable); - XFreeGC(drw->dpy, drw->gc); - drw_fontset_free(drw->fonts); - free(drw); -} - -/* This function is an implementation detail. Library users should use - * drw_fontset_create instead. - */ -static Fnt * -xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) -{ - Fnt *font; - XftFont *xfont = NULL; - FcPattern *pattern = NULL; - - if (fontname) { - /* Using the pattern found at font->xfont->pattern does not yield the - * same substitution results as using the pattern returned by - * FcNameParse; using the latter results in the desired fallback - * behaviour whereas the former just results in missing-character - * rectangles being drawn, at least with some fonts. */ - if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) { - fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname); - return NULL; - } - if (!(pattern = FcNameParse((FcChar8 *) fontname))) { - fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname); - XftFontClose(drw->dpy, xfont); - return NULL; - } - } else if (fontpattern) { - if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { - fprintf(stderr, "error, cannot load font from pattern.\n"); - return NULL; - } - } else { - die("no font specified."); - } - - /* Do not allow using color fonts. This is a workaround for a BadLength - * error from Xft with color glyphs. Modelled on the Xterm workaround. See - * https://bugzilla.redhat.com/show_bug.cgi?id=1498269 - * https://lists.suckless.org/dev/1701/30932.html - * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349 - * and lots more all over the internet. - */ - FcBool iscol; - if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { - XftFontClose(drw->dpy, xfont); - return NULL; - } - - font = ecalloc(1, sizeof(Fnt)); - font->xfont = xfont; - font->pattern = pattern; - font->h = xfont->ascent + xfont->descent; - font->dpy = drw->dpy; - - return font; -} - -static void -xfont_free(Fnt *font) -{ - if (!font) - return; - if (font->pattern) - FcPatternDestroy(font->pattern); - XftFontClose(font->dpy, font->xfont); - free(font); -} - -Fnt* -drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) -{ - Fnt *cur, *ret = NULL; - size_t i; - - if (!drw || !fonts) - return NULL; - - for (i = 1; i <= fontcount; i++) { - if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { - cur->next = ret; - ret = cur; - } - } - return (drw->fonts = ret); -} - -void -drw_fontset_free(Fnt *font) -{ - if (font) { - drw_fontset_free(font->next); - xfont_free(font); - } -} - -void -drw_clr_create(Drw *drw, Clr *dest, const char *clrname) -{ - if (!drw || !dest || !clrname) - return; - - if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), - DefaultColormap(drw->dpy, drw->screen), - clrname, dest)) - die("error, cannot allocate color '%s'", clrname); -} - -/* Wrapper to create color schemes. The caller has to call free(3) on the - * returned color scheme when done using it. */ -Clr * -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) -{ - size_t i; - Clr *ret; - - /* need at least two colors for a scheme */ - if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor)))) - return NULL; - - for (i = 0; i < clrcount; i++) - drw_clr_create(drw, &ret[i], clrnames[i]); - return ret; -} - -void -drw_setfontset(Drw *drw, Fnt *set) -{ - if (drw) - drw->fonts = set; -} - -void -drw_setscheme(Drw *drw, Clr *scm) -{ - if (drw) - drw->scheme = scm; -} - -void -drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) -{ - if (!drw || !drw->scheme) - return; - XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel); - if (filled) - XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); - else - XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1); -} - -int -drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) -{ - char buf[1024]; - int ty; - unsigned int ew; - XftDraw *d = NULL; - Fnt *usedfont, *curfont, *nextfont; - size_t i, len; - int utf8strlen, utf8charlen, render = x || y || w || h; - long utf8codepoint = 0; - const char *utf8str; - FcCharSet *fccharset; - FcPattern *fcpattern; - FcPattern *match; - XftResult result; - int charexists = 0; - - if (!drw || (render && !drw->scheme) || !text || !drw->fonts) - return 0; - - if (!render) { - w = ~w; - } else { - XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); - XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); - d = XftDrawCreate(drw->dpy, drw->drawable, - DefaultVisual(drw->dpy, drw->screen), - DefaultColormap(drw->dpy, drw->screen)); - x += lpad; - w -= lpad; - } - - usedfont = drw->fonts; - while (1) { - utf8strlen = 0; - utf8str = text; - nextfont = NULL; - while (*text) { - utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ); - for (curfont = drw->fonts; curfont; curfont = curfont->next) { - charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint); - if (charexists) { - if (curfont == usedfont) { - utf8strlen += utf8charlen; - text += utf8charlen; - } else { - nextfont = curfont; - } - break; - } - } - - if (!charexists || nextfont) - break; - else - charexists = 0; - } - - if (utf8strlen) { - drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL); - /* shorten text if necessary */ - for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--) - drw_font_getexts(usedfont, utf8str, len, &ew, NULL); - - if (len) { - memcpy(buf, utf8str, len); - buf[len] = '\0'; - if (len < utf8strlen) - for (i = len; i && i > len - 3; buf[--i] = '.') - ; /* NOP */ - - if (render) { - ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; - XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], - usedfont->xfont, x, ty, (XftChar8 *)buf, len); - } - x += ew; - w -= ew; - } - } - - if (!*text) { - break; - } else if (nextfont) { - charexists = 0; - usedfont = nextfont; - } else { - /* Regardless of whether or not a fallback font is found, the - * character must be drawn. */ - charexists = 1; - - fccharset = FcCharSetCreate(); - FcCharSetAddChar(fccharset, utf8codepoint); - - if (!drw->fonts->pattern) { - /* Refer to the comment in xfont_create for more information. */ - die("the first font in the cache must be loaded from a font string."); - } - - fcpattern = FcPatternDuplicate(drw->fonts->pattern); - FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); - FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); - FcPatternAddBool(fcpattern, FC_COLOR, FcFalse); - - FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); - FcDefaultSubstitute(fcpattern); - match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); - - FcCharSetDestroy(fccharset); - FcPatternDestroy(fcpattern); - - if (match) { - usedfont = xfont_create(drw, NULL, match); - if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) { - for (curfont = drw->fonts; curfont->next; curfont = curfont->next) - ; /* NOP */ - curfont->next = usedfont; - } else { - xfont_free(usedfont); - usedfont = drw->fonts; - } - } - } - } - if (d) - XftDrawDestroy(d); - - return x + (render ? w : 0); -} - -void -drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) -{ - if (!drw) - return; - - XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); - XSync(drw->dpy, False); -} - -unsigned int -drw_fontset_getwidth(Drw *drw, const char *text) -{ - if (!drw || !drw->fonts || !text) - return 0; - return drw_text(drw, 0, 0, 0, 0, 0, text, 0); -} - -void -drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) -{ - XGlyphInfo ext; - - if (!font || !text) - return; - - XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); - if (w) - *w = ext.xOff; - if (h) - *h = font->h; -} - -Cur * -drw_cur_create(Drw *drw, int shape) -{ - Cur *cur; - - if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) - return NULL; - - cur->cursor = XCreateFontCursor(drw->dpy, shape); - - return cur; -} - -void -drw_cur_free(Drw *drw, Cur *cursor) -{ - if (!cursor) - return; - - XFreeCursor(drw->dpy, cursor->cursor); - free(cursor); -} diff --git a/dwm-6.2/drw.h b/dwm-6.2/drw.h deleted file mode 100644 index 4bcd5ad..0000000 --- a/dwm-6.2/drw.h +++ /dev/null @@ -1,57 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -typedef struct { - Cursor cursor; -} Cur; - -typedef struct Fnt { - Display *dpy; - unsigned int h; - XftFont *xfont; - FcPattern *pattern; - struct Fnt *next; -} Fnt; - -enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */ -typedef XftColor Clr; - -typedef struct { - unsigned int w, h; - Display *dpy; - int screen; - Window root; - Drawable drawable; - GC gc; - Clr *scheme; - Fnt *fonts; -} Drw; - -/* Drawable abstraction */ -Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); -void drw_resize(Drw *drw, unsigned int w, unsigned int h); -void drw_free(Drw *drw); - -/* Fnt abstraction */ -Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); -void drw_fontset_free(Fnt* set); -unsigned int drw_fontset_getwidth(Drw *drw, const char *text); -void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); - -/* Colorscheme abstraction */ -void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); - -/* Cursor abstraction */ -Cur *drw_cur_create(Drw *drw, int shape); -void drw_cur_free(Drw *drw, Cur *cursor); - -/* Drawing context manipulation */ -void drw_setfontset(Drw *drw, Fnt *set); -void drw_setscheme(Drw *drw, Clr *scm); - -/* Drawing functions */ -void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert); -int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert); - -/* Map functions */ -void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); diff --git a/dwm-6.2/drw.o b/dwm-6.2/drw.o Binary files differdeleted file mode 100644 index ecc65b6..0000000 --- a/dwm-6.2/drw.o +++ /dev/null diff --git a/dwm-6.2/dwm b/dwm-6.2/dwm Binary files differdeleted file mode 100755 index 8c801ca..0000000 --- a/dwm-6.2/dwm +++ /dev/null diff --git a/dwm-6.2/dwm.o b/dwm-6.2/dwm.o Binary files differdeleted file mode 100644 index a28b09d..0000000 --- a/dwm-6.2/dwm.o +++ /dev/null diff --git a/dwm-6.2/util.o b/dwm-6.2/util.o Binary files differdeleted file mode 100644 index 3b48c2f..0000000 --- a/dwm-6.2/util.o +++ /dev/null diff --git a/dwm-6.2/LICENSE b/dwm-6.3/LICENSE index d221f09..d221f09 100644 --- a/dwm-6.2/LICENSE +++ b/dwm-6.3/LICENSE diff --git a/dwm-6.2/Makefile b/dwm-6.3/Makefile index 03900cd..afe3788 100644 --- a/dwm-6.2/Makefile +++ b/dwm-6.3/Makefile @@ -2,6 +2,7 @@ # See LICENSE file for copyright and license details. include config.mk +include ../config.mk SRC = drw.c dwm.c util.c OBJ = ${SRC:.c=.o} @@ -39,7 +40,6 @@ dist: clean install: all mkdir -p ${DESTDIR}${PREFIX}/bin cp -f dwm ${DESTDIR}${PREFIX}/bin - cp -f wmbar ${DESTDIR}${PREFIX}/bin chmod 755 ${DESTDIR}${PREFIX}/bin/dwm mkdir -p ${DESTDIR}${MANPREFIX}/man1 sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1 diff --git a/dwm-6.2/README b/dwm-6.3/README index 95d4fd0..95d4fd0 100644 --- a/dwm-6.2/README +++ b/dwm-6.3/README diff --git a/dwm-6.3/colors.h b/dwm-6.3/colors.h new file mode 100644 index 0000000..2a89d87 --- /dev/null +++ b/dwm-6.3/colors.h @@ -0,0 +1,50 @@ +/* Sarc config file */ + +/* + * DWM CONFIGURATION +*/ + +/* primary color */ + +static const char col_cyan[] = "#5f605e"; + +/* secondary colors */ + +static const char col_gray1[] = "#0B0A13"; +static const char col_gray2[] = "#444444"; +static const char col_gray3[] = "#bbbbbb"; +static const char col_gray4[] = "#eeeeee"; + +/* st config */ + +float alpha = 0.6; + +static const char *colorname[] = { + /* 8 normal colors */ + "black", + "red3", + "green3", + "yellow3", + "blue2", + "magenta3", + "cyan3", + "gray90", + + /* 8 bright colors */ + "gray50", + "red", + "green", + "yellow", + "#5c5cff", + "magenta", + "cyan", + "white", + + [255] = 0, + + /* more colors can be added after 255 to use with DefaultXX */ + "#cccccc", + "#555555", + "#000000", /* 258 -> bg */ + "#cfcfcf", /* 259 -> fg */ +}; diff --git a/dwm-6.2/config.def.h b/dwm-6.3/config.def.h index e1c116d..ccf2dea 100644 --- a/dwm-6.2/config.def.h +++ b/dwm-6.3/config.def.h @@ -17,11 +17,18 @@ static const char col_gray2[] = "#444444"; static const char col_gray3[] = "#bbbbbb"; static const char col_gray4[] = "#eeeeee"; static const char col_cyan[] = "#005577"; +static const unsigned int baralpha = 0xd0; +static const unsigned int borderalpha = OPAQUE; static const char *colors[][3] = { /* fg bg border */ [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, [SchemeSel] = { col_gray4, col_cyan, col_cyan }, }; +static const unsigned int alphas[][3] = { + /* fg bg border */ + [SchemeNorm] = { OPAQUE, baralpha, borderalpha }, + [SchemeSel] = { OPAQUE, baralpha, borderalpha }, +}; static const char *const autostart[] = { "st", NULL, @@ -45,6 +52,7 @@ static const Rule rules[] = { static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ +static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ #define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */ #include "vanitygaps.c" @@ -79,6 +87,8 @@ static const Layout layouts[] = { /* helper for spawning shell commands in the pre dwm-5.0 fashion */ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } +#define STATUSBAR "dwmblocks" + /* commands */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; @@ -144,7 +154,9 @@ static Button buttons[] = { { ClkLtSymbol, 0, Button1, setlayout, {0} }, { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, { ClkWinTitle, 0, Button2, zoom, {0} }, - { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, + { ClkStatusText, 0, Button1, sigstatusbar, {.i = 1} }, + { ClkStatusText, 0, Button2, sigstatusbar, {.i = 2} }, + { ClkStatusText, 0, Button3, sigstatusbar, {.i = 3} }, { ClkClientWin, MODKEY, Button1, movemouse, {0} }, { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, diff --git a/dwm-6.2/config.mk b/dwm-6.3/config.mk index 6d36cb7..5cb4322 100644 --- a/dwm-6.2/config.mk +++ b/dwm-6.3/config.mk @@ -1,10 +1,9 @@ # dwm version -VERSION = 6.2 +VERSION = 6.3 # Customize below to fit your system # paths -PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include @@ -22,10 +21,10 @@ FREETYPEINC = /usr/include/freetype2 # includes and libs INCS = -I${X11INC} -I${FREETYPEINC} -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender # flags -CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} #CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} diff --git a/dmenu-5.0/drw.c.orig b/dwm-6.3/drw.c index fe3aadd..fe3aadd 100644 --- a/dmenu-5.0/drw.c.orig +++ b/dwm-6.3/drw.c diff --git a/dmenu-5.0/drw.h.orig b/dwm-6.3/drw.h index f6fa5cd..a56f523 100644 --- a/dmenu-5.0/drw.h.orig +++ b/dwm-6.3/drw.h @@ -12,7 +12,7 @@ typedef struct Fnt { struct Fnt *next; } Fnt; -enum { ColFg, ColBg }; /* Clr scheme index */ +enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */ typedef XftColor Clr; typedef struct { @@ -30,7 +30,7 @@ typedef struct { } Drw; /* Drawable abstraction */ -Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual*, unsigned int, Colormap); +Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap); void drw_resize(Drw *drw, unsigned int w, unsigned int h); void drw_free(Drw *drw); diff --git a/dwm-6.2/dwm.1 b/dwm-6.3/dwm.1 index 13b3729..ddc8321 100644 --- a/dwm-6.2/dwm.1 +++ b/dwm-6.3/dwm.1 @@ -33,7 +33,7 @@ dwm draws a small border around windows to indicate the focus state. .SH OPTIONS .TP .B \-v -prints version information to standard output, then exits. +prints version information to stderr, then exits. .SH USAGE .SS Status bar .TP diff --git a/dwm-6.2/dwm.c b/dwm-6.3/dwm.c index 5030ac4..8a2d6cf 100644 --- a/dwm-6.2/dwm.c +++ b/dwm-6.3/dwm.c @@ -57,6 +57,8 @@ #define TAGMASK ((1 << LENGTH(tags)) - 1) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) +#define OPAQUE 0xffU + /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel }; /* color schemes */ @@ -173,8 +175,10 @@ static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); +static Atom getatomprop(Client *c, Atom prop); static int getrootptr(int *x, int *y); static long getstate(Window w); +static pid_t getstatusbarpid(); static int gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, int focused); static void grabkeys(void); @@ -209,6 +213,7 @@ static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void sigchld(int unused); +static void sigstatusbar(const Arg *arg); static void spawn(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); @@ -235,12 +240,16 @@ static Monitor *wintomon(Window w); static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); +static void xinitvisual(); static void zoom(const Arg *arg); static void autostart_exec(void); /* variables */ static const char broken[] = "broken"; static char stext[256]; +static int statusw; +static int statussig; +static pid_t statuspid = -1; static int screen; static int sw, sh; /* X display screen geometry width, height */ static int bh, blw = 0; /* bar geometry */ @@ -272,6 +281,11 @@ static Drw *drw; static Monitor *mons, *selmon; static Window root, wmcheckwin; +static int useargb = 0; +static Visual *visual; +static int depth; +static Colormap cmap; + /* configuration, allows nested code to access above variables */ #include "config.h" @@ -453,6 +467,7 @@ buttonpress(XEvent *e) Client *c; Monitor *m; XButtonPressedEvent *ev = &e->xbutton; + char *text, *s, ch; click = ClkRootWin; /* focus monitor if necessary */ @@ -471,9 +486,23 @@ buttonpress(XEvent *e) arg.ui = 1 << i; } else if (ev->x < x + blw) click = ClkLtSymbol; - else if (ev->x > selmon->ww - (int)TEXTW(stext)) + else if (ev->x > selmon->ww - statusw) { + x = selmon->ww - statusw; click = ClkStatusText; - else + statussig = 0; + for (text = s = stext; *s && x <= ev->x; s++) { + if ((unsigned char)(*s) < ' ') { + ch = *s; + *s = '\0'; + x += TEXTW(text) - lrpad; + *s = ch; + text = s + 1; + if (x >= ev->x) + break; + statussig = ch; + } + } + } else click = ClkWinTitle; } else if ((c = wintoclient(ev->window))) { focus(c); @@ -731,19 +760,35 @@ dirtomon(int dir) void drawbar(Monitor *m) { - int x, w, sw = 0; + int x, w, tw = 0; int boxs = drw->fonts->h / 9; int boxw = drw->fonts->h / 6 + 2; unsigned int i, occ = 0, urg = 0; Client *c; + if (!m->showbar) return; /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ + char *text, *s, ch; drw_setscheme(drw, scheme[SchemeNorm]); - sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ - drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0); + + x = 0; + for (text = s = stext; *s; s++) { + if ((unsigned char)(*s) < ' ') { + ch = *s; + *s = '\0'; + tw = TEXTW(text) - lrpad; + drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0); + x += tw; + *s = ch; + text = s + 1; + } + } + tw = TEXTW(text) - lrpad + 2; + drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0); + tw = statusw; } for (c = m->clients; c; c = c->next) { @@ -766,7 +811,7 @@ drawbar(Monitor *m) drw_setscheme(drw, scheme[SchemeNorm]); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); - if ((w = m->ww - sw - x) > bh) { + if ((w = m->ww - tw - x) > bh) { if (m->sel) { drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); @@ -872,7 +917,7 @@ focusstack(const Arg *arg) { Client *c = NULL, *i; - if (!selmon->sel) + if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen)) return; if (arg->i > 0) { for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); @@ -909,6 +954,30 @@ getatomprop(Client *c, Atom prop) return atom; } +pid_t +getstatusbarpid() +{ + char buf[32], *str = buf, *c; + FILE *fp; + + if (statuspid > 0) { + snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid); + if ((fp = fopen(buf, "r"))) { + fgets(buf, sizeof(buf), fp); + while ((c = strchr(str, '/'))) + str = c + 1; + fclose(fp); + if (!strcmp(str, STATUSBAR)) + return statuspid; + } + } + if (!(fp = popen("pidof -s "STATUSBAR, "r"))) + return -1; + fgets(buf, sizeof(buf), fp); + pclose(fp); + return strtol(buf, NULL, 10); +} + int getrootptr(int *x, int *y) { @@ -1568,7 +1637,7 @@ setmfact(const Arg *arg) if (!arg || !selmon->lt[selmon->sellt]->arrange) return; f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; - if (f < 0.1 || f > 0.9) + if (f < 0.05 || f > 0.95) return; selmon->mfact = f; arrange(selmon); @@ -1589,7 +1658,8 @@ setup(void) sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); root = RootWindow(dpy, screen); - drw = drw_create(dpy, screen, root, sw, sh); + xinitvisual(); + drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap); if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) die("no fonts could be loaded."); lrpad = drw->fonts->h; @@ -1617,7 +1687,7 @@ setup(void) /* init appearance */ scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); for (i = 0; i < LENGTH(colors); i++) - scheme[i] = drw_scm_create(drw, colors[i], 3); + scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3); /* init bars */ updatebars(); updatestatus(); @@ -1701,6 +1771,20 @@ sigchld(int unused) } void +sigstatusbar(const Arg *arg) +{ + union sigval sv; + + if (!statussig) + return; + sv.sival_int = arg->i; + if ((statuspid = getstatusbarpid()) <= 0) + return; + + sigqueue(statuspid, SIGRTMIN+statussig, sv); +} + +void spawn(const Arg *arg) { if (arg->v == dmenucmd) @@ -1842,16 +1926,18 @@ updatebars(void) Monitor *m; XSetWindowAttributes wa = { .override_redirect = True, - .background_pixmap = ParentRelative, + .background_pixel = 0, + .border_pixel = 0, + .colormap = cmap, .event_mask = ButtonPressMask|ExposureMask }; XClassHint ch = {"dwm", "dwm"}; for (m = mons; m; m = m->next) { if (m->barwin) continue; - m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), - CopyFromParent, DefaultVisual(dpy, screen), - CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); + m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth, + InputOutput, visual, + CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa); XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); XMapRaised(dpy, m->barwin); XSetClassHint(dpy, m->barwin, &ch); @@ -2025,8 +2111,25 @@ updatesizehints(Client *c) void updatestatus(void) { - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) + if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) { strcpy(stext, "dwm-"VERSION); + statusw = TEXTW(stext) - lrpad + 2; + } else { + char *text, *s, ch; + + statusw = 0; + for (text = s = stext; *s; s++) { + if ((unsigned char)(*s) < ' ') { + ch = *s; + *s = '\0'; + statusw += TEXTW(text) - lrpad; + *s = ch; + text = s + 1; + } + } + statusw += TEXTW(text) - lrpad + 2; + + } drawbar(selmon); } @@ -2149,6 +2252,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee) } void +xinitvisual() +{ + XVisualInfo *infos; + XRenderPictFormat *fmt; + int nitems; + int i; + + XVisualInfo tpl = { + .screen = screen, + .depth = 32, + .class = TrueColor + }; + long masks = VisualScreenMask | VisualDepthMask | VisualClassMask; + + infos = XGetVisualInfo(dpy, masks, &tpl, &nitems); + visual = NULL; + for(i = 0; i < nitems; i ++) { + fmt = XRenderFindVisualFormat(dpy, infos[i].visual); + if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) { + visual = infos[i].visual; + depth = infos[i].depth; + cmap = XCreateColormap(dpy, root, visual, AllocNone); + useargb = 1; + break; + } + } + + XFree(infos); + + if (! visual) { + visual = DefaultVisual(dpy, screen); + depth = DefaultDepth(dpy, screen); + cmap = DefaultColormap(dpy, screen); + } +} + +void zoom(const Arg *arg) { Client *c = selmon->sel; diff --git a/dwm-6.2/dwm.png b/dwm-6.3/dwm.png Binary files differindex b1f9ba7..b1f9ba7 100644 --- a/dwm-6.2/dwm.png +++ b/dwm-6.3/dwm.png diff --git a/dwm-6.2/patches/dwm-alpha-20201019-61bb8b2.diff b/dwm-6.3/patches/dwm-alpha-20201019-61bb8b2.diff index 9a8e92a..9a8e92a 100644 --- a/dwm-6.2/patches/dwm-alpha-20201019-61bb8b2.diff +++ b/dwm-6.3/patches/dwm-alpha-20201019-61bb8b2.diff diff --git a/dwm-6.2/patches/dwm-cool-autostart-6.2.diff b/dwm-6.3/patches/dwm-cool-autostart-6.2.diff index 84a93ea..84a93ea 100644 --- a/dwm-6.2/patches/dwm-cool-autostart-6.2.diff +++ b/dwm-6.3/patches/dwm-cool-autostart-6.2.diff diff --git a/dwm-6.3/patches/dwm-setstatus-6.2.diff b/dwm-6.3/patches/dwm-setstatus-6.2.diff new file mode 100644 index 0000000..ae73c46 --- /dev/null +++ b/dwm-6.3/patches/dwm-setstatus-6.2.diff @@ -0,0 +1,49 @@ +From dbfb346a86c79b50bfa27c75547b42e34cb54715 Mon Sep 17 00:00:00 2001 +From: aleks <aleks.stier@icloud.com> +Date: Fri, 11 Sep 2020 17:42:50 +0200 +Subject: [PATCH] Apply setstatus-6.2 + +Enables to set the status with dwm itself. No more xsetroot bloat! +To change the status to `foo bar` execute: + + dwm -s "foo bar" + +Piping into `dwm -s` is currently not supported but you can set the +status to the output of any command by doing something like: + + dwm -s "$(run_command_which_outputs_the_status)" + +For example to set the status to the current date run: + + dwm -s "$(date)" + +--- + dwm.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/dwm.c b/dwm.c +index 4465af1..b3c8f71 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -2129,12 +2129,17 @@ main(int argc, char *argv[]) + { + if (argc == 2 && !strcmp("-v", argv[1])) + die("dwm-"VERSION); +- else if (argc != 1) ++ else if (argc != 1 && strcmp("-s", argv[1])) + die("usage: dwm [-v]"); + if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) + fputs("warning: no locale support\n", stderr); + if (!(dpy = XOpenDisplay(NULL))) + die("dwm: cannot open display"); ++ if (argc > 1 && !strcmp("-s", argv[1])) { ++ XStoreName(dpy, RootWindow(dpy, DefaultScreen(dpy)), argv[2]); ++ XCloseDisplay(dpy); ++ return 0; ++ } + checkotherwm(); + setup(); + #ifdef __OpenBSD__ +-- +2.28.0 + diff --git a/dwm-6.3/patches/dwm-statuscmd-20210405-67d76bd.diff b/dwm-6.3/patches/dwm-statuscmd-20210405-67d76bd.diff new file mode 100644 index 0000000..4b26420 --- /dev/null +++ b/dwm-6.3/patches/dwm-statuscmd-20210405-67d76bd.diff @@ -0,0 +1,208 @@ +From f58c7e4fd05ec13383518ccd51663167d45e92d0 Mon Sep 17 00:00:00 2001 +From: Daniel Bylinka <daniel.bylinka@gmail.com> +Date: Fri, 2 Apr 2021 19:02:58 +0200 +Subject: [PATCH] [statuscmd] Signal mouse button and click location to status + monitor + +--- + config.def.h | 6 +++- + dwm.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++--- + 2 files changed, 100 insertions(+), 6 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 1c0b587..154a59b 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -54,6 +54,8 @@ static const Layout layouts[] = { + /* helper for spawning shell commands in the pre dwm-5.0 fashion */ + #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } + ++#define STATUSBAR "dwmblocks" ++ + /* commands */ + static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ + static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; +@@ -103,7 +105,9 @@ static Button buttons[] = { + { ClkLtSymbol, 0, Button1, setlayout, {0} }, + { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, + { ClkWinTitle, 0, Button2, zoom, {0} }, +- { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, ++ { ClkStatusText, 0, Button1, sigstatusbar, {.i = 1} }, ++ { ClkStatusText, 0, Button2, sigstatusbar, {.i = 2} }, ++ { ClkStatusText, 0, Button3, sigstatusbar, {.i = 3} }, + { ClkClientWin, MODKEY, Button1, movemouse, {0} }, + { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, + { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, +diff --git a/dwm.c b/dwm.c +index b0b3466..d871457 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -172,6 +172,7 @@ static void focusstack(const Arg *arg); + static Atom getatomprop(Client *c, Atom prop); + static int getrootptr(int *x, int *y); + static long getstate(Window w); ++static pid_t getstatusbarpid(); + static int gettextprop(Window w, Atom atom, char *text, unsigned int size); + static void grabbuttons(Client *c, int focused); + static void grabkeys(void); +@@ -206,6 +207,7 @@ static void setup(void); + static void seturgent(Client *c, int urg); + static void showhide(Client *c); + static void sigchld(int unused); ++static void sigstatusbar(const Arg *arg); + static void spawn(const Arg *arg); + static void tag(const Arg *arg); + static void tagmon(const Arg *arg); +@@ -238,6 +240,9 @@ static void zoom(const Arg *arg); + /* variables */ + static const char broken[] = "broken"; + static char stext[256]; ++static int statusw; ++static int statussig; ++static pid_t statuspid = -1; + static int screen; + static int sw, sh; /* X display screen geometry width, height */ + static int bh, blw = 0; /* bar geometry */ +@@ -422,6 +427,7 @@ buttonpress(XEvent *e) + Client *c; + Monitor *m; + XButtonPressedEvent *ev = &e->xbutton; ++ char *text, *s, ch; + + click = ClkRootWin; + /* focus monitor if necessary */ +@@ -440,9 +446,23 @@ buttonpress(XEvent *e) + arg.ui = 1 << i; + } else if (ev->x < x + blw) + click = ClkLtSymbol; +- else if (ev->x > selmon->ww - (int)TEXTW(stext)) ++ else if (ev->x > selmon->ww - statusw) { ++ x = selmon->ww - statusw; + click = ClkStatusText; +- else ++ statussig = 0; ++ for (text = s = stext; *s && x <= ev->x; s++) { ++ if ((unsigned char)(*s) < ' ') { ++ ch = *s; ++ *s = '\0'; ++ x += TEXTW(text) - lrpad; ++ *s = ch; ++ text = s + 1; ++ if (x >= ev->x) ++ break; ++ statussig = ch; ++ } ++ } ++ } else + click = ClkWinTitle; + } else if ((c = wintoclient(ev->window))) { + focus(c); +@@ -704,9 +724,24 @@ drawbar(Monitor *m) + + /* draw status first so it can be overdrawn by tags later */ + if (m == selmon) { /* status is only drawn on selected monitor */ ++ char *text, *s, ch; + drw_setscheme(drw, scheme[SchemeNorm]); +- tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ +- drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0); ++ ++ x = 0; ++ for (text = s = stext; *s; s++) { ++ if ((unsigned char)(*s) < ' ') { ++ ch = *s; ++ *s = '\0'; ++ tw = TEXTW(text) - lrpad; ++ drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0); ++ x += tw; ++ *s = ch; ++ text = s + 1; ++ } ++ } ++ tw = TEXTW(text) - lrpad + 2; ++ drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0); ++ tw = statusw; + } + + for (c = m->clients; c; c = c->next) { +@@ -872,6 +907,30 @@ getatomprop(Client *c, Atom prop) + return atom; + } + ++pid_t ++getstatusbarpid() ++{ ++ char buf[32], *str = buf, *c; ++ FILE *fp; ++ ++ if (statuspid > 0) { ++ snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid); ++ if ((fp = fopen(buf, "r"))) { ++ fgets(buf, sizeof(buf), fp); ++ while ((c = strchr(str, '/'))) ++ str = c + 1; ++ fclose(fp); ++ if (!strcmp(str, STATUSBAR)) ++ return statuspid; ++ } ++ } ++ if (!(fp = popen("pidof -s "STATUSBAR, "r"))) ++ return -1; ++ fgets(buf, sizeof(buf), fp); ++ pclose(fp); ++ return strtol(buf, NULL, 10); ++} ++ + int + getrootptr(int *x, int *y) + { +@@ -1637,6 +1696,20 @@ sigchld(int unused) + while (0 < waitpid(-1, NULL, WNOHANG)); + } + ++void ++sigstatusbar(const Arg *arg) ++{ ++ union sigval sv; ++ ++ if (!statussig) ++ return; ++ sv.sival_int = arg->i; ++ if ((statuspid = getstatusbarpid()) <= 0) ++ return; ++ ++ sigqueue(statuspid, SIGRTMIN+statussig, sv); ++} ++ + void + spawn(const Arg *arg) + { +@@ -1990,8 +2063,25 @@ updatesizehints(Client *c) + void + updatestatus(void) + { +- if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) ++ if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) { + strcpy(stext, "dwm-"VERSION); ++ statusw = TEXTW(stext) - lrpad + 2; ++ } else { ++ char *text, *s, ch; ++ ++ statusw = 0; ++ for (text = s = stext; *s; s++) { ++ if ((unsigned char)(*s) < ' ') { ++ ch = *s; ++ *s = '\0'; ++ statusw += TEXTW(text) - lrpad; ++ *s = ch; ++ text = s + 1; ++ } ++ } ++ statusw += TEXTW(text) - lrpad + 2; ++ ++ } + drawbar(selmon); + } + +-- +2.31.0 + diff --git a/dwm-6.2/patches/dwm-vanitygaps-6.2.diff b/dwm-6.3/patches/dwm-vanitygaps-6.2.diff index 18cbd6d..18cbd6d 100644 --- a/dwm-6.2/patches/dwm-vanitygaps-6.2.diff +++ b/dwm-6.3/patches/dwm-vanitygaps-6.2.diff diff --git a/dwm-6.2/transient.c b/dwm-6.3/transient.c index 040adb5..040adb5 100644 --- a/dwm-6.2/transient.c +++ b/dwm-6.3/transient.c diff --git a/dwm-6.2/util.c b/dwm-6.3/util.c index fe044fc..fe044fc 100644 --- a/dwm-6.2/util.c +++ b/dwm-6.3/util.c diff --git a/dwm-6.2/util.h b/dwm-6.3/util.h index f633b51..f633b51 100644 --- a/dwm-6.2/util.h +++ b/dwm-6.3/util.h diff --git a/dwm-6.2/vanitygaps.c b/dwm-6.3/vanitygaps.c index 3f31593..3f31593 100644 --- a/dwm-6.2/vanitygaps.c +++ b/dwm-6.3/vanitygaps.c diff --git a/dwm-6.2/wmbar b/dwm-6.3/wmbar index efb720a..185758a 100755 --- a/dwm-6.2/wmbar +++ b/dwm-6.3/wmbar @@ -1,9 +1,9 @@ #!/bin/sh -OS="Arch Linux" +OS="Slackware 15" KERNEL=$(uname -r) HOSTNAME=$(uname -n) WMVER=sarc-3.0 # User can be printed by $USER -xsetroot -name "$USER | $KERNEL | $HOSTNAME | $WMVER" +dwm -s "$USER | $KERNEL | $OS | $HOSTNAME | $WMVER" diff --git a/farbfeld/2ff b/farbfeld/2ff new file mode 100755 index 0000000..6ce91b9 --- /dev/null +++ b/farbfeld/2ff @@ -0,0 +1,38 @@ +#!/bin/sh + +# arguments +if [ "$#" -ne 0 ]; then + echo "usage: $0" >&2 + exit 1 +fi + +# write input into temporary file +TMP=$(mktemp) +trap 'rm "$TMP"' EXIT +cat > "$TMP" + +# determine the mime-type +if [ "$(dd if="$TMP" bs=1 count=8 2>/dev/null | tr -d '\0')" = "farbfeld" ]; then + cat "$TMP" +else + MIME=$(file -ib "$TMP" | cut -d ";" -f 1) + + case "$MIME" in + image/png) + png2ff < "$TMP" + ;; + image/jpeg) + jpg2ff < "$TMP" + ;; + *) + convert "$TMP" png:- | png2ff + ;; + esac +fi + +# errors +if [ $? -ne 0 ]; then + exit 1 +else + exit 0 +fi diff --git a/farbfeld/2ff.1 b/farbfeld/2ff.1 new file mode 100644 index 0000000..426e3fd --- /dev/null +++ b/farbfeld/2ff.1 @@ -0,0 +1,45 @@ +.Dd 2018-04-11 +.Dt 2FF 1 +.Os suckless.org +.Sh NAME +.Nm 2ff +.Nd convert image to farbfeld +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +reads an image from stdin, converts it to +.Xr farbfeld 5 +and writes the result to stdout. +.Pp +.Nm +is a wrapper script around the farbfeld conversion tools +with a fallback to obtaining a PNG using +.Xr ImageMagick 1 +and passing it through +.Xr png2ff 1 . +.Pp +In case of an error +.Nm +writes a diagnostic message to stderr. +.Sh EXIT STATUS +.Bl -tag -width Ds +.It 0 +Image processed successfully. +.It 1 +An error occurred. +.El +.Sh EXAMPLES +$ +.Nm +< image.* > image.ff +.Pp +$ +.Nm +< image.* | bzip2 > image.ff.bz2 +.Sh SEE ALSO +.Xr bzip2 1 , +.Xr ImageMagick 1 , +.Xr farbfeld 5 +.Sh AUTHORS +.An Laslo Hunhold Aq Mt dev@frign.de diff --git a/farbfeld/FORMAT b/farbfeld/FORMAT new file mode 100644 index 0000000..0c082ea --- /dev/null +++ b/farbfeld/FORMAT @@ -0,0 +1,14 @@ + + FARBFELD IMAGE FORMAT SPECIFICATION + + ╔════════╤═════════════════════════════════════════════════════════╗ + ║ Bytes │ Description ║ + ╠════════╪═════════════════════════════════════════════════════════╣ + ║ 8 │ "farbfeld" magic value ║ + ╟────────┼─────────────────────────────────────────────────────────╢ + ║ 4 │ 32-Bit BE unsigned integer (width) ║ + ╟────────┼─────────────────────────────────────────────────────────╢ + ║ 4 │ 32-Bit BE unsigned integer (height) ║ + ╟────────┼─────────────────────────────────────────────────────────╢ + ║ [2222] │ 4⋅16-Bit BE unsigned integers [RGBA] / pixel, row-major ║ + ╚════════╧═════════════════════════════════════════════════════════╝ diff --git a/farbfeld/LICENSE b/farbfeld/LICENSE new file mode 100644 index 0000000..05640a5 --- /dev/null +++ b/farbfeld/LICENSE @@ -0,0 +1,24 @@ +ISC-License + +Copyright 2014-2018 Laslo Hunhold <dev@frign.de> + +Copyright 2004 Ted Unangst <tedu@openbsd.org> +Copyright 2004 Todd C. Miller <Todd.Miller@courtesan.com> +Copyright 2008 Otto Moerbeek <otto@drijf.net> +Copyright 2014-2015 Dimitris Papastamos <sin@2f30.org> +Copyright 2014-2016 Hiltjo Posthuma <hiltjo@codemadness.org> +Copyright 2015 Willy Goiffon <willy@mailoo.org> +Copyright 2016 Alexander Krotov <ilabdsf@yandex.ru> +Copyright 2017 Mattias Andrée <maandree@kth.se> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/farbfeld/Makefile b/farbfeld/Makefile new file mode 100644 index 0000000..ac3d22a --- /dev/null +++ b/farbfeld/Makefile @@ -0,0 +1,68 @@ +# See LICENSE file for copyright and license details +# farbfeld - suckless image format with conversion tools +.POSIX: + +include config.mk +include ../config.mk + +REQ = util +HDR = arg.h +BIN = png2ff ff2png jpg2ff ff2jpg ff2pam ff2ppm +SCR = 2ff +MAN1 = 2ff.1 $(BIN:=.1) +MAN5 = farbfeld.5 + +all: $(BIN) + +png2ff-LDLIBS = $(PNG-LDLIBS) +ff2png-LDLIBS = $(PNG-LDLIBS) +jpg2ff-LDLIBS = $(JPG-LDLIBS) +ff2jpg-LDLIBS = $(JPG-LDLIBS) + +png2ff: png2ff.o $(REQ:=.o) +ff2png: ff2png.o $(REQ:=.o) +jpg2ff: jpg2ff.o $(REQ:=.o) +ff2jpg: ff2jpg.o $(REQ:=.o) +ff2pam: ff2pam.o $(REQ:=.o) +ff2ppm: ff2ppm.o $(REQ:=.o) + +png2ff.o: png2ff.c config.mk $(HDR) $(REQ:=.h) +ff2png.o: ff2png.c config.mk $(HDR) $(REQ:=.h) +jpg2ff.o: jpg2ff.c config.mk $(HDR) $(REQ:=.h) +ff2jpg.o: ff2jpg.c config.mk $(HDR) $(REQ:=.h) +ff2pam.o: ff2pam.c config.mk $(HDR) $(REQ:=.h) +ff2ppm.o: ff2ppm.c config.mk $(HDR) $(REQ:=.h) + +.o: + $(CC) -o $@ $(LDFLAGS) $< $(REQ:=.o) $($*-LDLIBS) + +.c.o: + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< + +clean: + rm -f $(BIN) $(BIN:=.o) $(REQ:=.o) + +dist: + rm -rf "farbfeld-$(VERSION)" + mkdir -p "farbfeld-$(VERSION)" + cp -R FORMAT LICENSE Makefile README config.mk $(SCR) \ + $(HDR) $(BIN:=.c) $(REQ:=.c) $(REQ:=.h) \ + $(MAN1) $(MAN5) "farbfeld-$(VERSION)" + tar -cf - "farbfeld-$(VERSION)" | gzip -c > "farbfeld-$(VERSION).tar.gz" + rm -rf "farbfeld-$(VERSION)" + +install: all + mkdir -p "$(DESTDIR)$(PREFIX)/bin" + cp -f $(SCR) $(BIN) "$(DESTDIR)$(PREFIX)/bin" + for f in $(BIN) $(SCR); do chmod 755 "$(DESTDIR)$(PREFIX)/bin/$$f"; done + mkdir -p "$(DESTDIR)$(MANPREFIX)/man1" + cp -f $(MAN1) "$(DESTDIR)$(MANPREFIX)/man1" + for m in $(MAN1); do chmod 644 "$(DESTDIR)$(MANPREFIX)/man1/$$m"; done + mkdir -p "$(DESTDIR)$(MANPREFIX)/man5" + cp -f $(MAN5) "$(DESTDIR)$(MANPREFIX)/man5" + for m in $(MAN5); do chmod 644 "$(DESTDIR)$(MANPREFIX)/man5/$$m"; done + +uninstall: + for f in $(BIN) $(SCR); do rm -f "$(DESTDIR)$(PREFIX)/bin/$$f"; done + for m in $(MAN1); do rm -f "$(DESTDIR)$(MANPREFIX)/man1/$$m"; done + for m in $(MAN5); do rm -f "$(DESTDIR)$(MANPREFIX)/man5/$$m"; done diff --git a/farbfeld/README b/farbfeld/README new file mode 100644 index 0000000..1fe1125 --- /dev/null +++ b/farbfeld/README @@ -0,0 +1,74 @@ + + ███ ███ ██ ██ ███ ███ █ ██ + █ █ █ █ █ █ █ █ █ █ █ █ + ██ ███ ██ ███ ██ ██ █ █ █ + █ █ █ █ █ █ █ █ █ █ █ █ + █ █ █ █ █ ██ █ ███ ███ ██ + + +WHAT IS FARBFELD? + Farbfeld is a lossless image-format designed to be + parsed and piped easily. It is probably the simplest + image-format you can find (see FORMAT). + It does not have integrated compression, but allows + compression algorithms to work with it easily by adding + little entropy to the image data itself. This beats PNG + in many cases. + Given the free choice of compression algorithms, it + is trivial to switch to better and faster ones as they + show up in the future. + +HOW DO I USE THE TOOLS? + encoding: + png2ff < example.png > example.ff + png2ff < example.png | bzip2 > example.ff.bz2 + + decoding: + ff2png < example.ff > example.png + bzcat example.ff.bz2 | ff2png > example.png + + bzip2 is used in this example and a recommended + compression algorithm. Of course you are free + to use something else. + +WHY FARBFELD? + Current image-formats have integrated compression, + making it complicated to read the image data. + One is forced to use complex libraries like libpng, + libjpeg, libjpeg-turbo, giflib and others, read the + documentation and write a lot of boilerplate in order + to get started. + Farbfeld leaves this behind and is designed to be as + simple as possible, leaving the task of compression + to outside tools. + The simple design, which was the primary objective, + implicitly lead to the very good compression + characteristics, as it often happens when you go with + the UNIX philosophy. + Reading farbfeld images doesn't require any special + libraries. The tools in this folder are just a toolbox + to make it easy to convert between common image formats + and farbfeld. + +HOW DOES IT WORK? + In farbfeld, pattern resolution is not done while + converting, but while compressing the image. + For example, farbfeld always stores the alpha-channel, + even if the image doesn't have alpha-variation. + This may sound like a big waste at first, but as + soon as you compress an image of this kind, the + compression-algorithm (e.g. bzip2) recognizes the + pattern that every 48 bits the 16 bits store the + same information. + And the compression-algorithms get better and better + at this. + Same applies to the idea of having 16 bits per channel. + It sounds excessive, but if you for instance only have + a greyscale image, the R, G and B channels will store + the same value, which is recognized by the compression + algorithm easily. + This effectively leads to filesizes you'd normally only + reach with paletted images, and in some cases bzip2 even + beats png's compression, for instance when you're dealing + with grayscale data, line drawings, decals and even + photographs. diff --git a/farbfeld/arg.h b/farbfeld/arg.h new file mode 100644 index 0000000..7f503ec --- /dev/null +++ b/farbfeld/arg.h @@ -0,0 +1,49 @@ +/* + * ISC-License + * + * Copyright 2017 Laslo Hunhold <dev@frign.de> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef ARG_H +#define ARG_H + +extern char *argv0; + +/* int main(int argc, char *argv[]) */ +#define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void *)0); \ + *argv && (*argv)[0] == '-' && (*argv)[1]; argc--, argv++) { \ + int i_, argused_; \ + if ((*argv)[1] == '-' && !(*argv)[2]) { \ + argc--, argv++; \ + break; \ + } \ + for (i_ = 1, argused_ = 0; (*argv)[i_]; i_++) { \ + switch((*argv)[i_]) +#define ARGEND if (argused_) { \ + if ((*argv)[i_ + 1]) { \ + break; \ + } else { \ + argc--, argv++; \ + break; \ + } \ + } \ + } \ + } +#define ARGC() ((*argv)[i_]) +#define ARGF_(x) (((*argv)[i_ + 1]) ? (argused_ = 1, &((*argv)[i_ + 1])) : \ + (*(argv + 1)) ? (argused_ = 1, *(argv + 1)) : (x)) +#define EARGF(x) ARGF_(((x), exit(1), (char *)0)) +#define ARGF() ARGF_((char *)0) + +#endif diff --git a/farbfeld/config.mk b/farbfeld/config.mk new file mode 100644 index 0000000..8ba827a --- /dev/null +++ b/farbfeld/config.mk @@ -0,0 +1,17 @@ +# farbfeld version +VERSION = 4 + +# Customize below to fit your system + +# paths +MANPREFIX = $(PREFIX)/share/man + +# flags +CPPFLAGS = -D_DEFAULT_SOURCE +CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os +LDFLAGS = -s +PNG-LDLIBS = -lpng +JPG-LDLIBS = -ljpeg + +# compiler and linker +CC = cc diff --git a/farbfeld/farbfeld.5 b/farbfeld/farbfeld.5 new file mode 100644 index 0000000..55dc47c --- /dev/null +++ b/farbfeld/farbfeld.5 @@ -0,0 +1,177 @@ +.Dd 2018-04-11 +.Dt FARBFELD 5 +.Os suckless.org +.Sh NAME +.Nm farbfeld +.Nd suckless image format +.Sh DESCRIPTION +.Nm +is a +.Em lossless +image format which is easy to parse, pipe and compress. +It has the following format: +.Bd -literal -offset left +BYTES DESCRIPTION +8 "farbfeld" magic value +4 32-Bit BE unsigned integer (width) +4 32-Bit BE unsigned integer (height) +[2222] 4*16-Bit BE unsigned integers [RGBA] / pixel, row-major +.Ed +.Pp +The RGB-data should be sRGB for best interoperability and not +alpha-premultiplied. +.Sh USAGE +.Nm +provides the tools +.Xr 2ff 1 , +.Xr jpg2ff 1 , +.Xr png2ff 1 +and +.Xr ff2jpg 1 , +.Xr ff2pam 1 , +.Xr ff2png 1 , +.Xr ff2ppm 1 +to +.Em convert +to and from farbfeld images respectively. +.Pp +.Xr bzip2 1 +is recommended for +.Em compression , +giving results comparable with PNG for photographs and much better results +for other image types. +.sp +The +.Em file extension +is ".ff" and compression extensions shall be +appended (e.g. ".ff.bz2"). +.Sh MOTIVATION +.Nm +was created because the author was not satisfied with the boilerplate +and inherent complexity involved in handling common image formats +(PNG, JPEG, GIF,...), having to rely on bloated libraries while not being +able to focus on the task at hand for a given image processing problem. +.Sh EXAMPLES +The following code listing +.Em invert.c +is a ready-to-use color inverter with all necessary error handling and +reporting. This program can be integrated into a farbfeld pipeline as +follows: +.Pp +$ png2ff < image.png | invert | ff2png > image-inverted.png +.Pp +It shall be noted here that due to the simplicity of the format no +external libraries are needed to handle the farbfeld image data. The +0BSD-License gives you the freedom to throw away the license block and +just use the code as you wish. Happy hacking! +.Bd -literal -offset left +/* + * 0BSD-License + * + * (c) 2017 Laslo Hunhold <dev@frign.de> + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ +#include <arpa/inet.h> + +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +#define LEN(x) (sizeof (x) / sizeof *(x)) + +static void +invert(uint16_t rgba[4]) +{ + rgba[0] = UINT16_MAX - rgba[0]; + rgba[1] = UINT16_MAX - rgba[1]; + rgba[2] = UINT16_MAX - rgba[2]; +} + +int +main(int argc, char *argv[]) +{ + uint32_t hdr[4], width, height, i, j, k; + uint16_t rgba[4]; + + /* arguments */ + if (argc != 1) { + fprintf(stderr, "usage: %s\\n", argv[0]); + return 1; + } + + /* read header */ + if (fread(hdr, sizeof(*hdr), LEN(hdr), stdin) != LEN(hdr)) { + goto readerr; + } + if (memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) { + fprintf(stderr, "%s: invalid magic value\\n", argv[0]); + return 1; + } + width = ntohl(hdr[2]); + height = ntohl(hdr[3]); + + /* write data */ + if (fwrite(hdr, sizeof(*hdr), LEN(hdr), stdout) != 4) { + goto writerr; + } + + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + if (fread(rgba, sizeof(*rgba), LEN(rgba), + stdin) != LEN(rgba)) { + goto readerr; + } + for (k = 0; k < 4; k++) { + rgba[k] = ntohs(rgba[k]); + } + + invert(rgba); + + for (k = 0; k < 4; k++) { + rgba[k] = htons(rgba[k]); + } + if (fwrite(rgba, sizeof(*rgba), LEN(rgba), + stdout) != LEN(rgba)) { + goto writerr; + } + } + } + + /* clean up */ + if (fclose(stdout)) { + fprintf(stderr, "%s: fclose: %s\\n", argv[0], + strerror(errno)); + return 1; + } + + return 0; +readerr: + fprintf(stderr, "%s: fread: Unexpected EOF\\n", argv[0]); + return 1; +writerr: + fprintf(stderr, "%s: fwrite: %s\\n", argv[0], strerror(errno)); + return 1; +} +.Ed +.Sh SEE ALSO +.Xr 2ff 1 , +.Xr ff2jpg 1 , +.Xr ff2pam 1 , +.Xr ff2png 1 , +.Xr ff2ppm 1 , +.Xr jpg2ff 1 , +.Xr png2ff 1 +.Sh AUTHORS +.An Laslo Hunhold Aq Mt dev@frign.de diff --git a/farbfeld/ff2jpg.1 b/farbfeld/ff2jpg.1 new file mode 100644 index 0000000..745ae6e --- /dev/null +++ b/farbfeld/ff2jpg.1 @@ -0,0 +1,54 @@ +.Dd 2018-04-11 +.Dt FF2JPG 1 +.Os suckless.org +.Sh NAME +.Nm ff2jpg +.Nd convert farbfeld to JPG +.Sh SYNOPSIS +.Nm +.Op Fl b Ar colour +.Op Fl o +.Op Fl q Ar quality +.Sh DESCRIPTION +.Nm +reads a +.Xr farbfeld 5 +image from stdin, converts it to JPG (8-bit RGB) and writes the result to +stdout. +.Pp +In case of an error +.Nm +writes a diagnostic message to stderr. +.Sh OPTIONS +.Bl -tag -width Ds +.It Fl b Ar colour +Blend the transparent colours with +.Ar colour +specified as rgb, rrggbb or rrrrggggbbbb. The default is fff. +.It Fl o +Optimize the Huffman table, which reduces the file size but takes longer. +.It Fl q Ar quality +Set the output +.Ar quality +ranging from 0 to 100. The default is 85. +.El +.Sh EXIT STATUS +.Bl -tag -width Ds +.It 0 +Image processed successfully. +.It 1 +An error occurred. +.El +.Sh EXAMPLES +$ +.Nm +< image.ff > image.jpg +.Pp +$ bunzip2 < image.ff.bz2 | +.Nm +-b 0f0 -q 90 > image.jpg +.Sh SEE ALSO +.Xr bzip2 1 , +.Xr farbfeld 5 +.Sh AUTHORS +.An Hiltjo Posthuma Aq Mt hiltjo@codemadness.org diff --git a/farbfeld/ff2jpg.c b/farbfeld/ff2jpg.c new file mode 100644 index 0000000..f4514b8 --- /dev/null +++ b/farbfeld/ff2jpg.c @@ -0,0 +1,114 @@ +/* See LICENSE file for copyright and license details. */ +#include <arpa/inet.h> + +#include <errno.h> +#include <inttypes.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <jpeglib.h> + +#include "arg.h" +#include "util.h" + +static void +jpeg_error(j_common_ptr js) +{ + fprintf(stderr, "%s: libjpeg: ", argv0); + (*js->err->output_message)(js); + exit(1); +} + +static void +jpeg_setup_writer(struct jpeg_compress_struct *s, struct jpeg_error_mgr *e, + uint32_t w, uint32_t h, int quality, int opt) +{ + jpeg_create_compress(s); + e->error_exit = jpeg_error; + s->err = jpeg_std_error(e); + + jpeg_stdio_dest(s, stdout); + s->image_width = w; + s->image_height = h; + s->input_components = 3; /* color components per pixel */ + s->in_color_space = JCS_RGB; /* output color space */ + jpeg_set_defaults(s); + + if (opt) { + s->optimize_coding = 1; + } + jpeg_set_quality(s, quality, 1); + + jpeg_start_compress(s, 1); +} + +static void +usage(void) +{ + die("usage: %s [-b colour] [-o] [-q quality]", argv0); +} + +int +main(int argc, char *argv[]) +{ + struct jpeg_compress_struct jcomp; + struct jpeg_error_mgr jerr; + size_t rowlen; + uint64_t a; + uint32_t width, height, i, j, k, l; + uint16_t *row, mask[3] = { 0xffff, 0xffff, 0xffff }; + uint8_t *rowout; + int optimize = 0, quality = 85; + + /* arguments */ + ARGBEGIN { + case 'b': + if (parse_mask(EARGF(usage()), mask)) { + usage(); + } + break; + case 'o': + optimize = 1; + break; + case 'q': + quality = estrtonum(EARGF(usage()), 0, 100); + break; + default: + usage(); + } ARGEND + + if (argc) { + usage(); + } + + /* prepare */ + ff_read_header(&width, &height); + jpeg_setup_writer(&jcomp, &jerr, width, height, quality, optimize); + row = ereallocarray(NULL, width, (sizeof("RGBA") - 1) * sizeof(uint16_t)); + rowlen = width * (sizeof("RGBA") - 1); + rowout = ereallocarray(NULL, width, (sizeof("RGB") - 1) * sizeof(uint8_t)); + + /* write data */ + for (i = 0; i < height; ++i) { + efread(row, sizeof(uint16_t), rowlen, stdin); + for (j = 0, k = 0; j < rowlen; j += 4, k += 3) { + a = ntohs(row[j + 3]); + for (l = 0; l < 3; l++) { + /* alpha blending and 8-bit-reduction */ + rowout[k + l] = (a * ntohs(row[j + l]) + + (UINT16_MAX - a) * mask[l]) / + (UINT16_MAX * + (UINT16_MAX / UINT8_MAX)); + } + } + jpeg_write_scanlines(&jcomp, &rowout, 1); + } + + /* clean up */ + jpeg_finish_compress(&jcomp); + jpeg_destroy_compress(&jcomp); + + return fshut(stdout, "<stdout>"); +} diff --git a/farbfeld/ff2pam.1 b/farbfeld/ff2pam.1 new file mode 100644 index 0000000..3f4acfe --- /dev/null +++ b/farbfeld/ff2pam.1 @@ -0,0 +1,38 @@ +.Dd 2018-04-11 +.Dt FF2PAM 1 +.Os suckless.org +.Sh NAME +.Nm ff2pam +.Nd convert farbfeld to PAM +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +reads a +.Xr farbfeld 5 +image from stdin, converts it to PAM (16-bit RGBA) and writes the result +to stdout. +.Pp +In case of an error +.Nm +writes a diagnostic message to stderr. +.Sh EXIT STATUS +.Bl -tag -width Ds +.It 0 +Image processed successfully. +.It 1 +An error occurred. +.El +.Sh EXAMPLES +$ +.Nm +< image.ff > image.pam +.Pp +$ bunzip2 < image.ff.bz2 | +.Nm +> image.pam +.Sh SEE ALSO +.Xr bzip2 1 , +.Xr farbfeld 5 +.Sh AUTHORS +.An Mattias Andrée Aq Mt maandree@kth.se diff --git a/farbfeld/ff2pam.c b/farbfeld/ff2pam.c new file mode 100644 index 0000000..fca5c6f --- /dev/null +++ b/farbfeld/ff2pam.c @@ -0,0 +1,55 @@ +/* See LICENSE file for copyright and license details. */ +#include <arpa/inet.h> + +#include <errno.h> +#include <inttypes.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "util.h" + +static void +usage(void) +{ + die("usage: %s", argv0); +} + +int +main(int argc, char *argv[]) +{ + size_t rowlen; + uint32_t width, height, i; + uint16_t *row; + + /* arguments */ + argv0 = argv[0], argc--, argv++; + + if (argc) { + usage(); + } + + /* prepare */ + ff_read_header(&width, &height); + row = ereallocarray(NULL, width, (sizeof("RGBA") - 1) * sizeof(uint16_t)); + rowlen = width * (sizeof("RGBA") - 1); + + /* write data */ + printf("P7\n" + "WIDTH %" PRIu32 "\n" + "HEIGHT %" PRIu32 "\n" + "DEPTH 4\n" /* number of channels */ + "MAXVAL 65535\n" + "TUPLTYPE RGB_ALPHA\n" + "ENDHDR\n", + width, height); + + for (i = 0; i < height; i++) { + efread(row, sizeof(uint16_t), rowlen, stdin); + efwrite(row, sizeof(uint16_t), rowlen, stdout); + } + + return fshut(stdout, "<stdout>"); +} diff --git a/farbfeld/ff2png.1 b/farbfeld/ff2png.1 new file mode 100644 index 0000000..d8e1fab --- /dev/null +++ b/farbfeld/ff2png.1 @@ -0,0 +1,38 @@ +.Dd 2018-04-11 +.Dt FF2PNG 1 +.Os suckless.org +.Sh NAME +.Nm ff2png +.Nd convert farbfeld to PNG +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +reads a +.Xr farbfeld 5 +image from stdin, converts it to PNG (16-bit RGBA) and writes the result +to stdout. +.Pp +In case of an error +.Nm +writes a diagnostic message to stderr. +.Sh EXIT STATUS +.Bl -tag -width Ds +.It 0 +Image processed successfully. +.It 1 +An error occurred. +.El +.Sh EXAMPLES +$ +.Nm +< image.ff > image.png +.Pp +$ bunzip2 < image.ff.bz2 | +.Nm +> image.png +.Sh SEE ALSO +.Xr bzip2 1 , +.Xr farbfeld 5 +.Sh AUTHORS +.An Laslo Hunhold Aq Mt dev@frign.de diff --git a/farbfeld/ff2png.c b/farbfeld/ff2png.c new file mode 100644 index 0000000..193b375 --- /dev/null +++ b/farbfeld/ff2png.c @@ -0,0 +1,77 @@ +/* See LICENSE file for copyright and license details. */ +#include <arpa/inet.h> + +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <png.h> + +#include "util.h" + +static void +png_err(png_struct *pngs, const char *msg) +{ + (void)pngs; + die("libpng: %s", msg); +} + +static void +png_setup_writer(png_struct **s, png_info **i, uint32_t w, uint32_t h) +{ + *s = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_err, NULL); + *i = png_create_info_struct(*s); + + if (!*s || !*i) { + die("Failed to initialize libpng"); + } + + png_init_io(*s, stdout); + png_set_IHDR(*s, *i, w, h, 16, PNG_COLOR_TYPE_RGB_ALPHA, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, + PNG_FILTER_TYPE_BASE); + png_write_info(*s, *i); +} + +static void +usage(void) +{ + die("usage: %s", argv0); +} + +int +main(int argc, char *argv[]) +{ + png_struct *pngs; + png_info *pngi; + size_t rowlen; + uint32_t width, height, i; + uint16_t *row; + + /* arguments */ + argv0 = argv[0], argc--, argv++; + + if (argc) { + usage(); + } + + /* prepare */ + ff_read_header(&width, &height); + png_setup_writer(&pngs, &pngi, width, height); + row = ereallocarray(NULL, width, (sizeof("RGBA") - 1) * sizeof(uint16_t)); + rowlen = width * (sizeof("RGBA") - 1); + + /* write data */ + for (i = 0; i < height; ++i) { + efread(row, sizeof(uint16_t), rowlen, stdin); + png_write_row(pngs, (uint8_t *)row); + } + + /* clean up */ + png_write_end(pngs, NULL); + png_destroy_write_struct(&pngs, NULL); + + return fshut(stdout, "<stdout>"); +} diff --git a/farbfeld/ff2ppm.1 b/farbfeld/ff2ppm.1 new file mode 100644 index 0000000..1687346 --- /dev/null +++ b/farbfeld/ff2ppm.1 @@ -0,0 +1,46 @@ +.Dd 2018-04-11 +.Dt FF2PPM 1 +.Os suckless.org +.Sh NAME +.Nm ff2ppm +.Nd convert farbfeld to PPM +.Sh SYNOPSIS +.Nm +.Op Fl b Ar colour +.Sh DESCRIPTION +.Nm +reads a +.Xr farbfeld 5 +image from stdin, converts it to PPM (16-Bit RGB P6 binary format) and +writes the result to stdout. +.Pp +In case of an error +.Nm +writes a diagnostic message to stderr. +.Sh OPTIONS +.Bl -tag -width Ds +.It Fl b Ar colour +Blend the transparent colours with +.Ar colour +specified as rgb, rrggbb or rrrrggggbbbb. The default is fff. +.El +.Sh EXIT STATUS +.Bl -tag -width Ds +.It 0 +Image processed successfully. +.It 1 +An error occurred. +.El +.Sh EXAMPLES +$ +.Nm +< image.ff > image.ppm +.Pp +$ bunzip2 < image.ff.bz2 | +.Nm +-b 0f0 > image.ppm +.Sh SEE ALSO +.Xr bzip2 1 , +.Xr farbfeld 5 +.Sh AUTHORS +.An Hiltjo Posthuma Aq Mt hiltjo@codemadness.org diff --git a/farbfeld/ff2ppm.c b/farbfeld/ff2ppm.c new file mode 100644 index 0000000..9b82d9c --- /dev/null +++ b/farbfeld/ff2ppm.c @@ -0,0 +1,72 @@ +/* See LICENSE file for copyright and license details. */ +#include <arpa/inet.h> + +#include <errno.h> +#include <inttypes.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "arg.h" +#include "util.h" + +static void +usage(void) +{ + die("usage: %s [-b colour]", argv0); +} + +int +main(int argc, char *argv[]) +{ + size_t rowlen, rowoutlen; + uint64_t a; + uint32_t width, height, i, j, k, l; + uint16_t *row, mask[3] = { 0xffff, 0xffff, 0xffff }; + uint8_t *rowout; + + /* arguments */ + ARGBEGIN { + case 'b': + if (parse_mask(EARGF(usage()), mask)) { + usage(); + } + break; + default: + usage(); + } ARGEND + + if (argc) { + usage(); + } + + /* prepare */ + ff_read_header(&width, &height); + row = ereallocarray(NULL, width, (sizeof("RGBA") - 1) * sizeof(uint16_t)); + rowout = ereallocarray(NULL, width, (sizeof("RGB") - 1) * sizeof(uint8_t)); + rowlen = width * (sizeof("RGBA") - 1); + rowoutlen = width * (sizeof("RGB") - 1); + + /* write data */ + printf("P6\n%" PRIu32 " %" PRIu32 "\n255\n", width, height); + + for (i = 0; i < height; ++i) { + efread(row, sizeof(uint16_t), rowlen, stdin); + + for (j = 0, k = 0; j < rowlen; j += 4, k += 3) { + a = ntohs(row[j + 3]); + for (l = 0; l < 3; l++) { + /* alpha blending and 8-bit-reduction */ + rowout[k + l] = (a * ntohs(row[j + l]) + + (UINT16_MAX - a) * mask[l]) / + (UINT16_MAX * + (UINT16_MAX / UINT8_MAX)); + } + } + + efwrite(rowout, sizeof(uint8_t), rowoutlen, stdout); + } + + return fshut(stdout, "<stdout>"); +} diff --git a/farbfeld/jpg2ff.1 b/farbfeld/jpg2ff.1 new file mode 100644 index 0000000..6ae67e2 --- /dev/null +++ b/farbfeld/jpg2ff.1 @@ -0,0 +1,38 @@ +.Dd 2018-04-11 +.Dt JPG2FF 1 +.Os suckless.org +.Sh NAME +.Nm jpg2ff +.Nd convert JPG to farbfeld +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +reads a JPG image from stdin, converts it to +.Xr farbfeld 5 +and writes the result to stdout. +.Pp +In case of an error +.Nm +writes a diagnostic message to stderr. +.Sh EXIT STATUS +.Bl -tag -width Ds +.It 0 +Image processed successfully. +.It 1 +An error occurred. +.El +.Sh EXAMPLES +$ +.Nm +< image.jpg > image.ff +.Pp +$ +.Nm +< image.jpg | bzip2 > image.ff.bz2 +.Sh SEE ALSO +.Xr 2ff 1 , +.Xr bzip2 1 , +.Xr farbfeld 5 +.Sh AUTHORS +.An Laslo Hunhold Aq Mt dev@frign.de diff --git a/farbfeld/jpg2ff.c b/farbfeld/jpg2ff.c new file mode 100644 index 0000000..360ace4 --- /dev/null +++ b/farbfeld/jpg2ff.c @@ -0,0 +1,90 @@ +/* See LICENSE file for copyright and license details. */ +#include <arpa/inet.h> + +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <jpeglib.h> + +#include "util.h" + +static void +jpeg_error(j_common_ptr js) +{ + fprintf(stderr, "%s: libjpeg: ", argv0); + (*js->err->output_message)(js); + exit(1); +} + +static void +jpeg_setup_reader(struct jpeg_decompress_struct *s, struct jpeg_error_mgr *e, + uint32_t *w, uint32_t *h) +{ + jpeg_create_decompress(s); + e->error_exit = jpeg_error; + s->err = jpeg_std_error(e); + + jpeg_stdio_src(s, stdin); + jpeg_read_header(s, 1); + *w = s->image_width; + *h = s->image_height; + s->output_components = 3; /* color components per pixel */ + s->out_color_space = JCS_RGB; /* input color space */ + + jpeg_start_decompress(s); +} + +static void +usage(void) +{ + die("usage: %s", argv0); +} + +int +main(int argc, char *argv[]) +{ + struct jpeg_decompress_struct js; + struct jpeg_error_mgr jerr; + uint32_t width, height; + uint16_t *row; + uint8_t *rowin; + size_t rowlen, i; + + /* arguments */ + argv0 = argv[0], argc--, argv++; + + if (argc) { + usage(); + } + + /* prepare */ + jpeg_setup_reader(&js, &jerr, &width, &height); + row = ereallocarray(NULL, width, (sizeof("RGBA") - 1) * sizeof(uint16_t)); + rowlen = width * (sizeof("RGBA") - 1); + rowin = ereallocarray(NULL, width, (sizeof("RGB") - 1) * sizeof(uint8_t)); + + /* write data */ + ff_write_header(width, height); + + while (js.output_scanline < js.output_height) { + jpeg_read_scanlines(&js, &rowin, 1); + + for (i = 0; i < width; ++i) { + row[4 * i + 0] = htons(rowin[3 * i + 0] * 257); + row[4 * i + 1] = htons(rowin[3 * i + 1] * 257); + row[4 * i + 2] = htons(rowin[3 * i + 2] * 257); + row[4 * i + 3] = htons(65535); + } + + efwrite(row, sizeof(uint16_t), rowlen, stdout); + } + + /* clean up */ + jpeg_finish_decompress(&js); + jpeg_destroy_decompress(&js); + + return fshut(stdout, "<stdout>"); +} diff --git a/farbfeld/png2ff.1 b/farbfeld/png2ff.1 new file mode 100644 index 0000000..5ede5c9 --- /dev/null +++ b/farbfeld/png2ff.1 @@ -0,0 +1,38 @@ +.Dd 2018-04-11 +.Dt PNG2FF 1 +.Os suckless.org +.Sh NAME +.Nm png2ff +.Nd convert PNG to farbfeld +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +reads a PNG image from stdin, converts it to +.Xr farbfeld 5 +and writes the result to stdout. +.Pp +In case of an error +.Nm +writes a diagnostic message to stderr. +.Sh EXIT STATUS +.Bl -tag -width Ds +.It 0 +Image processed successfully. +.It 1 +An error occurred. +.El +.Sh EXAMPLES +$ +.Nm +< image.png > image.ff +.Pp +$ +.Nm +< image.png | bzip2 > image.ff.bz2 +.Sh SEE ALSO +.Xr 2ff 1 , +.Xr bzip2 1 , +.Xr farbfeld 5 +.Sh AUTHORS +.An Laslo Hunhold Aq Mt dev@frign.de diff --git a/farbfeld/png2ff.c b/farbfeld/png2ff.c new file mode 100644 index 0000000..74109d8 --- /dev/null +++ b/farbfeld/png2ff.c @@ -0,0 +1,97 @@ +/* See LICENSE file for copyright and license details. */ +#include <arpa/inet.h> + +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <png.h> + +#include "util.h" + +static void +png_err(png_struct *pngs, const char *msg) +{ + (void)pngs; + die("libpng: %s", msg); +} + +static void +png_setup_reader(png_struct **s, png_info **i, uint32_t *w, uint32_t *h) +{ + *s = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, png_err, NULL); + *i = png_create_info_struct(*s); + + if (!*s || !*i) { + die("Failed to initialize libpng"); + } + + png_init_io(*s, stdin); + if (png_get_valid(*s, *i, PNG_INFO_tRNS)) { + png_set_tRNS_to_alpha(*s); + } + png_set_add_alpha(*s, 255*257, PNG_FILLER_AFTER); + png_set_expand_gray_1_2_4_to_8(*s); + png_set_gray_to_rgb(*s); + png_set_packing(*s); + png_read_png(*s, *i, PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL); + *w = png_get_image_width(*s, *i); + *h = png_get_image_height(*s, *i); +} + +static void +usage(void) +{ + die("usage: %s", argv0); +} + +int +main(int argc, char *argv[]) +{ + png_struct *pngs; + png_info *pngi; + uint32_t width, height, rowlen, r, i; + uint16_t *row; + uint8_t **pngrows; + + /* arguments */ + argv0 = argv[0], argc--, argv++; + + if (argc) { + usage(); + } + + /* prepare */ + png_setup_reader(&pngs, &pngi, &width, &height); + row = ereallocarray(NULL, width, (sizeof("RGBA") - 1) * sizeof(uint16_t)); + rowlen = width * (sizeof("RGBA") - 1); + pngrows = png_get_rows(pngs, pngi); + + /* write data */ + ff_write_header(width, height); + + switch(png_get_bit_depth(pngs, pngi)) { + case 8: + for (r = 0; r < height; ++r) { + for (i = 0; i < rowlen; i++) { + row[i] = htons(257 * pngrows[r][i]); + } + efwrite(row, sizeof(uint16_t), rowlen, stdout); + } + break; + case 16: + for (r = 0; r < height; ++r) { + efwrite(pngrows[r], sizeof(uint16_t), rowlen, stdout); + } + break; + default: + die("Invalid bit-depth"); + } + + /* clean up */ + png_destroy_read_struct(&pngs, &pngi, NULL); + + return fshut(stdout, "<stdout>"); +} diff --git a/farbfeld/util.c b/farbfeld/util.c new file mode 100644 index 0000000..6418bc9 --- /dev/null +++ b/farbfeld/util.c @@ -0,0 +1,242 @@ +/* See LICENSE file for copyright and license details. */ +#include <arpa/inet.h> + +#include <errno.h> +#include <limits.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> + +#include "util.h" + +char *argv0; + +static void +verr(const char *fmt, va_list ap) +{ + if (argv0 && strncmp(fmt, "usage", sizeof("usage") - 1)) { + fprintf(stderr, "%s: ", argv0); + } + + vfprintf(stderr, fmt, ap); + + if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { + fputc(' ', stderr); + perror(NULL); + } else { + fputc('\n', stderr); + } +} + +void +warn(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + verr(fmt, ap); + va_end(ap); +} + +void +die(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + verr(fmt, ap); + va_end(ap); + + exit(1); +} + +void +ff_read_header(uint32_t *width, uint32_t *height) +{ + uint32_t hdr[4]; + + efread(hdr, sizeof(*hdr), LEN(hdr), stdin); + + if (memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) { + die("Invalid magic value"); + } + + *width = ntohl(hdr[2]); + *height = ntohl(hdr[3]); +} + +void +ff_write_header(uint32_t width, uint32_t height) +{ + uint32_t tmp; + + fputs("farbfeld", stdout); + + tmp = htonl(width); + efwrite(&tmp, sizeof(tmp), 1, stdout); + + tmp = htonl(height); + efwrite(&tmp, sizeof(tmp), 1, stdout); +} + +int +parse_mask(const char *s, uint16_t mask[3]) +{ + size_t slen, i; + unsigned int col[3], colfac; + char fmt[] = "%#x%#x%#x"; + + slen = strlen(s); + if (slen != 3 && slen != 6 && slen != 12) { + return 1; + } + + fmt[1] = fmt[4] = fmt[7] = ((slen / 3) + '0'); + if (sscanf(s, fmt, col, col + 1, col + 2) != 3) { + return 1; + } + + colfac = (slen == 3) ? UINT16_MAX / 0xf : + (slen == 6) ? UINT16_MAX / 0xff : + UINT16_MAX / 0xffff; + + for (i = 0; i < 3; i++) { + mask[i] = col[i] * colfac; + } + + return 0; +} + +int +fshut(FILE *fp, const char *fname) +{ + int ret = 0; + + /* fflush() is undefined for input streams by ISO C, + * but not POSIX 2008 if you ignore ISO C overrides. + * Leave it unchecked and rely on the following + * functions to detect errors. + */ + fflush(fp); + + if (ferror(fp) && !ret) { + warn("ferror '%s':", fname); + ret = 1; + } + + if (fclose(fp) && !ret) { + warn("fclose '%s':", fname); + ret = 1; + } + + return ret; +} + +void +efread(void *p, size_t s, size_t n, FILE *f) +{ + if (fread(p, s, n, f) != n) { + if (ferror(f)) { + die("fread:"); + } else { + die("fread: Unexpected end of file"); + } + } +} + +void +efwrite(const void *p, size_t s, size_t n, FILE *f) +{ + if (fwrite(p, s, n, f) != n) { + die("fwrite:"); + } +} + +void * +ereallocarray(void *optr, size_t nmemb, size_t size) +{ + void *p; + + if (!(p = reallocarray(optr, nmemb, size))) { + die("reallocarray: Out of memory"); + } + + return p; +} + +long long +estrtonum(const char *numstr, long long minval, long long maxval) +{ + const char *errstr; + long long ll; + + ll = strtonum(numstr, minval, maxval, &errstr); + if (errstr) { + die("strtonum '%s': %s", numstr, errstr); + } + + return ll; +} + +/* + * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX + * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW + */ +#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) + +void * +reallocarray(void *optr, size_t nmemb, size_t size) +{ + if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && + nmemb > 0 && SIZE_MAX / nmemb < size) { + errno = ENOMEM; + return NULL; + } + return realloc(optr, size * nmemb); +} + +#define INVALID 1 +#define TOOSMALL 2 +#define TOOLARGE 3 + +long long +strtonum(const char *numstr, long long minval, long long maxval, + const char **errstrp) +{ + long long ll = 0; + int error = 0; + char *ep; + struct errval { + const char *errstr; + int err; + } ev[4] = { + { NULL, 0 }, + { "invalid", EINVAL }, + { "too small", ERANGE }, + { "too large", ERANGE }, + }; + + ev[0].err = errno; + errno = 0; + if (minval > maxval) { + error = INVALID; + } else { + ll = strtoll(numstr, &ep, 10); + if (numstr == ep || *ep != '\0') + error = INVALID; + else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) + error = TOOSMALL; + else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) + error = TOOLARGE; + } + if (errstrp != NULL) + *errstrp = ev[error].errstr; + errno = ev[error].err; + if (error) + ll = 0; + + return (ll); +} diff --git a/farbfeld/util.h b/farbfeld/util.h new file mode 100644 index 0000000..f6e32c6 --- /dev/null +++ b/farbfeld/util.h @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdint.h> +#include <stdio.h> + +#define LEN(x) (sizeof (x) / sizeof *(x)) + +extern char *argv0; + +void warn(const char *, ...); +void die(const char *, ...); + +void ff_read_header(uint32_t *width, uint32_t *height); +void ff_write_header(uint32_t width, uint32_t height); + +int parse_mask(const char *, uint16_t mask[3]); + +int fshut(FILE *, const char *); + +void efread(void *, size_t, size_t, FILE *); +void efwrite(const void *, size_t, size_t, FILE *); + +#undef reallocarray +void *reallocarray(void *, size_t, size_t); +void *ereallocarray(void *optr, size_t nmemb, size_t size); + +#undef strtonum +long long strtonum(const char *, long long, long long, const char **); +long long estrtonum(const char *, long long, long long); diff --git a/install.sh b/install.sh deleted file mode 100755 index 430f61a..0000000 --- a/install.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -cd scripts/ -cp * /usr/local/bin/ - -cd ../dmenu-5.0/ -make install - -cd ../dwm-6.2 -make install - -cd ../st-0.8.4 -make install -cd .. diff --git a/scripts/Makefile b/scripts/Makefile new file mode 100644 index 0000000..b275cfb --- /dev/null +++ b/scripts/Makefile @@ -0,0 +1,6 @@ +include ../config.mk + +install: + cp brighter darker vol_down vol_up mute mic_toggle $(PREFIX)/bin +clean: + rm $(PREFIX)/bin/{brighter,darker,vol_down,vol_up,mute,mic_toggle} diff --git a/scripts/dmenumount b/scripts/dmenumount new file mode 100755 index 0000000..9556063 --- /dev/null +++ b/scripts/dmenumount @@ -0,0 +1,7 @@ +#!/bin/sh + +DEVICE=$(lsblk -o NAME -n -r -p | dmenu) +ROOT="sudo" +MOUNTPOINT=$(echo -e "/mnt\n/mnt2" | dmenu) + +$ROOT mount $DEVICE $MOUNTPOINT diff --git a/scripts/dmenuumount b/scripts/dmenuumount new file mode 100755 index 0000000..b921b04 --- /dev/null +++ b/scripts/dmenuumount @@ -0,0 +1,6 @@ +#!/bin/sh + +DEVICE=$(lsblk -o NAME -n -r -p | dmenu) +ROOT=$(sudo) + +$ROOT umount $DEVICE diff --git a/scripts/ip.c b/scripts/ip.c new file mode 100644 index 0000000..3276696 --- /dev/null +++ b/scripts/ip.c @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <unistd.h> +#include <string.h> /* for strncpy */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <netinet/in.h> +#include <net/if.h> +#include <arpa/inet.h> + +int +main() +{ + int fd; + struct ifreq ifr; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + + /* I want to get an IPv4 IP address */ + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ-1); + + ioctl(fd, SIOCGIFADDR, &ifr); + + close(fd); + + /* display result */ + printf("%s\n", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + + return 0; +} diff --git a/scripts/mic_toggle b/scripts/mic_toggle index f36e8a4..044b9d6 100755 --- a/scripts/mic_toggle +++ b/scripts/mic_toggle @@ -1,3 +1,3 @@ #!/bin/sh -amixer set Capture toggle +amixer -D pulse sset Capture toggle notify-send "Toggled mute" diff --git a/scripts/set_theme.sh b/scripts/set_theme.sh new file mode 100755 index 0000000..c25883d --- /dev/null +++ b/scripts/set_theme.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +echo "Choose a theme:" && ls ./theme/ +read theme + +cp ./theme/$theme/$theme.png $HOME/.config/wallpaper.png +cp ./theme/$theme/colors.h ./dwm-6.3 + +echo "Done" diff --git a/scripts/xrandrdmenu b/scripts/xrandrdmenu new file mode 100755 index 0000000..f6a918e --- /dev/null +++ b/scripts/xrandrdmenu @@ -0,0 +1,4 @@ +#!/bin/sh + +OUTPUT=$(xrandr | grep " connected " | awk '{ print$1 }' | dmenu) +CHOICE=$(echo "Change resolution\nCh diff --git a/st-0.8.4/Makefile b/st-0.8.4/Makefile index 470ac86..c0aa027 100644 --- a/st-0.8.4/Makefile +++ b/st-0.8.4/Makefile @@ -3,6 +3,7 @@ .POSIX: include config.mk +include ../config.mk SRC = st.c x.c OBJ = $(SRC:.c=.o) diff --git a/st-0.8.4/config.h b/st-0.8.4/config.h index 6ac76a1..ae92fc9 100644 --- a/st-0.8.4/config.h +++ b/st-0.8.4/config.h @@ -1,4 +1,4 @@ -#include "../dwm-6.2/colors.h" +#include "../dwm-6.3/colors.h" /* See LICENSE file for copyright and license details. */ /* diff --git a/st-0.8.4/config.mk b/st-0.8.4/config.mk index aaa54ff..5672e9a 100644 --- a/st-0.8.4/config.mk +++ b/st-0.8.4/config.mk @@ -4,7 +4,6 @@ VERSION = 0.8.4 # Customize below to fit your system # paths -PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man X11INC = /usr/X11R6/include diff --git a/st-0.8.4/st b/st-0.8.4/st Binary files differdeleted file mode 100755 index b5216af..0000000 --- a/st-0.8.4/st +++ /dev/null diff --git a/st-0.8.4/st.o b/st-0.8.4/st.o Binary files differdeleted file mode 100644 index e3f7921..0000000 --- a/st-0.8.4/st.o +++ /dev/null diff --git a/st-0.8.4/x.o b/st-0.8.4/x.o Binary files differdeleted file mode 100644 index 5eb1e8b..0000000 --- a/st-0.8.4/x.o +++ /dev/null diff --git a/theme/blue_wave/blue_wave.png b/theme/blue_wave/blue_wave.png Binary files differnew file mode 100644 index 0000000..14fdc12 --- /dev/null +++ b/theme/blue_wave/blue_wave.png diff --git a/theme/blue_wave/colors.h b/theme/blue_wave/colors.h new file mode 100644 index 0000000..5ed1f78 --- /dev/null +++ b/theme/blue_wave/colors.h @@ -0,0 +1,50 @@ +/* Sarc config file */ + +/* + * DWM CONFIGURATION +*/ + +/* primary color */ + +static const char col_cyan[] = "#001D7B"; + +/* secondary colors */ + +static const char col_gray1[] = "#000000"; +static const char col_gray2[] = "#444444"; +static const char col_gray3[] = "#ffffff"; +static const char col_gray4[] = "#ffffff"; + +/* st config */ + +float alpha = 0.6; + +static const char *colorname[] = { + /* 8 normal colors */ + "black", + "red3", + "green3", + "yellow3", + "blue2", + "magenta3", + "cyan3", + "gray90", + + /* 8 bright colors */ + "gray50", + "red", + "green", + "yellow", + "#5c5cff", + "magenta", + "cyan", + "white", + + [255] = 0, + + /* more colors can be added after 255 to use with DefaultXX */ + "#cccccc", + "#555555", + "#000000", /* 258 -> bg */ + "#cfcfcf", /* 259 -> fg */ +}; diff --git a/theme/lake/colors.h b/theme/lake/colors.h new file mode 100644 index 0000000..2a89d87 --- /dev/null +++ b/theme/lake/colors.h @@ -0,0 +1,50 @@ +/* Sarc config file */ + +/* + * DWM CONFIGURATION +*/ + +/* primary color */ + +static const char col_cyan[] = "#5f605e"; + +/* secondary colors */ + +static const char col_gray1[] = "#0B0A13"; +static const char col_gray2[] = "#444444"; +static const char col_gray3[] = "#bbbbbb"; +static const char col_gray4[] = "#eeeeee"; + +/* st config */ + +float alpha = 0.6; + +static const char *colorname[] = { + /* 8 normal colors */ + "black", + "red3", + "green3", + "yellow3", + "blue2", + "magenta3", + "cyan3", + "gray90", + + /* 8 bright colors */ + "gray50", + "red", + "green", + "yellow", + "#5c5cff", + "magenta", + "cyan", + "white", + + [255] = 0, + + /* more colors can be added after 255 to use with DefaultXX */ + "#cccccc", + "#555555", + "#000000", /* 258 -> bg */ + "#cfcfcf", /* 259 -> fg */ +}; diff --git a/theme/lake/lake.png b/theme/lake/lake.png Binary files differnew file mode 100644 index 0000000..7879e49 --- /dev/null +++ b/theme/lake/lake.png diff --git a/theme/purple_mountain/colors.h b/theme/purple_mountain/colors.h index 8026ee1..5f4f2b2 100644 --- a/theme/purple_mountain/colors.h +++ b/theme/purple_mountain/colors.h @@ -7,7 +7,7 @@ static const char col_cyan[] = "#4B4E74"; /* st config */ -float alpha = 0.6; /* some themes may have this lighter or stronger then others */ +float alpha = 0.8; /* some themes may have this lighter or stronger then others */ static const char *colorname[] = { /* 8 normal colors */ diff --git a/theme/snowleopard/colors.h b/theme/snowleopard/colors.h new file mode 100644 index 0000000..c1cb087 --- /dev/null +++ b/theme/snowleopard/colors.h @@ -0,0 +1,50 @@ +/* Sarc config file */ + +/* + * DWM CONFIGURATION +*/ + +/* primary color */ + +static const char col_cyan[] = "#CD63C8"; + +/* secondary colors */ + +static const char col_gray1[] = "#0B0A13"; +static const char col_gray2[] = "#444444"; +static const char col_gray3[] = "#bbbbbb"; +static const char col_gray4[] = "#eeeeee"; + +/* st config */ + +float alpha = 0.6; + +static const char *colorname[] = { + /* 8 normal colors */ + "black", + "red3", + "green3", + "yellow3", + "blue2", + "magenta3", + "cyan3", + "gray90", + + /* 8 bright colors */ + "gray50", + "red", + "green", + "yellow", + "#5c5cff", + "magenta", + "cyan", + "white", + + [255] = 0, + + /* more colors can be added after 255 to use with DefaultXX */ + "#cccccc", + "#555555", + "#000000", /* 258 -> bg */ + "#cfcfcf", /* 259 -> fg */ +}; diff --git a/theme/snowleopard/snowleopard.png b/theme/snowleopard/snowleopard.png Binary files differnew file mode 100644 index 0000000..480ced0 --- /dev/null +++ b/theme/snowleopard/snowleopard.png diff --git a/wmname/LICENSE b/wmname/LICENSE new file mode 100644 index 0000000..bf73bff --- /dev/null +++ b/wmname/LICENSE @@ -0,0 +1,21 @@ +MIT/X Consortium License + +© 2008 Anselm R Garbe <garbeam at gmail dot com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/wmname/Makefile b/wmname/Makefile new file mode 100644 index 0000000..61e7027 --- /dev/null +++ b/wmname/Makefile @@ -0,0 +1,51 @@ +# wmname - prints/sets the WM name + +include config.mk +include ../config.mk + +SRC = wmname.c +OBJ = ${SRC:.c=.o} + +all: options wmname + +options: + @echo wmname build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "CC = ${CC}" + @echo "LD = ${LD}" + +.c.o: + @echo CC $< + @${CC} -c ${CFLAGS} $< + +${OBJ}: config.mk + +wmname: ${OBJ} + @echo LD $@ + @${LD} -o $@ ${OBJ} ${LDFLAGS} + @strip $@ + +clean: + @echo cleaning + @rm -f wmname ${OBJ} wmname-${VERSION}.tar.gz + +dist: clean + @echo creating dist tarball + @mkdir -p wmname-${VERSION} + @cp -R LICENSE Makefile README config.mk ${SRC} wmname-${VERSION} + @tar -cf wmname-${VERSION}.tar wmname-${VERSION} + @gzip wmname-${VERSION}.tar + @rm -rf wmname-${VERSION} + +install: all + @echo installing executable file to ${DESTDIR}${PREFIX}/bin + @mkdir -p ${DESTDIR}${PREFIX}/bin + @cp -f wmname ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/wmname + +uninstall: + @echo removing executable file from ${DESTDIR}${PREFIX}/bin + @rm -f ${DESTDIR}${PREFIX}/bin/wmname + +.PHONY: all options clean dist install uninstall diff --git a/wmname/README b/wmname/README new file mode 100644 index 0000000..a7d4b2c --- /dev/null +++ b/wmname/README @@ -0,0 +1,25 @@ +wmname - prints/sets the WM name +================================ +Prints/sets the EWMH WM name property. + + +Requirements +------------ +In order to build wmname you need the Xlib header files. + + +Installation +------------ +Edit config.mk to match your local setup (wmname is installed into +the /usr/local namespace by default). + +Afterwards enter the following command to build and install wmname +(if necessary as root): + + make clean install + + +Running wmname +-------------- +Run 'wmname' to print the current WM name. Run 'wmname <name>' to set it. This +is pretty much similiar to hostname(1). diff --git a/wmname/config.mk b/wmname/config.mk new file mode 100644 index 0000000..3291924 --- /dev/null +++ b/wmname/config.mk @@ -0,0 +1,22 @@ +# wmname version +VERSION = 0.1 + +# Customize below to fit your system + +MANPREFIX = ${PREFIX}/share/man + +X11INC = /usr/X11R6/include +X11LIB = /usr/X11R6/lib + +# includes and libs +INCS = -I. -I/usr/include -I${X11INC} +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 + +# flags +CPPFLAGS = -DVERSION=\"${VERSION}\" +CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} +LDFLAGS = -s ${LIBS} + +# compiler and linker +CC = cc +LD = ${CC} diff --git a/wmname/wmname.c b/wmname/wmname.c new file mode 100644 index 0000000..7d846f3 --- /dev/null +++ b/wmname/wmname.c @@ -0,0 +1,53 @@ +/* See LICENSE file for details. */ +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <X11/Xutil.h> + +void +eprint(const char *errstr, ...) { + va_list ap; + + va_start(ap, errstr); + vfprintf(stderr, errstr, ap); + va_end(ap); + exit(EXIT_FAILURE); +} + +int +main(int argc, char **argv) { + int status, format; + unsigned char *data = NULL; + unsigned long n, extra; + Display *dpy; + Window root; + Atom netwmcheck, netwmname, utf8_string, real; + + if(argc > 2) + eprint("usage: wmname [name] [-v]\n"); + else if(argc == 2 && !strncmp(argv[1], "-v", 3)) + eprint("wmname-"VERSION", © 2008 Anselm R Garbe\n", stdout); + + if(!(dpy = XOpenDisplay(0))) + eprint("wmname: cannot open display\n"); + root = DefaultRootWindow(dpy); + netwmcheck = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); + netwmname = XInternAtom(dpy, "_NET_WM_NAME", False); + utf8_string = XInternAtom(dpy, "UTF8_STRING", False); + if(argc == 1) { + status = XGetWindowProperty(dpy, root, netwmname, 0L, 32L, False, utf8_string, &real, &format, &n, &extra, (unsigned char **) &data); + if(status == Success && data != NULL) + fprintf(stdout, "%s\n", data); + XFree(data); + } + else { + XChangeProperty(dpy, root, netwmcheck, XA_WINDOW, 32, PropModeReplace, (unsigned char *)&root, 1); + XChangeProperty(dpy, root, netwmname, utf8_string, 8, PropModeReplace, (unsigned char *)argv[1], strlen(argv[1])); + } + XSync(dpy, False); + XCloseDisplay(dpy); + return 0; +} |