summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu OTHACEHE <m.othacehe@gmail.com>2016-12-07 10:03:58 +0100
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2016-12-08 17:51:46 +0100
commit25ec4e4ad39fc1074d1ac7949103b70ea4790cb9 (patch)
treea5f78bcfc6e52eda92f6a5c2266986d439952b4b
parent2afbce75d61319e5fbbc7c8a1a4844870ef6a9e7 (diff)
downloadratpoison-25ec4e4ad39fc1074d1ac7949103b70ea4790cb9.zip
Select xrandr primary screen at startup if possible
If xrandr support is enabled and a screen is marked primary, use it as current screen at startup. Otherwise, use the first screen in sorted screen list as current screen at startup.
-rw-r--r--src/main.c7
-rw-r--r--src/screen.c27
2 files changed, 27 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index cce4f94..76af702 100644
--- a/src/main.c
+++ b/src/main.c
@@ -589,7 +589,6 @@ main (int argc, char *argv[])
int c;
char **cmd = NULL;
int cmd_count = 0;
- rp_screen *cur;
char *display = NULL;
unsigned char interactive = 0;
char *alt_rcfile = NULL;
@@ -739,12 +738,6 @@ main (int argc, char *argv[])
initialize_default_keybindings ();
history_load ();
- list_for_each_entry (cur, &rp_screens, node)
- {
- if (!rp_current_screen)
- rp_current_screen = cur;
- }
-
scanwins ();
if (read_startup_files (alt_rcfile) == -1)
diff --git a/src/screen.c b/src/screen.c
index 7bbc133..1f720de 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -249,6 +249,32 @@ screen_set_numbers (void)
}
static void
+screen_select_primary (void)
+{
+ rp_screen *cur;
+
+ /* By default, take the first screen as current screen */
+ list_first(cur, &rp_screens, node);
+ if (!rp_current_screen)
+ rp_current_screen = cur;
+
+#ifdef HAVE_XRANDR
+ if (!rp_have_xrandr)
+ return;
+
+ list_for_each_entry (cur, &rp_screens, node)
+ {
+ if (xrandr_is_primary(cur)) {
+ rp_current_screen = cur;
+ PRINT_DEBUG(("Xrandr primary screen %d detected\n",
+ rp_current_screen->number));
+ break;
+ }
+ }
+#endif
+}
+
+static void
init_global_screen (rp_global_screen *s)
{
int screen_num;
@@ -298,6 +324,7 @@ init_screens (void)
screen_sort ();
screen_set_numbers ();
+ screen_select_primary ();
free (rr_outputs);
}