spmenu/spmenu.c

643 lines
16 KiB
C
Raw Normal View History

2023-04-02 01:49:58 +02:00
/* spmenu - fancy dynamic menu
2023-03-06 16:23:03 +01:00
*
* If you're looking for functions used to draw text, see 'libs/draw.c'
* If you're looking for wrapper functions used inside the draw functions, see 'libs/libdrw/drw.c'
2023-03-06 16:23:03 +01:00
* If you're looking for functions used to draw images, see 'libs/img.c'
* If you're looking for the .Xresources array, see 'libs/x11/xresources.h'
2023-03-06 16:23:03 +01:00
*
* You don't need to edit spmenu.c if you aren't making big changes to the software.
*
2023-05-08 12:05:15 +02:00
* After making changes, run `./build.sh` to attempt to build the software.
* `scripts/make/generate-docs.sh` will generate a man page from 'docs/docs.md', which is a Markdown document. Run this before commiting.
2023-03-06 16:23:03 +01:00
*
* See LICENSE file for copyright and license details.
*/
2023-01-20 23:17:30 +01:00
#include <ctype.h>
#include <locale.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>
// check if we should enable right to left language support
#ifndef RTL
#define USERTL 0
2023-02-28 15:51:32 +01:00
#else
#define USERTL 1
#endif
// check if we should enable pango or use xft
#ifndef PANGO
#define USEPANGO 0
#else
#define USEPANGO 1
#endif
// check if we should enable image support
#ifndef IMAGE
2023-02-26 16:38:26 +01:00
#define USEIMAGE 0
#else
#define USEIMAGE 1
#endif
// check if we should enable multimonitor support using libXinerama
2023-03-28 21:46:23 +02:00
#ifndef XINERAMA
2023-02-28 15:51:32 +01:00
#define USEXINERAMA 0
2023-03-28 21:46:23 +02:00
#else
#define USEXINERAMA 1
2023-02-28 15:51:32 +01:00
#endif
// check if we should enable config file support using libconfig
#ifndef CONFIG
#define USECONFIG 0
#else
#define USECONFIG 1
#endif
// check if we should enable .Xresources support
#ifndef XRESOURCES
#define USEXRESOURCES 0
#else
#define USEXRESOURCES 1
#endif
#ifndef VERSION
#define VERSION "unknown"
#endif
// include fribidi used for right to left language support
2023-02-28 15:51:32 +01:00
#if USERTL
#include <fribidi.h>
#endif
// include libraries used for image support
#if USEIMAGE
#include <errno.h>
#include <pwd.h>
#include <Imlib2.h>
#include <openssl/md5.h>
// openssl is used to generate a checksum, used for caching
// TODO: remove this dependency by doing it some other way
#endif
// include xinerama used for multi monitor support
2023-02-28 15:51:32 +01:00
#if USEXINERAMA
#include <X11/extensions/Xinerama.h>
#endif
// include X11 headers
#include <X11/XKBlib.h>
2023-01-20 23:17:30 +01:00
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
2023-01-20 23:17:30 +01:00
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include <X11/extensions/Xrender.h>
// include xresources
#if USEXRESOURCES
#include <X11/Xresource.h>
#endif
// include pango used for markup
#if USEPANGO
2023-01-20 23:17:30 +01:00
#include <pango/pango.h>
#endif
2023-01-20 23:17:30 +01:00
// 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
2023-05-10 08:20:29 +02:00
#include "libs/libdrw/drw.h"
#include "libs/sl/main.h"
#include "libs/x11/init.h"
2023-03-26 16:42:11 +02:00
#include "libs/draw.h"
#include "libs/stream.h"
#include "libs/schemes.h"
#include "libs/arg.h"
#include "libs/x11/xrdb.h"
2023-05-21 23:40:19 +02:00
#include "libs/x11/xim.h"
#include "libs/x11/key.h"
#include "libs/x11/mouse.h"
2023-03-09 10:10:29 +01:00
#include "libs/sort.h"
2023-03-31 12:42:15 +02:00
#include "libs/history.h"
2023-02-25 17:44:52 +01:00
// text
static char text[BUFSIZ] = "";
2023-01-20 23:17:30 +01:00
static char numbers[NUMBERSBUFSIZE] = "";
// high priority
2023-03-09 10:10:29 +01:00
static int hplength = 0;
2023-03-09 11:56:44 +01:00
static char **hpitems = NULL;
// embed
2023-01-20 23:17:30 +01:00
static char *embed;
// keybinds
static int numlockmask = 0;
static int capslockstate = 0;
// height of each item, menu width, menu height
2023-01-20 23:17:30 +01:00
static int bh, mw, mh;
static int reallines = 0;
2023-03-16 17:25:39 +01:00
static int inputw = 0;
static int promptw;
static int plw = 0;
2023-03-16 17:25:39 +01:00
static int lrpad; // sum of left and right padding
static int vp; // vertical padding for bar
static int sp; // side padding for bar
2023-04-29 16:08:00 +02:00
static int cursorstate = 1; // cursor state
2023-05-07 15:33:09 +02:00
static int itemnumber = 0; // item number
2023-01-20 23:17:30 +01:00
static size_t cursor;
static struct item *items = NULL, *backup_items, *list_items;
2023-01-20 23:17:30 +01:00
static struct item *matches, *matchend;
static struct item *prev, *curr, *next, *sel;
static int *sel_index = NULL;
static unsigned int sel_size = 0;
2023-03-06 16:23:03 +01:00
static int screen;
2023-05-13 16:07:29 +02:00
static int itemn = 0;
// item struct
struct item {
2023-05-08 23:00:45 +02:00
char *text;
char *clntext;
2023-05-08 23:00:45 +02:00
#if USEIMAGE
char *image;
2023-05-08 23:00:45 +02:00
#endif
char *ex;
2023-05-08 23:00:45 +02:00
struct item *left, *right;
int hp;
int index;
2023-05-08 23:00:45 +02:00
double distance;
};
// image globals
#if USEIMAGE
static int flip = 0;
static int rotation = 0;
static int needredraw = 1;
static int longestedge = 0;
static int imagew = 0;
static int imageh = 0;
static int imageg = 0;
static int ow = 0;
static int oh = 0;
#endif
static int fullscreen = 0;
2023-05-01 17:07:35 +02:00
// config file
#if USECONFIG
2023-05-01 17:07:35 +02:00
static int cconf = 0; // use custom config path?
static int ctheme = 0; // use custom theme path?
static char *argconf = NULL; // arg config path
static char *argtheme = NULL; // arg theme path
#endif
2023-03-16 14:56:41 +01:00
// set an integer to 1 if we have rtl enabled, this saves a lot of lines and duplicate code
#if USERTL
static int isrtl = 1;
#else
static int isrtl = 0;
#endif
2023-04-25 09:56:11 +02:00
static int ignoreconfkeys = 0; // can be set globally if you don't want to override keybinds with config file keys
static int ignoreglobalkeys = 0; // should be set in the config file, if 1, the Keys keys array is ignored
static int ignoreconfmouse = 0; // same for mouse
static int ignoreglobalmouse = 0; // same for mouse
2023-04-25 09:56:11 +02:00
// colors
2023-03-16 17:25:39 +01:00
static int useargb = 0;
2023-01-20 23:17:30 +01:00
static Visual *visual;
static int depth;
static Colormap cmap;
static Drw *drw;
2023-05-08 17:50:48 +02:00
static Clr **scheme;
2023-01-20 23:17:30 +01:00
static Clr textclrs[256];
2023-03-16 17:25:39 +01:00
// declare functions
static int is_selected(size_t index);
static void calcoffsets(void);
2023-03-02 11:40:52 +01:00
static void recalculatenumbers(void);
static void insert(const char *str, ssize_t n);
static void cleanup(void);
static void navigatehistfile(int dir);
static void grabfocus(void);
static void pastesel(void);
2023-03-13 21:21:40 +01:00
static void appenditem(struct item *item, struct item **list, struct item **last);
static void xinitvisual(void);
2023-03-08 17:20:32 +01:00
static int max_textw(void);
2023-03-16 14:56:41 +01:00
static size_t nextrune(int inc);
2023-02-25 17:44:52 +01:00
static char **list;
static size_t listsize;
static int listcount;
static int listchanged = 0;
2023-03-16 14:56:41 +01:00
// user configuration
#include "options.h"
#include "keybinds.h"
#include "mouse.h"
2023-03-06 16:23:03 +01:00
2023-03-16 14:56:41 +01:00
// xresources/color arrays
#include "libs/x11/xresources.h"
2023-03-06 16:23:03 +01:00
#include "libs/colors.h"
2023-01-20 23:17:30 +01:00
static char *fonts[] = { font };
// config file
#if USECONFIG
#include "libs/conf/config.h"
#include "libs/conf/config.c"
#endif
2023-03-16 14:56:41 +01:00
// matching
2023-01-20 23:17:30 +01:00
static char * cistrstr(const char *s, const char *sub);
static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp;
static char *(*fstrstr)(const char *, const char *) = cistrstr;
2023-03-13 21:21:40 +01:00
// include functions
#include "libs/img.h"
#include "libs/img.c"
#include "libs/rtl.h"
#include "libs/rtl.c"
2023-05-21 23:40:19 +02:00
#include "libs/x11/xim.c"
#include "libs/x11/key.c"
#include "libs/x11/mouse.c"
2023-03-09 10:10:29 +01:00
#include "libs/sort.c"
2023-03-02 11:40:52 +01:00
#include "libs/draw.c"
#include "libs/schemes.c"
2023-03-02 14:53:48 +01:00
#include "libs/argv.h"
#include "libs/argv.c"
#include "libs/x11/xrdb.c"
#include "libs/x11/client.h"
#include "libs/x11/client.c"
2023-03-13 22:45:04 +01:00
#include "libs/match.h"
#include "libs/match.c"
2023-03-31 12:42:15 +02:00
#include "libs/history.c"
2023-03-13 22:45:04 +01:00
#include "libs/arg.c"
#include "libs/stream.c"
#include "libs/event.h"
#include "libs/event.c"
#include "libs/x11/init.c"
2023-02-25 17:44:52 +01:00
int is_selected(size_t index) {
for (int i = 0; i < sel_size; i++) {
if (sel_index[i] == index) {
return 1;
}
}
return 0;
}
void appenditem(struct item *item, struct item **list, struct item **last) {
2023-05-08 23:00:45 +02:00
if (*last)
(*last)->right = item;
else
*list = item;
item->left = *last;
item->right = NULL;
*last = item;
2023-01-20 23:17:30 +01:00
}
void recalculatenumbers(void) {
unsigned int numer = 0, denom = 0, selected = 0;
2023-05-08 23:00:45 +02:00
struct item *item;
if (matchend) {
numer++;
2023-03-31 12:42:15 +02:00
// walk through items that match and add to numer
2023-05-08 23:00:45 +02:00
for (item = matchend; item && item->left; item = item->left)
numer++;
}
2023-03-31 12:42:15 +02:00
// walk through all items, matching or not and add to denom
2023-05-08 23:00:45 +02:00
for (item = items; item && item->text; item++)
denom++;
2023-03-31 12:42:15 +02:00
for (int i = 0; i < sel_size; i++) {
if (sel_index[i] == -1) {
break;
}
selected++;
}
if (selected) {
snprintf(numbers, NUMBERSBUFSIZE, "%d/%d/%d", numer, denom, selected);
} else {
snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
}
2023-01-20 23:17:30 +01:00
}
void calcoffsets(void) {
2023-05-08 23:00:45 +02:00
int i, n;
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
if (lines > 0)
n = lines * columns * bh;
else { // no lines, therefore the size of items must be decreased to fit the menu elements
int numberWidth = 0;
int modeWidth = 0;
int larrowWidth = 0;
int rarrowWidth = 0;
2023-04-21 09:49:38 +02:00
int capsWidth = 0;
2023-03-02 18:25:28 +01:00
if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(numbers) : TEXTW(numbers);
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow);
if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
2023-04-21 09:49:38 +02:00
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
2023-04-21 09:49:38 +02:00
if (!strcmp(capstext, ""))
capsWidth = 0;
2023-05-08 23:00:45 +02:00
n = mw - (promptw + inputw + larrowWidth + rarrowWidth + modeWidth + numberWidth + capsWidth + menumarginv);
}
2023-05-08 23:00:45 +02:00
// calculate which items will begin the next page
for (i = 0, next = curr; next; next = next->right)
if ((i += (lines > 0) ? bh : MIN(TEXTWM(next->text), n)) > n)
break;
2023-03-31 12:42:15 +02:00
2023-05-08 23:00:45 +02:00
// calculate which items will begin the previous page
for (i = 0, prev = curr; prev && prev->left; prev = prev->left)
if ((i += (lines > 0) ? bh : MIN(TEXTWM(prev->left->text), n)) > n)
break;
2023-01-20 23:17:30 +01:00
}
int max_textw(void) {
2023-05-08 23:00:45 +02:00
int len = 0;
2023-03-31 12:42:15 +02:00
2023-05-08 23:00:45 +02:00
for (struct item *item = items; item && item->text; item++)
len = MAX(TEXTW(item->text), len);
2023-03-31 12:42:15 +02:00
2023-05-08 23:00:45 +02:00
return len;
2023-01-20 23:17:30 +01:00
}
void cleanup(void) {
2023-05-08 23:00:45 +02:00
size_t i;
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
#if USEIMAGE
2023-03-31 12:42:15 +02:00
cleanupimage(); // function frees images
2023-05-08 23:00:45 +02:00
#endif
2023-03-02 11:46:44 +01:00
2023-05-08 23:00:45 +02:00
XUngrabKey(dpy, AnyKey, AnyModifier, root); // ungrab keys
2023-03-09 11:56:44 +01:00
2023-03-31 12:42:15 +02:00
// free color scheme
2023-05-08 23:00:45 +02:00
for (i = 0; i < LENGTH(colors) + 1; i++)
free(scheme[i]);
2023-03-09 11:56:44 +01:00
2023-03-31 12:42:15 +02:00
// free high priority items
2023-03-09 11:56:44 +01:00
for (i = 0; i < hplength; ++i)
2023-05-08 23:00:45 +02:00
free(hpitems[i]);
2023-03-09 11:56:44 +01:00
2023-03-31 12:42:15 +02:00
// free drawing and close the display
2023-05-08 23:00:45 +02:00
drw_free(drw);
XSync(dpy, False);
XCloseDisplay(dpy);
free(sel_index);
2023-01-20 23:17:30 +01:00
}
char * cistrstr(const char *h, const char *n) {
2023-05-08 23:00:45 +02:00
size_t i;
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
if (!n[0])
return (char *)h;
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
for (; *h; ++h) {
for (i = 0; n[i] && tolower((unsigned char)n[i]) ==
tolower((unsigned char)h[i]); ++i);
2023-03-31 12:42:15 +02:00
2023-05-08 23:00:45 +02:00
if (n[i] == '\0')
return (char *)h;
}
2023-03-31 12:42:15 +02:00
2023-05-08 23:00:45 +02:00
return NULL;
2023-01-20 23:17:30 +01:00
}
void grabfocus(void) {
2023-05-08 23:00:45 +02:00
struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
Window focuswin;
int i, revertwin;
XWindowAttributes wa;
XSync(dpy, False);
2023-05-08 23:00:45 +02:00
XGetWindowAttributes(dpy, win, &wa);
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
for (i = 0; i < 100; ++i) {
XGetInputFocus(dpy, &focuswin, &revertwin);
if (focuswin == win)
return;
2023-03-31 12:42:15 +02:00
// if it's a client, we can't just steal all the input for ourselves
2023-05-08 23:00:45 +02:00
if (managed) {
if (wa.map_state == IsViewable) {
XTextProperty prop;
char *windowtitle = prompt != NULL ? prompt : "spmenu";
Xutf8TextListToTextProperty(dpy, &windowtitle, 1, XUTF8StringStyle, &prop);
XSetWMName(dpy, win, &prop);
XSetTextProperty(dpy, win, &prop, XInternAtom(dpy, "_NET_WM_NAME", False));
XFree(prop.value);
}
2023-03-31 12:42:15 +02:00
} else { // spmenu is not managed, and is very greedy
if (wa.map_state == IsViewable) // it must be viewable first, otherwise we get a BadMatch error
XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
2023-03-31 12:42:15 +02:00
}
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
nanosleep(&ts, NULL);
}
2023-03-31 12:42:15 +02:00
2023-05-08 23:00:45 +02:00
die("spmenu: cannot grab focus"); // not possible to grab focus, abort immediately
2023-01-20 23:17:30 +01:00
}
void insert(const char *str, ssize_t n) {
2023-05-08 23:00:45 +02:00
if (strlen(text) + n > sizeof text - 1)
return;
2023-03-31 12:42:15 +02:00
static char l[BUFSIZ] = "";
if (requirematch) memcpy(l, text, BUFSIZ);
2023-05-08 23:00:45 +02:00
// 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));
2023-03-31 12:42:15 +02:00
// update cursor
2023-05-08 23:00:45 +02:00
if (n > 0 && str && n)
memcpy(&text[cursor], str, n);
2023-03-31 12:42:15 +02:00
// add to cursor position and continue matching
2023-05-08 23:00:45 +02:00
cursor += n;
match();
if (!matches && requirematch) {
memcpy(text, l, BUFSIZ);
cursor -= n;
match();
}
2023-01-20 23:17:30 +01:00
}
size_t nextrune(int inc) {
2023-05-08 23:00:45 +02:00
ssize_t n;
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
// 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)
2023-03-31 12:42:15 +02:00
;
2023-05-08 23:00:45 +02:00
return n;
2023-01-20 23:17:30 +01:00
}
void pastesel(void) {
2023-05-08 23:00:45 +02:00
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)); // insert selection
XFree(p);
}
2023-03-31 12:42:15 +02:00
// draw the menu
2023-05-08 23:00:45 +02:00
drawmenu();
2023-01-20 23:17:30 +01:00
}
void xinitvisual(void) {
2023-05-08 23:00:45 +02:00
XVisualInfo *infos;
XRenderPictFormat *fmt;
int nitems;
int i;
2023-01-20 23:17:30 +01:00
2023-03-31 12:42:15 +02:00
// visual properties
2023-05-08 23:00:45 +02:00
XVisualInfo tpl = {
.screen = screen,
.depth = 32,
.class = TrueColor
};
2023-03-16 14:56:41 +01:00
2023-05-08 23:00:45 +02:00
long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
visual = NULL;
2023-03-31 12:42:15 +02:00
// create colormap
2023-05-08 23:00:45 +02:00
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);
2023-01-20 23:17:30 +01:00
2023-03-16 14:56:41 +01:00
// no alpha, reset to default
2023-05-08 23:00:45 +02:00
if (!visual || !alpha) {
visual = DefaultVisual(dpy, screen);
depth = DefaultDepth(dpy, screen);
cmap = DefaultColormap(dpy, screen);
}
2023-01-20 23:17:30 +01:00
}
int main(int argc, char *argv[]) {
2023-05-08 23:00:45 +02:00
XWindowAttributes wa;
2023-01-20 23:17:30 +01:00
2023-03-31 12:42:15 +02:00
readargs(argc, argv); // start by reading arguments
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
#if USEIMAGE
longestedge = MAX(imagewidth, imageheight);
2023-05-08 23:00:45 +02:00
#endif
if (!type) {
mode = 0;
}
2023-03-31 12:42:15 +02:00
// set default mode, must be done before the event loop or keybindings will not work
if (mode) {
2023-03-06 14:15:01 +01:00
curMode = 1;
2023-02-26 06:05:27 +01:00
allowkeys = 1;
strcpy(modetext, instext);
} else {
2023-03-06 14:15:01 +01:00
curMode = 0;
allowkeys = !curMode;
strcpy(modetext, normtext);
}
2023-05-08 23:00:45 +02:00
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
2023-03-31 12:42:15 +02:00
fputs("warning: no locale support\n", stderr); // invalid locale, so notify the user about it
2023-03-08 17:20:32 +01:00
2023-04-01 00:10:21 +02:00
if (!XSetLocaleModifiers(""))
2023-05-08 23:00:45 +02:00
fputs("warning: no locale modifiers support\n", stderr);
2023-04-01 00:10:21 +02:00
2023-03-31 12:42:15 +02:00
if (!(dpy = XOpenDisplay(NULL)))
die("spmenu: cannot open display"); // failed to open display
2023-03-08 17:20:32 +01:00
2023-03-31 12:42:15 +02:00
// set screen and root window
2023-03-08 17:20:32 +01:00
screen = DefaultScreen(dpy);
2023-05-08 23:00:45 +02:00
root = RootWindow(dpy, screen);
2023-03-08 17:20:32 +01:00
2023-03-31 12:42:15 +02:00
// parent window is the root window (ie. window manager) because we're not embedding
2023-03-08 17:20:32 +01:00
if (!embed || !(parentwin = strtol(embed, NULL, 0)))
2023-05-08 23:00:45 +02:00
parentwin = root;
2023-03-08 17:20:32 +01:00
if (!XGetWindowAttributes(dpy, parentwin, &wa))
2023-05-08 23:00:45 +02:00
die("spmenu: could not get embedding window attributes: 0x%lx", parentwin);
2023-03-08 17:20:32 +01:00
2023-05-08 23:00:45 +02:00
xinitvisual(); // init visual and create drawable after
drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap); // wrapper function creating a drawable
2023-01-20 23:17:30 +01:00
2023-03-20 15:32:20 +01:00
// load fonts
2023-05-08 23:00:45 +02:00
if (!drw_font_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
2023-01-20 23:17:30 +01:00
2023-03-31 12:42:15 +02:00
// resize window
2023-03-29 21:37:48 +02:00
lrpad = drw->font->h + textpadding;
2023-03-31 12:42:15 +02:00
prepare_window_size(); // this function sets padding size
2023-01-20 23:17:30 +01:00
// pledge limits what programs can do, so here we specify what spmenu should be allowed to do
2023-05-08 23:00:45 +02:00
#ifdef __OpenBSD__
if (pledge("stdio rpath wpath cpath", NULL) == -1)
die("pledge");
#endif
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
loadhistory(); // read history entries
2023-01-20 23:17:30 +01:00
2023-03-20 15:32:20 +01:00
// fast (-f) means we grab keyboard before reading standard input
2023-05-08 23:00:45 +02:00
if (fast && !isatty(0)) {
grabkeyboard();
readstdin();
} else {
readstdin();
grabkeyboard();
}
// set default values
2023-05-08 23:00:45 +02:00
#if USEIMAGE
if (!imagew || !imageh || !imageg) {
imagew = imagewidth;
imageh = imageheight;
imagegaps = imagegaps;
}
2023-05-08 23:00:45 +02:00
#endif
init_appearance(); // init colorschemes by reading arrays
2023-05-08 23:00:45 +02:00
setupdisplay(); // set up display and create window
eventloop(); // function is a loop which checks X11 events and calls other functions accordingly
2023-01-20 23:17:30 +01:00
2023-05-08 23:00:45 +02:00
return 1; // should be unreachable
2023-01-20 23:17:30 +01:00
}