summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--NEWS8
-rw-r--r--src/communications.c7
-rw-r--r--src/communications.h1
-rw-r--r--src/data.h1
-rw-r--r--src/events.c39
-rw-r--r--src/main.c34
7 files changed, 100 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e536c0..06582e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2001-03-19 shawn <sabetts@diggin.lamenet.tmp>
+
+ * src/main.c (ratpoison_longopts): add --command to recognized
+ command-line options.
+
+ * src/communications.h (send_command): new function prototype
+
+ * src/data.h (rp_command): new global variable
+
+ * src/events.c (receive_command): new function
+ (property_notify): handles rp_command Atoms
+
+ * src/communications.c (send_command): new function
+
+ * src/main.c (print_help): prints help for --command
+ (main): handles --command command-line option
+
2001-03-14 shawn <sabetts@diggin.lamenet.tmp>
* src/events.c (delegate_event): calls focus_change on FocusOut
diff --git a/NEWS b/NEWS
index 0a3c04c..12c9699 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,14 @@
ratpoison NEWS --- history of user-visible changes. -*- outline -*-
* Changes since 0.1.0
+** new command-line option --command
+
+You can now send ratpoison commands (colon-commands) to ratpoison via
+the command line. for example to tell ratpoison to go to the next
+window type this:
+
+$ ratpoison --command next
+
** window borders are configurable
WINDOW_BORDER_WIDTH has been added to conf.h. This constant determines
the border width for all windows.
diff --git a/src/communications.c b/src/communications.c
index 7d94a1b..f87e115 100644
--- a/src/communications.c
+++ b/src/communications.c
@@ -66,3 +66,10 @@ send_kill ()
PRINT_ERROR ("failed to send kill event\n");
}
}
+
+int
+send_command (unsigned char *cmd)
+{
+ return XChangeProperty (dpy, DefaultRootWindow (dpy), rp_command, XA_STRING,
+ 8, PropModeAppend, cmd, strlen (cmd) + 1);
+}
diff --git a/src/communications.h b/src/communications.h
index e88e17b..ade37ac 100644
--- a/src/communications.h
+++ b/src/communications.h
@@ -24,5 +24,6 @@
void send_kill ();
void send_restart ();
+int send_command (unsigned char *cmd);
#endif /* ! _RATPOISON_COMMUNICATIONS_H */
diff --git a/src/data.h b/src/data.h
index 142b015..34a006c 100644
--- a/src/data.h
+++ b/src/data.h
@@ -123,6 +123,7 @@ extern XEvent *rp_current_event;
extern Display *dpy;
extern Atom rp_restart;
extern Atom rp_kill;
+extern Atom rp_command;
extern Atom wm_state;
extern Atom wm_change_state;
diff --git a/src/events.c b/src/events.c
index ee858d0..f32b4fa 100644
--- a/src/events.c
+++ b/src/events.c
@@ -383,12 +383,51 @@ key_press (XEvent *ev)
}
void
+receive_command()
+{
+ Atom type_ret;
+ int format_ret;
+ unsigned long nitems;
+ unsigned long bytes_after;
+ unsigned char *req;
+
+ if (XGetWindowProperty (dpy, DefaultRootWindow (dpy), rp_command,
+ 0, 0, False, XA_STRING,
+ &type_ret, &format_ret, &nitems, &bytes_after,
+ &req) == Success
+ &&
+ XGetWindowProperty (dpy, DefaultRootWindow (dpy), rp_command,
+ 0, (bytes_after / 4) + (bytes_after % 4 ? 1 : 0),
+ True, XA_STRING, &type_ret, &format_ret, &nitems,
+ &bytes_after, &req) == Success)
+ {
+ if (req)
+ {
+ PRINT_DEBUG ("command: %s\n", req);
+ command (req);
+ }
+ XFree (req);
+ }
+ else
+ {
+ PRINT_DEBUG ("Couldn't get RP_COMMAND Property\n");
+ }
+}
+
+void
property_notify (XEvent *ev)
{
rp_window *win;
PRINT_DEBUG ("atom: %ld\n", ev->xproperty.atom);
+ if (ev->xproperty.atom == rp_command
+ && ev->xproperty.window == DefaultRootWindow (dpy))
+ {
+ PRINT_DEBUG ("ratpoison command\n");
+ receive_command();
+ }
+
win = find_window (ev->xproperty.window);
if (win)
diff --git a/src/main.c b/src/main.c
index a7c9674..5cbf4c2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -50,6 +50,7 @@ Atom wm_colormaps;
Atom rp_restart;
Atom rp_kill;
+Atom rp_command;
screen_info *screens;
int num_screens;
@@ -68,12 +69,15 @@ struct rp_key prefix_key;
struct modifier_info rp_modifier_info;
/* Command line options */
-static struct option ratpoison_longopts[] = { {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'v'},
- {"restart", no_argument, 0, 'r'},
- {"kill", no_argument, 0, 'k'},
- {0, 0, 0, 0} };
-static char ratpoison_opts[] = "hvrk";
+static struct option ratpoison_longopts[] =
+ { {"help", no_argument, 0, 'h'},
+ {"version", no_argument, 0, 'v'},
+ {"restart", no_argument, 0, 'r'},
+ {"kill", no_argument, 0, 'k'},
+ {"command", required_argument, 0, 'c'},
+ {0, 0, 0, 0} };
+
+static char ratpoison_opts[] = "hvrkc:";
void
fatal (const char *msg)
@@ -205,7 +209,8 @@ print_help ()
printf ("-h, --help Display this help screen\n");
printf ("-v, --version Display the version\n");
printf ("-r, --restart Restart ratpoison\n");
- printf ("-k, --kill Kill ratpoison\n\n");
+ printf ("-k, --kill Kill ratpoison\n");
+ printf ("-c, --command Send ratpoison a colon-command\n\n");
printf ("Report bugs to ratpoison-devel@lists.sourceforge.net\n\n");
@@ -306,6 +311,8 @@ main (int argc, char *argv[])
int c;
int do_kill = 0;
int do_restart = 0;
+ int do_command = 0;
+ char *command;
myargv = argv;
@@ -331,6 +338,11 @@ main (int argc, char *argv[])
case 'r':
do_restart = 1;
break;
+ case 'c':
+ command = xmalloc (strlen (optarg) + 1);
+ strcpy (command, optarg);
+ do_command = 1;
+ break;
default:
exit (EXIT_FAILURE);
}
@@ -352,6 +364,7 @@ main (int argc, char *argv[])
/* Set ratpoison specific Atoms. */
rp_restart = XInternAtom (dpy, "RP_RESTART", False);
rp_kill = XInternAtom (dpy, "RP_KILL", False);
+ rp_command = XInternAtom (dpy, "RP_COMMAND", False);
if (do_kill)
{
@@ -367,6 +380,13 @@ main (int argc, char *argv[])
clean_up ();
return EXIT_SUCCESS;
}
+ if (do_command)
+ {
+ send_command (command);
+ free (command);
+ clean_up();
+ return EXIT_SUCCESS;
+ }
/* Set our Atoms */
wm_state = XInternAtom(dpy, "WM_STATE", False);