Coverage Report

Created: 2025-08-24 07:01

/src/tmux/cmd-rotate-window.c
Line
Count
Source (jump to first uncovered line)
1
/* $OpenBSD$ */
2
3
/*
4
 * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
5
 *
6
 * Permission to use, copy, modify, and distribute this software for any
7
 * purpose with or without fee is hereby granted, provided that the above
8
 * copyright notice and this permission notice appear in all copies.
9
 *
10
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
 */
18
19
#include <sys/types.h>
20
21
#include "tmux.h"
22
23
/*
24
 * Rotate the panes in a window.
25
 */
26
27
static enum cmd_retval  cmd_rotate_window_exec(struct cmd *,
28
          struct cmdq_item *);
29
30
const struct cmd_entry cmd_rotate_window_entry = {
31
  .name = "rotate-window",
32
  .alias = "rotatew",
33
34
  .args = { "Dt:UZ", 0, 0, NULL },
35
  .usage = "[-DUZ] " CMD_TARGET_WINDOW_USAGE,
36
37
  .target = { 't', CMD_FIND_WINDOW, 0 },
38
39
  .flags = 0,
40
  .exec = cmd_rotate_window_exec
41
};
42
43
static enum cmd_retval
44
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
45
0
{
46
0
  struct args   *args = cmd_get_args(self);
47
0
  struct cmd_find_state *current = cmdq_get_current(item);
48
0
  struct cmd_find_state *target = cmdq_get_target(item);
49
0
  struct winlink    *wl = target->wl;
50
0
  struct window   *w = wl->window;
51
0
  struct window_pane  *wp, *wp2;
52
0
  struct layout_cell  *lc;
53
0
  u_int      sx, sy, xoff, yoff;
54
55
0
  window_push_zoom(w, 0, args_has(args, 'Z'));
56
57
0
  if (args_has(args, 'D')) {
58
0
    wp = TAILQ_LAST(&w->panes, window_panes);
59
0
    TAILQ_REMOVE(&w->panes, wp, entry);
60
0
    TAILQ_INSERT_HEAD(&w->panes, wp, entry);
61
62
0
    lc = wp->layout_cell;
63
0
    xoff = wp->xoff; yoff = wp->yoff;
64
0
    sx = wp->sx; sy = wp->sy;
65
0
    TAILQ_FOREACH(wp, &w->panes, entry) {
66
0
      if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
67
0
        break;
68
0
      wp->layout_cell = wp2->layout_cell;
69
0
      if (wp->layout_cell != NULL)
70
0
        wp->layout_cell->wp = wp;
71
0
      wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
72
0
      window_pane_resize(wp, wp2->sx, wp2->sy);
73
0
    }
74
0
    wp->layout_cell = lc;
75
0
    if (wp->layout_cell != NULL)
76
0
      wp->layout_cell->wp = wp;
77
0
    wp->xoff = xoff; wp->yoff = yoff;
78
0
    window_pane_resize(wp, sx, sy);
79
80
0
    if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
81
0
      wp = TAILQ_LAST(&w->panes, window_panes);
82
0
  } else {
83
0
    wp = TAILQ_FIRST(&w->panes);
84
0
    TAILQ_REMOVE(&w->panes, wp, entry);
85
0
    TAILQ_INSERT_TAIL(&w->panes, wp, entry);
86
87
0
    lc = wp->layout_cell;
88
0
    xoff = wp->xoff; yoff = wp->yoff;
89
0
    sx = wp->sx; sy = wp->sy;
90
0
    TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
91
0
      if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
92
0
        break;
93
0
      wp->layout_cell = wp2->layout_cell;
94
0
      if (wp->layout_cell != NULL)
95
0
        wp->layout_cell->wp = wp;
96
0
      wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
97
0
      window_pane_resize(wp, wp2->sx, wp2->sy);
98
0
    }
99
0
    wp->layout_cell = lc;
100
0
    if (wp->layout_cell != NULL)
101
0
      wp->layout_cell->wp = wp;
102
0
    wp->xoff = xoff; wp->yoff = yoff;
103
0
    window_pane_resize(wp, sx, sy);
104
105
0
    if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
106
0
      wp = TAILQ_FIRST(&w->panes);
107
0
  }
108
109
0
  window_set_active_pane(w, wp, 1);
110
0
  cmd_find_from_winlink_pane(current, wl, wp, 0);
111
0
  window_pop_zoom(w);
112
0
  server_redraw_window(w);
113
114
0
  return (CMD_RETURN_NORMAL);
115
0
}