selection_classic.c (scrot-1.7.tar.bz2) | : | selection_classic.c (scrot-1.8) | ||
---|---|---|---|---|
/* scrot_selection_classic.c | /* scrot_selection_classic.c | |||
Copyright 2020-2021 Daniel T. Borelli <danieltborelli@gmail.com> | Copyright 2020-2021 Daniel T. Borelli <danieltborelli@gmail.com> | |||
Copyright 2021-2022 Guilherme Janczak <guilherme.janczak@yandex.com> | ||||
Copyright 2021 Peter Wu <peterwu@hotmail.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 | |||
skipping to change at line 29 | skipping to change at line 30 | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
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 scrot.c file and maintains its authorship. | |||
*/ | */ | |||
#include "selection_classic.h" | ||||
extern void selectionCalculateRect(int, int, int, int); | #include <assert.h> | |||
extern struct Selection** selectionGet(void); | #include <stdlib.h> | |||
#include <X11/Xlib.h> | ||||
#include "imlib.h" | ||||
#include "options.h" | ||||
#include "scrot.h" | ||||
#include "scrot_selection.h" | ||||
#include "selection_classic.h" | ||||
#include "selection_edge.h" | ||||
struct SelectionClassic { | struct SelectionClassic { | |||
XGCValues gcValues; | XGCValues gcValues; | |||
GC gc; | GC gc; | |||
}; | }; | |||
void selectionClassicCreate(void) | void selectionClassicCreate(void) | |||
{ | { | |||
struct Selection* const sel = *selectionGet(); | struct Selection *const sel = *selectionGet(); | |||
sel->classic = calloc(1, sizeof(*sel->classic)); | sel->classic = calloc(1, sizeof(*sel->classic)); | |||
struct SelectionClassic* pc = sel->classic; | struct SelectionClassic *pc = sel->classic; | |||
unsigned long const whiteColor = XWhitePixel(disp, 0); | const unsigned long whiteColor = XWhitePixel(disp, 0); | |||
unsigned long const blackColor = XBlackPixel(disp, 0); | const unsigned long blackColor = XBlackPixel(disp, 0); | |||
pc->gcValues.function = GXxor; | pc->gcValues.function = GXxor; | |||
pc->gcValues.foreground = whiteColor; | pc->gcValues.foreground = whiteColor; | |||
pc->gcValues.background = blackColor; | pc->gcValues.background = blackColor; | |||
pc->gcValues.plane_mask = pc->gcValues.background ^ pc->gcValues.foreground; | pc->gcValues.plane_mask = pc->gcValues.background ^ pc->gcValues.foreground; | |||
pc->gcValues.subwindow_mode = IncludeInferiors; | pc->gcValues.subwindow_mode = IncludeInferiors; | |||
XColor color; | XColor color; | |||
scrotSelectionGetLineColor(&color); | scrotSelectionGetLineColor(&color); | |||
if (color.pixel != blackColor) | if (color.pixel != blackColor) | |||
pc->gcValues.foreground = color.pixel; | pc->gcValues.foreground = color.pixel; | |||
pc->gc = XCreateGC(disp, root, | pc->gc = XCreateGC(disp, root, | |||
GCFunction | GCForeground | GCBackground | GCSubwindowMode, | GCFunction | GCForeground | GCBackground | GCSubwindowMode, | |||
&pc->gcValues); | &pc->gcValues); | |||
assert(pc->gc != NULL); | assert(pc->gc != NULL); | |||
XSetLineAttributes(disp, pc->gc, opt.lineWidth, opt.lineStyle, CapRound, Joi | XSetLineAttributes(disp, pc->gc, opt.lineWidth, opt.lineStyle, CapRound, | |||
nRound); | JoinRound); | |||
if (opt.freeze) | if (opt.freeze) | |||
XGrabServer(disp); | XGrabServer(disp); | |||
} | } | |||
void selectionClassicDestroy(void) | ||||
{ | ||||
struct Selection const* const sel = *selectionGet(); | ||||
struct SelectionClassic* pc = sel->classic; | ||||
if (opt.freeze) | ||||
XUngrabServer(disp); | ||||
if (pc->gc) | ||||
XFreeGC(disp, pc->gc); | ||||
free(pc); | ||||
} | ||||
void selectionClassicDraw(void) | void selectionClassicDraw(void) | |||
{ | { | |||
struct Selection const* const sel = *selectionGet(); | const struct Selection *const sel = *selectionGet(); | |||
struct SelectionClassic const* const pc = sel->classic; | const struct SelectionClassic *const pc = sel->classic; | |||
XDrawRectangle(disp, root, pc->gc, sel->rect.x, sel->rect.y, sel->rect.w, se | XDrawRectangle(disp, root, pc->gc, sel->rect.x, sel->rect.y, sel->rect.w, | |||
l->rect.h); | sel->rect.h); | |||
XFlush(disp); | XFlush(disp); | |||
} | } | |||
void selectionClassicMotionDraw(int x0, int y0, int x1, int y1) | void selectionClassicMotionDraw(int x0, int y0, int x1, int y1) | |||
{ | { | |||
struct Selection const* const sel = *selectionGet(); | const struct Selection *const sel = *selectionGet(); | |||
if (sel->rect.w) | if (sel->rect.w) | |||
selectionClassicDraw(); | selectionClassicDraw(); | |||
selectionCalculateRect(x0, y0, x1, y1); | selectionCalculateRect(x0, y0, x1, y1); | |||
selectionClassicDraw(); | selectionClassicDraw(); | |||
} | } | |||
void selectionClassicDestroy(void) | ||||
{ | ||||
const struct Selection *const sel = *selectionGet(); | ||||
struct SelectionClassic *pc = sel->classic; | ||||
if (opt.freeze) | ||||
XUngrabServer(disp); | ||||
if (pc->gc) | ||||
XFreeGC(disp, pc->gc); | ||||
free(pc); | ||||
XFlush(disp); | ||||
} | ||||
End of changes. 12 change blocks. | ||||
29 lines changed or deleted | 24 lines changed or added |