Skip to content

Commit

Permalink
simplify scrotSelectionGetLineColor()
Browse files Browse the repository at this point in the history
- return a value instead of out pointer
- remove scrotSelectionCreateNamedColor
  • Loading branch information
N-R-K committed Mar 7, 2025
1 parent fa1c88d commit 888f40c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
22 changes: 7 additions & 15 deletions src/scrot_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
static void scrotSelectionCreate(void);
static void scrotSelectionDestroy(void);
static void scrotSelectionMotionDraw(int, int, int, int);
static Status scrotSelectionCreateNamedColor(const char *, XColor *);
static bool scrotSelectionGetUserSel(struct SelectionRect *);

struct Selection selection;
Expand Down Expand Up @@ -187,23 +186,17 @@ static void scrotSelectionMotionDraw(int x0, int y0, int x1, int y1)
sel->motionDraw(x0, y0, x1, y1);
}

static Status scrotSelectionCreateNamedColor(const char *nameColor, XColor *color)
XColor scrotSelectionGetLineColor(void)
{
scrotAssert(nameColor != NULL);
scrotAssert(color != NULL);
scrotAssert(opt.lineColor != NULL);

return XAllocNamedColor(disp, XDefaultColormap(disp, DefaultScreen(disp)),
nameColor, color, &(XColor){0});
}

void scrotSelectionGetLineColor(XColor *color)
{
const Status ret = scrotSelectionCreateNamedColor(opt.lineColor, color);

if (!ret) {
XColor color;
Colormap cmap = XDefaultColormap(disp, DefaultScreen(disp));
if (!XAllocNamedColor(disp, cmap, opt.lineColor, &color, &(XColor){0})) {
scrotSelectionDestroy();
errx(EXIT_FAILURE, "Error allocating color: %s", opt.lineColor);
}
return color;
}

static bool scrotSelectionGetUserSel(struct SelectionRect *selectionRect)
Expand Down Expand Up @@ -461,8 +454,7 @@ Imlib_Image scrotSelectionSelectMode(void)
if (opt.selection.mode == SELECTION_MODE_CAPTURE)
return capture;

XColor color;
scrotSelectionGetLineColor(&color);
XColor color = scrotSelectionGetLineColor();

const int x = rect1.x - rect0.x; /* NOLINT(*UndefinedBinaryOperatorResult) */
const int y = rect1.y - rect0.y;
Expand Down
2 changes: 1 addition & 1 deletion src/scrot_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct Selection {
extern struct Selection selection;

void selectionCalculateRect(int, int, int, int);
void scrotSelectionGetLineColor(XColor *);
XColor scrotSelectionGetLineColor(void);
Imlib_Image scrotSelectionSelectMode(void);

#endif /* !defined(H_SCROT_SELECTION) */
3 changes: 1 addition & 2 deletions src/selection_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ void selectionClassicCreate(void)
pc->gcValues.plane_mask = pc->gcValues.background ^ pc->gcValues.foreground;
pc->gcValues.subwindow_mode = IncludeInferiors;

XColor color;
scrotSelectionGetLineColor(&color);
XColor color = scrotSelectionGetLineColor();

if (color.pixel != blackColor)
pc->gcValues.foreground = color.pixel;
Expand Down
3 changes: 1 addition & 2 deletions src/selection_edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void selectionEdgeCreate(void)
{
struct SelectionEdge *const pe = &selection.edge;

XColor color;
scrotSelectionGetLineColor(&color);
XColor color = scrotSelectionGetLineColor();

XSetWindowAttributes attr;
attr.background_pixel = color.pixel;
Expand Down

0 comments on commit 888f40c

Please sign in to comment.