Pedro Silva <psilva-p1a6hwqlyz+kuzhoyis...@public.gmane.org> writes:

> focusright, focusleft, focusup, and focusdown previously worked solely
> within the frame's screen, because their underlying handling logic in
> split.c strictly did not consider their screen offsets.

> This patch introduces 4 new functions, frame_*_abs, which instead report
> the frame's left, right, top, and bottom coordinates offset by it's
> screen arrangement. This allows the use of the focus* commands as
> additional screen navigation tools, and has the added benefit of making
> the find_frame_* functions clearer.
> ---
>  doc/ratpoison.texi |  4 +++-
>  src/frame.c        | 27 ++++++++++++++++++++++++
>  src/frame.h        |  4 ++++
>  src/split.c        | 62 
> +++++++++++++++++++++++++++++++++++-------------------
>  4 files changed, 74 insertions(+), 23 deletions(-)

This is a nice idea.  It makes ratpoison behave similar to StumpWM with respect 
to multiple screens, which I find more intuitive.

I've attached an updated patch, which applies against the xrandr branch.

From cb7ffe6b056e3d579bfbb81a17e96aacc20fd9e2 Mon Sep 17 00:00:00 2001
From: Joseph Mingrone <j...@ftfl.ca>
Date: Sun, 11 Dec 2016 19:03:29 -0400
Subject: [PATCH] Update screen-aware focus* commands after changes to support
 XRandR

This is an update to Pedro Silva's patch, so that it applies against the
xrandr branch.  That patch introduced four new functions, frame_*_abs,
which report a frame's left, right, top, and bottom coordinates offset by
it's screen arrangement.  This allows the use of the focus* commands as
additional screen navigation tools, and has the added benefit of making the
find_frame_* functions clearer.
---
 doc/ratpoison.texi |  4 +++-
 src/frame.c        | 27 +++++++++++++++++++++++++++
 src/frame.h        |  4 ++++
 src/split.c        | 44 ++++++++++++++++++++++++--------------------
 4 files changed, 58 insertions(+), 21 deletions(-)

diff --git a/doc/ratpoison.texi b/doc/ratpoison.texi
index da9da16..8876db1 100644
--- a/doc/ratpoison.texi
+++ b/doc/ratpoison.texi
@@ -904,7 +904,9 @@ window.'' ratpoison means there's no other window to switch to in the
 current screen. If you want to switch to the other xterm you can
 switch to it by name (use @command{select} or @kbd{C-t '}), by number,
 or you can use @command{nextscreen}, @command{prevscreen}, and
-@command{sselect}.
+@command{sselect}. Note, however, that the commands
+@command{focusright}, @command{focusleft}, @command{focusup}, and
+@command{focusdown} do work across screens.
 
 @deffn Command nextscreen
 This jumps you to the next X11 screen. @command{nextscreen} is
diff --git a/src/frame.c b/src/frame.c
index c42e2ab..95e4952 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -47,6 +47,33 @@ frame_bottom (rp_frame *frame)
   return frame->y + frame->height;
 }
 
+
+int
+frame_left_abs (rp_frame *frame)
+{
+  rp_screen *s = frames_screen (frame);
+  return s->left + frame->x;
+}
+
+int
+frame_top_abs (rp_frame *frame)
+{
+  rp_screen *s = frames_screen (frame);
+  return s->top + frame->y;
+}
+
+int
+frame_right_abs (rp_frame *frame)
+{
+  return frame_left_abs (frame) + frame->width;
+}
+
+int
+frame_bottom_abs (rp_frame *frame)
+{
+  return frame_top_abs (frame) + frame->height;
+}
+
 int
 frame_width(rp_frame *frame)
 {
diff --git a/src/frame.h b/src/frame.h
index 611ecc0..f78f86c 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -35,6 +35,10 @@ int frame_bottom (rp_frame *frame);
 int frame_right (rp_frame *frame);
 int frame_top (rp_frame *frame);
 int frame_left (rp_frame *frame);
+int frame_bottom_abs (rp_frame *frame);
+int frame_right_abs (rp_frame *frame);
+int frame_top_abs (rp_frame *frame);
+int frame_left_abs (rp_frame *frame);
 
 rp_frame *frame_new (rp_screen *s);
 void frame_free (rp_screen *s, rp_frame *f);
diff --git a/src/split.c b/src/split.c
index 5f74777..7042a55 100644
--- a/src/split.c
+++ b/src/split.c
@@ -997,15 +997,16 @@ show_frame_message (char *msg)
 rp_frame *
 find_frame_up (rp_frame *frame)
 {
-  rp_screen *s = frames_screen (frame);
+  rp_screen *s;
   rp_frame *cur;
 
-  list_for_each_entry (cur, &s->frames, node)
+  list_for_each_entry (s, &rp_screens, node)
     {
-      if (frame->y == cur->y + cur->height)
+      list_for_each_entry (cur, &s->frames, node)
         {
-          if (frame->x >= cur->x && frame->x < cur->x + cur->width)
-            return cur;
+          if (frame_top_abs (frame) == frame_bottom_abs (cur))
+            if (frame_right_abs (frame) >= frame_left_abs (cur) && frame_left_abs (frame) <= frame_right_abs (cur))
+              return cur;
         }
     }
 
@@ -1015,15 +1016,16 @@ find_frame_up (rp_frame *frame)
 rp_frame *
 find_frame_down (rp_frame *frame)
 {
-  rp_screen *s = frames_screen (frame);
+  rp_screen *s;
   rp_frame *cur;
 
-  list_for_each_entry (cur, &s->frames, node)
+  list_for_each_entry (s, &rp_screens, node)
     {
-      if (frame->y + frame->height == cur->y)
+      list_for_each_entry (cur, &s->frames, node)
         {
-          if (frame->x >= cur->x && frame->x < cur->x + cur->width)
-            return cur;
+          if (frame_bottom_abs (frame) == frame_top_abs (cur))
+            if (frame_right_abs (frame) >= frame_left_abs (cur) && frame_left_abs (frame) <= frame_right_abs (cur))
+              return cur;
         }
     }
 
@@ -1033,15 +1035,16 @@ find_frame_down (rp_frame *frame)
 rp_frame *
 find_frame_left (rp_frame *frame)
 {
-  rp_screen *s = frames_screen (frame);
+  rp_screen *s;
   rp_frame *cur;
 
-  list_for_each_entry (cur, &s->frames, node)
+  list_for_each_entry (s, &rp_screens, node)
     {
-      if (frame->x == cur->x + cur->width)
+      list_for_each_entry (cur, &s->frames, node)
         {
-          if (frame->y >= cur->y && frame->y < cur->y + cur->height)
-            return cur;
+          if (frame_left_abs (frame) == frame_right_abs (cur))
+            if (frame_top_abs (frame) >= frame_top_abs (cur) && frame_top_abs (frame) < frame_bottom_abs (cur))
+              return cur;
         }
     }
 
@@ -1051,15 +1054,16 @@ find_frame_left (rp_frame *frame)
 rp_frame *
 find_frame_right (rp_frame *frame)
 {
-  rp_screen *s = frames_screen (frame);
+  rp_screen *s;
   rp_frame *cur;
 
-  list_for_each_entry (cur, &s->frames, node)
+  list_for_each_entry (s, &rp_screens, node)
     {
-      if (frame->x + frame->width == cur->x)
+      list_for_each_entry (cur, &s->frames, node)
         {
-          if (frame->y >= cur->y && frame->y < cur->y + cur->height)
-            return cur;
+          if (frame_right_abs (frame) == frame_left_abs (cur))
+            if (frame_top_abs (frame) >= frame_top_abs (cur) && frame_top_abs (frame) < frame_bottom_abs (cur))
+              return cur;
         }
     }
 
-- 
2.11.0

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Ratpoison-devel mailing list
Ratpoison-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/ratpoison-devel

Reply via email to