1998-10-06 23:14:55 +04:00
|
|
|
//
|
2003-01-31 00:46:07 +03:00
|
|
|
// "$Id: Fl_visual.cxx,v 1.7.2.4.2.5 2003/01/30 21:43:10 easysw Exp $"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Visual support for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2003-01-31 00:46:07 +03:00
|
|
|
// Copyright 1998-2003 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2000-06-06 01:21:24 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
|
1998-10-06 23:14:55 +04:00
|
|
|
// Set the default visual according to passed switches:
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/x.H>
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
int Fl::visual(int flags) {
|
|
|
|
fl_GetDC(0);
|
|
|
|
if (flags & FL_DOUBLE) return 0;
|
|
|
|
if (!(flags & FL_INDEX) &&
|
|
|
|
GetDeviceCaps(fl_gc,BITSPIXEL) <= 8) return 0;
|
|
|
|
if ((flags & FL_RGB8) && GetDeviceCaps(fl_gc,BITSPIXEL)<24) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2001-11-27 20:44:08 +03:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
2002-01-03 11:08:21 +03:00
|
|
|
// \todo Mac : need to implement Visual flags
|
2001-11-27 20:44:08 +03:00
|
|
|
int Fl::visual(int flags) {
|
|
|
|
(void)flags;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-10-06 23:14:55 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
#if USE_XDBE
|
|
|
|
#include <X11/extensions/Xdbe.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int test_visual(XVisualInfo& v, int flags) {
|
|
|
|
if (v.screen != fl_screen) return 0;
|
2000-01-23 04:56:42 +03:00
|
|
|
#if USE_COLORMAP
|
1998-10-06 23:14:55 +04:00
|
|
|
if (!(flags & FL_INDEX)) {
|
1998-12-06 17:44:00 +03:00
|
|
|
if (v.c_class != StaticColor && v.c_class != TrueColor) return 0;
|
1998-10-06 23:14:55 +04:00
|
|
|
if (v.depth <= 8) return 0; // fltk will work better in colormap mode
|
|
|
|
}
|
|
|
|
if (flags & FL_RGB8) {
|
|
|
|
if (v.depth < 24) return 0;
|
|
|
|
}
|
|
|
|
// for now, fltk does not like colormaps of more than 8 bits:
|
1998-12-06 17:44:00 +03:00
|
|
|
if ((v.c_class&1) && v.depth > 8) return 0;
|
2000-01-23 04:56:42 +03:00
|
|
|
#else
|
|
|
|
// simpler if we can't use colormapped visuals at all:
|
|
|
|
if (v.c_class != StaticColor && v.c_class != TrueColor) return 0;
|
|
|
|
#endif
|
1998-10-06 23:14:55 +04:00
|
|
|
#if USE_XDBE
|
|
|
|
if (flags & FL_DOUBLE) {
|
|
|
|
static XdbeScreenVisualInfo *xdbejunk;
|
|
|
|
if (!xdbejunk) {
|
|
|
|
int event_base, error_base;
|
|
|
|
if (!XdbeQueryExtension(fl_display, &event_base, &error_base)) return 0;
|
|
|
|
Drawable root = RootWindow(fl_display,fl_screen);
|
|
|
|
int numscreens = 1;
|
|
|
|
xdbejunk = XdbeGetVisualInfo(fl_display,&root,&numscreens);
|
|
|
|
if (!xdbejunk) return 0;
|
|
|
|
}
|
|
|
|
for (int j = 0; ; j++) {
|
|
|
|
if (j >= xdbejunk->count) return 0;
|
|
|
|
if (xdbejunk->visinfo[j].visual == v.visualid) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl::visual(int flags) {
|
|
|
|
#if USE_XDBE == 0
|
|
|
|
if (flags & FL_DOUBLE) return 0;
|
|
|
|
#endif
|
|
|
|
fl_open_display();
|
|
|
|
// always use default if possible:
|
|
|
|
if (test_visual(*fl_visual, flags)) return 1;
|
|
|
|
// get all the visuals:
|
|
|
|
XVisualInfo vTemplate;
|
|
|
|
int num;
|
|
|
|
XVisualInfo *visualList = XGetVisualInfo(fl_display, 0, &vTemplate, &num);
|
|
|
|
// find all matches, use the one with greatest depth:
|
|
|
|
XVisualInfo *found = 0;
|
|
|
|
for (int i=0; i<num; i++) if (test_visual(visualList[i], flags)) {
|
|
|
|
if (!found || found->depth < visualList[i].depth)
|
|
|
|
found = &visualList[i];
|
|
|
|
}
|
|
|
|
if (!found) {XFree((void*)visualList); return 0;}
|
|
|
|
fl_visual = found;
|
|
|
|
fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
|
|
|
|
fl_visual->visual, AllocNone);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
1998-10-20 00:46:58 +04:00
|
|
|
|
|
|
|
//
|
2003-01-31 00:46:07 +03:00
|
|
|
// End of "$Id: Fl_visual.cxx,v 1.7.2.4.2.5 2003/01/30 21:43:10 easysw Exp $".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|