commit d3f4eabd38936fae96a96b94801bcb753d42cde1
parent 9abe5617bed41b35fe53c8830708fd6a6eb2ec0e
Author: lumidify <nobody@lumidify.org>
Date: Sat, 6 Mar 2021 19:02:07 +0100
Avoid unnecessary redraws
Diffstat:
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/croptool.c b/croptool.c
@@ -79,7 +79,7 @@ struct Selection {
int orig_h;
int scaled_w;
int scaled_h;
- short valid;
+ char valid;
};
static struct {
@@ -105,10 +105,11 @@ static struct {
int cursor_x;
int cursor_y;
struct Point move_handle;
- short moving;
- short resizing;
- short lock_x;
- short lock_y;
+ char moving;
+ char resizing;
+ char lock_x;
+ char lock_y;
+ char dirty;
XColor col1;
XColor col2;
int cur_col;
@@ -510,6 +511,7 @@ static void
queue_update(int x, int y, int w, int h) {
if (state.cur_selection < 0 || !state.selections[state.cur_selection].valid)
return;
+ state.dirty = 1;
struct Selection *sel = &state.selections[state.cur_selection];
if (x > sel->scaled_w || y > sel->scaled_h)
return;
@@ -524,6 +526,8 @@ static void
redraw(void) {
Imlib_Image buffer;
Imlib_Updates current_update;
+ if (!state.dirty)
+ return;
if (!state.cur_image || state.cur_selection < 0) {
/* clear the window completely */
XSetForeground(state.dpy, state.gc, BlackPixel(state.dpy, state.screen));
@@ -591,9 +595,8 @@ swap_buffers:
if (!XdbeSwapBuffers(state.dpy, &swap_info, 1))
fprintf(stderr, "Warning: Unable to swap buffers.\n");
}
- #else
- ;
#endif
+ state.dirty = 0;
}
static void