Skip to content

Commit 888f40c

Browse files
committed
simplify scrotSelectionGetLineColor()
- return a value instead of out pointer - remove scrotSelectionCreateNamedColor
1 parent fa1c88d commit 888f40c

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

src/scrot_selection.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5555
static void scrotSelectionCreate(void);
5656
static void scrotSelectionDestroy(void);
5757
static void scrotSelectionMotionDraw(int, int, int, int);
58-
static Status scrotSelectionCreateNamedColor(const char *, XColor *);
5958
static bool scrotSelectionGetUserSel(struct SelectionRect *);
6059

6160
struct Selection selection;
@@ -187,23 +186,17 @@ static void scrotSelectionMotionDraw(int x0, int y0, int x1, int y1)
187186
sel->motionDraw(x0, y0, x1, y1);
188187
}
189188

190-
static Status scrotSelectionCreateNamedColor(const char *nameColor, XColor *color)
189+
XColor scrotSelectionGetLineColor(void)
191190
{
192-
scrotAssert(nameColor != NULL);
193-
scrotAssert(color != NULL);
191+
scrotAssert(opt.lineColor != NULL);
194192

195-
return XAllocNamedColor(disp, XDefaultColormap(disp, DefaultScreen(disp)),
196-
nameColor, color, &(XColor){0});
197-
}
198-
199-
void scrotSelectionGetLineColor(XColor *color)
200-
{
201-
const Status ret = scrotSelectionCreateNamedColor(opt.lineColor, color);
202-
203-
if (!ret) {
193+
XColor color;
194+
Colormap cmap = XDefaultColormap(disp, DefaultScreen(disp));
195+
if (!XAllocNamedColor(disp, cmap, opt.lineColor, &color, &(XColor){0})) {
204196
scrotSelectionDestroy();
205197
errx(EXIT_FAILURE, "Error allocating color: %s", opt.lineColor);
206198
}
199+
return color;
207200
}
208201

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

464-
XColor color;
465-
scrotSelectionGetLineColor(&color);
457+
XColor color = scrotSelectionGetLineColor();
466458

467459
const int x = rect1.x - rect0.x; /* NOLINT(*UndefinedBinaryOperatorResult) */
468460
const int y = rect1.y - rect0.y;

src/scrot_selection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct Selection {
109109
extern struct Selection selection;
110110

111111
void selectionCalculateRect(int, int, int, int);
112-
void scrotSelectionGetLineColor(XColor *);
112+
XColor scrotSelectionGetLineColor(void);
113113
Imlib_Image scrotSelectionSelectMode(void);
114114

115115
#endif /* !defined(H_SCROT_SELECTION) */

src/selection_classic.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ void selectionClassicCreate(void)
5757
pc->gcValues.plane_mask = pc->gcValues.background ^ pc->gcValues.foreground;
5858
pc->gcValues.subwindow_mode = IncludeInferiors;
5959

60-
XColor color;
61-
scrotSelectionGetLineColor(&color);
60+
XColor color = scrotSelectionGetLineColor();
6261

6362
if (color.pixel != blackColor)
6463
pc->gcValues.foreground = color.pixel;

src/selection_edge.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ void selectionEdgeCreate(void)
5050
{
5151
struct SelectionEdge *const pe = &selection.edge;
5252

53-
XColor color;
54-
scrotSelectionGetLineColor(&color);
53+
XColor color = scrotSelectionGetLineColor();
5554

5655
XSetWindowAttributes attr;
5756
attr.background_pixel = color.pixel;

0 commit comments

Comments
 (0)