You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Geometry.cxx 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (C) 2006-2008 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. // Geometry.cxx
  20. //
  21. #include <rfb/LogWriter.h>
  22. #include <x0vncserver/Geometry.h>
  23. using namespace rfb;
  24. static LogWriter vlog("Geometry");
  25. StringParameter Geometry::m_geometryParam("Geometry",
  26. "Screen area shown to VNC clients. "
  27. "Format is <width>x<height>+<offset_x>+<offset_y>, "
  28. "more information in man X, section GEOMETRY SPECIFICATIONS. "
  29. "If the argument is empty, full screen is shown to VNC clients.",
  30. "");
  31. Geometry::Geometry(int fullWidth, int fullHeight)
  32. {
  33. recalc(fullWidth, fullHeight);
  34. }
  35. void Geometry::recalc(int fullWidth, int fullHeight)
  36. {
  37. m_fullWidth = fullWidth;
  38. m_fullHeight = fullHeight;
  39. m_rect.setXYWH(0, 0, fullWidth, fullHeight);
  40. // Parse geometry specification and save the result in m_rect.
  41. const char *param = m_geometryParam.getData();
  42. bool geometrySpecified = (strlen(param) > 0);
  43. if (geometrySpecified) {
  44. m_rect = parseString(param);
  45. }
  46. delete[] param; // don't forget to deallocate memory
  47. // allocated by StringParameter::getData()
  48. if (m_rect.is_empty()) {
  49. vlog.info("Desktop geometry is invalid");
  50. return; // further processing does not make sense
  51. }
  52. // Everything went good so far.
  53. vlog.info("Desktop geometry is set to %dx%d+%d+%d",
  54. width(), height(), offsetLeft(), offsetTop());
  55. }
  56. Rect Geometry::parseString(const char *arg) const
  57. {
  58. Rect result; // empty by default
  59. if (arg != NULL && strlen(arg) > 0) {
  60. int w, h;
  61. int x = 0, y = 0;
  62. char sign_x[2] = "+";
  63. char sign_y[2] = "+";
  64. int n = sscanf(arg, "%dx%d%1[+-]%d%1[+-]%d",
  65. &w, &h, sign_x, &x, sign_y, &y);
  66. if ((n == 2 || n == 6) && w > 0 && h > 0 && x >= 0 && y >= 0) {
  67. if (sign_x[0] == '-')
  68. x = m_fullWidth - w - x;
  69. if (sign_y[0] == '-')
  70. y = m_fullHeight - h - y;
  71. Rect partRect(x, y, x + w, y + h);
  72. result = partRect.intersect(m_rect);
  73. if (result.area() <= 0) {
  74. vlog.error("Requested area is out of the desktop boundaries");
  75. result.clear();
  76. }
  77. } else {
  78. vlog.error("Wrong argument format");
  79. }
  80. } else {
  81. vlog.error("Missing argument");
  82. }
  83. return result;
  84. }