summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsabetts <sabetts>2002-10-18 08:39:17 +0000
committersabetts <sabetts>2002-10-18 08:39:17 +0000
commit306424d93d5a1a379a751394acbc696415b4281b (patch)
tree9af6849d515046d8414f7e6ac7db6cc6104fbbd1 /src
parentcb9b0e5ee455fd615338baf828fd3ea8a541b395 (diff)
downloadratpoison-306424d93d5a1a379a751394acbc696415b4281b.zip
* src/split.c (VERTICALLY): new define
(VERTICALLY): likewise (split_frame): new argument 'pixels'. The current frame is split and resized to 'pixels' pixels. (v_split_frame): new argument 'pixels'. prototype updated. (h_split_frame): likewise * src/actions.c (user_commands): hsplit, vsplit, and split take a string argument. (read_split): new function (cmd_h_split): takes a ratio or number to determine how big the frame split will be. (cmd_v_split): likewise
Diffstat (limited to 'src')
-rw-r--r--src/actions.c55
-rw-r--r--src/split.c33
-rw-r--r--src/split.h4
3 files changed, 71 insertions, 21 deletions
diff --git a/src/actions.c b/src/actions.c
index 4fcd0e4..87ad310 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -52,7 +52,7 @@ static user_command user_commands[] =
{"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 @@ static user_command user_commands[] =
{"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,62 @@ cmd_echo (int interactive, void *data)
return NULL;
}
+static int
+read_split (const char *str, int max)
+{
+ int a, b, p;
+
+ if (sscanf(str, "%d/%d", &a, &b) == 2)
+ {
+ p = (int)(max * (float)(a) / (float)(b));
+ }
+ else if (sscanf(str, "%d", &p) == 1)
+ {
+ }
+ else
+ {
+ /* Failed to read input. */
+ p = -1;
+ }
+
+ /* Input out of range. */
+ if (p <= 0 || p >= max)
+ return -1;
+
+ return p;
+}
+
char *
cmd_h_split (int interactive, void *data)
{
- h_split_frame (current_screen()->rp_current_frame);
+ int pixels;
+
+ /* Default to dividing the frame in half. */
+ if (data == NULL)
+ pixels = current_screen()->rp_current_frame->height / 2;
+ else
+ pixels = read_split (data, current_screen()->rp_current_frame->height);
+
+ if (pixels > 0)
+ h_split_frame (current_screen()->rp_current_frame, pixels);
+
return NULL;
}
char *
cmd_v_split (int interactive, void *data)
{
- v_split_frame (current_screen()->rp_current_frame);
+ int pixels;
+
+ /* Default to dividing the frame in half. */
+ if (data == NULL)
+ pixels = current_screen()->rp_current_frame->width / 2;
+ else
+ pixels = read_split (data, current_screen()->rp_current_frame->width);
+
+ if (pixels > 0)
+ v_split_frame (current_screen()->rp_current_frame, pixels);
+
return NULL;
}
diff --git a/src/split.c b/src/split.c
index f9805ce..b364868 100644
--- a/src/split.c
+++ b/src/split.c
@@ -26,6 +26,9 @@
#include "ratpoison.h"
+#define VERTICALLY 0
+#define HORIZONTALLY 1
+
static void
update_last_access (rp_window_frame *frame)
{
@@ -272,7 +275,7 @@ find_window_for_frame (rp_window_frame *frame)
/* 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 pixels)
{
screen_info *s;
rp_window *win;
@@ -294,23 +297,23 @@ split_frame (rp_window_frame *frame, int way)
set_frames_window (new_frame, NULL);
- if (way)
+ if (way == HORIZONTALLY)
{
new_frame->x = frame->x;
- new_frame->y = frame->y + frame->height / 2;
+ new_frame->y = frame->y + pixels;
new_frame->width = frame->width;
- new_frame->height = frame->height / 2 + frame->height % 2;
+ new_frame->height = frame->height - pixels;
- frame->height /= 2;
+ frame->height = pixels;
}
else
{
- new_frame->x = frame->x + frame->width / 2;
+ new_frame->x = frame->x + pixels;
new_frame->y = frame->y;
- new_frame->width = frame->width / 2 + frame->width % 2;
+ new_frame->width = frame->width - pixels;
new_frame->height = frame->height;
- frame->width /= 2;
+ frame->width = pixels;
}
win = find_window_for_frame (new_frame);
@@ -341,18 +344,20 @@ split_frame (rp_window_frame *frame, int way)
show_frame_indicator();
}
-/* Splits the window vertically in 2. */
+/* Splits the window vertically leaving the original with 'pixels'
+ pixels . */
void
-v_split_frame (rp_window_frame *frame)
+v_split_frame (rp_window_frame *frame, int pixels)
{
- split_frame (frame, 0);
+ split_frame (frame, VERTICALLY, pixels);
}
-/* Splits the window horizontally in 2. */
+/* Splits the frame horizontally leaving the original with 'pixels'
+ pixels . */
void
-h_split_frame (rp_window_frame *frame)
+h_split_frame (rp_window_frame *frame, int pixels)
{
- split_frame (frame, 1);
+ split_frame (frame, HORIZONTALLY, pixels);
}
void
diff --git a/src/split.h b/src/split.h
index 606981e..7879329 100644
--- a/src/split.h
+++ b/src/split.h
@@ -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 pixels);
+void v_split_frame (rp_window_frame *frame, int pixels);
void remove_all_splits ();
void remove_frame (rp_window_frame *frame);
rp_window *find_window_for_frame (rp_window_frame *frame);