aboutsummaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorConstantin Kaplinsky <const@tightvnc.com>2008-06-04 03:58:07 +0000
committerConstantin Kaplinsky <const@tightvnc.com>2008-06-04 03:58:07 +0000
commit23c60222f2d481166230788c87df801ec2902678 (patch)
tree03839bcf302c45804bb97a3d728771541d1a759d /unix
parente0c80c566649a80697556b767cd014a9625e913f (diff)
downloadtigervnc-23c60222f2d481166230788c87df801ec2902678.tar.gz
tigervnc-23c60222f2d481166230788c87df801ec2902678.zip
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
Diffstat (limited to 'unix')
-rw-r--r--unix/x0vncserver/Geometry.cxx21
-rw-r--r--unix/x0vncserver/Geometry.h18
-rw-r--r--unix/x0vncserver/x0vncserver.cxx4
3 files changed, 22 insertions, 21 deletions
diff --git a/unix/x0vncserver/Geometry.cxx b/unix/x0vncserver/Geometry.cxx
index ccb4e699..b12a386b 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 @@ StringParameter Geometry::m_geometryParam("Geometry",
"");
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 @@ Geometry::Geometry(int fullWidth, int fullHeight)
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 95059e7d..fdd9033d 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 @@ class Geometry
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 f2ff4306..5016d12c 100644
--- a/unix/x0vncserver/x0vncserver.cxx
+++ b/unix/x0vncserver/x0vncserver.cxx
@@ -438,6 +438,10 @@ int main(int argc, char** argv)
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);