screen.c 2.1 KB

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