replace a lot of suckless coding decisions with my own

This commit is contained in:
speedie 2023-05-06 14:29:45 +02:00
parent 104d46640b
commit c1d36670fa
21 changed files with 126 additions and 268 deletions

View file

@ -1,6 +1,4 @@
void
moveleft(Arg *arg)
{
void moveleft(Arg *arg) {
struct item *tmpsel;
int i, offscreen = 0;
int argu = arg->i ? arg->i : 1;
@ -36,9 +34,7 @@ moveleft(Arg *arg)
}
}
void
moveright(Arg *arg)
{
void moveright(Arg *arg) {
struct item *tmpsel;
int i, offscreen = 0;
int argu = arg->i ? arg->i : 1;
@ -73,10 +69,7 @@ moveright(Arg *arg)
}
}
void
movedown(Arg *arg)
{
void movedown(Arg *arg) {
int argu = arg->i ? arg->i : 1;
for (int j = 0; j < argu; j++) {
@ -89,9 +82,7 @@ movedown(Arg *arg)
drawmenu();
}
void
moveup(Arg *arg)
{
void moveup(Arg *arg) {
int argu = arg->i ? arg->i : 1;
for (int j = 0; j < argu; j++) {
@ -104,20 +95,18 @@ moveup(Arg *arg)
drawmenu();
}
void
complete(Arg *arg)
{
void complete(Arg *arg) {
if (hideitem) return;
strncpy(text, sel->clntext, sizeof text - 1);
text[sizeof text - 1] = '\0';
cursor = strlen(text);
match();
drawmenu();
}
void
movenext(Arg *arg)
{
void movenext(Arg *arg) {
if (!next)
return;
@ -126,9 +115,7 @@ movenext(Arg *arg)
drawmenu();
}
void
moveprev(Arg *arg)
{
void moveprev(Arg *arg) {
if (!prev)
return;
@ -137,9 +124,7 @@ moveprev(Arg *arg)
drawmenu();
}
void
movestart(Arg *arg)
{
void movestart(Arg *arg) {
if (sel == matches) {
cursor = 0;
drawmenu();
@ -151,9 +136,7 @@ movestart(Arg *arg)
drawmenu();
}
void
moveend(Arg *arg)
{
void moveend(Arg *arg) {
if (text[cursor] != '\0') {
cursor = strlen(text);
drawmenu();
@ -174,9 +157,7 @@ moveend(Arg *arg)
drawmenu();
}
void
paste(Arg *arg)
{
void paste(Arg *arg) {
int clipboard;
if (arg->i == 1) {
@ -190,9 +171,7 @@ paste(Arg *arg)
}
void
viewhist(Arg *arg)
{
void viewhist(Arg *arg) {
int i;
if (histfile) {
@ -218,9 +197,7 @@ viewhist(Arg *arg)
drawmenu();
}
void
deleteword(Arg *arg)
{
void deleteword(Arg *arg) {
if (cursor == 0) return;
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) {
@ -232,9 +209,7 @@ deleteword(Arg *arg)
drawmenu();
}
void
moveword(Arg *arg)
{
void moveword(Arg *arg) {
if (arg->i < 0) { // move cursor to the start of the word
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) {
cursor = nextrune(-1);
@ -252,9 +227,7 @@ moveword(Arg *arg)
drawmenu();
}
void
movecursor(Arg *arg)
{
void movecursor(Arg *arg) {
if (arg->i < 0) {
if (cursor > 0) {
cursor = nextrune(-1);
@ -268,9 +241,7 @@ movecursor(Arg *arg)
drawmenu();
}
void
backspace(Arg *arg)
{
void backspace(Arg *arg) {
if (cursor == 0)
return;
@ -278,9 +249,7 @@ backspace(Arg *arg)
drawmenu();
}
void
selectitem(Arg *arg)
{
void selectitem(Arg *arg) {
char *selection;
if (sel && arg->i && !hideitem) {
@ -299,31 +268,23 @@ selectitem(Arg *arg)
exit(0);
}
void
navhistory(Arg *arg)
{
void navhistory(Arg *arg) {
navigatehistfile(arg->i);
drawmenu();
}
void
restoresel(Arg *arg)
{
void restoresel(Arg *arg) {
text[cursor] = '\0';
match();
drawmenu();
}
void
clear(Arg *arg)
{
void clear(Arg *arg) {
insert(NULL, 0 - cursor);
drawmenu();
}
void
clearins(Arg *arg)
{
void clearins(Arg *arg) {
insert(NULL, 0 - cursor);
curMode = 1;
@ -334,16 +295,12 @@ clearins(Arg *arg)
drawmenu();
}
void
quit(Arg *arg)
{
void quit(Arg *arg) {
cleanup();
exit(1);
exit(0);
}
void
savehistory(char *input)
{
void savehistory(char *input) {
unsigned int i;
FILE *fp;
@ -378,17 +335,13 @@ out:
free(history);
}
void
setimgsize(Arg *arg)
{
void setimgsize(Arg *arg) {
#if USEIMAGE
setimagesize(imagewidth + arg->i, imageheight + arg->i);
#endif
}
void
flipimg(Arg *arg)
{
void flipimg(Arg *arg) {
#if USEIMAGE
if (!image) return;
@ -400,9 +353,7 @@ flipimg(Arg *arg)
#endif
}
void
setimgpos(Arg *arg)
{
void setimgpos(Arg *arg) {
#if USEIMAGE
if (!image || hideimage) return;
@ -416,9 +367,7 @@ setimgpos(Arg *arg)
#endif
}
void
setimggaps(Arg *arg)
{
void setimggaps(Arg *arg) {
#if USEIMAGE
imagegaps += arg->i;
@ -435,9 +384,7 @@ setimggaps(Arg *arg)
#endif
}
void
rotateimg(Arg *arg)
{
void rotateimg(Arg *arg) {
#if USEIMAGE
if (!image || hideimage) return;
@ -448,9 +395,7 @@ rotateimg(Arg *arg)
#endif
}
void
toggleimg(Arg *arg)
{
void toggleimg(Arg *arg) {
#if USEIMAGE
hideimage = !hideimage;
@ -460,9 +405,7 @@ toggleimg(Arg *arg)
#endif
}
void
defaultimg(Arg *arg)
{
void defaultimg(Arg *arg) {
#if USEIMAGE
if (hideimage || !image) return;
@ -477,9 +420,7 @@ defaultimg(Arg *arg)
#endif
}
void
setlines(Arg *arg)
{
void setlines(Arg *arg) {
lines += arg->i;
if (lines < 0) lines = 0;
@ -488,9 +429,7 @@ setlines(Arg *arg)
drawmenu();
}
void
setcolumns(Arg *arg)
{
void setcolumns(Arg *arg) {
columns += arg->i;
if (columns < 1) columns = 1;
@ -499,27 +438,31 @@ setcolumns(Arg *arg)
drawmenu();
}
void
spawn(Arg *arg)
{
void spawn(Arg *arg) {
if (!system(arg->c))
die("spmenu: failed to execute command '%s'", arg->c);
else
exit(0);
}
void
togglehighlight(Arg *arg)
{
void togglehighlight(Arg *arg) {
hidehighlight = !hidehighlight;
drawmenu();
}
void
setprofile(Arg *arg)
{
if (!system("command -v spmenu_profile > /dev/null && spmenu_profile --spmenu-set-profile"))
void setprofile(Arg *arg) {
if (!system("command -v spmenu_profile > /dev/null && spmenu_profile --spmenu-set-profile")) {
die("spmenu: failed to run profile menu\n");
else
} else {
exit(0);
}
}
void switchmode(Arg *arg) {
curMode = !curMode;
allowkeys = !curMode;
strncpy(modetext, curMode ? instext : normtext, 15);
drawmenu();
}

View file

@ -40,3 +40,4 @@ static void setcolumns(Arg *arg);
static void spawn(Arg *arg);
static void togglehighlight(Arg *arg);
static void setprofile(Arg *arg);
static void switchmode(Arg *arg);

View file

@ -1,6 +1,4 @@
void
readargs(int argc, char *argv[])
{
void readargs(int argc, char *argv[]) {
int i = 0;
int j = 0;
int k = 0;
@ -433,9 +431,7 @@ readargs(int argc, char *argv[])
insert(input, strlen(input));
}
void
usage(void)
{
void usage(void) {
// print help
fputs("spmenu: fancy dynamic menu\n\n"
"- Arguments -\n"

View file

@ -1,6 +1,4 @@
void
prepare_window_size(void)
{
void prepare_window_size(void) {
// set horizontal and vertical padding
sp = menupaddingh;
vp = (menuposition == 1) ? menupaddingv : - menupaddingv;
@ -8,9 +6,7 @@ prepare_window_size(void)
return;
}
void
create_window(int x, int y, int w, int h)
{
void create_window(int x, int y, int w, int h) {
XSetWindowAttributes swa;
swa.override_redirect = managed ? False : True;
@ -32,27 +28,22 @@ create_window(int x, int y, int w, int h)
return;
}
void
set_window(void)
{
void set_window(void) {
XClassHint ch = { class, class };
// set border and class
XSetWindowBorder(dpy, win, scheme[SchemeBorder][ColBg].pixel);
XSetClassHint(dpy, win, &ch);
return;
}
void
set_prop(void)
{
void set_prop(void) {
if (dockproperty) XChangeProperty(dpy, win, types, XA_ATOM, 32, PropModeReplace, (unsigned char *) &dock, 1); // set dock property
return;
}
void
resizeclient(void)
{
void resizeclient(void) {
int omh = mh;
int x, y;
#if USEXINERAMA

View file

@ -40,7 +40,7 @@ static char *colors[SchemeLast][2] = {
[SchemeBorder] = { NULL, col_border },
};
// sgr color array
// sgr color array, first 16 colors are defined in the config, the rest are 256 colors
static char *textcolors[] = {
col_sgr0,
col_sgr1,

View file

@ -1,9 +1,7 @@
#include <libconfig.h>
#include "../theme/theme.c"
void
conf_init(void)
{
void conf_init(void) {
char *xdg_conf;
char *cfgfile = NULL;
char *home = NULL;

View file

@ -1,4 +1,4 @@
// declare macros
// declare various macros
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
#define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \
@ -13,11 +13,3 @@
// item
#define MAXITEMLENGTH 1024
// user friendly names for all the modifiers we're using, but there are many more
#define Ctrl ControlMask
#define Shift ShiftMask
#define Alt Mod1Mask
#define AltGr Mod3Mask
#define Super Mod4Mask
#define ShiftGr Mod5Mask

View file

@ -6,6 +6,14 @@ typedef struct {
Arg arg;
} Key;
// user friendly names for all the modifiers we're using, but there are many more
#define Ctrl ControlMask
#define Shift ShiftMask
#define Alt Mod1Mask
#define AltGr Mod3Mask
#define Super Mod4Mask
#define ShiftGr Mod5Mask
static void updatenumlockmask(void);
static void keypress(XEvent *e);
static void grabkeyboard(void);

View file

@ -1,6 +1,4 @@
void
fuzzymatch(void)
{
void fuzzymatch(void) {
struct item *it;
struct item **fuzzymatches = NULL;
struct item *lhpprefix, *hpprefixend;
@ -83,9 +81,7 @@ fuzzymatch(void)
}
}
void
match(void)
{
void match(void) {
if (fuzzy) {
fuzzymatch();
return;
@ -165,9 +161,7 @@ match(void)
calcoffsets();
}
int
compare_distance(const void *a, const void *b)
{
int compare_distance(const void *a, const void *b) {
struct item *da = *(struct item **) a;
struct item *db = *(struct item **) b;

View file

@ -1,10 +0,0 @@
void
switchmode(Arg *arg)
{
curMode = !curMode;
allowkeys = !curMode;
strncpy(modetext, curMode ? instext : normtext, 15);
drawmenu();
}

View file

@ -1,8 +0,0 @@
static char modetext[16] = "Insert"; // default mode text
// mode settings
static int curMode = 1; // 0 is command mode
static int allowkeys = 1; // whether or not to interpret a keypress as an insertion
// mode functions
static void switchmode(Arg *arg);

View file

@ -1,6 +1,4 @@
void
buttonpress(XEvent *e)
{
void buttonpress(XEvent *e) {
struct item *item;
XButtonPressedEvent *ev = &e->xbutton;
int x = 0, y = 0, h = bh, w, item_num = 0;

View file

@ -1,7 +1,5 @@
#if USERTL
void
apply_fribidi(char *str)
{
void apply_fribidi(char *str) {
FriBidiStrIndex len = strlen(str);
FriBidiChar logical[BUFSIZ];
FriBidiChar visual[BUFSIZ];
@ -10,22 +8,18 @@ apply_fribidi(char *str)
fribidi_boolean result;
fribidi_text[0] = 0;
if (len>0) {
if (len > 0) {
charset = fribidi_parse_charset("UTF-8");
len = fribidi_charset_to_unicode(charset, str, len, logical);
result = fribidi_log2vis(logical, len, &base, visual, NULL, NULL, NULL);
len = fribidi_unicode_to_charset(charset, visual, len, fribidi_text);
}
if (result)
return;
else
return;
if (result||!result) return;
}
#else
void
apply_fribidi(char *str)
{
void apply_fribidi(char *str) {
return;
}
#endif

View file

@ -1,12 +1,8 @@
char
sixd_to_8bit(int x)
{
char sixd_to_8bit(int x) {
return x == 0 ? 0 : 0x37 + 0x28 * x;
}
void
init_appearance(void)
{
void init_appearance(void) {
int i, j;
char cbuf[8];

View file

@ -6,9 +6,7 @@
#include "main.h"
void *
ecalloc(size_t nmemb, size_t size)
{
void * ecalloc(size_t nmemb, size_t size) {
void *p;
if (!(p = calloc(nmemb, size)))
@ -16,8 +14,7 @@ ecalloc(size_t nmemb, size_t size)
return p;
}
void
die(const char *fmt, ...) {
void die(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);

View file

@ -1,6 +1,4 @@
char **
tokenize(char *source, const char *delim, int *llen)
{
char ** tokenize(char *source, const char *delim, int *llen) {
int listlength = 0, list_size = 0;
char **list = NULL, *token;
@ -20,9 +18,7 @@ tokenize(char *source, const char *delim, int *llen)
return list;
}
int
arrayhas(char **list, int length, char *item)
{
int arrayhas(char **list, int length, char *item) {
int i;
for (i = 0; i < length; i++) {

View file

@ -1,6 +1,4 @@
void
readstdin(void)
{
void readstdin(void) {
char buf[sizeof text], *p;
size_t i, imax = 0, itemsiz = 0;
unsigned int tmpmax = 0;

View file

@ -1,6 +1,4 @@
void
theme_load(void)
{
void theme_load(void) {
char *xdg_conf;
char *theme = NULL;
char *home = NULL;

View file

@ -1,6 +1,4 @@
void
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
{
void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst) {
char *sdst = NULL;
int *idst = NULL;
float *fdst = NULL;
@ -29,9 +27,7 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
}
}
void
load_xresources(void)
{
void load_xresources(void) {
Display *display;
char *resm;
XrmDatabase db;

View file

@ -158,6 +158,7 @@ ResourcePref resources[] = {
{ "pango_highlight", INTEGER, &pango_highlight },
};
// global colors
ResourcePref cols[] = {
{ "color10", STRING, &col_caretfg },
{ "color0", STRING, &col_caretbg },

View file

@ -94,6 +94,11 @@
// include macros and other defines
#include "libs/define.c"
// mode
static char modetext[16] = "Insert"; // default mode text
static int curMode = 1; // 0 is command mode
static int allowkeys = 1; // whether or not to interpret a keypress as an insertion
// various headers
#include "libs/libdrw/draw.h"
#include "libs/sl/main.h"
@ -101,7 +106,6 @@
#include "libs/stream.h"
#include "libs/schemes.h"
#include "libs/arg.h"
#include "libs/mode.h"
#include "libs/xrdb.h"
#include "libs/key.h"
#include "libs/mouse.h"
@ -208,6 +212,8 @@ static void navigatehistfile(int dir);
static void grabfocus(void);
static void pastesel(void);
static void appenditem(struct item *item, struct item **list, struct item **last);
static void xinitvisual(void);
static void setupdisplay(void);
static int max_textw(void);
static size_t nextrune(int inc);
@ -248,7 +254,6 @@ static char *(*fstrstr)(const char *, const char *) = cistrstr;
#include "libs/argv.h"
#include "libs/argv.c"
#include "libs/xrdb.c"
#include "libs/mode.c"
#include "libs/client.h"
#include "libs/client.c"
#include "libs/match.h"
@ -257,9 +262,7 @@ static char *(*fstrstr)(const char *, const char *) = cistrstr;
#include "libs/arg.c"
#include "libs/stream.c"
void
appenditem(struct item *item, struct item **list, struct item **last)
{
void appenditem(struct item *item, struct item **list, struct item **last) {
if (*last)
(*last)->right = item;
else
@ -270,9 +273,7 @@ appenditem(struct item *item, struct item **list, struct item **last)
*last = item;
}
void
recalculatenumbers(void)
{
void recalculatenumbers(void) {
unsigned int numer = 0, denom = 0;
struct item *item;
if (matchend) {
@ -290,9 +291,7 @@ recalculatenumbers(void)
snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
}
void
calcoffsets(void)
{
void calcoffsets(void) {
int i, n;
if (lines > 0)
@ -327,9 +326,7 @@ calcoffsets(void)
break;
}
int
max_textw(void)
{
int max_textw(void) {
int len = 0;
for (struct item *item = items; item && item->text; item++)
@ -338,9 +335,7 @@ max_textw(void)
return len;
}
void
cleanup(void)
{
void cleanup(void) {
size_t i;
#if USEIMAGE
@ -363,9 +358,7 @@ cleanup(void)
XCloseDisplay(dpy);
}
char *
cistrstr(const char *h, const char *n)
{
char * cistrstr(const char *h, const char *n) {
size_t i;
if (!n[0])
@ -382,9 +375,7 @@ cistrstr(const char *h, const char *n)
return NULL;
}
void
grabfocus(void)
{
void grabfocus(void) {
struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
Window focuswin;
int i, revertwin;
@ -419,9 +410,7 @@ grabfocus(void)
die("spmenu: cannot grab focus"); // not possible to grab focus, abort immediately
}
void
insert(const char *str, ssize_t n)
{
void insert(const char *str, ssize_t n) {
if (strlen(text) + n > sizeof text - 1)
return;
@ -437,9 +426,7 @@ insert(const char *str, ssize_t n)
match();
}
size_t
nextrune(int inc)
{
size_t nextrune(int inc) {
ssize_t n;
// return location of next utf8 rune in the given direction (+1 or -1)
@ -448,9 +435,7 @@ nextrune(int inc)
return n;
}
void
pastesel(void)
{
void pastesel(void) {
char *p, *q;
int di;
unsigned long dl;
@ -468,9 +453,7 @@ pastesel(void)
drawmenu();
}
void
xinitvisual()
{
void xinitvisual(void) {
XVisualInfo *infos;
XRenderPictFormat *fmt;
int nitems;
@ -510,9 +493,7 @@ xinitvisual()
}
}
void
setupdisplay(void)
{
void setupdisplay(void) {
int x, y, i;
#if USEXINERAMA
int j, di;
@ -679,9 +660,7 @@ setupdisplay(void)
drawmenu();
}
int
main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
XWindowAttributes wa;
readargs(argc, argv); // start by reading arguments