add rounded variant of the powerline

This commit is contained in:
speedie 2023-06-07 21:31:10 +02:00
parent a105dccb90
commit 9eb97d5da0
5 changed files with 78 additions and 17 deletions

View file

@ -137,10 +137,10 @@ spmenu = {
} );
/* Powerline options */
powerline = ( { promptstyle = 0; // Prompt powerline style (0: >, 1: \)
matchcountstyle = 0; // Match count powerline style (0: <, 1: /)
modestyle = 0; // Mode indicator powerline style (0: <, 1: /)
capsstyle = 0; // Caps lock indicator powerline style (0: <, 1: /)
powerline = ( { promptstyle = 0; // Prompt powerline style (0: >, 1: \, 2: ))
matchcountstyle = 0; // Match count powerline style (0: <, 1: /, 2: ()
modestyle = 0; // Mode indicator powerline style (0: <, 1: /, 2: ()
capsstyle = 0; // Caps lock indicator powerline style (0: <, 1: /, 2: ()
prompt = 1; // Enable prompt powerline (0/1)
matchcount = 1; // Enable match count powerline (0/1)
mode = 1; // Enable mode indicator powerline (0/1)

View file

@ -359,7 +359,12 @@ int drawprompt(int x, int y, int w) {
x = drw_text(drw, x, y, w, bh, lrpad / 2, prompt, 0, pango_prompt ? True : False, col_promptfg, col_promptbg, alpha_promptfg, alpha_promptbg);
if (!hidepowerline && powerlineprompt) {
drw_arrow(drw, x, y, plw, bh, 1, promptpwlstyle, col_menu, col_promptbg, alpha_menu, alpha_promptbg);
if (promptpwlstyle == 2) {
drw_circle(drw, x, y, plw, bh, 1, col_menu, col_promptbg, alpha_menu, alpha_promptbg);
} else {
drw_arrow(drw, x, y, plw, bh, 1, promptpwlstyle, col_menu, col_promptbg, alpha_menu, alpha_promptbg);
}
x += plw;
}
}
@ -433,7 +438,11 @@ int drawnumber(int x, int y, int w) {
// draw powerline for match count
if (!hidepowerline && powerlinecount) {
drw_arrow(drw, x, y, plw, bh, 0, matchcountpwlstyle, col_menu, col_numbg, alpha_menu, alpha_numbg);
if (matchcountpwlstyle == 2) {
drw_circle(drw, x, y, plw, bh, 0, col_menu, col_numbg, alpha_menu, alpha_numbg);
} else {
drw_arrow(drw, x, y, plw, bh, 0, matchcountpwlstyle, col_menu, col_numbg, alpha_menu, alpha_numbg);
}
x += plw;
}
@ -453,9 +462,15 @@ int drawmode(int x, int y, int w) {
// draw powerline for match count
if (!hidepowerline && powerlinemode) {
drw_arrow(drw, x, y, plw, bh, 0, modepwlstyle,
hidematchcount ? col_menu : col_numbg, col_modebg,
hidematchcount ? alpha_menu : alpha_numbg, alpha_modebg);
if (modepwlstyle == 2) {
drw_circle(drw, x, y, plw, bh, 0,
hidematchcount ? col_menu : col_numbg, col_modebg,
hidematchcount ? alpha_menu : alpha_numbg, alpha_modebg);
} else {
drw_arrow(drw, x, y, plw, bh, 0, modepwlstyle,
hidematchcount ? col_menu : col_numbg, col_modebg,
hidematchcount ? alpha_menu : alpha_numbg, alpha_modebg);
}
x += plw;
}
@ -478,9 +493,15 @@ int drawcaps(int x, int y, int w) {
// draw powerline for caps lock indicator
if (!hidepowerline && powerlinecaps) {
drw_arrow(drw, x, y, plw, bh, 0, capspwlstyle,
hidemode ? hidematchcount ? col_menu : col_numbg : col_modebg, col_capsbg,
hidemode ? hidematchcount ? alpha_menu : alpha_numbg : alpha_modebg, alpha_capsbg);
if (capspwlstyle == 2) {
drw_circle(drw, x, y, plw, bh, 0,
hidemode ? hidematchcount ? col_menu : col_numbg : col_modebg, col_capsbg,
hidemode ? hidematchcount ? alpha_menu : alpha_numbg : alpha_modebg, alpha_capsbg);
} else {
drw_arrow(drw, x, y, plw, bh, 0, capspwlstyle,
hidemode ? hidematchcount ? col_menu : col_numbg : col_modebg, col_capsbg,
hidemode ? hidematchcount ? alpha_menu : alpha_numbg : alpha_modebg, alpha_capsbg);
}
x += plw;
}

View file

@ -6,7 +6,7 @@
#include <cairo/cairo.h>
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <iconv.h>
#include <math.h>
#include "drw.h"
#include "../sl/main.h"
@ -191,6 +191,45 @@ void drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direc
cairo_surface_destroy(sf);
}
void drw_circle(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, char *prevcol, char *nextcol, int prevalpha, int nextalpha) {
if (!drw)
return;
cairo_surface_t *sf = NULL;
if (drw->protocol) {
sf = cairo_image_surface_create_for_data(drw->data, CAIRO_FORMAT_ARGB32, drw->w, drw->h, drw->w * 4);
} else {
sf = cairo_xlib_surface_create(drw->dpy, drw->drawable, drw->visual, drw->w, drw->h);
}
cairo_t *cr = cairo_create(sf);
cairo_set_source_hex(cr, prevcol, prevalpha);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
// draw rectangle
cairo_rectangle(cr, x, y, w, h);
cairo_fill(cr);
double cx = direction ? x + w - h / 2.0 : x + h / 2.0;
double cy = y + h / 2;
double rad = h / 2.0;
double start = direction ? -M_PI_2 : M_PI_2;
double end = direction ? M_PI_2 : 3 * M_PI_2;
// draw circle
cairo_arc(cr, cx, cy, rad, start, end);
cairo_close_path(cr);
cairo_set_source_hex(cr, nextcol, nextalpha);
cairo_fill(cr);
cairo_destroy(cr);
cairo_surface_destroy(sf);
}
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert, char *fgcol, char *bgcol, int fgalpha, int bgalpha) {
if (!drw) {
return;

View file

@ -64,3 +64,4 @@ void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
/* Powerline functions */
void drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash, char *prevcol, char *nextcol, int prevalpha, int nextalpha);
void drw_circle(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, char *prevcol, char *nextcol, int prevalpha, int nextalpha);

View file

@ -40,10 +40,10 @@ static int powerlineprompt = 1; /* Enable powerline for the prompt *
static int powerlinecount = 1; /* Enable powerline for the match count */
static int powerlinemode = 1; /* Enable powerline for the mode indicator */
static int powerlinecaps = 1; /* Enable powerline for the caps lock indicator */
static int promptpwlstyle = 0; /* Prompt powerline style (0: >, 1: \) */
static int matchcountpwlstyle = 0; /* Match count powerline style (0: <, 1: /) */
static int modepwlstyle = 0; /* Mode indicator powerline style (0: <, 1: /) */
static int capspwlstyle = 0; /* Caps lock indicator powerline style (0: <, 1: /) */
static int promptpwlstyle = 0; /* Prompt powerline style (0: >, 1: \, 2: )) */
static int matchcountpwlstyle = 0; /* Match count powerline style (0: <, 1: /, 2: () */
static int modepwlstyle = 0; /* Mode indicator powerline style (0: <, 1: /, 2: () */
static int capspwlstyle = 0; /* Caps lock indicator powerline style (0: <, 1: /, 2: () */
/* Window properties */
static int dockproperty = 1; /* Set _NET_WM_WINDOW_TYPE_DOCK */