Re: Try to implement next-in-frame feature

[email protected]
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
diff --git a/src/actions.c b/src/actions.c
index b3baadb..8edb4ec 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -387,6 +387,9 @@ init_user_commands(void)
                "Text: ", arg_RAW);
   add_command ("getsel",        cmd_getsel,     0, 0, 0);
   add_command ("compat",        cmd_compat,     0, 0, 0);
+  /*NEW*/
+  add_command ("nextframe",     cmd_nextframe, 0, 0, 0);
+  /*NEW*/
   /*@end (tag required for genrpbindings) */
 
   /* Commands to help debug ratpoison. */
@@ -1263,7 +1266,6 @@ cmd_other (int interactive UNUSED, struct cmdarg **args UNUSED)
     return cmdret_new (RET_FAILURE, "%s", MESSAGE_NO_OTHER_WINDOW);
   else
     set_active_window_force (w);
-
   return cmdret_new (RET_SUCCESS, NULL);
 }
 
@@ -5565,6 +5567,49 @@ set_maxundos (struct cmdarg **args)
   return cmdret_new (RET_SUCCESS, NULL);
 }
 
+/*NEW*/
+cmdret *
+cmd_nextframe (int interactive, struct cmdarg **args)
+{
+  rp_window *cur, *last, *win;
+
+  cur = current_window();
+  
+  if (!cur)
+    return cmd_next (interactive, args);
+
+  /*NEW*/
+  //see cmd_undo
+  if(cur->in_frame==-1)
+    return cmd_next (interactive, args);
+  /*NEW*/
+
+  int current_frame=current_screen()->current_frame;
+
+  /* CUR !in cycle list, so LAST marks last node. */
+  last = group_prev_window (rp_current_group, cur);
+
+  if (last)
+    for (win = group_next_window (rp_current_group, cur);
+         win;
+         win = group_next_window (rp_current_group, win))
+      {
+        if (current_frame == win->in_frame)
+          {
+	    set_active_window_force (win);
+            return cmdret_new (RET_SUCCESS, NULL);
+          }
+
+        if (win == last) break;
+      }
+
+  //need if you make a nextframe on window, which in_frame isn't equals to
+  //the current frame number, and if the windows is the only one in the frame
+  cur->in_frame=current_frame;
+  return cmdret_new (RET_FAILURE, "%s", MESSAGE_NO_OTHER_WINDOW);
+}
+/*NEW*/
+
 cmdret *
 cmd_cnext (int interactive, struct cmdarg **args)
 {
@@ -5732,6 +5777,16 @@ cmd_undo (int interactive UNUSED, struct cmdarg **args UNUSED)
       cmdret *ret;
 
       ret = frestore (cur->frames, cur->screen);
+      /*NEW*/
+      //unability to store "in_frame" information, so they are set to -1
+      //to avoid lost a windows if tou use just "nextframe"
+      //but all "in_frame" layout is lost.
+      rp_window_elem *win;
+      list_for_each_entry (win, &rp_current_group->mapped_windows, node)
+	{
+	  win->win->in_frame=-1;
+	}
+      /*NEW*/
       return ret;
     }
 }
diff --git a/src/actions.h b/src/actions.h
index 5db4a56..04d91e1 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -218,6 +218,9 @@ RP_CMD (undo);
 RP_CMD (redo);
 RP_CMD (putsel);
 RP_CMD (getsel);
+/*NEW*/
+RP_CMD (nextframe);
+/*NEW*/
 
 void del_frame_undo (rp_frame_undo *u);
 
diff --git a/src/data.h b/src/data.h
index 541ca9e..648de0b 100644
--- a/src/data.h
+++ b/src/data.h
@@ -111,6 +111,12 @@ struct rp_window
      is mapped and this is >0 then use the frame (if it exists). */
   int intended_frame_number;
 
+  /*NEW*/
+  //refer to the frame where the window is supposed to be displayed in
+  int in_frame;
+  /*NEW*/
+
+
   struct list_head node;
 };
 
diff --git a/src/format.c b/src/format.c
index 0706f21..82e7e79 100644
--- a/src/format.c
+++ b/src/format.c
@@ -169,12 +169,12 @@ format_string (char *fmt, rp_window_elem *win_elem, struct sbuf *buffer)
 static void
 fmt_framenum (rp_window_elem *win_elem, struct sbuf *buf)
 {
-  if (win_elem->win->frame_number != EMPTY)
+  //if (win_elem->win->frame_number != EMPTY)
     {
-      sbuf_printf_concat (buf, "%d", win_elem->win->frame_number);
+      sbuf_printf_concat (buf, "%d", win_elem->win->in_frame);
     }
-  else
-    sbuf_copy (buf, " ");
+    //  else
+    //    sbuf_copy (buf, " ");
 }
 
 static void
diff --git a/src/split.c b/src/split.c
index 480fca1..12d2a60 100644
--- a/src/split.c
+++ b/src/split.c
@@ -390,8 +390,12 @@ remove_all_splits (void)
   /* Hide all the windows not in the current frame. */
   list_for_each_entry (win, &rp_mapped_window, node)
     {
-      if (win->frame_number != s->current_frame && win->scr == s)
-        hide_window (win);
+      if (win->frame_number != s->current_frame && win->scr == s){
+	hide_window (win);
+        /*NEW*/
+	  win->in_frame=s->current_frame;
+	/*NEW*/
+      }
     }
 
   /* Delete all the frames except the current one. */
@@ -716,8 +720,16 @@ remove_frame (rp_frame *frame)
   area = total_frame_area(s);
   PRINT_DEBUG (("Total Area: %d\n", area));
 
+  /*NEW*/
+  int tmp_in_frame=find_frame_prev(frame)->number;
+  /*NEW*/
+  
   list_del (&frame->node);
   win = find_window_number (frame->win_number);
+  /*NEW*/
+  if(win)
+    win->in_frame=tmp_in_frame;
+  /*NEW*/
   hide_window (win);
   hide_others (win);
 
diff --git a/src/window.c b/src/window.c
index 889772c..209f8c8 100644
--- a/src/window.c
+++ b/src/window.c
@@ -231,6 +231,11 @@ add_to_window_list (rp_screen *s, Window w)
   if (frame_num >= 0)
     new_window->intended_frame_number = frame_num;
 
+  /*NEW*/
+  //a window created gets the current frame number
+  if (frame_num >= 0)
+    new_window->in_frame = frame_num;
+  /*NEW*/
   return new_window;
 }
 
@@ -665,6 +670,15 @@ set_active_window_body (rp_window *win, int force)
 
   last_win = set_frames_window (frame, win);
 
+  /*NEW*/
+  //when a window is displayed in a frame, it gets the current frame number
+  //as in_frame number.
+  win->in_frame=frame->number;
+  if(last_win)
+    last_win->in_frame=frame->number;
+  /*NEW*/
+
+
   if (last_win) PRINT_DEBUG (("last window: %s\n", window_name (last_win)));
   PRINT_DEBUG (("new window: %s\n", window_name (win)));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.