olaf neophyte and de.po updates, valgrind tweaks, delete green lady, inkscape dpi=96
[goodguy/history.git] / cinelerra-5.1 / guicast / bcdisplayinfo.C
index ff701011691bce992ec434c41562b2ebf6dd63e0..5bbe991ce925492b454fbc2fc58c0d59e9ac34ef 100644 (file)
@@ -2,21 +2,21 @@
 /*
  * CINELERRA
  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
- * 
+ *
  * 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"
@@ -64,31 +64,33 @@ void BC_DisplayInfo::parse_geometry(char *geom, int *x, int *y, int *width, int
 
 static void get_top_coords(Display *display, Window win, int &px,int &py, int &tx,int &ty)
 {
-       Window *pcwin;  unsigned int ncwin;
+       Window *pcwin = 0;  unsigned int ncwin = 0;
        Window cwin = 0, pwin = 0, root = 0;
-       int nx=0, ny=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;
-               XQueryTree(display, win, &root, &pwin, &pcwin, &ncwin);
+               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( pwin == root ) break;
+               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;
 }
 
-       
-void BC_DisplayInfo::test_window(int &x_out, 
-       int &y_out, 
-       int &x_out2, 
-       int &y_out2, 
-       int x_in, 
+
+void BC_DisplayInfo::test_window(int &x_out,
+       int &y_out,
+       int &x_out2,
+       int &y_out2,
+       int x_in,
        int y_in)
 {
 #ifdef SINGLE_THREAD
@@ -107,9 +109,9 @@ void BC_DisplayInfo::test_window(int &x_out,
        attr.event_mask = StructureNotifyMask;
        attr.win_gravity = SouthEastGravity;
        attr.background_pixel = BlackPixel(display,screen);
-       Window win = XCreateWindow(display, rootwin, 
-                       x_in, y_in, TEST_SIZE, TEST_SIZE, 
-                       0, default_depth, InputOutput, 
+       Window win = XCreateWindow(display, rootwin,
+                       x_in, y_in, TEST_SIZE, TEST_SIZE,
+                       0, default_depth, InputOutput,
                        vis, mask, &attr);
        XSizeHints size_hints;
        XGetNormalHints(display, win, &size_hints);
@@ -118,10 +120,10 @@ void BC_DisplayInfo::test_window(int &x_out,
        size_hints.y = y_in;
        size_hints.width = TEST_SIZE;
        size_hints.height = TEST_SIZE;
-       XSetStandardProperties(display, win, 
+       XSetStandardProperties(display, win,
                "x", "x", None, 0, 0, &size_hints);
        XClearWindow(display, win);
-       XMapWindow(display, win); 
+       XMapWindow(display, win);
        XFlush(display);  XSync(display, 0);  usleep(100000);
 
        XEvent event;
@@ -187,11 +189,11 @@ void BC_DisplayInfo::init_borders()
        if(top_border < 0)
        {
                BC_DisplayInfo display_info;
-               display_info.test_window(left_border, top_border, 
+               display_info.test_window(left_border, top_border,
                        auto_reposition_x, auto_reposition_y, 100, 100);
                right_border = left_border;
                bottom_border = left_border;
-//printf("BC_DisplayInfo::init_borders border=%d %d auto=%d %d\n", 
+//printf("BC_DisplayInfo::init_borders border=%d %d auto=%d %d\n",
 //  left_border, top_border, auto_reposition_x, auto_reposition_y);
        }
 }
@@ -228,7 +230,7 @@ void BC_DisplayInfo::init_window(const char *display_name, int show_error)
 #ifdef SINGLE_THREAD
        display = BC_Display::get_display(display_name);
 #else
-       
+
 // This function must be the first Xlib
 // function a multi-threaded program calls
        XInitThreads();
@@ -295,14 +297,14 @@ int BC_DisplayInfo::get_abs_cursor_x()
 #ifdef SINGLE_THREAD
        BC_Display::lock_display("BC_DisplayInfo::get_abs_cursor_x");
 #endif
-       XQueryPointer(display, 
-          rootwin, 
-          &temp_win, 
+       XQueryPointer(display,
+          rootwin,
           &temp_win,
-       &abs_x, 
-          &abs_y, 
-          &win_x, 
-          &win_y, 
+          &temp_win,
+       &abs_x,
+          &abs_y,
+          &win_x,
+          &win_y,
           &temp_mask);
 #ifdef SINGLE_THREAD
        BC_Display::unlock_display();
@@ -319,14 +321,14 @@ int BC_DisplayInfo::get_abs_cursor_y()
 #ifdef SINGLE_THREAD
        BC_Display::lock_display("BC_DisplayInfo::get_abs_cursor_y");
 #endif
-       XQueryPointer(display, 
-          rootwin, 
-          &temp_win, 
+       XQueryPointer(display,
+          rootwin,
+          &temp_win,
           &temp_win,
-       &abs_x, 
-          &abs_y, 
-          &win_x, 
-          &win_y, 
+       &abs_x,
+          &abs_y,
+          &win_x,
+          &win_y,
           &temp_mask);
 #ifdef SINGLE_THREAD
        BC_Display::unlock_display();