diff --git a/docs/docs.md b/docs/docs.md index dda196d..63c6977 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -157,6 +157,9 @@ You may use long, descriptive arguments or the shorter arguments. `-hpr, --hide-prompt ` : Hide prompt +`-hpl, --hide-powerline ` +: Hide powerline + `-hc, --hide-cursor ` : Hide cursor @@ -181,6 +184,9 @@ You may use long, descriptive arguments or the shorter arguments. `-spr, --show-prompt ` : Show prompt +`-spl, --show-powerline ` +: Show powerline + `-sc, --show-cursor ` : Show cursor diff --git a/docs/example.Xresources b/docs/example.Xresources index 2db97b7..50ccd54 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -59,7 +59,7 @@ spmenu.accuratewidth: 1 spmenu.borderwidth: 0 !! Lines and columns -spmenu.lineheight: 5 +spmenu.lineheight: 1 spmenu.lines: 0 spmenu.columns: 10 spmenu.preselected: 0 @@ -103,6 +103,7 @@ spmenu.hidemode: 0 spmenu.hidelarrow: 0 spmenu.hiderarrow: 0 spmenu.hideprompt: 0 +spmenu.hidepowerline: 0 spmenu.hidecursor: 0 spmenu.hidehighlight: 0 spmenu.hideimage: 0 diff --git a/libs/argv.c b/libs/argv.c index 28b9b62..af23a0a 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -112,8 +112,12 @@ readargs(int argc, char *argv[]) hiderarrow = 0; } else if (!strcmp(argv[i], "-hpr") || (!strcmp(argv[i], "--hide-prompt"))) { // hide prompt hideprompt = 1; + } else if (!strcmp(argv[i], "-hpl") || (!strcmp(argv[i], "--hide-powerline"))) { // hide powerline + hidepowerline = 1; } else if (!strcmp(argv[i], "-spr") || (!strcmp(argv[i], "--show-prompt"))) { // show prompt hideprompt = 0; + } else if (!strcmp(argv[i], "-spl") || (!strcmp(argv[i], "--show-powerline"))) { // show prompt + hidepowerline = 0; } else if (!strcmp(argv[i], "-hc") || (!strcmp(argv[i], "--hide-cursor"))) { // hide cursor hidecursor = 1; } else if (!strcmp(argv[i], "-sc") || (!strcmp(argv[i], "--show-cursor"))) { // show cursor @@ -379,6 +383,7 @@ usage(void) "spmenu -hla, --hide-left-arrow Hide left arrow\n" "spmenu -hra, --hide-right-arrow Hide right arrow\n" "spmenu -hpr, --hide-prompt Hide prompt\n" + "spmenu -hpl, --hide-powerline Hide powerline\n" "spmenu -hc, --hide-cursor Hide cursor\n" "spmenu -hhl, --hide-highlighting Hide highlight\n" "spmenu -hi, --hide-image Hide image\n" diff --git a/libs/draw.c b/libs/draw.c index 277eeaf..a0dfe59 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -153,10 +153,13 @@ drawmenu(void) struct item *item; int x = 0, y = 0, fh = drw->font->h, w; #if USEIMAGE - int ox = 0; + int ox = 0; // original x position #endif - char *censort; + char *censort; // censor text (password) + plw = hidepowerline ? 0 : drw->font->h / 2 + 1; // powerline size + Clr *prevscheme, *nextscheme; + // draw menu first using menu scheme drw_setscheme(drw, scheme[SchemeMenu]); drw_rect(drw, 0, 0, mw, mh, 1, 1); @@ -165,17 +168,24 @@ drawmenu(void) int larrowWidth = 0; int rarrowWidth = 0; + // add width 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); if (prompt && *prompt) { + prevscheme = scheme[SchemePrompt]; drw_setscheme(drw, scheme[SchemePrompt]); #if USEIMAGE ox = x; #endif x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0, pango_prompt ? True : False); + + drw_settrans(drw, scheme[SchemePrompt], scheme[SchemeMenu]); + drw_arrow(drw, x, 0, plw, bh, 1, 0); + + x += plw; } // draw input diff --git a/libs/mouse.c b/libs/mouse.c index 02d665d..dd3f160 100644 --- a/libs/mouse.c +++ b/libs/mouse.c @@ -4,6 +4,11 @@ buttonpress(XEvent *e) struct item *item; XButtonPressedEvent *ev = &e->xbutton; int x = 0, y = 0, h = bh, w, item_num = 0; + int xpad = 0; + + if (!hidepowerline) { + x = xpad = plw; + } // if incorrect or wrong window, return if (ev->window != win) @@ -14,7 +19,7 @@ buttonpress(XEvent *e) exit(1); if (prompt && *prompt) - x += promptw; + x += promptw + plw; // input field w = (lines > 0 || !matches) ? mw - x : inputw; diff --git a/libs/sl/draw-pango.c b/libs/sl/draw-pango.c index 2bbe581..28566d2 100644 --- a/libs/sl/draw-pango.c +++ b/libs/sl/draw-pango.c @@ -12,6 +12,8 @@ #include "draw.h" #include "main.h" +Clr transcheme[3]; + Drw * drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap) { @@ -153,6 +155,44 @@ drw_setscheme(Drw *drw, Clr *scm) drw->scheme = scm; } +void +drw_settrans(Drw *drw, Clr *psc, Clr *nsc) +{ + if (drw) { + transcheme[0] = psc[ColBg]; transcheme[1] = nsc[ColBg]; transcheme[2] = psc[ColPwl]; + drw->scheme = transcheme; + } +} + +void +drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash) +{ + if (!drw || !drw->scheme) + return; + + x = direction ? x : x + w; + w = direction ? w : -w; + unsigned int hh = slash ? (direction ? 0 : h) : h/2; + + XPoint points[] = { + {x , y }, + {x + w, y + hh }, + {x , y + h }, + }; + + XPoint bg[] = { + {x , y }, + {x + w, y }, + {x + w, y + h}, + {x , y + h}, + }; + + XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel); + XFillPolygon(drw->dpy, drw->drawable, drw->gc, bg, 4, Convex, CoordModeOrigin); + XSetForeground(drw->dpy, drw->gc, drw->scheme[ColFg].pixel); + XFillPolygon(drw->dpy, drw->drawable, drw->gc, points, 3, Nonconvex, CoordModeOrigin); +} + void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) { diff --git a/libs/sl/draw-pango.h b/libs/sl/draw-pango.h index 07cc59b..c4ea777 100644 --- a/libs/sl/draw-pango.h +++ b/libs/sl/draw-pango.h @@ -10,7 +10,7 @@ typedef struct Fnt { PangoLayout *layout; } Fnt; -enum { ColFg, ColBg }; /* Clr scheme index */ +enum { ColFg, ColBg, ColPwl }; /* Clr scheme index */ typedef XftColor Clr; typedef struct { @@ -55,3 +55,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned in /* Map functions */ void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); + +/* Powerline functions */ +void drw_settrans(Drw *drw, Clr *psc, Clr *nsc); +void drw_arrow(Drw* drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash); diff --git a/libs/sl/draw-xft.c b/libs/sl/draw-xft.c index 6b5d2a0..65ab020 100644 --- a/libs/sl/draw-xft.c +++ b/libs/sl/draw-xft.c @@ -16,6 +16,8 @@ static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8} static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; +Clr transcheme[3]; + static long utf8decodebyte(const char c, size_t *i) { @@ -227,6 +229,44 @@ drw_setscheme(Drw *drw, Clr *scm) drw->scheme = scm; } +void +drw_settrans(Drw *drw, Clr *psc, Clr *nsc) +{ + if (drw) { + transcheme[0] = psc[ColBg]; transcheme[1] = nsc[ColBg]; transcheme[2] = psc[ColPwl]; + drw->scheme = transcheme; + } +} + +void +drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash) +{ + if (!drw || !drw->scheme) + return; + + x = direction ? x : x + w; + w = direction ? w : -w; + unsigned int hh = slash ? (direction ? 0 : h) : h/2; + + XPoint points[] = { + {x , y }, + {x + w, y + hh }, + {x , y + h }, + }; + + XPoint bg[] = { + {x , y }, + {x + w, y }, + {x + w, y + h}, + {x , y + h}, + }; + + XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel); + XFillPolygon(drw->dpy, drw->drawable, drw->gc, bg, 4, Convex, CoordModeOrigin); + XSetForeground(drw->dpy, drw->gc, drw->scheme[ColFg].pixel); + XFillPolygon(drw->dpy, drw->drawable, drw->gc, points, 3, Nonconvex, CoordModeOrigin); +} + void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) { @@ -422,3 +462,4 @@ drw_cur_free(Drw *drw, Cur *cursor) XFreeCursor(drw->dpy, cursor->cursor); free(cursor); } + diff --git a/libs/sl/draw-xft.h b/libs/sl/draw-xft.h index b400e9f..0ce0843 100644 --- a/libs/sl/draw-xft.h +++ b/libs/sl/draw-xft.h @@ -12,7 +12,7 @@ typedef struct Fnt { struct Fnt *next; } Fnt; -enum { ColFg, ColBg }; /* Clr scheme index */ +enum { ColFg, ColBg, ColPwl }; /* Clr scheme index */ typedef XftColor Clr; typedef struct { @@ -58,3 +58,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned in /* Map functions */ void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); + +/* Powerline functions */ +void drw_settrans(Drw *drw, Clr *psc, Clr *nsc); +void drw_arrow(Drw* drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash); diff --git a/libs/xresources.h b/libs/xresources.h index e253849..3facefb 100644 --- a/libs/xresources.h +++ b/libs/xresources.h @@ -120,6 +120,7 @@ ResourcePref resources[] = { { "hidelarrow", INTEGER, &hidelarrow }, { "hiderarrow", INTEGER, &hiderarrow }, { "hideprompt", INTEGER, &hideprompt }, + { "hidepowerline", INTEGER, &hidepowerline }, { "hidecursor", INTEGER, &hidecursor }, { "histnodup", INTEGER, &histnodup }, { "casesensitive", INTEGER, &casesensitive }, diff --git a/options.h b/options.h index 48092bb..e7fce53 100644 --- a/options.h +++ b/options.h @@ -50,7 +50,7 @@ static int accuratewidth = 1; /* Enable accurate width. May have a static int fuzzy = 1; /* Whether or not to enable fuzzy matching by default */ /* Line options */ -static int lineheight = 5; /* Line height (0: Calculate automatically) */ +static int lineheight = 1; /* Line height (0: Calculate automatically) */ static int lines = 0; /* Default number of lines */ static int columns = 10; /* Default number of columns */ @@ -59,6 +59,7 @@ static unsigned int maxhist = 64; /* Max number of history entries */ static int histnodup = 1; /* If 0, record repeated histories */ /* Prompt options */ +static int promptheight = 10; /* Extra prompt height */ static int indentitems = 1; /* Indent items to prompt width? (0/1) */ static char *prompt = NULL; /* Default prompt, set to NULL (nothing) */ @@ -68,6 +69,7 @@ static int hidemode = 0; /* Hide mode (0/1) */ static int hidelarrow = 0; /* Hide left arrow (0/1) */ static int hiderarrow = 0; /* Hide right arrow (0/1) */ static int hideprompt = 0; /* Hide prompt (0/1) */ +static int hidepowerline = 0; /* Hide powerline (0/1) */ static int hidecursor = 0; /* Hide cursor (0/1) */ static int hidehighlight = 0; /* Hide highlight (0/1) */ static int hideimage = 0; /* Hide image (0/1) */ diff --git a/spmenu.c b/spmenu.c index d1ade8c..43601b4 100644 --- a/spmenu.c +++ b/spmenu.c @@ -123,6 +123,7 @@ static int dmy = 0; // put spmenu at this y offset (measured from the bottom if static unsigned int dmw = 0; // make spmenu this wide static int inputw = 0; static int promptw; +static int plw = 0; static int passwd = 0; static int lrpad; // sum of left and right padding static int vp; // vertical padding for bar