Skip to content

Commit

Permalink
change custom settings and add other patches
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusHuelsmann committed Apr 25, 2021
1 parent d580379 commit 0ea7bc1
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 23 deletions.
53 changes: 45 additions & 8 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ static const char *colorname[] = {
"black",
};


/*
* Default colors (colorname index)
* foreground, background, cursor, reverse cursor
Expand All @@ -135,15 +134,15 @@ unsigned int defaultfg = 7;
unsigned int defaultbg = 0;
static unsigned int defaultcs = 256;
static unsigned int defaultrcs = 257;
unsigned int bg = 17, bgUnfocused = 16;
unsigned int const currentBg = 6, buffSize = 2048;
unsigned int bg = 16, bgUnfocused = 0;
unsigned int const currentBg = 8, buffSize = 2048;
/// Enable double / triple click yanking / selection of word / line.
int const mouseYank = 1, mouseSelect = 0;
/// [Vim Browse] Colors for search results currently on screen.
unsigned int const highlightBg = 160, highlightFg = 15;
char const wDelS[] = "!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", wDelL[] = " \t";
char *nmKeys [] = { ///< Shortcusts executed in normal mode
"R/Building\nN", "r/Building\n", "X/juli@machine\nN", "x/juli@machine\n",
"R/Building\nN", "r/Building\n", "X/x@machine\nN", "x/x@machine\n",
"Q?[Leaving vim, starting execution]\n","F/: error:\nN", "f/: error:\n", "DQf"
};
unsigned int const amountNmKeys = sizeof(nmKeys) / sizeof(*nmKeys);
Expand Down Expand Up @@ -188,6 +187,44 @@ static unsigned int defaultattr = 11;
*/
static uint forcemousemod = ShiftMask;

/*
* Xresources preferences to load at startup
*/
ResourcePref resources[] = {
{ "font", STRING, &font },
{ "color0", STRING, &colorname[0] },
{ "color1", STRING, &colorname[1] },
{ "color2", STRING, &colorname[2] },
{ "color3", STRING, &colorname[3] },
{ "color4", STRING, &colorname[4] },
{ "color5", STRING, &colorname[5] },
{ "color6", STRING, &colorname[6] },
{ "color7", STRING, &colorname[7] },
{ "color8", STRING, &colorname[8] },
{ "color9", STRING, &colorname[9] },
{ "color10", STRING, &colorname[10] },
{ "color11", STRING, &colorname[11] },
{ "color12", STRING, &colorname[12] },
{ "color13", STRING, &colorname[13] },
{ "color14", STRING, &colorname[14] },
{ "color15", STRING, &colorname[15] },
{ "alpha", FLOAT, &alpha },
{ "alphaUnfocused",FLOAT, &alphaUnfocused },
{ "background", STRING, &colorname[256] },
{ "foreground", STRING, &colorname[257] },
{ "cursorColor", STRING, &colorname[258] },
{ "termname", STRING, &termname },
{ "shell", STRING, &shell },
{ "minlatency", INTEGER, &minlatency },
{ "maxlatency", INTEGER, &maxlatency },
{ "blinktimeout", INTEGER, &blinktimeout },
{ "bellvolume", INTEGER, &bellvolume },
{ "tabspaces", INTEGER, &tabspaces },
{ "borderpx", INTEGER, &borderpx },
{ "cwscale", FLOAT, &cwscale },
{ "chscale", FLOAT, &chscale },
};

/*
* Internal mouse shortcuts.
* Beware that overloading Button1 will disable the selection.
Expand All @@ -211,11 +248,11 @@ static Shortcut shortcuts[] = {
{ ControlMask, XK_Print, toggleprinter, {.i = 0} },
{ ShiftMask, XK_Print, printscreen, {.i = 0} },
{ XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
{ TERMMOD, XK_Prior, zoom, {.f = +1} },
{ TERMMOD, XK_Next, zoom, {.f = -1} },
{ MODKEY, XK_m, zoom, {.f = +1} },
{ MODKEY, XK_n, zoom, {.f = -1} },
{ TERMMOD, XK_Home, zoomreset, {.f = 0} },
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
{ TERMMOD, XK_V, clippaste, {.i = 0} },
{ MODKEY|ShiftMask, XK_C, clipcopy, {.i = 0} },
{ MODKEY|ShiftMask, XK_V, clippaste, {.i = 0} },
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
Expand Down
96 changes: 81 additions & 15 deletions x.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <X11/keysym.h>
#include <X11/Xft/Xft.h>
#include <X11/XKBlib.h>
#include <X11/Xresource.h>

char *argv0;
#include "arg.h"
Expand Down Expand Up @@ -46,6 +47,19 @@ typedef struct {
signed char appcursor; /* application cursor */
} Key;

/* Xresources preferences */
enum resource_type {
STRING = 0,
INTEGER = 1,
FLOAT = 2
};

typedef struct {
char *name;
enum resource_type type;
void *dst;
} ResourcePref;

/* X modifiers */
#define XK_ANY_MOD UINT_MAX
#define XK_NO_MOD 0
Expand Down Expand Up @@ -84,6 +98,7 @@ typedef struct {
int w, h; /* window width and height */
int ch; /* char height */
int cw; /* char width */
int cyo; /* char y offset */
int mode; /* window state/mode flags */
int cursor; /* cursor style */
} TermWindow;
Expand Down Expand Up @@ -753,10 +768,6 @@ xresize(int col, int row)
win.tw = col * win.cw;
win.th = row * win.ch;

XFreePixmap(xw.dpy, xw.buf);
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
xw.depth);
XftDrawChange(xw.draw, xw.buf);
xclear(0, 0, win.w, win.h);

/* resize to new width */
Expand Down Expand Up @@ -861,8 +872,8 @@ xclear(int x1, int y1, int x2, int y2)
void
xhints(void)
{
XClassHint class = {opt_name ? opt_name : termname,
opt_class ? opt_class : termname};
XClassHint class = {opt_name ? opt_name : "st",
opt_class ? opt_class : "St"};
XWMHints wm = {.flags = InputHint, .input = 1};
XSizeHints *sizeh;

Expand Down Expand Up @@ -1033,6 +1044,7 @@ xloadfonts(char *fontstr, double fontsize)
/* Setting character width and height. */
win.cw = ceilf(dc.font.width * cwscale);
win.ch = ceilf(dc.font.height * chscale);
win.cyo = floorf(dc.font.height * (chscale - 1) / 2);

FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
Expand Down Expand Up @@ -1139,8 +1151,6 @@ xinit(int cols, int rows)
XWindowAttributes attr;
XVisualInfo vis;

if (!(xw.dpy = XOpenDisplay(NULL)))
die("can't open display\n");
xw.scr = XDefaultScreen(xw.dpy);

if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
Expand Down Expand Up @@ -1189,7 +1199,7 @@ xinit(int cols, int rows)

memset(&gcvalues, 0, sizeof(gcvalues));
gcvalues.graphics_exposures = False;
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
xw.buf = xw.win;
dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
Expand Down Expand Up @@ -1264,7 +1274,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
FcCharSet *fccharset;
int i, f, numspecs = 0;

for (i = 0, xp = winx, yp = winy + font->ascent; i < len; ++i) {
for (i = 0, xp = winx, yp = winy + font->ascent + win.cyo; i < len; ++i) {
/* Fetch rune and mode for current glyph. */
Glyph g = glyphs[i];
historyOverlay(x+i, y, &g);
Expand All @@ -1291,7 +1301,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
font = &dc.bfont;
frcflags = FRC_BOLD;
}
yp = winy + font->ascent;
yp = winy + font->ascent + win.cyo;
}

/* Lookup character index with default font. */
Expand Down Expand Up @@ -1504,12 +1514,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i

/* Render underline and strikethrough. */
if (base.mode & ATTR_UNDERLINE) {
XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
XftDrawRect(xw.draw, fg, winx, winy + win.cyo + dc.font.ascent + 1,
width, 1);
}

if (base.mode & ATTR_STRUCK) {
XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
XftDrawRect(xw.draw, fg, winx, winy + win.cyo + 2 * dc.font.ascent / 3,
width, 1);
}

Expand Down Expand Up @@ -1676,8 +1686,6 @@ xdrawline(Line line, int x1, int y1, int x2)
void
xfinishdraw(void)
{
XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w,
win.h, 0, 0);
XSetForeground(xw.dpy, dc.gc,
dc.col[IS_SET(MODE_REVERSE)?
defaultfg : defaultbg].pixel);
Expand Down Expand Up @@ -2023,6 +2031,59 @@ run(void)
}
}

int
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
{
char **sdst = dst;
int *idst = dst;
float *fdst = dst;

char fullname[256];
char fullclass[256];
char *type;
XrmValue ret;

snprintf(fullname, sizeof(fullname), "%s.%s",
opt_name ? opt_name : "st", name);
snprintf(fullclass, sizeof(fullclass), "%s.%s",
opt_class ? opt_class : "St", name);
fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';

XrmGetResource(db, fullname, fullclass, &type, &ret);
if (ret.addr == NULL || strncmp("String", type, 64))
return 1;

switch (rtype) {
case STRING:
*sdst = ret.addr;
break;
case INTEGER:
*idst = strtoul(ret.addr, NULL, 10);
break;
case FLOAT:
*fdst = strtof(ret.addr, NULL);
break;
}
return 0;
}

void
config_init(void)
{
char *resm;
XrmDatabase db;
ResourcePref *p;

XrmInitialize();
resm = XResourceManagerString(xw.dpy);
if (!resm)
return;

db = XrmGetStringDatabase(resm);
for (p = resources; p < resources + LEN(resources); p++)
resource_load(db, p->name, p->type, p->dst);
}

void
usage(void)
{
Expand Down Expand Up @@ -2099,6 +2160,11 @@ main(int argc, char *argv[])

setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");

if(!(xw.dpy = XOpenDisplay(NULL)))
die("Can't open display\n");

config_init();
cols = MAX(cols, 1);
rows = MAX(rows, 1);
defaultbg = MAX(LEN(colorname), 256);
Expand Down

0 comments on commit 0ea7bc1

Please sign in to comment.