diff options
author | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-12-31 10:15:06 +0100 |
---|---|---|
committer | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-12-31 11:28:51 +0100 |
commit | 0c9bfbf8878716cadf59db16d512063b05755ae0 (patch) | |
tree | 086142c14afbf382e871094396acbf4f6521b302 | |
parent | 0eed7e7bcac0ebeb29b1850ae36ee5c1bd098bbe (diff) | |
download | ratpoison-0c9bfbf8878716cadf59db16d512063b05755ae0.zip |
Third try at cleaning set_active_window_body
Delete the weird logic and the nested loops. Use a true helper
function, don't just move code around.
-rw-r--r-- | src/window.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/window.c b/src/window.c index d398b75..7d31a87 100644 --- a/src/window.c +++ b/src/window.c @@ -452,8 +452,41 @@ void set_active_window_force (rp_window *win) set_active_window_body(win, 1); } -/* FIXME: This function is probably a mess. I can't remember a time - when I didn't think this. It probably needs to be fixed up. */ +static rp_frame * +find_frame_non_dedicated(rp_screen *current_screen, rp_frame *current_frame) +{ + rp_frame *cur; + + /* Try the only / current screen... */ + for (cur = list_next_entry (current_frame, ¤t_screen->frames, node); + cur != current_frame; + cur = list_next_entry (cur, ¤t_screen->frames, node)) + { + if (!cur->dedicated) + return cur; + } + + /* If we have Xinerama, we can check *all* screens... */ + if (rp_have_xinerama) + { + int i; + + for (i = 0; i < num_screens; i++) + { + if (current_screen == &screens[i]) + continue; + + list_for_each_entry (cur, &screens[i].frames, node) + { + if (!cur->dedicated) + return cur; + } + } + } + + return NULL; +} + void set_active_window_body (rp_window *win, int force) { @@ -485,48 +518,15 @@ set_active_window_body (rp_window *win, int force) if (frame->dedicated && !force) { - /* Try to find a non-dedicated frame. */ - rp_frame *cur; - rp_screen *scr; - int done; - - scr = (rp_have_xinerama)?&screens[rp_current_screen]:win->scr; - done = 0; - - /* Try the only / current screen... */ - for (cur = list_next_entry (frame, &scr->frames, node); - cur != frame && !done; - cur = list_next_entry (cur, &scr->frames, node)) - { - if (!cur->dedicated) - { - set_active_frame (cur, 0); - last_frame = frame; - frame = cur; - done = 1; - } - } + /* Try to find a non-dedicated frame. */ + rp_frame *non_dedicated; - /* If we have Xinerama, we can check *all* screens... */ - if (rp_have_xinerama && !done) + non_dedicated = find_frame_non_dedicated (screen, frame); + if (non_dedicated != NULL) { - int i; - - for (i=0; i<num_screens && !done; i++) - { - if (scr == &screens[i]) continue; - list_for_each_entry (cur,&screens[i].frames,node) - { - if (!cur->dedicated) - { - set_active_frame (cur, 0); - last_frame = frame; - frame = cur; - done = 1; /* Break outer loop. */ - break; /* Break inner loop. */ - } - } - } + last_frame = frame; + frame = non_dedicated; + set_active_frame (frame, 0); } } |