selection_classic.c (scrot-1.6.tar.bz2) | : | selection_classic.c (scrot-1.7.tar.bz2) | ||
---|---|---|---|---|
/* scrot_selection_classic.c | /* scrot_selection_classic.c | |||
Copyright 2020-2021 Daniel T. Borelli <daltomi@disroot.org> | Copyright 2020-2021 Daniel T. Borelli <danieltborelli@gmail.com> | |||
Copyright 2021 Peter Wu <peterwu@hotmail.com> | ||||
Permission is hereby granted, free of charge, to any person obtaining a copy | Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to | of this software and associated documentation files (the "Software"), to | |||
deal in the Software without restriction, including without limitation the | deal in the Software without restriction, including without limitation the | |||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |||
sell copies of the Software, and to permit persons to whom the Software is | sell copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | The above copyright notice and this permission notice shall be included in | |||
all copies of the Software and its documentation and acknowledgment shall be | all copies of the Software and its documentation and acknowledgment shall be | |||
skipping to change at line 32 | skipping to change at line 33 | |||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
*/ | */ | |||
/* | /* | |||
This file is part of the scrot project. | This file is part of the scrot project. | |||
Part of the code comes from the main.c file and maintains its authorship. | Part of the code comes from the main.c file and maintains its authorship. | |||
*/ | */ | |||
#include "selection_classic.h" | #include "selection_classic.h" | |||
extern void selection_calculate_rect(int x0, int y0, int x1, int y1); | extern void selectionCalculateRect(int, int, int, int); | |||
extern struct selection_t** selection_get(void); | extern struct Selection** selectionGet(void); | |||
struct selection_classic_t { | struct SelectionClassic { | |||
XGCValues gcval; | XGCValues gcValues; | |||
GC gc; | GC gc; | |||
}; | }; | |||
void selection_classic_create(void) | void selectionClassicCreate(void) | |||
{ | { | |||
struct selection_t *const sel = *selection_get(); | struct Selection* const sel = *selectionGet(); | |||
sel->classic = calloc(1, sizeof(struct selection_classic_t)); | sel->classic = calloc(1, sizeof(*sel->classic)); | |||
struct selection_classic_t* pc = sel->classic; | struct SelectionClassic* pc = sel->classic; | |||
pc->gcval.function = GXxor; | unsigned long const whiteColor = XWhitePixel(disp, 0); | |||
pc->gcval.foreground = XWhitePixel(disp, 0); | unsigned long const blackColor = XBlackPixel(disp, 0); | |||
pc->gcval.background = XBlackPixel(disp, 0); | ||||
pc->gcval.plane_mask = pc->gcval.background ^ pc->gcval.foreground; | ||||
pc->gcval.subwindow_mode = IncludeInferiors; | ||||
if (opt.line_color != NULL) { | pc->gcValues.function = GXxor; | |||
XColor clr_exact, clr_closest; | pc->gcValues.foreground = whiteColor; | |||
Status ret; | pc->gcValues.background = blackColor; | |||
pc->gcValues.plane_mask = pc->gcValues.background ^ pc->gcValues.foreground; | ||||
pc->gcValues.subwindow_mode = IncludeInferiors; | ||||
ret = XAllocNamedColor(disp, XDefaultColormap(disp, DefaultScreen(disp)) | XColor color; | |||
, | scrotSelectionGetLineColor(&color); | |||
opt.line_color, &clr_exact, &clr_closest); | ||||
if (ret == 0) { | if (color.pixel != blackColor) | |||
free(opt.line_color); | pc->gcValues.foreground = color.pixel; | |||
fprintf(stderr, "Error allocate color:%s\n", strerror(BadColor)); | ||||
scrot_selection_destroy(); | ||||
exit(EXIT_FAILURE); | ||||
} | ||||
pc->gcval.foreground = clr_exact.pixel; | ||||
free(opt.line_color); | ||||
opt.line_color = NULL; | ||||
} | ||||
pc->gc = XCreateGC(disp, root, | pc->gc = XCreateGC(disp, root, | |||
GCFunction | GCForeground | GCBackground | GCSubwindowMode, | GCFunction | GCForeground | GCBackground | GCSubwindowMode, | |||
&pc->gcval); | &pc->gcValues); | |||
assert(pc->gc != NULL); | assert(pc->gc != NULL); | |||
XSetLineAttributes(disp, pc->gc, opt.line_width, opt.line_style, CapRound, J oinRound); | XSetLineAttributes(disp, pc->gc, opt.lineWidth, opt.lineStyle, CapRound, Joi nRound); | |||
if (opt.freeze == 1) { | if (opt.freeze) | |||
XGrabServer(disp); | XGrabServer(disp); | |||
} | ||||
} | } | |||
void selection_classic_destroy(void) | void selectionClassicDestroy(void) | |||
{ | { | |||
struct selection_t const *const sel = *selection_get(); | struct Selection const* const sel = *selectionGet(); | |||
struct selection_classic_t* pc = sel->classic; | struct SelectionClassic* pc = sel->classic; | |||
if (opt.freeze == 1) { | if (opt.freeze) | |||
XUngrabServer(disp); | XUngrabServer(disp); | |||
} | ||||
if (pc->gc) { | if (pc->gc) | |||
XFreeGC(disp, pc->gc); | XFreeGC(disp, pc->gc); | |||
} | ||||
free(pc); | free(pc); | |||
} | } | |||
void selection_classic_draw(void) | void selectionClassicDraw(void) | |||
{ | { | |||
struct selection_t const *const sel = *selection_get(); | struct Selection const* const sel = *selectionGet(); | |||
struct selection_classic_t const *const pc = sel->classic; | struct SelectionClassic const* const pc = sel->classic; | |||
XDrawRectangle(disp, root, pc->gc, sel->rect.x, sel->rect.y, sel->rect.w, se l->rect.h); | XDrawRectangle(disp, root, pc->gc, sel->rect.x, sel->rect.y, sel->rect.w, se l->rect.h); | |||
XFlush(disp); | XFlush(disp); | |||
} | } | |||
void selection_classic_motion_draw(int x0, int y0, int x1, int y1) | void selectionClassicMotionDraw(int x0, int y0, int x1, int y1) | |||
{ | { | |||
struct selection_t const *const sel = *selection_get(); | struct Selection const* const sel = *selectionGet(); | |||
if (sel->rect.w) { | if (sel->rect.w) | |||
selection_classic_draw(); | selectionClassicDraw(); | |||
} | selectionCalculateRect(x0, y0, x1, y1); | |||
selection_calculate_rect(x0, y0, x1, y1); | selectionClassicDraw(); | |||
selection_classic_draw(); | ||||
} | } | |||
End of changes. 26 change blocks. | ||||
54 lines changed or deleted | 39 lines changed or added |