ratinfo/ratrelinfo/banishrel patch

Rob Paisley <[email protected]>
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
ratpoison-devel:

Attached is a proposed patch for the following commands:

: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 the screen.

:ratinfo
Display the x y coordinates of the rat cursor relative to the screen.

:ratrelinfo
+Display the x y coordinates of the rat cursor relative to the window.

I considered sorting the RP_CMD's in src/actions.h but didn't in
order to keep this patch small.

For a little background, I have bound v -> ratclick 2 to allow me to "paste" into the current window without the use
of the rat.  Some of my machines the xterm doesn't occupy the entire screen and rather than adjust my gravity to get
the window to occupy the corner, I decided to add banishrel.  Also makes my paste work when I've got frames up and
running.

I appreciate any comments on the patch.

-Rob

_______________________________________________
Ratpoison-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/ratpoison-devel
ratpoison.patch (text/plain, 3.6 KB)
diff --git a/doc/ratpoison.1 b/doc/ratpoison.1
index d2abf49..ef2acc9 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 the screen.
 .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..002edd6 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,57 @@ cmd_banish (int interactive, struct cmdarg **args)
 }
 
 cmdret *
+cmd_banishrel (int interactive, struct cmdarg **args)
+{
+  rp_screen *s;
+  rp_window *w;
+
+  s = current_screen();
+  w = current_window();
+  if (!w)
+    cmd_banish (interactive, args);
+
+  XWarpPointer (dpy, None, w->w, 0, 0, 0, 0, w->x + w->width - 2, w->y + w->height - 2);
+  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.