Code improvements and better error checking in the Geometry class:
coordinates are now kept as a Rect, added new getRect() method. Also, when
the "Geometry" parameter is present but not valid, the constructor will not
set the geometry to full screen, zero-size rectangle will be used instead.
In that case, x0vncserver will exit with error.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2573 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/unix/x0vncserver/Geometry.cxx b/unix/x0vncserver/Geometry.cxx
index ccb4e69..b12a386 100644
--- a/unix/x0vncserver/Geometry.cxx
+++ b/unix/x0vncserver/Geometry.cxx
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 Constantin Kaplinsky.  All Rights Reserved.
+/* Copyright (C) 2006-2008 Constantin Kaplinsky.  All Rights Reserved.
  *    
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@
 // Geometry.cxx
 //
 
-#include <rfb/Rect.h>
 #include <rfb/LogWriter.h>
 #include <x0vncserver/Geometry.h>
 
@@ -34,8 +33,7 @@
   "");
 
 Geometry::Geometry(int fullWidth, int fullHeight)
-  : m_width(fullWidth), m_height(fullHeight),
-    m_offsetLeft(0), m_offsetTop(0)
+  : m_rect(0, 0, fullWidth, fullHeight)
 {
   const char *param = m_geometryParam.getData();
   if (strlen(param) != 0) {
@@ -52,20 +50,19 @@
         y = fullHeight - h - y;
       Rect fullRect(0, 0, fullWidth, fullHeight);
       Rect partRect(x, y, x + w, y + h);
-      Rect r = partRect.intersect(fullRect);
-      if (r.area() > 0) {
-        m_width = r.width();
-        m_height = r.height();
-        m_offsetLeft = r.tl.x;
-        m_offsetTop = r.tl.y;
-      } else {
+      m_rect = partRect.intersect(fullRect);
+      if (m_rect.area() <= 0) {
         vlog.error("Requested area is out of the desktop boundaries");
+        m_rect.clear();
+        return;
       }
     } else {
       vlog.error("Wrong argument format");
+      m_rect.clear();
+      return;
     }
   }
   vlog.info("Desktop geometry is %dx%d+%d+%d",
-            m_width, m_height, m_offsetLeft, m_offsetTop);
+            width(), height(), offsetLeft(), offsetTop());
 }
 
diff --git a/unix/x0vncserver/Geometry.h b/unix/x0vncserver/Geometry.h
index 95059e7..fdd9033 100644
--- a/unix/x0vncserver/Geometry.h
+++ b/unix/x0vncserver/Geometry.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 Constantin Kaplinsky.  All Rights Reserved.
+/* Copyright (C) 2006-2008 Constantin Kaplinsky.  All Rights Reserved.
  *    
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
 #ifndef __GEOMETRY_H__
 #define __GEOMETRY_H__
 
+#include <rfb/Rect.h>
 #include <rfb/Configuration.h>
 
 using namespace rfb;
@@ -32,18 +33,17 @@
 public:
   Geometry(int fullWidth, int fullHeight);
 
-  int width() const { return m_width; }
-  int height() const { return m_height; }
-  int offsetLeft() const { return m_offsetLeft; }
-  int offsetTop() const { return m_offsetTop; }
+  int width() const { return m_rect.width(); }
+  int height() const { return m_rect.height(); }
+  int offsetLeft() const { return m_rect.tl.x; }
+  int offsetTop() const { return m_rect.tl.y; }
+
+  const Rect& getRect() const { return m_rect; }
 
 protected:
   static StringParameter m_geometryParam;
 
-  int m_width;
-  int m_height;
-  int m_offsetLeft;
-  int m_offsetTop;
+  Rect m_rect;
 };
 
 #endif // __GEOMETRY_H__
diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx
index f2ff430..5016d12 100644
--- a/unix/x0vncserver/x0vncserver.cxx
+++ b/unix/x0vncserver/x0vncserver.cxx
@@ -438,6 +438,10 @@
     TXWindow::init(dpy,"x0vncserver");
     Geometry geo(DisplayWidth(dpy, DefaultScreen(dpy)),
                  DisplayHeight(dpy, DefaultScreen(dpy)));
+    if (geo.getRect().is_empty()) {
+      vlog.error("Exiting with error");
+      return 1;
+    }
     XDesktop desktop(dpy, &geo);
 
     VNCServerST server("x0vncserver", &desktop);