2
0

DtXinerama.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2013, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * Jon Trulson, Xi Graphics 4/11/2001
  25. *
  26. * $XiGId: DtXinerama.c,v 1.1 2001/04/12 03:01:14 jon Exp $
  27. *
  28. * A Xinerama wrapper for CDE
  29. *
  30. */
  31. #include <stdio.h>
  32. #include <unistd.h>
  33. #include <stdlib.h>
  34. #include <X11/Xlib.h>
  35. #include <Dt/DtXinerama.h>
  36. /* return a DtXineramaInfo_t (or NULL if no Xinerama) available */
  37. DtXineramaInfo_t *_DtXineramaInit(Display *dpy)
  38. {
  39. DtXineramaInfo_t *tmpDtXI = NULL;
  40. XineramaScreenInfo *XinerScrnInfo = NULL;
  41. int number = 0;
  42. if (!dpy)
  43. return(NULL);
  44. XinerScrnInfo = XineramaQueryScreens(dpy, &number);
  45. if (number <= 0 || XinerScrnInfo == NULL) /* then we don't have it */
  46. return(NULL);
  47. /* allocate some space for it */
  48. if ((tmpDtXI = (DtXineramaInfo_t *)malloc(sizeof(DtXineramaInfo_t))) == NULL)
  49. { /* malloc failure */
  50. #ifdef DEBUG
  51. fprintf(stderr, "_DtXineramaInit: malloc failed\n");
  52. #endif
  53. free(XinerScrnInfo);
  54. return(NULL);
  55. }
  56. tmpDtXI->numscreens = number;
  57. tmpDtXI->ScreenInfo = XinerScrnInfo;
  58. return(tmpDtXI);
  59. }
  60. /* Return w, h, xorg, and yorg for the specified screen. Return True */
  61. /* if a valid screen, False otherwise */
  62. Bool _DtXineramaGetScreen(DtXineramaInfo_t *DtXI, unsigned int screen,
  63. unsigned int *w, unsigned int *h,
  64. unsigned int *xorg, unsigned int *yorg)
  65. {
  66. if (DtXI == NULL)
  67. return(False);
  68. if (DtXI->numscreens == 0)
  69. return(False); /* no screens or no Xinerama */
  70. if (screen >= DtXI->numscreens)
  71. return(False); /* invalid screen */
  72. /* now get the info from the XinerInfo */
  73. /* struct and return it */
  74. if (w != NULL)
  75. *w = (DtXI->ScreenInfo[screen]).width;
  76. if (h != NULL)
  77. *h = (DtXI->ScreenInfo[screen]).height;
  78. if (xorg != NULL)
  79. *xorg = (DtXI->ScreenInfo[screen]).x_org;
  80. if (yorg != NULL)
  81. *yorg = (DtXI->ScreenInfo[screen]).y_org;
  82. return(True);
  83. }