ratpoison-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RP] [GIT PATCH 01/02] clean up set_active_window_body() - initial rewri


From: J.R. Mauro
Subject: [RP] [GIT PATCH 01/02] clean up set_active_window_body() - initial rewrite
Date: Tue, 29 Jul 2008 21:38:22 -0400
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

>From f9a13171fe5c4831509933f40a742b1a6c65946c Mon Sep 17 00:00:00 2001
From: J.R. Mauro <address@hidden>
Date: Tue, 29 Jul 2008 21:01:32 -0400
Subject: [PATCH] Started initial rewrite of set_active_window_body()

---
 src/window.c |  171 ++++++++++++++++++++++++++++++++--------------------------
 src/window.h |    4 ++
 2 files changed, 99 insertions(+), 76 deletions(-)

diff --git a/src/window.c b/src/window.c
index fe7bc1e..d98b9f0 100644
--- a/src/window.c
+++ b/src/window.c
@@ -565,84 +565,10 @@ set_active_window_body (rp_window *win, int force)
 
   PRINT_DEBUG (("intended_frame_number: %d\n", win->intended_frame_number));
 
-  /* With Xinerama, we can move a window over to the current screen; otherwise
-   * we have to switch to the screen that the window belongs to.
-   */
-  if (rp_have_xinerama)
-    {
-      /* use the intended frame if we can. */
-      if (win->intended_frame_number >= 0)
-        {
-          frame = screen_get_frame (current_screen(), 
win->intended_frame_number);
-          win->intended_frame_number = -1;
-          if (frame != current_frame())
-            last_frame = current_frame();
-        }
-
-      if (!frame)
-        frame = screen_get_frame (current_screen(), 
current_screen()->current_frame);
-    }
-  else
-    {
-      /* use the intended frame if we can. */
-      if (win->intended_frame_number >= 0)
-        {
-          frame = screen_get_frame (win->scr, win->intended_frame_number);
-          win->intended_frame_number = -1;
-          if (frame != current_frame())
-            last_frame = current_frame();
-        }
-
-      if (!frame)
-        frame = screen_get_frame (win->scr, win->scr->current_frame);
-    }
+  frame = get_frame(win, last_frame);
 
   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;
-            }
-        }
-
-      /* If we have Xinerama, we can check *all* screens... */
-      if (rp_have_xinerama && !done)
-        {
-          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. */
-                    }
-                }
-            }
-        }
-    }
+       find_non_dedicated_frame(win, frame, last_frame);
 
   last_win = set_frames_window (frame, win);
 
@@ -673,6 +599,99 @@ set_active_window_body (rp_window *win, int force)
   hook_run (&rp_switch_win_hook);
 }
 
+/* Gets frame from window 
+ *
+ * last_frame is modified by this... but since this is trying to fix ugly code
+ * I guess it can be a little ugly.
+ */
+rp_frame*
+get_frame(rp_window *win, rp_frame *last_frame)
+{
+       rp_frame* frame=NULL;
+       /* With Xinerama, we can move a window over to the current screen; 
otherwise
+        * we have to switch to the screen that the window belongs to.
+        */
+       if (rp_have_xinerama)
+       {
+               /* use the intended frame if we can. */
+               if (win->intended_frame_number >= 0)
+               {
+                       frame = screen_get_frame (current_screen(), 
win->intended_frame_number);
+                       win->intended_frame_number = -1;
+                       if (frame != current_frame())
+                               last_frame = current_frame();
+               }
+
+               if (!frame)
+                       frame = screen_get_frame (current_screen(), 
current_screen()->current_frame);
+       }
+       else
+       {
+               /* use the intended frame if we can. */
+               if (win->intended_frame_number >= 0)
+               {
+                       frame = screen_get_frame (win->scr, 
win->intended_frame_number);
+                       win->intended_frame_number = -1;
+                       if (frame != current_frame())
+                               last_frame = current_frame();
+               }
+
+               if (!frame)
+                       frame = screen_get_frame (win->scr, 
win->scr->current_frame);
+       }
+
+       return frame;
+}
+
+/* Finds a non-dedicated frame */
+void
+find_non_dedicated_frame(rp_window *win, rp_frame *frame, rp_frame *last_frame)
+{
+       /* 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;
+               }
+       }
+
+       /* If we have Xinerama, we can check *all* screens... */
+       if (rp_have_xinerama && !done)
+       {
+               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. */
+                               }
+                       }
+               }
+       }
+}
+
 /* Go to the window, switching frames if the window is already in a
    frame. */
 void
diff --git a/src/window.h b/src/window.h
index 922200b..7379b6b 100644
--- a/src/window.h
+++ b/src/window.h
@@ -68,6 +68,10 @@ rp_frame *win_get_frame (rp_window *win);
 void set_active_window_force (rp_window *win);
 void set_active_window_body (rp_window *win, int force);
 
+/* These probably won't be useful to anyone but set_active_window_body() */
+rp_frame* get_frame(rp_window *win, rp_frame *last_frame);
+void find_non_dedicated_frame(rp_window* win, rp_frame *frame, rp_frame 
*last_frame);
+
 struct rp_child_info *get_child_info (Window w);
 
 #endif /* ! _RATPOISON_LIST_H */
-- 
1.5.4.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]