screen.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  3. * For license, see COPYING.
  4. */
  5. #define HAVE_XINERAMA
  6. #ifdef HAVE_XINERAMA
  7. #include <X11/extensions/Xinerama.h>
  8. #endif /* HAVE_XINERAMA */
  9. #include "screen.h"
  10. #include "util.h"
  11. #include "tag.h"
  12. #include "infobar.h"
  13. #include "client.h"
  14. static struct screen*
  15. screen_new(struct geo *g, int id)
  16. {
  17. struct screen *s = (struct screen*)xcalloc(1, sizeof(struct screen));
  18. s->geo = s->ugeo = *g;
  19. s->seltag = NULL;
  20. s->id = id;
  21. TAILQ_INIT(&s->tags);
  22. SLIST_INIT(&s->infobars);
  23. SLIST_INSERT_HEAD(&W->h.screen, s, next);
  24. /* Set as selected screen */
  25. W->screen = s;
  26. return s;
  27. }
  28. void
  29. screen_init(void)
  30. {
  31. struct geo g;
  32. SLIST_INIT(&W->h.screen);
  33. #ifdef HAVE_XINERAMA
  34. XineramaScreenInfo *xsi;
  35. int i, n = 0;
  36. if(XineramaIsActive(W->dpy))
  37. {
  38. xsi = XineramaQueryScreens(W->dpy, &n);
  39. for(i = 0; i < n; ++i)
  40. {
  41. g.x = xsi[i].x_org;
  42. g.y = xsi[i].y_org;
  43. g.w = xsi[i].width;
  44. g.h = xsi[i].height;
  45. screen_new(&g, i);
  46. }
  47. XFree(xsi);
  48. }
  49. else
  50. #endif /* HAVE_XINERAMA */
  51. {
  52. g.x = g.y = 0;
  53. g.w = DisplayWidth(W->dpy, W->xscreen);
  54. g.h = DisplayHeight(W->dpy, W->xscreen);
  55. screen_new(&g, 0);
  56. }
  57. }
  58. /*
  59. * Update selected screen with mouse location
  60. */
  61. struct screen*
  62. screen_update_sel(void)
  63. {
  64. #ifdef HAVE_XINERAMA
  65. if(XineramaIsActive(W->dpy))
  66. {
  67. struct screen *s;
  68. Window w;
  69. int d, x, y;
  70. XQueryPointer(W->dpy, W->root, &w, &w, &x, &y, &d, &d, (unsigned int *)&d);
  71. SLIST_FOREACH(s, &W->h.screen, next)
  72. if(INAREA(x, y, s->geo))
  73. break;
  74. return (W->screen = s);
  75. }
  76. #endif /* HAVE_XINERAMA */
  77. return W->screen;
  78. }
  79. void
  80. screen_free(void)
  81. {
  82. struct screen *s;
  83. while(!SLIST_EMPTY(&W->h.screen))
  84. {
  85. s = SLIST_FIRST(&W->h.screen);
  86. SLIST_REMOVE_HEAD(&W->h.screen, next);
  87. infobar_free(s);
  88. tag_free(s);
  89. free(s);
  90. }
  91. }