summaryrefslogtreecommitdiff
path: root/src/events.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2001-03-29 04:29:15 +0000
committersabetts <sabetts>2001-03-29 04:29:15 +0000
commiteb256cbcbed3431ec5a330fe6dcb12f75ec76c8a (patch)
treed57dd638f39dc32492f92ac86fd16c88929bc0a8 /src/events.c
parent889c6fc041fe9af255f609ba434eceab74491e8c (diff)
downloadratpoison-eb256cbcbed3431ec5a330fe6dcb12f75ec76c8a.zip
better command functionality
Diffstat (limited to 'src/events.c')
-rw-r--r--src/events.c63
1 files changed, 56 insertions, 7 deletions
diff --git a/src/events.c b/src/events.c
index f32b4fa..9d8f140 100644
--- a/src/events.c
+++ b/src/events.c
@@ -286,7 +286,7 @@ configure_request (XConfigureRequestEvent *e)
static void
client_msg (XClientMessageEvent *ev)
{
- PRINT_DEBUG ("Recieved client message.\n");
+ PRINT_DEBUG ("Received client message.\n");
if (ev->message_type == rp_restart)
{
@@ -382,8 +382,12 @@ key_press (XEvent *ev)
}
}
-void
-receive_command()
+/* Read a command off the window and execute it. Some commands return
+ text. This text is passed back using the RP_COMMAND_RESULT
+ Atom. The client will wait for this property change so something
+ must be returned. */
+static void
+execute_remote_command (Window w)
{
Atom type_ret;
int format_ret;
@@ -391,12 +395,12 @@ receive_command()
unsigned long bytes_after;
unsigned char *req;
- if (XGetWindowProperty (dpy, DefaultRootWindow (dpy), rp_command,
+ if (XGetWindowProperty (dpy, w, rp_command,
0, 0, False, XA_STRING,
&type_ret, &format_ret, &nitems, &bytes_after,
&req) == Success
&&
- XGetWindowProperty (dpy, DefaultRootWindow (dpy), rp_command,
+ XGetWindowProperty (dpy, w, rp_command,
0, (bytes_after / 4) + (bytes_after % 4 ? 1 : 0),
True, XA_STRING, &type_ret, &format_ret, &nitems,
&bytes_after, &req) == Success)
@@ -414,6 +418,50 @@ receive_command()
}
}
+/* Command requests are posted as a property change using the
+ RP_COMMAND_REQUEST Atom on the root window. A Command request is a
+ Window that holds the actual command as a property using the
+ RP_COMMAND Atom. receive_command reads the list of Windows and
+ executes their associated command. */
+static void
+receive_command ()
+{
+ Atom type_ret;
+ int format_ret;
+ unsigned long nitems;
+ unsigned long bytes_after;
+ void *prop_return;
+
+ do
+ {
+ if (XGetWindowProperty (dpy, DefaultRootWindow (dpy),
+ rp_command_request, 0,
+ sizeof (Window) / 4 + (sizeof (Window) % 4 ?1:0),
+ True, XA_WINDOW, &type_ret, &format_ret, &nitems,
+ &bytes_after, (unsigned char **)&prop_return) == Success)
+ {
+ if (prop_return)
+ {
+ Window w;
+
+ w = *(Window *)prop_return;
+ XFree (prop_return);
+
+ execute_remote_command (w);
+ XChangeProperty (dpy, w, rp_command_result, XA_STRING,
+ 8, PropModeReplace, "Success", 8);
+ }
+ else
+ {
+ PRINT_DEBUG ("Couldn't get RP_COMMAND_REQUEST Property\n");
+ }
+
+ PRINT_DEBUG ("command requests: %ld\n", nitems);
+ }
+ } while (nitems > 0);
+
+}
+
void
property_notify (XEvent *ev)
{
@@ -421,8 +469,9 @@ property_notify (XEvent *ev)
PRINT_DEBUG ("atom: %ld\n", ev->xproperty.atom);
- if (ev->xproperty.atom == rp_command
- && ev->xproperty.window == DefaultRootWindow (dpy))
+ if (ev->xproperty.atom == rp_command_request
+ && ev->xproperty.window == DefaultRootWindow (dpy)
+ && ev->xproperty.state == PropertyNewValue)
{
PRINT_DEBUG ("ratpoison command\n");
receive_command();