blob: f23217039260af9fab4fa91661988a6201a927b4 [file] [log] [blame]
Constantin Kaplinsky44e99642006-05-20 12:58:38 +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 <stdio.h>
24
25#include <rfb/Rect.h>
26#include <rfb/LogWriter.h>
27#include <x0vncserver/Geometry.h>
28
29static LogWriter vlog("Geometry");
30
31StringParameter Geometry::m_geometryParam("Geometry",
32 "Screen area shown to VNC clients. "
33 "Format is <width>x<height>+<offset_x>+<offset_y>, "
34 "more information in man X, section GEOMETRY SPECIFICATIONS. "
35 "If the argument is empty, full screen is shown to VNC clients.",
36 "");
37
38Geometry::Geometry(int fullWidth, int fullHeight)
39 : m_width(fullWidth), m_height(fullHeight),
40 m_offsetLeft(0), m_offsetTop(0)
41{
42 const char *param = m_geometryParam.getData();
43 if (strlen(param) != 0) {
44 int w, h;
45 int x = 0, y = 0;
46 char sign_x[2] = "+";
47 char sign_y[2] = "+";
48 int n = sscanf(param, "%dx%d%1[+-]%d%1[+-]%d",
49 &w, &h, sign_x, &x, sign_y, &y);
50 if ((n == 2 || n == 6) && w > 0 && h > 0 && x >= 0 && y >= 0) {
51 if (sign_x[0] == '-')
52 x = fullWidth - w - x;
53 if (sign_y[0] == '-')
54 y = fullHeight - h - y;
55 Rect fullRect(0, 0, fullWidth, fullHeight);
56 Rect partRect(x, y, x + w, y + h);
57 Rect r = partRect.intersect(fullRect);
58 if (r.area() > 0) {
59 m_width = r.width();
60 m_height = r.height();
61 m_offsetLeft = r.tl.x;
62 m_offsetTop = r.tl.y;
63 } else {
64 vlog.error("Requested area is out of the desktop boundaries");
65 }
66 } else {
67 vlog.error("Wrong argument format");
68 }
69 }
70 vlog.info("Desktop geometry is %dx%d+%d+%d",
71 m_width, m_height, m_offsetLeft, m_offsetTop);
72}
73