ratpoison-devel
[Top][All Lists]
Advanced

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

[RP] [PATCH] frame split enhancement


From: Dan Aloni
Subject: [RP] [PATCH] frame split enhancement
Date: Tue Oct 15 14:58:04 2002
User-agent: Mutt/1.4i

This patch allows ratpoison to achieve even greater coolness 
by letting the user optionally specify exactly how to split 
the frame, in this manner:

split            - split 1 / 1, like always
split [x] [y]    - split the frame, to a ratio of x / y.
split  0  [x]    - split the frame, setting the size of the
                   new part to x pixels
split [x]  0     - split the frame, setting the size of the
                   old part to x pixels

(this works for vsplit, hsplit, and split).

diff -urN  ratpoison-1.1.1/src/actions.c ratpoison-splitenhanced/src/actions.c
--- ratpoison-1.1.1/src/actions.c       2002-07-07 00:31:27.000000000 +0300
+++ ratpoison-splitenhanced/src/actions.c       2002-10-15 23:46:11.000000000 
+0200
@@ -52,7 +52,7 @@
     {"meta",           cmd_meta,       arg_STRING},
     {"license",                cmd_license,    arg_VOID},
     {"help",           cmd_help,       arg_VOID},
-    {"hsplit",         cmd_h_split,    arg_VOID},
+    {"hsplit",         cmd_h_split,    arg_STRING},
     {"kill",           cmd_kill,       arg_VOID},
     {"redisplay",      cmd_redisplay,  arg_VOID},
     {"newwm",          cmd_newwm,      arg_STRING},
@@ -67,11 +67,11 @@
     {"rudeness",       cmd_rudeness,   arg_STRING},
     {"select",                 cmd_select,     arg_STRING},
     {"source",         cmd_source,     arg_STRING},
-    {"split",          cmd_h_split,    arg_VOID},
+    {"split",          cmd_h_split,    arg_STRING},
     {"title",          cmd_rename,     arg_STRING},
     {"unbind",         cmd_unbind,     arg_STRING},
     {"version",                cmd_version,    arg_VOID},
-    {"vsplit",         cmd_v_split,    arg_VOID},
+    {"vsplit",         cmd_v_split,    arg_STRING},
     {"windows",        cmd_windows,    arg_VOID},
     {"setenv",         cmd_setenv,     arg_STRING},
     {"getenv",         cmd_getenv,     arg_STRING},
@@ -1263,17 +1263,39 @@
   return NULL;
 }
 
+void
+parse_int_tuple(int *a, int *b, void *data)
+{
+  *a = 0;
+  *b = 0;
+
+  if (data)
+    {
+      if (sscanf(data, "%d %d", a, b) != 2)
+       {
+         *a = 0;
+         *b = 0;
+       }
+    }
+}
+
 char *
 cmd_h_split (int interactive, void *data)
 {
-  h_split_frame (current_screen()->rp_current_frame);
+  int part_a, part_b;
+
+  parse_int_tuple(&part_a, &part_b, data);
+  h_split_frame (current_screen()->rp_current_frame, part_a, part_b);
   return NULL;
 }
 
 char *
 cmd_v_split (int interactive, void *data)
 {
-  v_split_frame (current_screen()->rp_current_frame);
+  int part_a, part_b;
+
+  parse_int_tuple(&part_a, &part_b, data);
+  v_split_frame (current_screen()->rp_current_frame, part_a, part_b);
   return NULL;
 }
 
diff -urN  ratpoison-1.1.1/src/split.c ratpoison-splitenhanced/src/split.c
--- ratpoison-1.1.1/src/split.c 2002-03-13 10:08:15.000000000 +0200
+++ ratpoison-splitenhanced/src/split.c 2002-10-15 23:46:11.000000000 +0200
@@ -272,7 +272,7 @@
 /* Splits the frame in 2. if way is 0 then split vertically otherwise
    split it horizontally. */
 static void
-split_frame (rp_window_frame *frame, int way)
+split_frame (rp_window_frame *frame, int way, int part_a, int part_b)
 {
   screen_info *s;
   rp_window *win;
@@ -294,23 +294,47 @@
 
   set_frames_window (new_frame, NULL);
 
+  if (part_a == 0  &&  part_b == 0) 
+    {
+      part_a = 1;
+      part_b = 1;
+    }
+
   if (way)
     {
+      if (part_a == 0)
+       {
+         part_a = frame->height - part_b;
+       }      
+      else if (part_b != 0)
+       {
+         part_a = (frame->height * part_a / (part_a + part_b));
+       }
+
       new_frame->x = frame->x;
-      new_frame->y = frame->y + frame->height / 2;
+      new_frame->y = frame->y + part_a;
       new_frame->width = frame->width;
-      new_frame->height = frame->height / 2 + frame->height % 2;
+      new_frame->height = frame->height - part_a;
 
-      frame->height /= 2;
+      frame->height = part_a;
     }
   else
     {
-      new_frame->x = frame->x + frame->width / 2;
+      if (part_a == 0)
+       {
+         part_a = frame->width - part_b;
+       }
+      else if (part_b != 0)
+       {         
+         part_a = (frame->width * part_a / (part_a + part_b));
+       }
+
+      new_frame->x = frame->x + part_a;
       new_frame->y = frame->y;
-      new_frame->width = frame->width / 2 + frame->width % 2;
+      new_frame->width = frame->width - part_a;
       new_frame->height = frame->height;
 
-      frame->width /= 2;
+      frame->width = part_a;
     }
 
   win = find_window_for_frame (new_frame);
@@ -343,16 +367,16 @@
 
 /* Splits the window vertically in 2. */
 void
-v_split_frame (rp_window_frame *frame)
+v_split_frame (rp_window_frame *frame, int part_a, int part_b)
 {
-  split_frame (frame, 0);
+  split_frame (frame, 0, part_a, part_b);
 }
 
 /* Splits the window horizontally in 2. */
 void
-h_split_frame (rp_window_frame *frame)
+h_split_frame (rp_window_frame *frame, int part_a, int part_b)
 {
-  split_frame (frame, 1);
+  split_frame (frame, 1, part_a, part_b);
 }
 
 void
diff -urN  ratpoison-1.1.1/src/split.h ratpoison-splitenhanced/src/split.h
--- ratpoison-1.1.1/src/split.h 2002-02-08 04:45:04.000000000 +0200
+++ ratpoison-splitenhanced/src/split.h 2002-10-15 23:46:11.000000000 +0200
@@ -24,8 +24,8 @@
 
 rp_window *set_frames_window (rp_window_frame *frame, rp_window *win);
 void maximize_all_windows_in_frame (rp_window_frame *frame);
-void h_split_frame (rp_window_frame *frame);
-void v_split_frame (rp_window_frame *frame);
+void h_split_frame (rp_window_frame *frame, int part_a, int part_b);
+void v_split_frame (rp_window_frame *frame, int part_a, int part_b); 
 void remove_all_splits ();
 void remove_frame (rp_window_frame *frame);
 rp_window *find_window_for_frame (rp_window_frame *frame);



-- 
Dan Aloni
address@hidden



reply via email to

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