summaryrefslogtreecommitdiffstats
path: root/unix/x0vncserver/Geometry.cxx
diff options
context:
space:
mode:
authorConstantin Kaplinsky <const@tightvnc.com>2008-08-20 06:04:57 +0000
committerConstantin Kaplinsky <const@tightvnc.com>2008-08-20 06:04:57 +0000
commit5120e5e264ab76a0e62859df2445973dbb22f5ac (patch)
treebe26a9cba12be124af4c471e38f1d879ecbb203d /unix/x0vncserver/Geometry.cxx
parente0fd2da47ef75ffb31308199f47c971cfd2c18c7 (diff)
downloadtigervnc-5120e5e264ab76a0e62859df2445973dbb22f5ac.tar.gz
tigervnc-5120e5e264ab76a0e62859df2445973dbb22f5ac.zip
Geometry string parsing has been moved to a separate member function of the
Geometry class. Also, a memory leak has been fixed. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2679 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'unix/x0vncserver/Geometry.cxx')
-rw-r--r--unix/x0vncserver/Geometry.cxx38
1 files changed, 25 insertions, 13 deletions
diff --git a/unix/x0vncserver/Geometry.cxx b/unix/x0vncserver/Geometry.cxx
index b12a386b..9594112b 100644
--- a/unix/x0vncserver/Geometry.cxx
+++ b/unix/x0vncserver/Geometry.cxx
@@ -36,33 +36,45 @@ Geometry::Geometry(int fullWidth, int fullHeight)
: m_rect(0, 0, fullWidth, fullHeight)
{
const char *param = m_geometryParam.getData();
- if (strlen(param) != 0) {
+ if (strlen(param) > 0) {
+ m_rect = parseString(param);
+ }
+ delete[] param; // don't forget to deallocate memory
+ // allocated by StringParameter::getData()
+
+ vlog.info("Desktop geometry is %dx%d+%d+%d",
+ width(), height(), offsetLeft(), offsetTop());
+}
+
+Rect Geometry::parseString(const char *arg) const
+{
+ Rect result; // empty by default
+
+ if (arg != NULL && strlen(arg) > 0) {
int w, h;
int x = 0, y = 0;
char sign_x[2] = "+";
char sign_y[2] = "+";
- int n = sscanf(param, "%dx%d%1[+-]%d%1[+-]%d",
+ int n = sscanf(arg, "%dx%d%1[+-]%d%1[+-]%d",
&w, &h, sign_x, &x, sign_y, &y);
if ((n == 2 || n == 6) && w > 0 && h > 0 && x >= 0 && y >= 0) {
if (sign_x[0] == '-')
- x = fullWidth - w - x;
+ x = m_rect.width() - w - x;
if (sign_y[0] == '-')
- y = fullHeight - h - y;
- Rect fullRect(0, 0, fullWidth, fullHeight);
+ y = m_rect.height() - h - y;
Rect partRect(x, y, x + w, y + h);
- m_rect = partRect.intersect(fullRect);
- if (m_rect.area() <= 0) {
+ result = partRect.intersect(m_rect);
+ if (result.area() <= 0) {
vlog.error("Requested area is out of the desktop boundaries");
- m_rect.clear();
- return;
+ result.clear();
}
} else {
vlog.error("Wrong argument format");
- m_rect.clear();
- return;
}
+ } else {
+ vlog.error("Missing argument");
}
- vlog.info("Desktop geometry is %dx%d+%d+%d",
- width(), height(), offsetLeft(), offsetTop());
+
+ return result;
}