summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions.c6
-rw-r--r--src/data.h8
-rw-r--r--src/events.c119
-rw-r--r--src/events.h5
-rw-r--r--src/main.c77
-rw-r--r--src/manage.c4
6 files changed, 108 insertions, 111 deletions
diff --git a/src/actions.c b/src/actions.c
index 9a2db18..de2a2c9 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -127,7 +127,9 @@ initialize_default_keybindings (void)
add_keybinding (XK_v, ControlMask, "version");
add_keybinding (XK_w, 0, "windows");
add_keybinding (XK_w, ControlMask, "windows");
- add_keybinding (XK_S, 0, "split");
+ add_keybinding (XK_s, 0, "split");
+ add_keybinding (XK_s, ControlMask, "split");
+ add_keybinding (XK_S, 0, "vsplit");
add_keybinding (XK_S, ControlMask, "vsplit");
add_keybinding (XK_Tab, 0, "focus");
add_keybinding (XK_Q, 0, "only");
@@ -359,7 +361,7 @@ void
cmd_generate (void *data)
{
XEvent ev1, ev;
- ev = *rp_current_event;
+ ev = rp_current_event;
PRINT_DEBUG ("type==%d\n", ev.xkey.type);
PRINT_DEBUG ("serial==%ld\n", ev.xkey.serial);
diff --git a/src/data.h b/src/data.h
index 5f97c99..06f028b 100644
--- a/src/data.h
+++ b/src/data.h
@@ -130,7 +130,7 @@ extern rp_window_frame *rp_current_frame;
extern screen_info *screens;
extern int num_screens;
-extern XEvent *rp_current_event;
+extern XEvent rp_current_event;
extern Display *dpy;
extern Atom rp_restart;
@@ -172,4 +172,10 @@ struct modifier_info
/* Keeps track of which mod mask each modifier is under. */
extern struct modifier_info rp_modifier_info;
+/* nonzero if an alarm signal was raised. This means ratpoison should
+ hide its popup windows. */
+extern int alarm_signalled;
+extern int kill_signalled;
+extern int hup_signalled;
+
#endif /* _RATPOISON_DATA_H */
diff --git a/src/events.c b/src/events.c
index ac9d006..51c8279 100644
--- a/src/events.c
+++ b/src/events.c
@@ -27,15 +27,18 @@
#include <stdio.h>
#include <stdlib.h>
+#include <signal.h>
+#include <errno.h>
#include <unistd.h>
+#include <sys/time.h>
#include "ratpoison.h"
/* The event currently being processed. Mostly used in functions from
action.c which need to forward events to other windows. */
-XEvent *rp_current_event;
+XEvent rp_current_event;
-void
+static void
new_window (XCreateWindowEvent *e)
{
rp_window *win;
@@ -85,7 +88,7 @@ cleanup_frame (rp_window_frame *frame)
}
}
-void
+static void
unmap_notify (XEvent *ev)
{
screen_info *s;
@@ -126,7 +129,7 @@ unmap_notify (XEvent *ev)
}
}
-void
+static void
map_request (XEvent *ev)
{
screen_info *s;
@@ -177,20 +180,7 @@ map_request (XEvent *ev)
}
}
-int
-more_destroy_events ()
-{
- XEvent ev;
-
- if (XCheckTypedEvent (dpy, DestroyNotify, &ev))
- {
- XPutBackEvent (dpy, &ev);
- return 1;
- }
- return 0;
-}
-
-void
+static void
destroy_window (XDestroyWindowEvent *ev)
{
rp_window *win;
@@ -212,7 +202,7 @@ destroy_window (XDestroyWindowEvent *ev)
ignore_badwindow--;
}
-void
+static void
configure_notify (XConfigureEvent *e)
{
rp_window *win;
@@ -222,14 +212,10 @@ configure_notify (XConfigureEvent *e)
{
PRINT_DEBUG ("'%s' window notify: %d %d %d %d %d\n", win->name,
e->x, e->y, e->width, e->height, e->border_width);
-
- /* Once we get the notify that everything went through, try
- maximizing. Netscape doesn't seem to like it here. */
-/* maximize (win); */
}
}
-void
+static void
configure_request (XConfigureRequestEvent *e)
{
rp_window *win;
@@ -403,7 +389,7 @@ handle_key (screen_info *s)
ungrab_rat();
}
-void
+static void
key_press (XEvent *ev)
{
screen_info *s;
@@ -518,7 +504,7 @@ receive_command ()
}
-void
+static void
property_notify (XEvent *ev)
{
rp_window *win;
@@ -561,7 +547,7 @@ property_notify (XEvent *ev)
}
}
-void
+static void
colormap_notify (XEvent *ev)
{
rp_window *win;
@@ -638,7 +624,7 @@ mapping_notify (XMappingEvent *ev)
}
/* Given an event, call the correct function to handle it. */
-void
+static void
delegate_event (XEvent *ev)
{
switch (ev->type)
@@ -736,17 +722,80 @@ delegate_event (XEvent *ev)
}
}
+static void
+get_event (XEvent *ev)
+{
+ int x_fd;
+ fd_set fds;
+ struct timeval t;
+
+ /* An alarm means we need to hide the popup windows. */
+ if (alarm_signalled > 0)
+ {
+ int i;
+
+ PRINT_DEBUG ("Alarm recieved.\n");
+
+ for (i=0; i<num_screens; i++)
+ {
+ hide_bar (&screens[i]);
+ }
+ hide_frame_indicator();
+ alarm_signalled = 0;
+ }
+
+ if (hup_signalled > 0)
+ {
+ PRINT_DEBUG ("Restarting with a fresh plate.\n");
+ send_restart ();
+ }
+
+ if (kill_signalled > 0)
+ {
+ fprintf (stderr, "ratpoison: Agg! I've been SHOT!\n");
+ clean_up ();
+ exit (EXIT_FAILURE);
+ }
+
+ /* Is there anything in the event qeue? */
+ if (QLength (dpy) > 0)
+ {
+ XNextEvent (dpy, ev);
+ return;
+ }
+
+ /* If the event queue is empty, then select on it until there is
+ something. */
+ x_fd = ConnectionNumber (dpy);
+ FD_ZERO (&fds);
+ FD_SET (x_fd, &fds);
+ t.tv_sec = 0;
+ t.tv_usec = 0;
+
+ if (select(x_fd+1, &fds, NULL, NULL, &t) == 1)
+ {
+ XNextEvent(dpy, ev);
+ return;
+ }
+
+ XFlush(dpy);
+ FD_SET(x_fd, &fds);
+ t.tv_sec = 1;
+ t.tv_usec = 0;
+
+ if (select(x_fd+1, &fds, NULL, NULL, NULL) == 1)
+ {
+ XNextEvent(dpy, ev);
+ return;
+ }
+}
+
void
handle_events ()
{
- XEvent ev;
-
for (;;)
{
- XNextEvent (dpy, &ev);
- rp_current_event = &ev;
- delegate_event (&ev);
+ get_event (&rp_current_event);
+ delegate_event (&rp_current_event);
}
}
-
-
diff --git a/src/events.h b/src/events.h
index 9d86117..26230b4 100644
--- a/src/events.h
+++ b/src/events.h
@@ -23,9 +23,4 @@
#define _RATPOISON_EVENTS_H 1
void handle_events ();
-void delegate_event (XEvent *ev);
-void key_press (XEvent *ev);
-void map_request (XEvent *ev);
-void unmap_notify (XEvent *ev);
-void keymap_state (XKeymapEvent *ev);
#endif /* _RATPOISON_EVENTS_H */
diff --git a/src/main.c b/src/main.c
index 16b27bf..c34436a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,7 @@
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xproto.h>
+#include <X11/cursorfont.h>
#include <errno.h>
#include <stdio.h>
@@ -37,19 +38,9 @@
static void init_screen (screen_info *s, int screen_num);
-/* When a user hits the prefix key, the rat switches to a different
- pixmap to indicate that ratpoison expects the user to hit another
- key, these are the pixmaps. */
-static unsigned char rp_rat_bits[] = {
- 0x00, 0x00, 0xfe, 0x7f, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
- 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
- 0x02, 0x40, 0x02, 0x40, 0xfe, 0x7f, 0x00, 0x00};
-
-static unsigned char rp_rat_mask_bits[] = {
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-
+int alarm_signalled = 0;
+int kill_signalled = 0;
+int hup_signalled = 0;
int rat_x;
int rat_y;
int rat_visible = 1; /* rat is visible by default */
@@ -123,39 +114,19 @@ xrealloc (void *ptr, size_t size)
void
sighandler (int signum)
{
- fprintf (stderr, "ratpoison: Agg! I've been SHOT!\n");
- clean_up ();
- exit (EXIT_FAILURE);
+ kill_signalled++;
}
void
hup_handler (int signum)
{
- /* Doesn't function correctly. The event IS placed on the queue but
- XSync() doesn't seem to sync it and until other events come in
- the restart event won't be processed. */
- PRINT_DEBUG ("Restarting with a fresh plate.\n");
-
- send_restart ();
- XSync(dpy, False);
+ hup_signalled++;
}
void
alrm_handler (int signum)
{
- int i;
-
- PRINT_DEBUG ("alarm recieved.\n");
-
- /* FIXME: should only hide 1 bar, but we hide them all. */
- for (i=0; i<num_screens; i++)
- {
- hide_bar (&screens[i]);
- }
-
- hide_frame_indicator();
-
- XSync (dpy, False);
+ alarm_signalled++;
}
int
@@ -294,7 +265,9 @@ read_startup_files ()
homedir = getenv ("HOME");
if (!homedir)
- fprintf (stderr, "ratpoison: $HOME not set!?\n");
+ {
+ PRINT_ERROR ("ratpoison: $HOME not set!?\n");
+ }
else
{
char *filename = (char*)xmalloc (strlen (homedir) + strlen ("/.ratpoisonrc") + 1);
@@ -454,25 +427,7 @@ main (int argc, char *argv[])
static void
init_rat_cursor (screen_info *s)
{
- Pixmap fore, mask;
- XColor fg, bg, dummy;
-
- XAllocNamedColor(dpy, DefaultColormap(dpy, s->screen_num),
- "black", &fg, &dummy);
- XAllocNamedColor(dpy, DefaultColormap(dpy, s->screen_num),
- "white", &bg, &dummy);
-
- fore = XCreatePixmapFromBitmapData (dpy, s->root,
- rp_rat_bits, RAT_WIDTH, RAT_HEIGHT,
- 1, 0, 1);
- mask = XCreatePixmapFromBitmapData (dpy, s->root,
- rp_rat_mask_bits, RAT_WIDTH, RAT_HEIGHT,
- 1, 0, 1);
- s->rat = XCreatePixmapCursor(dpy, fore, mask,
- &fg, &bg, RAT_HOT_X, RAT_HOT_Y);
-
- XFreePixmap (dpy, fore);
- XFreePixmap (dpy, mask);
+ s->rat = XCreateFontCursor( dpy, XC_icon );
}
static void
@@ -508,11 +463,6 @@ init_screen (screen_info *s, int screen_num)
fprintf (stderr, "ratpoison: Unknown color '%s'\n", BACKGROUND);
}
-/* if (!XAllocNamedColor (dpy, s->def_cmap, BAR_BOLD_COLOR, &bold_color, &junk)) */
-/* { */
-/* fprintf (stderr, "ratpoison: Unknown color '%s'\n", BAR_BOLD_COLOR); */
-/* } */
-
/* Setup the GC for drawing the font. */
gv.foreground = fg_color.pixel;
gv.background = bg_color.pixel;
@@ -524,11 +474,6 @@ init_screen (screen_info *s, int screen_num)
GCForeground | GCBackground | GCFunction
| GCLineWidth | GCSubwindowMode | GCFont,
&gv);
-/* gv.foreground = bold_color.pixel; */
-/* s->bold_gc = XCreateGC(dpy, s->root, */
-/* GCForeground | GCBackground | GCFunction */
-/* | GCLineWidth | GCSubwindowMode | GCFont, */
-/* &gv); */
/* Create the program bar window. */
s->bar_is_raised = 0;
diff --git a/src/manage.c b/src/manage.c
index 030693c..434f698 100644
--- a/src/manage.c
+++ b/src/manage.c
@@ -536,10 +536,10 @@ withdraw_window (rp_window *win)
{
if (win == NULL) return;
- PRINT_DEBUG ("withdawn_window on '%s'\n", win->name);
+ PRINT_DEBUG ("withdraw_window on '%s'\n", win->name);
/* Give back the window number. the window will get another one,
- if it is remapped. */
+ if it is remapped. */
return_window_number (win->number);
win->number = -1;