Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/BlackCodec/jwm into Black…
Browse files Browse the repository at this point in the history
…Codec-master
  • Loading branch information
joewing committed Aug 1, 2024
2 parents 63b2ff5 + f1ab89e commit 5ffda19
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 50 deletions.
20 changes: 16 additions & 4 deletions src/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,22 @@ void LoadGradientBackground(BackgroundNode *bp)
char *temp;
char *sep;
int len;
int bg;
unsigned int w;
unsigned int h;

sep = strchr(bp->value, ':');
if (sep) {
bg = GRADIENT_VERTICAL;
w = 1;
h = rootHeight;
} else {
sep = strchr(bp->value, ';');
bg = GRADIENT_HORIZONTAL;
w = rootWidth;
h = 1;
}

if(sep) {

/* Gradient background. */
Expand Down Expand Up @@ -271,10 +285,8 @@ void LoadGradientBackground(BackgroundNode *bp)
JXSetForeground(display, rootGC, color1.pixel);
JXDrawPoint(display, bp->pixmap, rootGC, 0, 0);
} else {
bp->pixmap = JXCreatePixmap(display, rootWindow, 1, rootHeight,
rootDepth);
DrawHorizontalGradient(bp->pixmap, rootGC, color1.pixel,
color2.pixel, 0, 0, 1, rootHeight);
bp->pixmap = JXCreatePixmap(display, rootWindow, w, h, rootDepth);
DrawGradient(bp->pixmap, rootGC, color1.pixel, color2.pixel, 0, 0, w, h, bg);
}

}
Expand Down
8 changes: 5 additions & 3 deletions src/border.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ void DrawBorderHelper(const ClientNode *np)

long titleColor1, titleColor2;
long outlineColor;
int gradient;

int north, south, east, west;
unsigned int width, height;
Expand All @@ -411,14 +412,15 @@ void DrawBorderHelper(const ClientNode *np)
titleColor1 = colors[COLOR_TITLE_ACTIVE_BG1];
titleColor2 = colors[COLOR_TITLE_ACTIVE_BG2];
outlineColor = colors[COLOR_TITLE_ACTIVE_DOWN];
gradient = gradients[GRADIENT_TITLE_ACTIVE];

} else {

borderTextColor = COLOR_TITLE_FG;
titleColor1 = colors[COLOR_TITLE_BG1];
titleColor2 = colors[COLOR_TITLE_BG2];
outlineColor = colors[COLOR_TITLE_DOWN];

gradient = gradients[GRADIENT_TITLE];
}

/* Set parent background to reduce flicker. */
Expand All @@ -439,8 +441,8 @@ void DrawBorderHelper(const ClientNode *np)
XPoint point;

/* Draw a title bar. */
DrawHorizontalGradient(canvas, gc, titleColor1, titleColor2,
0, 1, width, titleHeight - 2);
DrawGradient(canvas, gc, titleColor1, titleColor2,
0, 1, width, titleHeight - 2, gradient);

/* Draw the buttons.
* This returns the start and end positions of the title as `x` and `y`.
Expand Down
4 changes: 2 additions & 2 deletions src/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ void DrawButton(ButtonNode *bp)
JXFillRectangle(display, drawable, gc, x, y, width, height);
} else {
/* gradient */
DrawHorizontalGradient(drawable, gc, bg1, bg2,
x, y, width, height);
DrawGradient(drawable, gc, bg1, bg2,
x, y, width, height, GRADIENT_VERTICAL);
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ void DrawClock(ClockType *clk, const TimeType *now)
JXFillRectangle(display, cp->pixmap, rootGC, 0, 0,
cp->width, cp->height);
} else {
DrawHorizontalGradient(cp->pixmap, rootGC,
DrawGradient(cp->pixmap, rootGC,
colors[COLOR_CLOCK_BG1], colors[COLOR_CLOCK_BG2],
0, 0, cp->width, cp->height);
0, 0, cp->width, cp->height, GRADIENT_VERTICAL);
}

/* Determine if the clock is the right size. */
Expand Down
1 change: 1 addition & 0 deletions src/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ unsigned long GetRGBFromXColor(const XColor *c)
return red | green | blue;
}


/** Set the color to use for a component. */
void SetColor(ColorType c, const char *value)
{
Expand Down
53 changes: 35 additions & 18 deletions src/gradient.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@
#include "color.h"
#include "main.h"

/** Draw a horizontal gradient. */
void DrawHorizontalGradient(Drawable d, GC g,
unsigned int gradients[GRADIENT_COUNT];

/** Set the color to use for a component. */
void SetGradient(GradientType c, const int value)
{
gradients[c] = value;
}

/** Draw a gradient. */
void DrawGradient(Drawable d, GC g,
long fromColor, long toColor,
int x, int y,
unsigned int width, unsigned int height)
unsigned int width, unsigned int height,
int type)
{

const int shift = 15;
unsigned int line;
unsigned int counter;
unsigned int limit;
XColor colors[2];
int red, green, blue;
int ared, agreen, ablue;
int bred, bgreen, bblue;
int redStep, greenStep, blueStep;

/* Return if there's nothing to do. */
if(width == 0 || height == 0) {
return;
}

/* Here we assume that the background was filled elsewhere. */
if(fromColor == toColor) {
/* Return if there's nothing to do or if the background was filled elsewhere. */
if((width == 0 || height == 0) || (fromColor == toColor)) {
return;
}

Expand All @@ -53,15 +58,23 @@ void DrawHorizontalGradient(Drawable d, GC g,
bblue = (unsigned int)colors[1].blue << shift;

/* Determine the step. */
redStep = (bred - ared) / (int)height;
greenStep = (bgreen - agreen) / (int)height;
blueStep = (bblue - ablue) / (int)height;
if (type == GRADIENT_VERTICAL) {
redStep = (bred - ared) / (int)height;
greenStep = (bgreen - agreen) / (int)height;
blueStep = (bblue - ablue) / (int)height;
limit = height;
} else {
redStep = (bred - ared) / (int)width;
greenStep = (bgreen - agreen) / (int)width;
blueStep = (bblue - ablue) / (int)width;
limit = width - 1;
}

/* Loop over each line. */
/* Loop over each line or column. */
red = ared;
blue = ablue;
green = agreen;
for(line = 0; line < height; line++) {
for(counter = 0; counter < limit; counter++) {

/* Determine the color for this line. */
colors[0].red = (unsigned short)(red >> shift);
Expand All @@ -72,8 +85,12 @@ void DrawHorizontalGradient(Drawable d, GC g,

/* Draw the line. */
JXSetForeground(display, g, colors[0].pixel);
JXDrawLine(display, d, g, x, y + line, x + width - 1, y + line);

if (type == GRADIENT_VERTICAL) {
JXDrawLine(display, d, g, x, y + counter, x + width - 1, y + counter);
} else {
JXDrawLine(display, d, g, x + counter, y, x + counter + 1, y + height - 1);
}

red += redStep;
green += greenStep;
blue += blueStep;
Expand Down
30 changes: 27 additions & 3 deletions src/gradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,28 @@
#ifndef GRADIENT_H
#define GRADIENT_H

/** Draw a horizontal gradient.
/** Enumeration of Gradient type used for determine gradient function to use.
*/
typedef unsigned char GradientType;
#define GRADIENT_DUMMY 0
#define GRADIENT_TITLE_ACTIVE 1
#define GRADIENT_TITLE 2
#define GRADIENT_COUNT 3

#define GRADIENT_HORIZONTAL 0
#define GRADIENT_VERTICAL 1

extern unsigned int gradients[GRADIENT_COUNT];

#define InitializeGradients() (void)(0)

/** Set the gradient type to use for a component.
* @param c The component whose color to set.
* @param value The gradient type to use.
*/
void SetGradient(GradientType c, const int value);

/** Draw a gradient.
* Note that no action is taken if fromColor == toColor.
* @param d The drawable on which to draw the gradient.
* @param g The graphics context to use.
Expand All @@ -20,11 +41,14 @@
* @param y The y-coordinate.
* @param width The width of the area to fill.
* @param height The height of the area to fill.
* @param type The gradient type
*/
void DrawHorizontalGradient(Drawable d, GC g,
void DrawGradient(Drawable d, GC g,
long fromColor, long toColor,
int x, int y,
unsigned int width, unsigned int height);
unsigned int width, unsigned int height,
int type);


#endif /* GRADIENT_H */

1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ void Initialize(void)
InitializeClients();
InitializeClock();
InitializeColors();
InitializeGradients();
InitializeCommands();
InitializeCursors();
InitializeDesktops();
Expand Down
37 changes: 21 additions & 16 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static void ParseFocusModel(const TokenNode *tp);

static AlignmentType ParseTextAlignment(const TokenNode *tp);
static void ParseDecorations(const TokenNode *tp, DecorationsType *deco);
static void ParseGradient(const char *value, ColorType a, ColorType b);
static void ParseGradient(const char *value, ColorType a, ColorType b, GradientType g);
static char *FindAttribute(AttributeNode *ap, const char *name);
static int ParseTokenValue(const StringMappingType *mapping, int count,
const TokenNode *tp, int def);
Expand Down Expand Up @@ -1045,10 +1045,10 @@ void ParseWindowStyle(const TokenNode *tp)
SetColor(COLOR_TITLE_FG, np->value);
break;
case TOK_BACKGROUND:
ParseGradient(np->value, COLOR_TITLE_BG1, COLOR_TITLE_BG2);
ParseGradient(np->value, COLOR_TITLE_BG1, COLOR_TITLE_BG2,GRADIENT_TITLE);
break;
case TOK_OUTLINE:
ParseGradient(np->value, COLOR_TITLE_DOWN, COLOR_TITLE_UP);
ParseGradient(np->value, COLOR_TITLE_DOWN, COLOR_TITLE_UP,GRADIENT_DUMMY);
break;
case TOK_OPACITY:
settings.inactiveClientOpacity = ParseOpacity(tp, np->value);
Expand All @@ -1075,11 +1075,10 @@ void ParseActiveWindowStyle(const TokenNode *tp)
break;
case TOK_BACKGROUND:
ParseGradient(np->value,
COLOR_TITLE_ACTIVE_BG1, COLOR_TITLE_ACTIVE_BG2);
COLOR_TITLE_ACTIVE_BG1, COLOR_TITLE_ACTIVE_BG2, GRADIENT_TITLE_ACTIVE);
break;
case TOK_OUTLINE:
ParseGradient(np->value, COLOR_TITLE_ACTIVE_DOWN,
COLOR_TITLE_ACTIVE_UP);
ParseGradient(np->value, COLOR_TITLE_ACTIVE_DOWN,COLOR_TITLE_ACTIVE_UP,GRADIENT_DUMMY);
break;
case TOK_OPACITY:
settings.activeClientOpacity = ParseOpacity(np, np->value);
Expand Down Expand Up @@ -1254,13 +1253,13 @@ void ParseTrayStyle(const TokenNode *tp, FontType font, ColorType fg)
ParseMinimized(np, minimizedFg, minimizedBg1, minimizedBg2, minimizedUp, minimizedDown);
break;
case TOK_BACKGROUND:
ParseGradient(np->value, bg1, bg2);
ParseGradient(np->value, bg1, bg2,GRADIENT_DUMMY);
break;
case TOK_FOREGROUND:
SetColor(fg, np->value);
break;
case TOK_OUTLINE:
ParseGradient(np->value, down, up);
ParseGradient(np->value, down, up,GRADIENT_DUMMY);
break;
case TOK_OPACITY:
if(tp->type == TOK_TRAYSTYLE) {
Expand Down Expand Up @@ -1289,15 +1288,15 @@ void ParseActive(const TokenNode *tp, ColorType fg,
if(bg1 == bg2) {
SetColor(bg1, np->value);
} else {
ParseGradient(np->value, bg1, bg2);
ParseGradient(np->value, bg1, bg2,GRADIENT_DUMMY);
}
break;
case TOK_FOREGROUND:
SetColor(fg, np->value);
break;
case TOK_OUTLINE:
if(up != COLOR_COUNT) {
ParseGradient(np->value, down, up);
ParseGradient(np->value, down, up,GRADIENT_DUMMY);
break;
}
/* fall through */
Expand Down Expand Up @@ -1510,13 +1509,13 @@ void ParseTrayButtonStyle(const TokenNode *tp)
COLOR_TRAYBUTTON_ACTIVE_UP, COLOR_TRAYBUTTON_ACTIVE_DOWN);
break;
case TOK_BACKGROUND:
ParseGradient(np->value, COLOR_TRAYBUTTON_BG1, COLOR_TRAYBUTTON_BG2);
ParseGradient(np->value, COLOR_TRAYBUTTON_BG1, COLOR_TRAYBUTTON_BG2,GRADIENT_DUMMY);
break;
case TOK_FOREGROUND:
SetColor(COLOR_TRAYBUTTON_FG, np->value);
break;
case TOK_OUTLINE:
ParseGradient(np->value, COLOR_TRAYBUTTON_DOWN, COLOR_TRAYBUTTON_UP);
ParseGradient(np->value, COLOR_TRAYBUTTON_DOWN, COLOR_TRAYBUTTON_UP,GRADIENT_DUMMY);
break;
default:
InvalidTag(np, TOK_TRAYBUTTONSTYLE);
Expand Down Expand Up @@ -1788,7 +1787,7 @@ void ParseClockStyle(const TokenNode *tp)
SetColor(COLOR_CLOCK_FG, np->value);
break;
case TOK_BACKGROUND:
ParseGradient(np->value, COLOR_CLOCK_BG1, COLOR_CLOCK_BG2);
ParseGradient(np->value, COLOR_CLOCK_BG1, COLOR_CLOCK_BG2,GRADIENT_DUMMY);
break;
case TOK_FONT:
SetFont(FONT_CLOCK, np->value);
Expand Down Expand Up @@ -1882,7 +1881,7 @@ void ParseMenuStyle(const TokenNode *tp)
COLOR_MENU_ACTIVE_UP, COLOR_MENU_ACTIVE_DOWN);
break;
case TOK_OUTLINE:
ParseGradient(np->value, COLOR_MENU_DOWN, COLOR_MENU_UP);
ParseGradient(np->value, COLOR_MENU_DOWN, COLOR_MENU_UP,GRADIENT_DUMMY);
break;
case TOK_OPACITY:
settings.menuOpacity = ParseOpacity(np, np->value);
Expand Down Expand Up @@ -1997,15 +1996,21 @@ void ParseDecorations(const TokenNode *tp, DecorationsType *deco)
}

/** Parse a color which may be a gradient. */
void ParseGradient(const char *value, ColorType a, ColorType b)
void ParseGradient(const char *value, ColorType a, ColorType b, GradientType g)
{

const char *sep;
char *temp;

/* Find the separator. */
sep = strchr(value, ':');

if (sep) {
SetGradient(g, GRADIENT_VERTICAL);
} else {
sep = strchr(value, ';');
SetGradient(g, GRADIENT_HORIZONTAL);
}

if(!sep) {

/* Only one color given - use the same color for both. */
Expand Down
4 changes: 2 additions & 2 deletions src/tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,9 @@ void ClearTrayDrawable(const TrayComponentType *cp)
JXSetForeground(display, rootGC, colors[COLOR_TRAY_BG1]);
JXFillRectangle(display, d, rootGC, 0, 0, cp->width, cp->height);
} else {
DrawHorizontalGradient(d, rootGC, colors[COLOR_TRAY_BG1],
DrawGradient(d, rootGC, colors[COLOR_TRAY_BG1],
colors[COLOR_TRAY_BG2], 0, 0,
cp->width, cp->height);
cp->width, cp->height, GRADIENT_VERTICAL);
}
}

Expand Down

0 comments on commit 5ffda19

Please sign in to comment.