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.

90 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. free(reply);
  41. }
  42. void xinerama_query_screens(void) {
  43. if (!xinerama_active)
  44. return;
  45. xcb_xinerama_query_screens_cookie_t cookie;
  46. xcb_xinerama_query_screens_reply_t *reply;
  47. xcb_xinerama_screen_info_t *screen_info;
  48. cookie = xcb_xinerama_query_screens_unchecked(conn);
  49. reply = xcb_xinerama_query_screens_reply(conn, cookie, NULL);
  50. if (!reply) {
  51. if (debug_mode)
  52. fprintf(stderr, "Couldn't get Xinerama screens\n");
  53. return;
  54. }
  55. screen_info = xcb_xinerama_query_screens_screen_info(reply);
  56. int screens = xcb_xinerama_query_screens_screen_info_length(reply);
  57. Rect *resolutions = malloc(screens * sizeof(Rect));
  58. /* No memory? Just keep on using the old information. */
  59. if (!resolutions) {
  60. free(reply);
  61. return;
  62. }
  63. xr_resolutions = resolutions;
  64. xr_screens = screens;
  65. for (int screen = 0; screen < xr_screens; screen++) {
  66. xr_resolutions[screen].x = screen_info[screen].x_org;
  67. xr_resolutions[screen].y = screen_info[screen].y_org;
  68. xr_resolutions[screen].width = screen_info[screen].width;
  69. xr_resolutions[screen].height = screen_info[screen].height;
  70. DEBUG("found Xinerama screen: %d x %d at %d x %d\n",
  71. screen_info[screen].width, screen_info[screen].height,
  72. screen_info[screen].x_org, screen_info[screen].y_org);
  73. }
  74. free(reply);
  75. }