xhelpers.h 3.6 KB

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