xhelpers.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Copyright (C) 2014 by Leonhard Oelke <[email protected]>
  3. This program 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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <xcb/shm.h>
  19. #include <xcb/xproto.h>
  20. #include <obs.h>
  21. typedef struct {
  22. xcb_connection_t *xcb;
  23. xcb_shm_seg_t seg;
  24. int shmid;
  25. uint8_t *data;
  26. } xcb_shm_t;
  27. /**
  28. * Check for Xinerama extension
  29. *
  30. * @return true if xinerama is available and active
  31. */
  32. bool xinerama_is_active(xcb_connection_t *xcb);
  33. /**
  34. * Get the number of Xinerama screens
  35. *
  36. * @return number of screens
  37. */
  38. int xinerama_screen_count(xcb_connection_t *xcb);
  39. /**
  40. * Get screen geometry for a Xinerama screen
  41. *
  42. * @note On error the passed coordinates/sizes will be set to 0.
  43. *
  44. * @param dpy X11 display
  45. * @param screen screen number to get geometry for
  46. * @param x x-coordinate of the screen
  47. * @param y y-coordinate of the screen
  48. * @param w width of the screen
  49. * @param h height of the screen
  50. *
  51. * @return < 0 on error
  52. */
  53. int xinerama_screen_geo(xcb_connection_t *xcb, int_fast32_t screen,
  54. int_fast32_t *x, int_fast32_t *y,
  55. int_fast32_t *w, int_fast32_t *h);
  56. /**
  57. * Get screen geometry for a X11 screen
  58. *
  59. * @note On error the passed sizes will be set to 0.
  60. *
  61. * @param dpy X11 display
  62. * @param screen screen number to get geometry for
  63. * @param w width of the screen
  64. * @param h height of the screen
  65. *
  66. * @return < 0 on error
  67. */
  68. int x11_screen_geo(xcb_connection_t *xcb, int_fast32_t screen,
  69. int_fast32_t *w, int_fast32_t *h);
  70. /**
  71. * Attach a shared memory segment to the X-Server
  72. *
  73. * @param xcb xcb connection
  74. * @param w width of the captured screen
  75. * @param h height of the captured screen
  76. *
  77. * @return NULL on error
  78. */
  79. xcb_shm_t *xshm_xcb_attach(xcb_connection_t *xcb, const int w, const int h);
  80. /**
  81. * Detach a shared memory segment
  82. */
  83. void xshm_xcb_detach(xcb_shm_t *shm);
  84. /**
  85. * Get screen by id for a xcb connection
  86. *
  87. * @param xcb xcb connection
  88. * @param screen id of the screen
  89. * @return screen info structure
  90. */
  91. xcb_screen_t *xcb_get_screen(xcb_connection_t *xcb, int screen);
  92. #ifdef __cplusplus
  93. }
  94. #endif