blob: ccb4e699051e65f17b9db5b014241d32c3deb323 [file] [log] [blame]
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +00001/* Copyright (C) 2006 Constantin Kaplinsky. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19//
20// Geometry.cxx
21//
22
23#include <rfb/Rect.h>
24#include <rfb/LogWriter.h>
25#include <x0vncserver/Geometry.h>
26
27static LogWriter vlog("Geometry");
28
29StringParameter Geometry::m_geometryParam("Geometry",
30 "Screen area shown to VNC clients. "
31 "Format is <width>x<height>+<offset_x>+<offset_y>, "
32 "more information in man X, section GEOMETRY SPECIFICATIONS. "
33 "If the argument is empty, full screen is shown to VNC clients.",
34 "");
35
36Geometry::Geometry(int fullWidth, int fullHeight)
37 : m_width(fullWidth), m_height(fullHeight),
38 m_offsetLeft(0), m_offsetTop(0)
39{
40 const char *param = m_geometryParam.getData();
41 if (strlen(param) != 0) {
42 int w, h;
43 int x = 0, y = 0;
44 char sign_x[2] = "+";
45 char sign_y[2] = "+";
46 int n = sscanf(param, "%dx%d%1[+-]%d%1[+-]%d",
47 &w, &h, sign_x, &x, sign_y, &y);
48 if ((n == 2 || n == 6) && w > 0 && h > 0 && x >= 0 && y >= 0) {
49 if (sign_x[0] == '-')
50 x = fullWidth - w - x;
51 if (sign_y[0] == '-')
52 y = fullHeight - h - y;
53 Rect fullRect(0, 0, fullWidth, fullHeight);
54 Rect partRect(x, y, x + w, y + h);
55 Rect r = partRect.intersect(fullRect);
56 if (r.area() > 0) {
57 m_width = r.width();
58 m_height = r.height();
59 m_offsetLeft = r.tl.x;
60 m_offsetTop = r.tl.y;
61 } else {
62 vlog.error("Requested area is out of the desktop boundaries");
63 }
64 } else {
65 vlog.error("Wrong argument format");
66 }
67 }
68 vlog.info("Desktop geometry is %dx%d+%d+%d",
69 m_width, m_height, m_offsetLeft, m_offsetTop);
70}
71