ratpoison-devel
[Top][All Lists]
Advanced

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

[RP] [PATCH 7/7] Select xrandr primary screen at startup if possible


From: Mathieu OTHACEHE
Subject: [RP] [PATCH 7/7] Select xrandr primary screen at startup if possible
Date: Wed, 7 Dec 2016 10:03:58 +0100

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.
---
 src/main.c   |  7 -------
 src/screen.c | 27 +++++++++++++++++++++++++++
 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 811a947..095040c 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;
@@ -299,6 +325,7 @@ init_screens (void)
 
   screen_sort ();
   screen_set_numbers ();
+  screen_select_primary ();
 
   free (rr_outputs);
 }
-- 
2.10.0




reply via email to

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