Re: ratinfo/ratrelinfo/banishrel patch

Rob Paisley <paisley-fBzVes0d2/ZWk0Htik3J/[email protected]>
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
This was my version of the non-crashing patch... :-\

See attached

Rob

On Mon, Apr 13, 2009 at 05:35:59AM -0700, Shawn Betts wrote:
> Rob Paisley <[email protected]> writes:
> 
> > Attached is a proposed patch for the following commands:
> 
> These commands skate the edge of chubby, but they seem to have enough
> healthful essential fatty acids that I decided to include them. Why
> not when we've already loosened the belt this much right?
> 
> Note that there was a segfault bug in banishrel and I changed them around a bit.
> 
> -Shawn
> 
> 
> _______________________________________________
> Ratpoison-devel mailing list
> [email protected]
> http://lists.nongnu.org/mailman/listinfo/ratpoison-devel

_______________________________________________
Ratpoison-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/ratpoison-devel
patch (text/plain, 3.8 KB)
diff --git a/doc/ratpoison.1 b/doc/ratpoison.1
index d2abf49..4cf31d1 100644
--- a/doc/ratpoison.1
+++ b/doc/ratpoison.1
@@ -225,6 +225,10 @@ Add \fIalias\fP as new way to call \fIcommand\fP.
 alias for "\fBdefinekey root\fP \fIkey\fP \fIcommand\fP"
 .cmd banish ( C\-t b )
 Banish the rat cursor to the lower right corner of the screen.
+.cmd banishrel
+Banish the rat cursor to the lower right corner of the curren window.
+If there isn't a window in the current frame, it banishes the rat cursor
+to the lower right corner of current frame.
 .cmd chdir [ directory ]
 If the optional argument is given, change the current directory
 of ratpoison to \fIdirectory\fP.
@@ -469,6 +473,10 @@ Replace the X selection with the text \fIx\-selection\fP. It can be
 inserted into the current window with \fBgetsel\fP.
 .cmd quit
 Quit ratpoison.
+.cmd ratinfo
+Display the x y coordinates of the rat cursor relative to the screen.
+.cmd ratrelinfo
+Display the x y coordinates of the rat cursor relative to the window.
 .cmd ratwarp x y
 Move the rat cursor to the position (\fIx\fP,\fIy\fP).
 .cmd ratrelwarp deltax deltay
diff --git a/src/actions.c b/src/actions.c
index ab5162e..b1ad326 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -303,6 +303,9 @@ init_user_commands(void)
   add_command ("prev",          cmd_prev,       0, 0, 0);
   add_command ("prevscreen",    cmd_prevscreen, 0, 0, 0);
   add_command ("quit",          cmd_quit,       0, 0, 0);
+  add_command ("ratinfo",       cmd_ratinfo,    0, 0, 0);
+  add_command ("ratrelinfo",    cmd_ratrelinfo, 0, 0, 0);
+  add_command ("banishrel",     cmd_banishrel,  0, 0, 0);
   add_command ("ratwarp",       cmd_ratwarp,    2, 2, 2,
                "X: ", arg_NUMBER,
                "Y: ", arg_NUMBER);
@@ -3101,6 +3104,69 @@ cmd_banish (int interactive, struct cmdarg **args)
 }
 
 cmdret *
+cmd_banishrel (int interactive, struct cmdarg **args)
+{
+  Window win;
+  rp_screen *s;
+  rp_window *rpw;
+  rp_frame *f;
+  int x, y;
+
+  s = current_screen ();
+  rpw = current_window ();
+  f = current_frame ();
+
+  if (rpw) {
+    win = rpw->w;
+    x = rpw->width - 2;
+    y = rpw->height - 2;
+  } else {
+    win = s->root;
+    x = s->left + f->x + f->width - 2;
+    y = s->top + f->y + f->height - 2;
+  }
+
+  XWarpPointer (dpy, None, win, 0, 0, 0, 0, x, y);
+  return cmdret_new (RET_SUCCESS, NULL);
+}
+
+cmdret *
+cmd_ratinfo (int interactive, struct cmdarg **args)
+{
+  rp_screen *s;
+  Window root_win, child_win;
+  int mouse_x, mouse_y, root_x, root_y;
+  unsigned int mask;
+
+  s = current_screen ();
+  XQueryPointer (dpy, s->root, &root_win, &child_win, &mouse_x, &mouse_y, &root_x, &root_y, &mask);
+  marked_message_printf (0, 0, "%d %d", mouse_x, mouse_y );
+
+  return cmdret_new (RET_SUCCESS, NULL);
+}
+
+cmdret *
+cmd_ratrelinfo (int interactive, struct cmdarg **args)
+{
+  rp_screen *s;
+  rp_window *rpw;
+  Window root_win, child_win;
+  int mouse_x, mouse_y, root_x, root_y;
+  unsigned int mask;
+
+  s = current_screen ();
+  rpw = current_window ();
+
+  if (!rpw)
+    return cmd_ratinfo (interactive, args);
+
+  XQueryPointer (dpy, rpw->w, &root_win, &child_win, &mouse_x, &mouse_y, &root_x, &root_y, &mask);
+  marked_message_printf (0, 0, "%d %d", root_x, root_y );
+
+  return cmdret_new (RET_SUCCESS, NULL);
+}
+
+cmdret *
 cmd_ratwarp (int interactive, struct cmdarg **args)
 {
   rp_screen *s;
diff --git a/src/actions.h b/src/actions.h
index 3fcd3b7..5db4a56 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -105,6 +105,7 @@ RP_CMD (abort);
 RP_CMD (addhook);
 RP_CMD (alias);
 RP_CMD (banish);
+RP_CMD (banishrel);
 RP_CMD (bind);
 RP_CMD (compat);
 RP_CMD (chdir);
@@ -196,6 +197,8 @@ RP_CMD (undefinekey);
 RP_CMD (set);
 RP_CMD (sselect);
 RP_CMD (ratwarp);
+RP_CMD (ratinfo);
+RP_CMD (ratrelinfo);
 RP_CMD (ratclick);
 RP_CMD (ratrelwarp);
 RP_CMD (rathold);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.