summaryrefslogtreecommitdiff
path: root/src/fe-common
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2016-12-20 21:01:16 +0100
committerailin-nemui <ailin-nemui@users.noreply.github.com>2016-12-20 21:01:16 +0100
commit9004265e5417c509e55c5141d5880ebd1e1c3281 (patch)
tree8a9109fbd7cf9130ff3e131010dbf503a33dcfef /src/fe-common
parent2f59fe206233c0f45256e9e541c121f4d63385dd (diff)
downloadirssi-9004265e5417c509e55c5141d5880ebd1e1c3281.zip
clean up window_refnum_{prev,next}
Diffstat (limited to 'src/fe-common')
-rw-r--r--src/fe-common/core/fe-windows.c46
1 files changed, 14 insertions, 32 deletions
diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c
index d02048be..97034192 100644
--- a/src/fe-common/core/fe-windows.c
+++ b/src/fe-common/core/fe-windows.c
@@ -473,35 +473,29 @@ static GSequenceIter *windows_seq_refnum_search_right(int refnum)
return g_sequence_search(windows_seq, GINT_TO_POINTER(refnum), (GCompareDataFunc)window_refnum_lookup, NULL);
}
+static GSequenceIter *windows_seq_refnum_search_left(int refnum)
+{
+ GSequenceIter *iter = windows_seq_refnum_search_right(refnum-1);
+ return iter == windows_seq_begin() ? NULL : g_sequence_iter_prev(iter);
+}
+
int window_refnum_prev(int refnum, int wrap)
{
+ WINDOW_REC *rec;
GSequenceIter *iter, *end;
- iter = windows_seq_refnum_search_right(refnum-1);
+ iter = windows_seq_refnum_search_left(refnum);
end = windows_seq_end();
if (iter != NULL) {
- WINDOW_REC *rec;
- if (iter != end) {
- rec = g_sequence_get(iter);
-
- if (rec->refnum < refnum)
- return rec->refnum;
- }
-
- iter = g_sequence_iter_prev(iter);
rec = g_sequence_get(iter);
-
- if (rec->refnum < refnum)
- return rec->refnum;
+ return rec->refnum;
}
if (wrap) {
- WINDOW_REC *rec;
iter = g_sequence_iter_prev(end);
if (iter != end) {
rec = g_sequence_get(iter);
-
return rec->refnum;
}
}
@@ -511,32 +505,21 @@ int window_refnum_prev(int refnum, int wrap)
int window_refnum_next(int refnum, int wrap)
{
+ WINDOW_REC *rec;
GSequenceIter *iter, *end;
iter = windows_seq_refnum_search_right(refnum);
end = windows_seq_end();
- if (iter != NULL && iter != end) {
- WINDOW_REC *rec = g_sequence_get(iter);
-
- if (rec->refnum > refnum)
- return rec->refnum;
-
- iter = g_sequence_iter_next(iter);
- if (iter != end) {
- rec = g_sequence_get(iter);
-
- if (rec->refnum > refnum)
- return rec->refnum;
- }
+ if (iter != end) {
+ rec = g_sequence_get(iter);
+ return rec->refnum;
}
if (wrap) {
- WINDOW_REC *rec;
iter = windows_seq_begin();
if (iter != end) {
rec = g_sequence_get(iter);
-
return rec->refnum;
}
}
@@ -546,14 +529,13 @@ int window_refnum_next(int refnum, int wrap)
int windows_refnum_last(void)
{
- GSequenceIter *end, *iter;
WINDOW_REC *rec;
+ GSequenceIter *end, *iter;
end = windows_seq_end();
iter = g_sequence_iter_prev(end);
if (iter != end) {
rec = g_sequence_get(iter);
-
return rec->refnum;
}