Constantin Kaplinsky | 23c6022 | 2008-06-04 03:58:07 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2006-2008 Constantin Kaplinsky. All Rights Reserved. |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 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 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 23 | #include <rfb/LogWriter.h> |
| 24 | #include <x0vncserver/Geometry.h> |
| 25 | |
| 26 | static LogWriter vlog("Geometry"); |
| 27 | |
| 28 | StringParameter Geometry::m_geometryParam("Geometry", |
| 29 | "Screen area shown to VNC clients. " |
| 30 | "Format is <width>x<height>+<offset_x>+<offset_y>, " |
| 31 | "more information in man X, section GEOMETRY SPECIFICATIONS. " |
| 32 | "If the argument is empty, full screen is shown to VNC clients.", |
| 33 | ""); |
| 34 | |
| 35 | Geometry::Geometry(int fullWidth, int fullHeight) |
Constantin Kaplinsky | 23c6022 | 2008-06-04 03:58:07 +0000 | [diff] [blame] | 36 | : m_rect(0, 0, fullWidth, fullHeight) |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 37 | { |
| 38 | const char *param = m_geometryParam.getData(); |
| 39 | if (strlen(param) != 0) { |
| 40 | int w, h; |
| 41 | int x = 0, y = 0; |
| 42 | char sign_x[2] = "+"; |
| 43 | char sign_y[2] = "+"; |
| 44 | int n = sscanf(param, "%dx%d%1[+-]%d%1[+-]%d", |
| 45 | &w, &h, sign_x, &x, sign_y, &y); |
| 46 | if ((n == 2 || n == 6) && w > 0 && h > 0 && x >= 0 && y >= 0) { |
| 47 | if (sign_x[0] == '-') |
| 48 | x = fullWidth - w - x; |
| 49 | if (sign_y[0] == '-') |
| 50 | y = fullHeight - h - y; |
| 51 | Rect fullRect(0, 0, fullWidth, fullHeight); |
| 52 | Rect partRect(x, y, x + w, y + h); |
Constantin Kaplinsky | 23c6022 | 2008-06-04 03:58:07 +0000 | [diff] [blame] | 53 | m_rect = partRect.intersect(fullRect); |
| 54 | if (m_rect.area() <= 0) { |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 55 | vlog.error("Requested area is out of the desktop boundaries"); |
Constantin Kaplinsky | 23c6022 | 2008-06-04 03:58:07 +0000 | [diff] [blame] | 56 | m_rect.clear(); |
| 57 | return; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 58 | } |
| 59 | } else { |
| 60 | vlog.error("Wrong argument format"); |
Constantin Kaplinsky | 23c6022 | 2008-06-04 03:58:07 +0000 | [diff] [blame] | 61 | m_rect.clear(); |
| 62 | return; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | vlog.info("Desktop geometry is %dx%d+%d+%d", |
Constantin Kaplinsky | 23c6022 | 2008-06-04 03:58:07 +0000 | [diff] [blame] | 66 | width(), height(), offsetLeft(), offsetTop()); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 67 | } |
| 68 | |