cmd-select-pane.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* $OpenBSD$ */
  2. /*
  3. * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
  14. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  15. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <sys/types.h>
  18. #include "tmux.h"
  19. /*
  20. * Select pane.
  21. */
  22. enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
  23. const struct cmd_entry cmd_select_pane_entry = {
  24. .name = "select-pane",
  25. .alias = "selectp",
  26. .args = { "DdegLlMmP:Rt:U", 0, 0 },
  27. .usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
  28. .tflag = CMD_PANE,
  29. .flags = 0,
  30. .exec = cmd_select_pane_exec
  31. };
  32. const struct cmd_entry cmd_last_pane_entry = {
  33. .name = "last-pane",
  34. .alias = "lastp",
  35. .args = { "det:", 0, 0 },
  36. .usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
  37. .tflag = CMD_WINDOW,
  38. .flags = 0,
  39. .exec = cmd_select_pane_exec
  40. };
  41. enum cmd_retval
  42. cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
  43. {
  44. struct args *args = self->args;
  45. struct winlink *wl = cmdq->state.tflag.wl;
  46. struct window *w = wl->window;
  47. struct session *s = cmdq->state.tflag.s;
  48. struct window_pane *wp = cmdq->state.tflag.wp, *lastwp, *markedwp;
  49. const char *style;
  50. if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
  51. if (wl->window->last == NULL) {
  52. cmdq_error(cmdq, "no last pane");
  53. return (CMD_RETURN_ERROR);
  54. }
  55. if (args_has(self->args, 'e'))
  56. w->last->flags &= ~PANE_INPUTOFF;
  57. else if (args_has(self->args, 'd'))
  58. w->last->flags |= PANE_INPUTOFF;
  59. else {
  60. server_unzoom_window(w);
  61. window_redraw_active_switch(w, w->last);
  62. if (window_set_active_pane(w, w->last)) {
  63. server_status_window(w);
  64. server_redraw_window_borders(w);
  65. }
  66. }
  67. return (CMD_RETURN_NORMAL);
  68. }
  69. if (args_has(args, 'm') || args_has(args, 'M')) {
  70. if (args_has(args, 'm') && !window_pane_visible(wp))
  71. return (CMD_RETURN_NORMAL);
  72. lastwp = marked_pane.wp;
  73. if (args_has(args, 'M') || server_is_marked(s, wl, wp))
  74. server_clear_marked();
  75. else
  76. server_set_marked(s, wl, wp);
  77. markedwp = marked_pane.wp;
  78. if (lastwp != NULL) {
  79. server_redraw_window_borders(lastwp->window);
  80. server_status_window(lastwp->window);
  81. }
  82. if (markedwp != NULL) {
  83. server_redraw_window_borders(markedwp->window);
  84. server_status_window(markedwp->window);
  85. }
  86. return (CMD_RETURN_NORMAL);
  87. }
  88. if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
  89. if (args_has(args, 'P')) {
  90. style = args_get(args, 'P');
  91. if (style_parse(&grid_default_cell, &wp->colgc,
  92. style) == -1) {
  93. cmdq_error(cmdq, "bad style: %s", style);
  94. return (CMD_RETURN_ERROR);
  95. }
  96. wp->flags |= PANE_REDRAW;
  97. }
  98. if (args_has(self->args, 'g'))
  99. cmdq_print(cmdq, "%s", style_tostring(&wp->colgc));
  100. return (CMD_RETURN_NORMAL);
  101. }
  102. if (args_has(self->args, 'L')) {
  103. server_unzoom_window(wp->window);
  104. wp = window_pane_find_left(wp);
  105. } else if (args_has(self->args, 'R')) {
  106. server_unzoom_window(wp->window);
  107. wp = window_pane_find_right(wp);
  108. } else if (args_has(self->args, 'U')) {
  109. server_unzoom_window(wp->window);
  110. wp = window_pane_find_up(wp);
  111. } else if (args_has(self->args, 'D')) {
  112. server_unzoom_window(wp->window);
  113. wp = window_pane_find_down(wp);
  114. }
  115. if (wp == NULL)
  116. return (CMD_RETURN_NORMAL);
  117. if (args_has(self->args, 'e')) {
  118. wp->flags &= ~PANE_INPUTOFF;
  119. return (CMD_RETURN_NORMAL);
  120. }
  121. if (args_has(self->args, 'd')) {
  122. wp->flags |= PANE_INPUTOFF;
  123. return (CMD_RETURN_NORMAL);
  124. }
  125. if (wp == w->active)
  126. return (CMD_RETURN_NORMAL);
  127. server_unzoom_window(wp->window);
  128. if (!window_pane_visible(wp)) {
  129. cmdq_error(cmdq, "pane not visible");
  130. return (CMD_RETURN_ERROR);
  131. }
  132. window_redraw_active_switch(w, wp);
  133. if (window_set_active_pane(w, wp)) {
  134. server_status_window(w);
  135. server_redraw_window_borders(w);
  136. }
  137. return (CMD_RETURN_NORMAL);
  138. }