SetPort(GetWindowPort(s->window));
SetPort((GrafPtr)GetWindowPort(s->window));
void pre_paint(Session *s) {    GDHandle gdh;    Rect myrect, tmprect;#if TARGET_API_MAC_CARBON    RgnHandle visrgn;#endif    if (HAVE_COLOR_QD()) {	s->term->attr_mask = 0;	SetPort(GetWindowPort(s->window));#if TARGET_API_MAC_CARBON	visrgn = NewRgn();	GetPortVisibleRegion(GetWindowPort(s->window), visrgn);	GetRegionBounds(visrgn, &myrect);	DisposeRgn(visrgn);#else	myrect = (*s->window->visRgn)->rgnBBox;#endif	LocalToGlobal((Point *)&myrect.top);	LocalToGlobal((Point *)&myrect.bottom);	for (gdh = GetDeviceList();	     gdh != NULL;	     gdh = GetNextDevice(gdh)) {	    if (TestDeviceAttribute(gdh, screenDevice) &&		TestDeviceAttribute(gdh, screenActive) &&		SectRect(&(*gdh)->gdRect, &myrect, &tmprect)) {		switch ((*(*gdh)->gdPMap)->pixelSize) {		  case 1:		    if (s->cfg.bold_colour)			s->term->attr_mask |= ~(ATTR_COLOURS |			    (s->cfg.bold_colour ? ATTR_BOLD : 0));		    break;		  case 2:		    s->term->attr_mask |= ~ATTR_COLOURS;		    break;		  default:		    s->term->attr_mask = ~0;		    return; /* No point checking more screens. */		}	    }	}    } else	s->term->attr_mask = ~(ATTR_COLOURS |			        (s->cfg.bold_colour ? ATTR_BOLD : 0));}