From e96af8537c8a0e3e53904be7e035f51f155e2493 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 9 Mar 2018 22:59:38 +0000 Subject: Only allow swapping active windows --- src/command/cmd_funcs.c | 31 ++++++++++++++++++++++--------- src/ui/window_list.c | 6 +----- src/ui/window_list.h | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 3fec5e16..ae7f2abc 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1269,21 +1269,34 @@ cmd_wins_swap(ProfWin *window, const char *const command, gchar **args) int source_win = atoi(args[1]); int target_win = atoi(args[2]); + if ((source_win == 1) || (target_win == 1)) { cons_show("Cannot move console window."); - } else if (source_win == 10 || target_win == 10) { + return TRUE; + } + + if (source_win == 10 || target_win == 10) { cons_show("Window 10 does not exist"); - } else if (source_win != target_win) { - gboolean swapped = wins_swap(source_win, target_win); - if (swapped) { - cons_show("Swapped windows %d <-> %d", source_win, target_win); - } else { - cons_show("Window %d does not exist", source_win); - } - } else { + return TRUE; + } + + if (source_win == target_win) { cons_show("Same source and target window supplied."); + return TRUE; + } + + if (wins_get_by_num(source_win) == NULL) { + cons_show("Window %d does not exist", source_win); + return TRUE; + } + + if (wins_get_by_num(target_win) == NULL) { + cons_show("Window %d does not exist", target_win); + return TRUE; } + wins_swap(source_win, target_win); + cons_show("Swapped windows %d <-> %d", source_win, target_win); return TRUE; } diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 09a53ed1..798f4e41 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -844,7 +844,7 @@ wins_lost_connection(void) g_list_free(values); } -gboolean +void wins_swap(int source_win, int target_win) { ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win)); @@ -869,7 +869,6 @@ wins_swap(int source_win, int target_win) wins_set_current_by_num(target_win); ui_focus_win(console); } - return TRUE; // target window occupied } else { @@ -894,10 +893,7 @@ wins_swap(int source_win, int target_win) if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { ui_focus_win(console); } - return TRUE; } - } else { - return FALSE; } } diff --git a/src/ui/window_list.h b/src/ui/window_list.h index f1a2ee24..68e72739 100644 --- a/src/ui/window_list.h +++ b/src/ui/window_list.h @@ -87,7 +87,7 @@ gboolean wins_tidy(void); GSList* wins_create_summary(gboolean unread); void wins_destroy(void); GList* wins_get_nums(void); -gboolean wins_swap(int source_win, int target_win); +void wins_swap(int source_win, int target_win); void wins_hide_subwin(ProfWin *window); void wins_show_subwin(ProfWin *window); -- cgit 1.4.1-2-gfad0 r Kartik K. Agaram <vc@akkartik.com> 2015-10-25 12:18:32 -0700 2273 - start expanding the type system' href='/akkartik/mu/commit/054dilated_reagent.cc?h=main&id=a796831f3e5697de7194607cfff3efddc588978a'>a796831f ^
c4f5d4cf ^

a796831f ^


1ead3562 ^
a796831f ^

acc4792d ^
a796831f ^
21c27706 ^
1ead3562 ^
21c27706 ^




d5f89e0f ^
1ead3562 ^
d5f89e0f ^

acc4792d ^
d5f89e0f ^


1ead3562 ^
d5f89e0f ^



a796831f ^

8619c618 ^
d18d1d3d ^




a796831f ^



a796831f ^

b24eb476 ^
a796831f ^
1f7e3c05 ^
79eef536 ^
21c27706 ^
79eef536 ^
a796831f ^



780b2ce1 ^
a796831f ^




a796831f ^

2d713167 ^



a796831f ^




2d713167 ^



a796831f ^



2d713167 ^



a796831f ^




d5f89e0f ^
a796831f ^



555d95c1 ^
4ad0f652 ^
a796831f ^


c4e143d6 ^

9dcbec39 ^
c4e143d6 ^


9dcbec39 ^
c4e143d6 ^


66abe7c1 ^






ce2e604e ^


c4e143d6 ^
08cf048f ^
79eef536 ^
b74443e5 ^
eb4eecea ^
66abe7c1 ^






ce2e604e ^
a17f9186 ^
a796831f ^
a796831f ^



79eef536 ^
a796831f ^
66abe7c1 ^




a072f674 ^
eb4eecea ^
a072f674 ^

a796831f ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151