fix segmentation fault when specifying a font in xrdb

This commit is contained in:
speedie 2023-03-14 11:42:56 +01:00
parent 392e5bfffc
commit d9bfcb067a
5 changed files with 43 additions and 18 deletions

View file

@ -1,6 +1,12 @@
! spmenu default configuration in .Xresources format
! spmenu 0.2.2 default configuration
!
! You may copy this configuration file to ~/.config/spmenu/spmenurc OR ~/.spmenurc, it will be loaded on runtime.
! It is .Xresources syntax. As such you may also append it to your existing .Xresources configuration, use programs like Pywal to have universal colorschemes.
!! Fonts
spmenu.font: Noto Sans Mono 8
!! Colors
spmenu.col_itemnormfg: #bbbbbb
spmenu.col_itemnormbg: #222222
spmenu.col_itemselfg: #eeeeee
@ -44,35 +50,50 @@ spmenu.col_sgrcolor12: #0000ff
spmenu.col_sgrcolor13: #ff00ff
spmenu.col_sgrcolor14: #00ffff
spmenu.col_sgrcolor15: #ffffff
!! Misc color
spmenu.alpha: 1
!! Width
spmenu.accuratewidth: 1
spmenu.borderwidth: 0
!! Lines and columns
spmenu.lineheight: 5
spmenu.lines: 0
spmenu.columns: 10
spmenu.preselected: 0
spmenu.indentitems: 1
!! History
spmenu.maxhist: 64
spmenu.histnodup: 1
!! Input
spmenu.type: 1
spmenu.casesensitive: 0
!! Menu
spmenu.menuposition: 1
spmenu.menupaddingv: 0
spmenu.menupaddingh: 0
spmenu.preselected: 0
spmenu.type: 1
!! General
spmenu.class: spmenu
spmenu.fast: 0
spmenu.mon: -1
spmenu.managed: 0
spmenu.loadconfig: 0
spmenu.leftarrow: <
spmenu.rightarrow: >
spmenu.password: .
!! Image
spmenu.imagewidth: 86
spmenu.imageheight: 86
spmenu.imagegaps: 0
spmenu.imageposition: 0
spmenu.generatecache: 1
!! Mode options
spmenu.mode: 0
spmenu.fast: 0
spmenu.indentitems: 1
!! Hide options
spmenu.hidematchcount: 0
spmenu.hidemode: 0
spmenu.hidelarrow: 0
@ -81,8 +102,13 @@ spmenu.hideprompt: 0
spmenu.hidecursor: 0
spmenu.hidehighlight: 0
spmenu.hideimage: 0
!! Text
spmenu.normtext: Normal
spmenu.instext: Insert
spmenu.password: .
!! Pango markup toggles
spmenu.pango_item: 1
spmenu.pango_prompt: 1
spmenu.pango_input: 1

View file

@ -3,8 +3,6 @@ readargs(int argc, char *argv[])
{
int i = 0;
XrmInitialize();
for (i = 1; i < argc; i++) {
/* xrdb first as it overrides other options */
if (!strcmp(argv[i], "-xrdb")) /* xresources */
@ -18,9 +16,9 @@ readargs(int argc, char *argv[])
}
if (xresources) {
if (loadconfig) {
load_xresources();
XrmInitialize();
if (loadconfig) {
int cxrdb = system("[ -e $HOME/.config/spmenu/spmenurc ] && xrdb -override $HOME/.config/spmenu/spmenurc");
int hxrdb = system("[ -e $HOME/.spmenurc ] && xrdb -override $HOME/.spmenurc");
}
@ -182,7 +180,7 @@ readargs(int argc, char *argv[])
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 */
font[0] = argv[++i];
fonts[0] = argv[++i];
else if (!strcmp(argv[i], "-nmt")) /* normal mode text */
strcpy(normtext, argv[++i]);
else if (!strcmp(argv[i], "-imt")) { /* insert mode text */

View file

@ -134,7 +134,6 @@ ResourcePref resources[] = {
{ "generatecache", INTEGER, &generatecache },
{ "mode", INTEGER, &mode },
{ "fast", INTEGER, &fast },
{ "loadconfig", INTEGER, &loadconfig },
{ "managed", INTEGER, &managed },
{ "mon", INTEGER, &mon },
{ "pango_item", INTEGER, &pango_item },

View file

@ -35,7 +35,7 @@ static char instext[] = "Insert"; /* Text to display for insert
static int borderwidth = 2; /* Width of the border */
/* Font options */
static char *font[] = { "Noto Sans Mono 8" }; /* Font to draw text and Pango markup with. */
static char font[] = "Noto Sans Mono 8"; /* Font to draw text and Pango markup with. */
/* Symbol options */
static char *leftarrow = "<"; /* Left arrow, used to indicate you can move to the left */

View file

@ -215,6 +215,8 @@ static int max_textw(void);
#include "libs/xresources.h"
#include "libs/colors.h"
static char *fonts[] = { font };
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;
@ -841,7 +843,7 @@ main(int argc, char *argv[])
xinitvisual();
drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
if (!drw_font_create(drw, font, LENGTH(font)))
if (!drw_font_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
lrpad = drw->font->h;