sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

emoji-highlight-5.0.diff (9317B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 1edb647..a4e775f 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -4,18 +4,34 @@
      6  static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */
      7  /* -fn option overrides fonts[0]; default X11 font or font set */
      8  static const char *fonts[] = {
      9 -	"monospace:size=10"
     10 +    "monospace:size=10",
     11 +    "FiraCode Nerd Font:size=12",
     12  };
     13 +
     14  static const char *prompt      = NULL;      /* -p  option; prompt to the left of input field */
     15 -static const char *colors[SchemeLast][2] = {
     16 -	/*     fg         bg       */
     17 -	[SchemeNorm] = { "#bbbbbb", "#222222" },
     18 -	[SchemeSel] = { "#eeeeee", "#005577" },
     19 -	[SchemeOut] = { "#000000", "#00ffff" },
     20 +static const char *colors[SchemeLast][11] = {
     21 +    /*     fg         bg       */
     22 +    [SchemeNorm] = { "#bbbbbb", "#222222", "#222222" },
     23 +    [SchemeSel] = { "#eeeeee", "#005577", "#005577" },
     24 +    [SchemeOut] = { "#000000", "#00ffff", "#00ffff" },
     25 +    [SchemeHighlight] = {"#f1fa8c", "#596377", "#3E485B"},
     26 +    [SchemeHover] = {"#ffffff", "#353D4B", "#3E485B"},
     27 +    [SchemeMid] = {"#A4ABAA", "#21222c", "#21222c"},
     28 +    [SchemeGreen] = {"#ffffff", "#52E067", "#41b252"},
     29 +    [SchemeRed] = {"#ffffff", "#e05252", "#c24343"},
     30 +    [SchemeYellow] = {"#ffffff", "#e0c452", "#bca33f"},
     31 +    [SchemeBlue] = {"#ffffff", "#5280e0", "#3a62b3"},
     32 +    [SchemePurple] = {"#ffffff", "#9952e0", "#7439b0"},
     33  };
     34  /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
     35  static unsigned int lines      = 0;
     36  
     37 +static unsigned int lineheight = 0; /* -h option; minimum height of a menu line     */
     38 +static unsigned int min_lineheight = 8;
     39 +static int sely = 0;
     40 +static int commented = 0;
     41 +static int animated = 0;
     42 +
     43  /*
     44   * Characters not considered part of a word while deleting words
     45   * for example: " /?\"&[]"
     46 diff --git a/dmenu.c b/dmenu.c
     47 index 65f25ce..f1bda1b 100644
     48 --- a/dmenu.c
     49 +++ b/dmenu.c
     50 @@ -26,7 +26,21 @@
     51  #define TEXTW(X)              (drw_fontset_getwidth(drw, (X)) + lrpad)
     52  
     53  /* enums */
     54 -enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
     55 +enum {
     56 +  SchemeNorm,
     57 +  SchemeFade,
     58 +  SchemeHighlight,
     59 +  SchemeHover,
     60 +  SchemeSel,
     61 +  SchemeOut,
     62 +  SchemeMid,
     63 +  SchemeGreen,
     64 +  SchemeYellow,
     65 +  SchemeBlue,
     66 +  SchemePurple,
     67 +  SchemeRed,
     68 +  SchemeLast
     69 +}; /* color schemes */
     70  
     71  struct item {
     72  	char *text;
     73 @@ -37,6 +51,9 @@ struct item {
     74  static char text[BUFSIZ] = "";
     75  static char *embed;
     76  static int bh, mw, mh;
     77 +static int dmx = 0; /* put dmenu at this x offset */
     78 +static int dmy = 0; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */
     79 +static unsigned int dmw = 0; /* make dmenu this wide */
     80  static int inputw = 0, promptw;
     81  static int lrpad; /* sum of left and right padding */
     82  static size_t cursor;
     83 @@ -114,16 +131,119 @@ cistrstr(const char *s, const char *sub)
     84  }
     85  
     86  static int
     87 -drawitem(struct item *item, int x, int y, int w)
     88 -{
     89 -	if (item == sel)
     90 -		drw_setscheme(drw, scheme[SchemeSel]);
     91 -	else if (item->out)
     92 -		drw_setscheme(drw, scheme[SchemeOut]);
     93 -	else
     94 -		drw_setscheme(drw, scheme[SchemeNorm]);
     95 -
     96 -	return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
     97 +drawitem(struct item *item, int x, int y, int w) {
     98 +  int iscomment = 0;
     99 +  if (item->text[0] == '>') {
    100 +    if (item->text[1] == '>') {
    101 +      iscomment = 3;
    102 +      switch (item->text[2]) {
    103 +      case 'r':
    104 +        drw_setscheme(drw, scheme[SchemeRed]);
    105 +        break;
    106 +      case 'g':
    107 +        drw_setscheme(drw, scheme[SchemeGreen]);
    108 +        break;
    109 +      case 'y':
    110 +        drw_setscheme(drw, scheme[SchemeYellow]);
    111 +        break;
    112 +      case 'b':
    113 +        drw_setscheme(drw, scheme[SchemeBlue]);
    114 +        break;
    115 +      case 'p':
    116 +        drw_setscheme(drw, scheme[SchemePurple]);
    117 +        break;
    118 +      case 'h':
    119 +        drw_setscheme(drw, scheme[SchemeHighlight]);
    120 +        break;
    121 +      case 's':
    122 +        drw_setscheme(drw, scheme[SchemeSel]);
    123 +        break;
    124 +      default:
    125 +        iscomment = 1;
    126 +        drw_setscheme(drw, scheme[SchemeNorm]);
    127 +        break;
    128 +      }
    129 +    } else {
    130 +      drw_setscheme(drw, scheme[SchemeNorm]);
    131 +      iscomment = 1;
    132 +    }
    133 +
    134 +  } else if (item->text[0] == ':') {
    135 +    iscomment = 2;
    136 +    if (item == sel) {
    137 +      switch (item->text[1]) {
    138 +      case 'r':
    139 +        drw_setscheme(drw, scheme[SchemeRed]);
    140 +        break;
    141 +      case 'g':
    142 +        drw_setscheme(drw, scheme[SchemeGreen]);
    143 +        break;
    144 +      case 'y':
    145 +        drw_setscheme(drw, scheme[SchemeYellow]);
    146 +        break;
    147 +      case 'b':
    148 +        drw_setscheme(drw, scheme[SchemeBlue]);
    149 +        break;
    150 +      case 'p':
    151 +        drw_setscheme(drw, scheme[SchemePurple]);
    152 +        break;
    153 +      case 'h':
    154 +        drw_setscheme(drw, scheme[SchemeHighlight]);
    155 +        break;
    156 +      case 's':
    157 +        drw_setscheme(drw, scheme[SchemeSel]);
    158 +        break;
    159 +      default:
    160 +        drw_setscheme(drw, scheme[SchemeSel]);
    161 +        iscomment = 0;
    162 +        break;
    163 +      }
    164 +    } else {
    165 +      drw_setscheme(drw, scheme[SchemeNorm]);
    166 +    }
    167 +  } else {
    168 +    if (item == sel)
    169 +      drw_setscheme(drw, scheme[SchemeSel]);
    170 +    else if (item->left == sel || item->right == sel)
    171 +      drw_setscheme(drw, scheme[SchemeMid]);
    172 +    else if (item->out)
    173 +      drw_setscheme(drw, scheme[SchemeOut]);
    174 +    else
    175 +      drw_setscheme(drw, scheme[SchemeNorm]);
    176 +  }
    177 +
    178 +  int temppadding;
    179 +  temppadding = 0;
    180 +  if (iscomment == 2) {
    181 +    if (item->text[2] == ' ') {
    182 +      temppadding = drw->fonts->h * 3;
    183 +      animated = 1;
    184 +      char dest[1000];
    185 +      strcpy(dest, item->text);
    186 +      dest[6] = '\0';
    187 +      drw_text(drw, x, y, temppadding, lineheight, temppadding / 2.6, dest + 3, 0);
    188 +      iscomment = 6;
    189 +      drw_setscheme(drw, sel == item ? scheme[SchemeHover] : scheme[SchemeNorm]);
    190 +    }
    191 +  }
    192 +
    193 +  char *output;
    194 +  if (commented) {
    195 +    static char onestr[2];
    196 +    onestr[0] = item->text[0];
    197 +    onestr[1] = '\0';
    198 +    output = onestr;
    199 +  } else {
    200 +    output = item->text;
    201 +  }
    202 +
    203 +  if (item == sel)
    204 +    sely = y;
    205 +  return drw_text(
    206 +      drw, x + ((iscomment == 6) ? temppadding : 0), y,
    207 +      commented ? bh : (w - ((iscomment == 6) ? temppadding : 0)), bh,
    208 +      commented ? (bh - drw_fontset_getwidth(drw, (output))) / 2 : lrpad / 2,
    209 +      output + iscomment, 0);
    210  }
    211  
    212  static void
    213 @@ -131,7 +251,7 @@ drawmenu(void)
    214  {
    215  	unsigned int curpos;
    216  	struct item *item;
    217 -	int x = 0, y = 0, w;
    218 +	int x = 0, y = 0, fh = drw->fonts->h, w;
    219  
    220  	drw_setscheme(drw, scheme[SchemeNorm]);
    221  	drw_rect(drw, 0, 0, mw, mh, 1, 1);
    222 @@ -148,7 +268,7 @@ drawmenu(void)
    223  	curpos = TEXTW(text) - TEXTW(&text[cursor]);
    224  	if ((curpos += lrpad / 2 - 1) < w) {
    225  		drw_setscheme(drw, scheme[SchemeNorm]);
    226 -		drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
    227 +		drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
    228  	}
    229  
    230  	if (lines > 0) {
    231 @@ -609,6 +729,7 @@ setup(void)
    232  
    233  	/* calculate menu geometry */
    234  	bh = drw->fonts->h + 2;
    235 +    bh = MAX(bh,lineheight);	/* make a menu line AT LEAST 'lineheight' tall */
    236  	lines = MAX(lines, 0);
    237  	mh = (lines + 1) * bh;
    238  #ifdef XINERAMA
    239 @@ -637,9 +758,9 @@ setup(void)
    240  				if (INTERSECT(x, y, 1, 1, info[i]))
    241  					break;
    242  
    243 -		x = info[i].x_org;
    244 -		y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
    245 -		mw = info[i].width;
    246 +		x = info[i].x_org + dmx;
    247 +		y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy);
    248 +		mw = (dmw>0 ? dmw : info[i].width);
    249  		XFree(info);
    250  	} else
    251  #endif
    252 @@ -647,9 +768,9 @@ setup(void)
    253  		if (!XGetWindowAttributes(dpy, parentwin, &wa))
    254  			die("could not get embedding window attributes: 0x%lx",
    255  			    parentwin);
    256 -		x = 0;
    257 -		y = topbar ? 0 : wa.height - mh;
    258 -		mw = wa.width;
    259 +		x = dmx;
    260 +		y = topbar ? dmy : wa.height - mh - dmy;
    261 +		mw = (dmw>0 ? dmw : wa.width);
    262  	}
    263  	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
    264  	inputw = MIN(inputw, mw/3);
    265 @@ -689,7 +810,8 @@ setup(void)
    266  static void
    267  usage(void)
    268  {
    269 -	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
    270 +	fputs("usage: dmenu [-bfiv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
    271 +	      "             [-x xoffset] [-y yoffset] [-z width]\n"
    272  	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
    273  	exit(1);
    274  }
    275 @@ -717,6 +839,16 @@ main(int argc, char *argv[])
    276  		/* these options take one argument */
    277  		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
    278  			lines = atoi(argv[++i]);
    279 +        else if (!strcmp(argv[i], "-x"))   /* window x offset */
    280 +			dmx = atoi(argv[++i]);
    281 +		else if (!strcmp(argv[i], "-y"))   /* window y offset (from bottom up if -b) */
    282 +			dmy = atoi(argv[++i]);
    283 +		else if (!strcmp(argv[i], "-z"))   /* make dmenu this wide */
    284 +			dmw = atoi(argv[++i]);
    285 +        else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
    286 +			lineheight = atoi(argv[++i]);
    287 +			lineheight = MAX(lineheight, min_lineheight);
    288 +		}
    289  		else if (!strcmp(argv[i], "-m"))
    290  			mon = atoi(argv[++i]);
    291  		else if (!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
    292 @@ -752,6 +884,9 @@ main(int argc, char *argv[])
    293  		die("no fonts could be loaded.");
    294  	lrpad = drw->fonts->h;
    295  
    296 +    if (lineheight == -1)
    297 +        lineheight = drw->fonts->h * 2.5;
    298 +
    299  #ifdef __OpenBSD__
    300  	if (pledge("stdio rpath", NULL) == -1)
    301  		die("pledge");