cmd-move-window.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* $OpenBSD$ */
  2. /*
  3. * Copyright (c) 2008 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 <stdlib.h>
  19. #include "tmux.h"
  20. /*
  21. * Move a window.
  22. */
  23. enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_q *);
  24. const struct cmd_entry cmd_move_window_entry = {
  25. .name = "move-window",
  26. .alias = "movew",
  27. .args = { "adkrs:t:", 0, 0 },
  28. .usage = "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
  29. .sflag = CMD_WINDOW,
  30. .tflag = CMD_MOVEW_R,
  31. .flags = 0,
  32. .exec = cmd_move_window_exec
  33. };
  34. const struct cmd_entry cmd_link_window_entry = {
  35. .name = "link-window",
  36. .alias = "linkw",
  37. .args = { "adks:t:", 0, 0 },
  38. .usage = "[-dk] " CMD_SRCDST_WINDOW_USAGE,
  39. .sflag = CMD_WINDOW,
  40. .tflag = CMD_WINDOW_INDEX,
  41. .flags = 0,
  42. .exec = cmd_move_window_exec
  43. };
  44. enum cmd_retval
  45. cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
  46. {
  47. #ifdef TMATE
  48. cmdq_error(cmdq, "move window is not supported with tmate");
  49. return (CMD_RETURN_ERROR);
  50. #else
  51. struct args *args = self->args;
  52. struct session *src = cmdq->state.sflag.s;
  53. struct session *dst = cmdq->state.tflag.s;
  54. struct winlink *wl = cmdq->state.sflag.wl;
  55. char *cause;
  56. int idx = cmdq->state.tflag.idx, kflag, dflag, sflag;
  57. kflag = args_has(self->args, 'k');
  58. dflag = args_has(self->args, 'd');
  59. if (args_has(args, 'r')) {
  60. session_renumber_windows(dst);
  61. recalculate_sizes();
  62. return (CMD_RETURN_NORMAL);
  63. }
  64. kflag = args_has(self->args, 'k');
  65. dflag = args_has(self->args, 'd');
  66. sflag = args_has(self->args, 's');
  67. if (args_has(self->args, 'a')) {
  68. if ((idx = winlink_shuffle_up(dst, dst->curw)) == -1)
  69. return (CMD_RETURN_ERROR);
  70. }
  71. if (server_link_window(src, wl, dst, idx, kflag, !dflag,
  72. &cause) != 0) {
  73. cmdq_error(cmdq, "can't link window: %s", cause);
  74. free(cause);
  75. return (CMD_RETURN_ERROR);
  76. }
  77. if (self->entry == &cmd_move_window_entry)
  78. server_unlink_window(src, wl);
  79. /*
  80. * Renumber the winlinks in the src session only, the destination
  81. * session already has the correct winlink id to us, either
  82. * automatically or specified by -s.
  83. */
  84. if (!sflag && options_get_number(src->options, "renumber-windows"))
  85. session_renumber_windows(src);
  86. recalculate_sizes();
  87. return (CMD_RETURN_NORMAL);
  88. #endif
  89. }