summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-06-05 00:49:19 +0200
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-06-05 00:56:59 +0200
commit1142b82fe4dec980846a620409bb462f765ea74f (patch)
tree88c6c2e46f1cc6b59342f550cce9a67633e9666e /contrib
parent89df18eef0e12cc308e69adee192856bdc9e7098 (diff)
downloadratpoison-1142b82fe4dec980846a620409bb462f765ea74f.zip
contrib/{sloppy,unrat}.c: make this code actually readable...
Diffstat (limited to 'contrib')
-rw-r--r--contrib/sloppy.c67
-rw-r--r--contrib/unrat.c55
2 files changed, 71 insertions, 51 deletions
diff --git a/contrib/sloppy.c b/contrib/sloppy.c
index 066dce1..3656476 100644
--- a/contrib/sloppy.c
+++ b/contrib/sloppy.c
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* unrat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
@@ -27,26 +27,26 @@
#include <sys/wait.h>
#include <unistd.h>
-int (*defaulthandler)(Display *, XErrorEvent *);
+int (*defaulthandler) (Display *, XErrorEvent *);
int
-errorhandler(Display *display, XErrorEvent *error)
+errorhandler (Display *display, XErrorEvent *error)
{
- if(error->error_code!=BadWindow)
- (*defaulthandler)(display,error);
+ if (error->error_code != BadWindow)
+ (*defaulthandler) (display, error);
return 0;
}
int
-spawn(char *cmd)
+spawn (char *cmd)
{
int pid;
- pid = fork();
- if (pid == 0)
+ pid = fork ();
+ if (pid == 0)
{
- execl("/bin/sh", "sh", "-c", cmd, (char *)NULL);
- _exit(EXIT_FAILURE);
+ execl ("/bin/sh", "sh", "-c", cmd, (char *)NULL);
+ _exit (EXIT_FAILURE);
}
return pid;
}
@@ -57,42 +57,51 @@ main (void)
Display *display;
int i, numscreens;
- display = XOpenDisplay(NULL);
- if(!display)
+ display = XOpenDisplay (NULL);
+ if (!display)
{
fprintf (stderr, "sloppy: could not open display\n");
- exit(1);
+ exit (1);
}
- defaulthandler = XSetErrorHandler(errorhandler);
- numscreens = ScreenCount(display);
+ defaulthandler = XSetErrorHandler (errorhandler);
+ numscreens = ScreenCount (display);
- for (i=0; i<numscreens; i++)
+ for (i = 0; i < numscreens; i++)
{
unsigned int j, nwins;
Window dw1, dw2, *wins;
-
- XSelectInput(display,RootWindow(display, i), SubstructureNotifyMask);
- XQueryTree(display, RootWindow(display, i), &dw1, &dw2, &wins, &nwins);
- for (j=0; j<nwins; j++)
- XSelectInput(display, wins[j], EnterWindowMask);
+
+ XSelectInput (display, RootWindow (display, i),
+ SubstructureNotifyMask);
+ XQueryTree (display, RootWindow (display, i),
+ &dw1, &dw2, &wins, &nwins);
+ for (j = 0; j < nwins; j++)
+ XSelectInput (display, wins[j], EnterWindowMask);
}
- while (1)
+ while (1)
{
XEvent event;
- do
+
+ do
{
- XNextEvent(display,&event);
+ XNextEvent (display, &event);
if (event.type == CreateNotify)
- XSelectInput(display, event.xcreatewindow.window, EnterWindowMask);
- } while(event.type != EnterNotify);
+ {
+ XSelectInput (display, event.xcreatewindow.window,
+ EnterWindowMask);
+ }
+ } while (event.type != EnterNotify);
/* A window was entered. select it. */
{
char shell[256];
- snprintf (shell, 255, "$RATPOISON -c \"select `$RATPOISON -c 'windows %%i %%n' | grep '%ld' | awk '{print $2}'`\"", event.xcrossing.window);
- //printf ("%s\n", shell);
+
+ snprintf (shell, sizeof(shell),
+ "$RATPOISON -c \"select `$RATPOISON -c 'windows %%i %%n' | "
+ "grep '%ld' | awk '{print $2}'`\"",
+ event.xcrossing.window);
spawn (shell);
wait (NULL);
}
diff --git a/contrib/unrat.c b/contrib/unrat.c
index dcd8dbf..686138b 100644
--- a/contrib/unrat.c
+++ b/contrib/unrat.c
@@ -31,13 +31,14 @@ gcc -g -Wall -O2 -I/usr/X11R6/include -o unrat unrat.c -L /usr/X11R6/lib -lX11
#include <stdio.h>
#include <stdlib.h>
-int (*defaulthandler)(Display *, XErrorEvent *);
+int (*defaulthandler) (Display *, XErrorEvent *);
int
-errorhandler(Display *display, XErrorEvent *error)
+errorhandler (Display *display, XErrorEvent *error)
{
- if(error->error_code!=BadWindow)
- (*defaulthandler)(display,error);
+ if (error->error_code != BadWindow)
+ (*defaulthandler) (display,error);
+
return 0;
}
@@ -47,25 +48,27 @@ main (void)
Display *display;
int i, numscreens;
- display = XOpenDisplay(NULL);
- if(!display)
+ display = XOpenDisplay (NULL);
+ if (!display)
{
fprintf (stderr, "unrat: could not open display\n");
- exit(1);
+ exit (1);
}
- defaulthandler = XSetErrorHandler(errorhandler);
- numscreens = ScreenCount(display);
+ defaulthandler = XSetErrorHandler (errorhandler);
+ numscreens = ScreenCount (display);
- for (i=0; i<numscreens; i++)
+ for (i = 0; i < numscreens; i++)
{
unsigned int j, nwins;
Window dw1, dw2, *wins;
- XSelectInput(display,RootWindow(display, i), KeyReleaseMask | SubstructureNotifyMask);
- XQueryTree(display, RootWindow(display, i), &dw1, &dw2, &wins, &nwins);
- for (j=0; j<nwins; j++)
- XSelectInput(display, wins[j], KeyReleaseMask);
+ XSelectInput (display, RootWindow (display, i),
+ KeyReleaseMask | SubstructureNotifyMask);
+ XQueryTree (display, RootWindow (display, i),
+ &dw1, &dw2, &wins, &nwins);
+ for (j = 0; j < nwins; j++)
+ XSelectInput (display, wins[j], KeyReleaseMask);
}
while (1)
@@ -73,25 +76,33 @@ main (void)
XEvent event;
do
{
- XNextEvent(display,&event);
+ XNextEvent (display, &event);
if (event.type == CreateNotify)
- XSelectInput(display, event.xcreatewindow.window, KeyReleaseMask);
- } while(event.type != KeyRelease);
+ {
+ XSelectInput (display, event.xcreatewindow.window,
+ KeyReleaseMask);
+ }
+ } while (event.type != KeyRelease);
/* A key was pressed. warp the rat. */
- for (i=0; i<numscreens; i++)
+ for (i = 0; i < numscreens; i++)
{
int x, y, wx, wy;
unsigned int mask;
Window root, child;
- XQueryPointer (display, RootWindow(display, i),
+ XQueryPointer (display, RootWindow (display, i),
&root, &child,
&x, &y, &wx, &wy,
&mask);
- if (x < DisplayWidth (display, i)-1
- || y < DisplayHeight (display, i)-1)
- XWarpPointer (display, None, RootWindow(display, i), 0, 0, 0, 0, DisplayWidth (display, i), DisplayHeight (display, i));
+ if (x < DisplayWidth (display, i) - 1
+ || y < DisplayHeight (display, i) - 1)
+ {
+ XWarpPointer (display, None, RootWindow (display, i),
+ 0, 0, 0, 0,
+ DisplayWidth (display, i),
+ DisplayHeight (display, i));
+ }
}
}