Skip to content

Commit

Permalink
Merge pull request #55 from danieljprice/band-bug
Browse files Browse the repository at this point in the history
Band bug - fix to incorrect window colours when clicking in a plot window
  • Loading branch information
danieljprice authored Dec 1, 2024
2 parents 7419e8f + fbcd541 commit b345d85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/giza-band.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ _giza_refresh_band (int mode, int nanc, const int *xanc, const int *yanc, int x2

/* Draw over the old band */
cairo_paint (Band.restore);
giza_flush_device();

/*
int topleftx = x1 - 10;
Expand Down
24 changes: 15 additions & 9 deletions src/giza-driver-xw.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ static void _giza_expose_xw (XEvent *event);
static void _giza_flush_xw_event_queue (XEvent *event);
static int _giza_errors_xw (Display *display, XErrorEvent *error);

static Atom wmDeleteMessage;
/*static int giza_xw_debug = 0;*/

/**
Expand Down Expand Up @@ -116,7 +117,7 @@ _giza_open_device_xw (double width, double height, int units)
XW[id].display = XOpenDisplay (NULL);
if (!XW[id].display)
{
_giza_error ("_giza_open_device_xw", "Connection to the X server could not be made");
_giza_error ("_giza_open_device_xw", "Cannot launch X window (use ssh -Y not ssh / install XQuartz if on Mac)");
return 1;
}

Expand Down Expand Up @@ -196,7 +197,7 @@ _giza_open_device_xw (double width, double height, int units)
XMapWindow (XW[id].display, XW[id].window);

/* register interest in the delete window message */
Atom wmDeleteMessage = XInternAtom(XW[id].display, "WM_DELETE_WINDOW", 1);
wmDeleteMessage = XInternAtom(XW[id].display, "WM_DELETE_WINDOW", 0);
XSetWMProtocols(XW[id].display, XW[id].window, &wmDeleteMessage, 1);

/* register the routine to handle non-fatal X errors */
Expand Down Expand Up @@ -374,7 +375,7 @@ _giza_xevent_loop (int mode, int moveCurs, int nanc, const int *anchorx, const i
}

XEvent event;
XSelectInput (XW[id].display, XW[id].window, ExposureMask | KeyPressMask | ButtonPressMask | PointerMotionMask);
XSelectInput (XW[id].display, XW[id].window, ExposureMask | KeyPressMask | ButtonPressMask | PointerMotionMask | StructureNotifyMask );

_giza_init_band (mode);
_giza_expand_clipping_xw();
Expand All @@ -383,19 +384,22 @@ _giza_xevent_loop (int mode, int moveCurs, int nanc, const int *anchorx, const i

/* wait for key press/expose (avoid using XNextEvent as breaks older systems) */
XWindowEvent(XW[id].display, XW[id].window,
(long) (ExposureMask | KeyPressMask | ButtonPressMask | PointerMotionMask), &event);
(long) (ExposureMask | KeyPressMask | ButtonPressMask | PointerMotionMask | StructureNotifyMask), &event);
/*XNextEvent(XW[id].display, &event);*/

/* always return x, y values for safety */
*x = 0;
*y = 0;

switch (event.type) {
case ClientMessage: /* catch close window event */
*ch = 'q';
if (!strcmp( XGetAtomName( XW[id].display, event.xclient.message_type ), "WM_PROTOCOLS" )) {
return;
}
if ((Atom)event.xclient.data.l[0] == wmDeleteMessage) {
return;
}
break;
case DestroyNotify:
*ch = 'q';
return;
case Expose: /* redraw */
_giza_expose_xw (&event);
break;
Expand Down Expand Up @@ -600,8 +604,10 @@ _giza_init_band_xw (void)
/* use grey for band */
cairo_set_source_rgba (Band.box, 0.5, 0.5, 0.5, 1.0);

/* Set up restore to remove box */
/* Set up restore to remove box (DP: 2/12/24 we now restore from pixmap instead of window to fix issue on Mac OS)*/
Band.onscreen = cairo_xlib_surface_create (XW[id].display, XW[id].pixmap, XW[id].visual, XW[id].width, XW[id].height);
Band.restore = cairo_create (Band.onscreen);

cairo_set_source_surface (Band.restore, Dev[id].surface, 0, 0);
Band.maxHeight = XW[id].height;
Band.maxWidth = XW[id].width;
Expand Down
2 changes: 1 addition & 1 deletion src/giza-drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ _giza_init_band (int mode)
#endif
default:
_giza_error ("_giza_init_band", "band not implemented for this device");
break;
break;
}
_giza_set_line_style (Band.ls, Band.box);
double lwDevice = Band.lw * Dev[id].deviceUnitsPermm * 0.25;
Expand Down

0 comments on commit b345d85

Please sign in to comment.