xhelpers.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 xcb xcb connection
  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, int_fast32_t *w,
  55. int_fast32_t *h);
  56. /**
  57. * Check for Randr extension
  58. *
  59. * @return true if randr is available which means it's active.
  60. */
  61. bool randr_is_active(xcb_connection_t *xcb);
  62. /**
  63. * Get the number of Randr screens
  64. *
  65. * @return number of screens
  66. */
  67. int randr_screen_count(xcb_connection_t *xcb);
  68. /**
  69. * Get screen geometry for a Rand crtc (screen)
  70. *
  71. * @note On error the passed coordinates/sizes will be set to 0.
  72. *
  73. * @param xcb xcb connection
  74. * @param screen screen number to get geometry for
  75. * @param x x-coordinate of the screen
  76. * @param y y-coordinate of the screen
  77. * @param w width of the screen
  78. * @param h height of the screen
  79. *
  80. * @return < 0 on error
  81. */
  82. int randr_screen_geo(xcb_connection_t *xcb, int_fast32_t screen,
  83. int_fast32_t *x, int_fast32_t *y, int_fast32_t *w,
  84. int_fast32_t *h, xcb_screen_t **rscreen, char **name);
  85. /**
  86. * Get screen geometry for a X11 screen
  87. *
  88. * @note On error the passed sizes will be set to 0.
  89. *
  90. * @param xcb xcb connection
  91. * @param screen screen number to get geometry for
  92. * @param w width of the screen
  93. * @param h height of the screen
  94. *
  95. * @return < 0 on error
  96. */
  97. int x11_screen_geo(xcb_connection_t *xcb, int_fast32_t screen, int_fast32_t *w,
  98. int_fast32_t *h);
  99. /**
  100. * Attach a shared memory segment to the X-Server
  101. *
  102. * @param xcb xcb connection
  103. * @param w width of the captured screen
  104. * @param h height of the captured screen
  105. *
  106. * @return NULL on error
  107. */
  108. xcb_shm_t *xshm_xcb_attach(xcb_connection_t *xcb, const int w, const int h);
  109. /**
  110. * Detach a shared memory segment
  111. */
  112. void xshm_xcb_detach(xcb_shm_t *shm);
  113. /**
  114. * Get screen by id for a xcb connection
  115. *
  116. * @param xcb xcb connection
  117. * @param screen id of the screen
  118. * @return screen info structure
  119. */
  120. xcb_screen_t *xcb_get_screen(xcb_connection_t *xcb, int screen);
  121. /**
  122. * Get the screen id for the given root window
  123. *
  124. * @param conn xcb connection
  125. * @param root window id for the root window
  126. * @return screen id
  127. */
  128. int xcb_get_screen_for_root(xcb_connection_t *conn, xcb_window_t root);
  129. #ifdef __cplusplus
  130. }
  131. #endif