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.

89 lines
2.4 KiB

  1. /*
  2. * vim:ts=4:sw=4:expandtab
  3. *
  4. * © 2010-2012 Michael Stapelberg
  5. *
  6. * See LICENSE for licensing information
  7. *
  8. */
  9. #include <stdbool.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <math.h>
  13. #include <xcb/xcb.h>
  14. #include <xcb/xinerama.h>
  15. #include "i3lock.h"
  16. #include "xcb.h"
  17. #include "xinerama.h"
  18. /* Number of Xinerama screens which are currently present. */
  19. int xr_screens = 0;
  20. /* The resolutions of the currently present Xinerama screens. */
  21. Rect *xr_resolutions;
  22. static bool xinerama_active;
  23. extern bool debug_mode;
  24. void xinerama_init(void) {
  25. if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
  26. DEBUG("Xinerama extension not found, disabling.\n");
  27. return;
  28. }
  29. xcb_xinerama_is_active_cookie_t cookie;
  30. xcb_xinerama_is_active_reply_t *reply;
  31. cookie = xcb_xinerama_is_active(conn);
  32. reply = xcb_xinerama_is_active_reply(conn, cookie, NULL);
  33. if (!reply)
  34. return;
  35. if (!reply->state) {
  36. free(reply);
  37. return;
  38. }
  39. xinerama_active = true;
  40. }
  41. void xinerama_query_screens(void) {
  42. if (!xinerama_active)
  43. return;
  44. xcb_xinerama_query_screens_cookie_t cookie;
  45. xcb_xinerama_query_screens_reply_t *reply;
  46. xcb_xinerama_screen_info_t *screen_info;
  47. cookie = xcb_xinerama_query_screens_unchecked(conn);
  48. reply = xcb_xinerama_query_screens_reply(conn, cookie, NULL);
  49. if (!reply) {
  50. if (debug_mode)
  51. fprintf(stderr, "Couldn't get Xinerama screens\n");
  52. return;
  53. }
  54. screen_info = xcb_xinerama_query_screens_screen_info(reply);
  55. int screens = xcb_xinerama_query_screens_screen_info_length(reply);
  56. Rect *resolutions = malloc(screens * sizeof(Rect));
  57. /* No memory? Just keep on using the old information. */
  58. if (!resolutions) {
  59. free(reply);
  60. return;
  61. }
  62. xr_resolutions = resolutions;
  63. xr_screens = screens;
  64. for (int screen = 0; screen < xr_screens; screen++) {
  65. xr_resolutions[screen].x = screen_info[screen].x_org;
  66. xr_resolutions[screen].y = screen_info[screen].y_org;
  67. xr_resolutions[screen].width = screen_info[screen].width;
  68. xr_resolutions[screen].height = screen_info[screen].height;
  69. DEBUG("found Xinerama screen: %d x %d at %d x %d\n",
  70. screen_info[screen].width, screen_info[screen].height,
  71. screen_info[screen].x_org, screen_info[screen].y_org);
  72. }
  73. free(reply);
  74. }