ratpoison-devel
[Top][All Lists]
Advanced

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

[RP] [PATCH] Make focus* commands screen aware.


From: Pedro Silva
Subject: [RP] [PATCH] Make focus* commands screen aware.
Date: Tue, 20 Sep 2016 12:17:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

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(-)

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
address@hidden
address@hidden Note, however, that the commands
address@hidden, @command{focusleft}, @command{focusup}, and
address@hidden 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..f541e63 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 frame->x + s->left;
+}
+
+int
+frame_top_abs (rp_frame *frame)
+{
+  rp_screen *s = frames_screen (frame);
+  return frame->y + s->top;
+}
+
+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 b36b99e..a9688ad 100644
--- a/src/split.c
+++ b/src/split.c
@@ -1000,15 +1000,19 @@ 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;
+  int i;
 
-  list_for_each_entry (cur, &s->frames, node)
+  for (i = 0; i < num_screens; i++)
     {
-      if (frame->y == cur->y + cur->height)
+      s = &screens[i];
+
+      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;
         }
     }
 
@@ -1018,15 +1022,19 @@ 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;
+  int i;
 
-  list_for_each_entry (cur, &s->frames, node)
+  for (i = 0; i < num_screens; i++)
     {
-      if (frame->y + frame->height == cur->y)
+      s = &screens[i];
+
+      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;
         }
     }
 
@@ -1036,33 +1044,42 @@ 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;
+  int i;
 
-  list_for_each_entry (cur, &s->frames, node)
+  for (i = 0; i < num_screens; i++)
     {
-      if (frame->x == cur->x + cur->width)
+      s = &screens[i];
+
+      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;
         }
     }
 
   return NULL;
 }
 
+
 rp_frame *
 find_frame_right (rp_frame *frame)
 {
-  rp_screen *s = frames_screen (frame);
+  rp_screen *s;
   rp_frame *cur;
+  int i;
 
-  list_for_each_entry (cur, &s->frames, node)
+  for (i = 0; i < num_screens; i++)
     {
-      if (frame->x + frame->width == cur->x)
+      s = &screens[i];
+
+      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;
         }
     }
 
@@ -1072,12 +1089,13 @@ find_frame_right (rp_frame *frame)
 rp_frame *
 find_frame_number (int num)
 {
-  int i;
+  rp_screen *s;
   rp_frame *cur;
+  int i;
 
   for (i=0; i<num_screens; i++)
     {
-      rp_screen *s = &screens[i];
+      s = &screens[i];
 
       list_for_each_entry (cur, &s->frames, node)
         {
-- 
2.10.0



reply via email to

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