[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RP] [PATCH 4/6] Use xrandr output identifiers in srestore.
From: |
Mathieu OTHACEHE |
Subject: |
[RP] [PATCH 4/6] Use xrandr output identifiers in srestore. |
Date: |
Fri, 25 Nov 2016 15:35:21 +0100 |
Handle xrandr output identifiers in sfrestore input string.
Also inform the user if frestore failed for a frame restoration.
Disable sfrestore if the user has no xrandr support.
---
src/actions.c | 77 ++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 58 insertions(+), 19 deletions(-)
diff --git a/src/actions.c b/src/actions.c
index faddbd1..476f359 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -5639,22 +5639,37 @@ cmd_sfdump (int interactively UNUSED, struct cmdarg
**args UNUSED)
#endif
}
+#ifndef HAVE_XRANDR
+cmdret *
+cmd_sfrestore (int interactively UNUSED, struct cmdarg **args UNUSED)
+{
+ return cmdret_new (RET_FAILURE, "sfrestore: no xrandr support");
+}
+#else
cmdret *
cmd_sfrestore (int interactively UNUSED, struct cmdarg **args)
{
char *copy, *ptr, *token;
- long screen;
+ int rr_output;
int out_of_screen = 0;
- int restored = 0;
int s_count = screen_count ();
- struct sbuf *buffer[s_count];
- rp_screen *cur_screen;
+
+ struct sf_data {
+ rp_screen *screen;
+ struct sbuf *frames;
+ int ret_restore;
+
+ } sf_data[s_count];
+
+ int sf_index = 0;
int i;
- return cmdret_new (RET_FAILURE, "FIXME: sfrestore is currently broken");
+ if (!rp_have_xrandr) {
+ return cmdret_new (RET_FAILURE, "sfrestore: no xrandr support");
+ }
for (i = 0; i < s_count; i++)
- buffer[i] = sbuf_new (0);
+ sf_data[i].frames = sbuf_new (0);
copy = xstrdup (ARG_STRING (0));
@@ -5667,22 +5682,26 @@ cmd_sfrestore (int interactively UNUSED, struct cmdarg
**args)
while (token != NULL)
{
+ rp_screen *screen;
+
/* search for end of frameset */
ptr = token;
while (*ptr != ')')
ptr++;
ptr++;
- screen = string_to_positive_int (ptr);
+ rr_output = string_to_positive_int (ptr);
- /* check that specified screen number is valid */
- if (screen >= 0 && screen < s_count)
+ screen = xrandr_screen_output(rr_output);
+ if (screen && sf_index < s_count)
{
/* clobber screen number here, frestore() doesn't need it */
*ptr = '\0';
- sbuf_concat (buffer[screen], token);
- sbuf_concat (buffer[screen], ",");
- restored++;
+ sbuf_concat (sf_data[sf_index].frames, token);
+ sbuf_concat (sf_data[sf_index].frames, ",");
+
+ sf_data[sf_index].screen = screen;
+ sf_index++;
}
else
out_of_screen++;
@@ -5694,24 +5713,44 @@ cmd_sfrestore (int interactively UNUSED, struct cmdarg
**args)
free (copy);
/* now restore the frames for each screen */
- list_for_each_entry (cur_screen, &rp_screens, node)
+ for (i = 0; i < sf_index; i++)
{
cmdret * ret;
+ rp_screen *cur_screen;
+ struct sbuf *cur_frames;
+
+ cur_screen = sf_data[i].screen;
+ cur_frames = sf_data[i].frames;
+
push_frame_undo (cur_screen); /* fdump to stack */
- /* FIXME: store RET_SUCCESS || RET_FAILURE for each screen and output
- it later */
- ret = frestore (sbuf_get (buffer[i]), cur_screen);
+
+ ret = frestore (sbuf_get (cur_frames), cur_screen);
+ sf_data[i].ret_restore = ret->success;
+
cmdret_free (ret);
- sbuf_free (buffer[i]);
+ sbuf_free (cur_frames);
+ }
+
+ for (i = 0; i < sf_index; i++)
+ {
+ int ret;
+
+ ret = sf_data[i].ret_restore;
+ if (ret != RET_SUCCESS)
+ {
+ return cmdret_new (ret, "Failed to restore frames for screen %d",
+ sf_data[i].screen->xrandr.output);
+ }
}
if (!out_of_screen)
- return cmdret_new (RET_SUCCESS, "Restored %i Frame(s)", restored);
+ return cmdret_new (RET_SUCCESS, "Restored %i Frame(s)", sf_index);
else
return cmdret_new (RET_SUCCESS,
"Restored %i Frame(s), %i Frame(s) out of Screen(s)",
- restored, out_of_screen);
+ sf_index, out_of_screen);
}
+#endif
cmdret *
cmd_sdump (int interactive UNUSED, struct cmdarg **args UNUSED)
--
2.10.0
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., (continued)
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., Jeremie Courreges-Anglas, 2016/11/26
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., Mathieu OTHACEHE, 2016/11/27
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., Jeremie Courreges-Anglas, 2016/11/27
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., Mathieu OTHACEHE, 2016/11/27
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., Jeremie Courreges-Anglas, 2016/11/27
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., Mathieu OTHACEHE, 2016/11/28
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., |cos|, 2016/11/27
- Re: [RP] [PATCH 3/6] Disable sfdump if there is no xrandr support., Mathieu OTHACEHE, 2016/11/28
[RP] [PATCH 2/6] Use xrandr output identifiers in sselect., Mathieu OTHACEHE, 2016/11/25
[RP] [PATCH 5/6] Kill gcc uninitialized warning, Mathieu OTHACEHE, 2016/11/25
[RP] [PATCH 4/6] Use xrandr output identifiers in srestore.,
Mathieu OTHACEHE <=
[RP] [PATCH 6/6] Update XRandr related documentation and man., Mathieu OTHACEHE, 2016/11/25