summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsabetts <sabetts>2006-04-21 00:14:25 +0000
committersabetts <sabetts>2006-04-21 00:14:25 +0000
commitda43881cd91e35267b094bab80873aa63ba4e109 (patch)
treee887fbe64daffdd3e71d6751841bebdd1645faf6 /src
parentfc0a1e5e68121502a02d556e90fe1ceb570e3493 (diff)
downloadratpoison-da43881cd91e35267b094bab80873aa63ba4e109.zip
* src/actions.h: new command sfrestore
* src/actions.c (init_user_commands): new command sfrestore (cmd_sfrestore): new function
Diffstat (limited to 'src')
-rw-r--r--src/actions.c74
-rw-r--r--src/actions.h1
2 files changed, 75 insertions, 0 deletions
diff --git a/src/actions.c b/src/actions.c
index 78736b1..8f57d7c 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -281,6 +281,8 @@ init_user_commands()
"Variable: ", arg_STRING,
"Value: ", arg_REST);
add_command ("shrink", cmd_shrink, 0, 0, 0);
+ add_command ("sfrestore", cmd_sfrestore, 1, 1, 1,
+ "Frames: ", arg_REST);
add_command ("source", cmd_source, 1, 1, 1,
"File: ", arg_REST);
add_command ("sselect", cmd_sselect, 1, 1, 1,
@@ -4933,6 +4935,78 @@ cmd_sfdump (int interactively, struct cmdarg **args)
}
cmdret *
+cmd_sfrestore (int interactively, struct cmdarg **args)
+{
+ int out_of_screen = 0;
+ int number_of_frames = 0;
+ int j;
+ long x;
+ char *dup;
+ char *token;
+ char *ptr;
+ struct sbuf *buffer[num_screens];
+
+ /* initialize frameset-buffer for each screen */
+ for (j=0; j<num_screens; j++) {
+ buffer[j] = sbuf_new(0);
+ }
+
+ /* now split the whole input to the corresponding screens */
+ dup = xstrdup (ARG_STRING(0));
+
+ token = strtok (dup, ",");
+ if (token == NULL) {
+ free (dup);
+ return cmdret_new (RET_FAILURE, "sfrestore: invalid frame format");
+ }
+
+ while (token != NULL) {
+ /* search for end of frameset */
+ ptr = token;
+ while (*ptr != ')') {
+ ptr++;
+ }
+ /* skip space */
+ ptr++;
+
+ /* convert to integer */
+ x = strtol (ptr, NULL, 10);
+
+ /* check that specified screen number is not bigger than current number of connected screens */
+ if (x < num_screens) {
+ /* append frameset to buffer[x] */
+ sbuf_concat(buffer[x], token);
+ sbuf_concat(buffer[x], ",");
+ number_of_frames++;
+ }
+ else {
+ out_of_screen++;
+ }
+
+ /* continue with next frameset */
+ token = strtok (NULL, ",");
+ }
+
+ free (dup);
+
+ /* now restore the frames for each screen */
+ for (j=0; j<num_screens; j++) {
+ push_frame_undo (&screens[j]); /* fdump to stack */
+ /* FIXME: store RET_SUCCESS || RET_FAILURE for each screen and output it later */
+ frestore (sbuf_get(buffer[j]), &screens[j]);
+ /* clear buffer */
+ sbuf_free(buffer[j]);
+ }
+
+ if (!out_of_screen) {
+ return cmdret_new (RET_SUCCESS, "Restored %i Frame(s)", number_of_frames);
+ }
+ else {
+ return cmdret_new (RET_SUCCESS, "Restored %i Frame(s), %i Frame(s) out of Screen(s)", number_of_frames, out_of_screen);
+ }
+}
+
+cmdret *
cmd_sdump (int interactive, struct cmdarg **args)
{
cmdret *ret;
diff --git a/src/actions.h b/src/actions.h
index dae4935..34bf3cc 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -201,6 +201,7 @@ RP_CMD (iprev);
RP_CMD (prompt);
RP_CMD (sdump);
RP_CMD (sfdump);
+RP_CMD (sfrestore);
RP_CMD (undo);
RP_CMD (redo);
RP_CMD (putsel);