tag.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * tag.c
  3. * Copyright © 2008, 2009 Martin Duquesnoy <xorg62@gmail.com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of the nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "wmfs.h"
  33. /* Set the tag
  34. * \param tag The tag number
  35. */
  36. void
  37. tag_set(int tag)
  38. {
  39. Client *c;
  40. screen_get_sel();
  41. prevseltag[selscreen] = seltag[selscreen];
  42. if(conf.tag_round)
  43. {
  44. if(tag <= 0)
  45. seltag[selscreen] = conf.ntag[selscreen];
  46. else if(tag > conf.ntag[selscreen])
  47. seltag[selscreen] = 1;
  48. else
  49. seltag[selscreen] = tag;
  50. }
  51. else
  52. {
  53. if(!tag || tag == seltag[selscreen]
  54. || tag > conf.ntag[selscreen])
  55. return;
  56. seltag[selscreen] = tag;
  57. }
  58. ewmh_update_current_tag_prop();
  59. /* Arrange infobar position */
  60. if(tags[selscreen][prevseltag[selscreen]].barpos != tags[selscreen][seltag[selscreen]].barpos)
  61. infobar_set_position(tags[selscreen][seltag[selscreen]].barpos);
  62. arrange(selscreen, False);
  63. if(tags[selscreen][tag].request_update)
  64. {
  65. tags[selscreen][seltag[selscreen]].layout.func(selscreen);
  66. tags[selscreen][tag].request_update = False;
  67. }
  68. /* To focus the first client in the new tag */
  69. for(c = clients; c; c = c->next)
  70. if(c->tag == seltag[selscreen] && c->screen == selscreen)
  71. break;
  72. client_focus((c) ? c : NULL);
  73. return;
  74. }
  75. /* Transfert a client to a tag
  76. * \param c Client pointer
  77. * \param tag Tag
  78. */
  79. void
  80. tag_transfert(Client *c, int tag)
  81. {
  82. screen_get_sel();
  83. CHECK(c);
  84. if(!tag)
  85. tag = 1;
  86. c->tag = tag;
  87. c->screen = selscreen;
  88. arrange(c->screen, True);
  89. if(c == sel && c->tag != tag)
  90. client_focus(NULL);
  91. client_update_attributes(c);
  92. tags[c->screen][tag].request_update = True;
  93. return;
  94. }
  95. /** Uicb Set a tag
  96. * \param cmd Tag number or '+' / '-', uicb_t type
  97. */
  98. void
  99. uicb_tag(uicb_t cmd)
  100. {
  101. int tmp = atoi(cmd);
  102. if(cmd[0] == '+' || cmd[0] == '-')
  103. tag_set(seltag[selscreen] + tmp);
  104. else
  105. tag_set(tmp);
  106. return;
  107. }
  108. /** Set the next tag
  109. * \param cmd uicb_t type unused
  110. */
  111. void
  112. uicb_tag_next(uicb_t cmd)
  113. {
  114. screen_get_sel();
  115. tag_set(seltag[selscreen] + 1);
  116. return;
  117. }
  118. /** Set the previous tag
  119. * \param cmd uicb_t type unused
  120. */
  121. void
  122. uicb_tag_prev(uicb_t cmd)
  123. {
  124. screen_get_sel();
  125. tag_set(seltag[selscreen] - 1);
  126. return;
  127. }
  128. /** Transfert the selected client to
  129. * the wanted tag
  130. * \param cmd Wanted tag, uicb_t type
  131. */
  132. void
  133. uicb_tagtransfert(uicb_t cmd)
  134. {
  135. CHECK(sel);
  136. tag_transfert(sel, atoi(cmd));
  137. return;
  138. }
  139. /** Set the previous selected tag
  140. * \param cmd uicb_t type unused
  141. */
  142. void
  143. uicb_tag_prev_sel(uicb_t cmd)
  144. {
  145. screen_get_sel();
  146. tag_set(prevseltag[selscreen]);
  147. return;
  148. }
  149. /** Transfert the selected client to the next tag
  150. * \param cmd uicb_t type unused
  151. */
  152. void
  153. uicb_tagtransfert_next(uicb_t cmd)
  154. {
  155. CHECK(sel);
  156. int tag = seltag[selscreen] + 1;
  157. if(tag > conf.ntag[selscreen])
  158. {
  159. if(!conf.tag_round)
  160. return;
  161. tag = 1;
  162. }
  163. tag_transfert(sel, tag);
  164. return;
  165. }
  166. /** Transfert the selected client to the prev tag
  167. * \param cmd uicb_t type unused
  168. */
  169. void
  170. uicb_tagtransfert_prev(uicb_t cmd)
  171. {
  172. CHECK(sel);
  173. int tag = seltag[selscreen] - 1;
  174. if(tag <= 0)
  175. {
  176. if(!conf.tag_round)
  177. return;
  178. tag = conf.ntag[selscreen];
  179. }
  180. tag_transfert(sel, tag);
  181. return;
  182. }