/* * CINELERRA * Copyright (C) 2008 Adam Williams * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "bcdisplay.h" #include "bcdisplayinfo.h" #include "bcsignals.h" #include "bcwindowbase.h" #include "clip.h" #include "language.h" #include #include #include #include #define TEST_SIZE 128 #define TEST_DSIZE 28 #define TEST_SIZE2 164 int BC_DisplayInfo::top_border = -1; int BC_DisplayInfo::left_border = -1; int BC_DisplayInfo::bottom_border = -1; int BC_DisplayInfo::right_border = -1; int BC_DisplayInfo::auto_reposition_x = -1; int BC_DisplayInfo::auto_reposition_y = -1; char BC_DisplayInfo::gl_shader_version[64] = { 0, }; BC_DisplayInfo::BC_DisplayInfo(const char *display_name, int show_error) { screen = -1; xinerama_screens = -1; xinerama_info = 0; init_window(display_name, show_error); } BC_DisplayInfo::~BC_DisplayInfo() { if( xinerama_info ) XFree(xinerama_info); #ifndef SINGLE_THREAD XCloseDisplay(display); #endif } void BC_DisplayInfo::parse_geometry(char *geom, int *x, int *y, int *width, int *height) { XParseGeometry(geom, x, y, (unsigned int*)width, (unsigned int*)height); } int BC_DisplayInfo::get_xinerama_screens() { if( xinerama_screens < 0 ) { xinerama_screens = 0; if( XineramaIsActive(display) ) xinerama_info = XineramaQueryScreens(display, &xinerama_screens); } return xinerama_screens; } int BC_DisplayInfo::xinerama_geometry(int screen, int &x, int &y, int &w, int &h) { int screens = get_xinerama_screens(); if( !screens ) return 1; if( screen >= 0 ) { int k = screens; while( --k >= 0 && xinerama_info[k].screen_number != screen ); if( k < 0 ) return 1; x = xinerama_info[k].x_org; w = xinerama_info[k].width; y = xinerama_info[k].y_org; h = xinerama_info[k].height; } else { int sx0 = INT_MAX, sx1 = INT_MIN; int sy0 = INT_MAX, sy1 = INT_MIN; for( int i=0; i x0 ) sx0 = x0; if( sx1 < x1 ) sx1 = x1; int y0 = xinerama_info[i].y_org; int y1 = y0 + xinerama_info[i].height; if( sy0 > y0 ) sy0 = y0; if( sy1 < y1 ) sy1 = y1; } x = sx0; w = sx1 - sx0; y = sy0; h = sy1 - sy0; } return 0; } static void get_top_coords(Display *display, Window win, int &px,int &py, int &tx,int &ty) { Window *pcwin = 0; unsigned int ncwin = 0; Window cwin = 0, pwin = 0, root = 0; XQueryTree(display, win, &root, &pwin, &pcwin, &ncwin); if( pcwin ) XFree(pcwin); XTranslateCoordinates(display, pwin, root, 0,0, &px,&py, &cwin); //printf(" win=%lx, px/py=%d/%d\n", win, px,py); int nx = px, ny = py; pwin = win; for( int i=5; --i>=0; ) { win = pwin; pwin = 0; pcwin = 0; ncwin = 0; Window rwin = 0; // XQuerytTree has been known to fail here XQueryTree(display, win, &rwin, &pwin, &pcwin, &ncwin); if( pcwin ) XFree(pcwin); if( !rwin || rwin != root || pwin == root ) break; XTranslateCoordinates(display, pwin, root, 0,0, &nx,&ny, &cwin); //printf(" win=%lx, nx/ny=%d/%d\n", win, nx,ny); } tx = nx; ty = ny; } int BC_DisplayInfo::gl_probe(Display *dpy, Window win) { #ifdef HAVE_GL int fbAttribSingle[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, False, None }; int fbAttribDouble[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, True, None }; int scrnum = DefaultScreen(dpy); int n_fb_cfgs = 0; GLXFBConfig *fb_cfgs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &n_fb_cfgs); if( !fb_cfgs ) fb_cfgs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &n_fb_cfgs); if( !fb_cfgs ) return 1; XVisualInfo *vis_info = 0; GLXFBConfig glx_fb_config = 0; for( int i=0; !vis_info && i