screen.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. W->nscreen = n;
  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. W->nscreen = 1;
  57. }
  58. }
  59. /*
  60. * Update selected screen with mouse location
  61. */
  62. struct screen*
  63. screen_update_sel(void)
  64. {
  65. #ifdef HAVE_XINERAMA
  66. if(XineramaIsActive(W->dpy))
  67. return (W->screen = screen_gb_mouse());
  68. #endif /* HAVE_XINERAMA */
  69. return W->screen;
  70. }
  71. static void
  72. screen_select(struct screen *s)
  73. {
  74. XWarpPointer(W->dpy, None, W->root, 0, 0, 0, 0,
  75. s->ugeo.x + (s->ugeo.w >> 1),
  76. s->ugeo.y + (s->ugeo.h >> 1));
  77. W->screen = s;
  78. }
  79. void
  80. uicb_screen_next(Uicb cmd)
  81. {
  82. struct screen *s = SLIST_NEXT(W->screen, next);
  83. (void)cmd;
  84. if(!s)
  85. s = SLIST_FIRST(&W->h.screen);
  86. screen_select(s);
  87. }
  88. void
  89. uicb_screen_prev(Uicb cmd)
  90. {
  91. struct screen *s = SLIST_FIRST(&W->h.screen);
  92. (void)cmd;
  93. while(SLIST_NEXT(s, next) && SLIST_NEXT(s, next) != s)
  94. s = SLIST_NEXT(s, next);
  95. screen_select(s);
  96. }
  97. void
  98. uicb_screen_move_client_next(Uicb cmd)
  99. {
  100. struct screen *s = SLIST_NEXT(W->screen, next);
  101. (void)cmd;
  102. if(!s)
  103. s = SLIST_FIRST(&W->h.screen);
  104. if(W->client)
  105. tag_client(s->seltag, W->client);
  106. }
  107. void
  108. uicb_screen_move_client_prev(Uicb cmd)
  109. {
  110. struct screen *s = SLIST_FIRST(&W->h.screen);
  111. (void)cmd;
  112. while(SLIST_NEXT(s, next) && SLIST_NEXT(s, next) != s)
  113. s = SLIST_NEXT(s, next);
  114. if(W->client)
  115. tag_client(s->seltag, W->client);
  116. }
  117. void
  118. screen_free(void)
  119. {
  120. struct screen *s;
  121. while(!SLIST_EMPTY(&W->h.screen))
  122. {
  123. s = SLIST_FIRST(&W->h.screen);
  124. SLIST_REMOVE_HEAD(&W->h.screen, next);
  125. infobar_free(s);
  126. tag_free(s);
  127. free(s);
  128. }
  129. }