tag.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. int otag;
  40. Client *c;
  41. screen_get_sel();
  42. otag = seltag[selscreen];
  43. if(conf.tag_round)
  44. {
  45. if(tag <= 0)
  46. seltag[selscreen] = conf.ntag[selscreen];
  47. else if(tag > conf.ntag[selscreen])
  48. seltag[selscreen] = 1;
  49. else
  50. seltag[selscreen] = tag;
  51. }
  52. else
  53. {
  54. if(!tag || tag == seltag[selscreen]
  55. || tag > conf.ntag[selscreen])
  56. return;
  57. seltag[selscreen] = tag;
  58. }
  59. ewmh_update_current_tag_prop();
  60. /* Arrange infobar position */
  61. if(tags[selscreen][otag].barpos != tags[selscreen][seltag[selscreen]].barpos)
  62. infobar_set_position(tags[selscreen][seltag[selscreen]].barpos);
  63. arrange(selscreen, False);
  64. if(tags[selscreen][tag].request_update)
  65. {
  66. tags[selscreen][seltag[selscreen]].layout.func(selscreen);
  67. tags[selscreen][tag].request_update = False;
  68. }
  69. /* To focus the first client in the new tag */
  70. for(c = clients; c; c = c->next)
  71. if(c->tag == seltag[selscreen] && c->screen == selscreen)
  72. break;
  73. client_focus((c) ? c : NULL);
  74. return;
  75. }
  76. /* Transfert a client to a tag
  77. * \param c Client pointer
  78. * \param tag Tag
  79. */
  80. void
  81. tag_transfert(Client *c, int tag)
  82. {
  83. screen_get_sel();
  84. CHECK(c);
  85. if(!tag)
  86. tag = 1;
  87. c->tag = tag;
  88. c->screen = selscreen;
  89. arrange(c->screen, True);
  90. if(c == sel)
  91. client_focus(NULL);
  92. client_update_attributes(c);
  93. tags[c->screen][tag].request_update = True;
  94. return;
  95. }
  96. /** Uicb Set a tag
  97. * \param cmd Tag number or '+' / '-', uicb_t type
  98. */
  99. void
  100. uicb_tag(uicb_t cmd)
  101. {
  102. int tmp = atoi(cmd);
  103. if(cmd[0] == '+' || cmd[0] == '-')
  104. tag_set(seltag[selscreen] + tmp);
  105. else
  106. tag_set(tmp);
  107. return;
  108. }
  109. /** Set the next tag
  110. * \param cmd uicb_t type unused
  111. */
  112. void
  113. uicb_tag_next(uicb_t cmd)
  114. {
  115. screen_get_sel();
  116. tag_set(seltag[selscreen] + 1);
  117. return;
  118. }
  119. /** Set the previous tag
  120. * \param cmd uicb_t type unused
  121. */
  122. void
  123. uicb_tag_prev(uicb_t cmd)
  124. {
  125. screen_get_sel();
  126. tag_set(seltag[selscreen] - 1);
  127. return;
  128. }
  129. /** Transfert the selected client to
  130. * the wanted tag
  131. * \param cmd Wanted tag, uicb_t type
  132. */
  133. void
  134. uicb_tagtransfert(uicb_t cmd)
  135. {
  136. CHECK(sel);
  137. tag_transfert(sel, atoi(cmd));
  138. return;
  139. }