diff options
author | sabetts <sabetts> | 2000-08-26 04:35:10 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2000-08-26 04:35:10 +0000 |
commit | 592583e898157e6047412a398e33ed89b080e1d6 (patch) | |
tree | d8560e0a118150bcfdb8b8ed3f132c8cb0ccf3a5 | |
parent | d8a5963532fb35687bedee59f2235144f3930fbd (diff) | |
download | ratpoison-592583e898157e6047412a398e33ed89b080e1d6.zip |
- Fixed some of the X_SetInputFocus bugs that were crashing ratpoison.
- Now responds to Raise and Lower X events (fixes the C-x 5 o bug with emacs)
- Added numbers to each window and the ability to jump to that window by
hitting Prefix <window num>
-rw-r--r-- | Makefile | 17 | ||||
-rw-r--r-- | bar.c | 25 | ||||
-rw-r--r-- | events.c | 66 | ||||
-rw-r--r-- | list.c | 33 | ||||
-rw-r--r-- | list.h | 1 | ||||
-rw-r--r-- | main.c | 16 | ||||
-rw-r--r-- | manage.c | 6 |
7 files changed, 105 insertions, 59 deletions
@@ -1,18 +1,25 @@ -CC = gcc +# Where to install the ratpoison executable +INSTALL_DIR=/usr/local/bin -SRC = main.o events.o manage.o list.o bar.o -LIBS = -lX11 +# Spew lots of debug messages +DEBUG = -DDEBUG +CC = gcc +LIBS = -lX11 LDFLAGS = -L/usr/X11R6/lib CFLAGS = -g -Wall -I/usr/X11R6/include -DEBUG = -DDEBUG +SRC = main.o events.o manage.o list.o bar.o +HEADERS = bar.h conf.h data.h events.h list.h manage.h ratpoison.h ratpoison: $(SRC) gcc $(SRC) -o $@ $(CFLAGS) $(LDFLAGS) $(LIBS) -%.o : %.c ratpoison.h conf.h +install: ratpoison + cp ratpoison $(INSTALL_DIR) + +%.o : %.c $(HEADERS) $(CC) -c $(CFLAGS) $(DEBUG) $< -o $@ clean : @@ -52,13 +52,18 @@ toggle_bar (screen_info *s) static int calc_bar_width (XFontStruct *font) { + char str[100]; /* window names are capped at 99 chars */ + int i; int size = 1; rp_window *cur; - for (cur = rp_window_head; cur; cur = cur->next) + for (i=0, cur = rp_window_head; cur; cur = cur->next) { if (cur->state == STATE_UNMAPPED) continue; - size += 10 + XTextWidth (font, cur->name, strlen (cur->name)); + + sprintf (str, "%d-%s", i, cur->name); + size += 10 + XTextWidth (font, str, strlen (str)); + i++; } return size; @@ -81,6 +86,8 @@ bar_y (screen_info *s) void update_window_names (screen_info *s) { + char str[100]; /* window names are capped at 99 chars */ + int i; int width = calc_bar_width (s->font); rp_window *cur; int cur_x = 5; @@ -95,23 +102,23 @@ update_window_names (screen_info *s) XRaiseWindow (dpy, s->bar_window); if (rp_window_head == NULL) return; - for (cur = rp_window_head; cur; cur = cur->next) + for (i=0, cur = rp_window_head; cur; cur = cur->next) { if (cur->state == STATE_UNMAPPED) continue; + sprintf (str, "%d-%s", i, cur->name); if ( rp_current_window == cur) { XDrawString (dpy, s->bar_window, s->bold_gc, cur_x, - BAR_PADDING + s->font->max_bounds.ascent, cur->name, strlen (cur->name)); + BAR_PADDING + s->font->max_bounds.ascent, str, strlen (str)); } else { XDrawString (dpy, s->bar_window, s->normal_gc, cur_x, - BAR_PADDING + s->font->max_bounds.ascent, cur->name, strlen (cur->name)); + BAR_PADDING + s->font->max_bounds.ascent, str, strlen (str)); } - cur_x += 10 + XTextWidth (s->font, cur->name, strlen (cur->name)); + + cur_x += 10 + XTextWidth (s->font, str, strlen (str)); + i++; } } - - - @@ -101,8 +101,6 @@ map_request (XEvent *ev) void destroy_window (XDestroyWindowEvent *ev) { - int tmp; - Window fwin; screen_info *s; rp_window *win; @@ -110,20 +108,10 @@ destroy_window (XDestroyWindowEvent *ev) win = find_window (ev->window); if (s && win) { - unmanage (win); - } + /* Goto the last accessed window. */ + if (win->state == STATE_MAPPED) last_window (); - XGetInputFocus (dpy, &fwin, &tmp); - win = find_window (fwin); - - if (win) - { - rp_current_window = win; - set_active_window (win); - } - else - { - update_window_names (s); + unmanage (win); } #ifdef DEBUG @@ -135,36 +123,12 @@ void configure_request (XConfigureRequestEvent *e) { XConfigureEvent ce; - // XWindowChanges wc; rp_window *win; win = find_window (e->window); if (win) { -/* if (e->value_mask & CWX) */ -/* wc->x = e->x; */ -/* if (e->value_mask & CWY) */ -/* wc->y = e->y; */ -/* if (e->value_mask & CWWidth) */ -/* wc->dx = e->width; */ -/* if (e->value_mask & CWHeight) */ -/* wc->dy = e->height; */ -/* if (e->value_mask & CWBorderWidth) */ -/* wc->border_width = e->border_width; */ - -/* if (e->value_mask & CWStackMode) { */ -/* if (wc.stack_mode == Above); */ -/* else */ -/* we->value_mask &= ~CWStackMode; */ -/* } */ - -/* wc.sibling = None; */ -/* wc.stack_mode = e.detail; */ - -/* XConfigureWindow (dpy, e->window, e->value_mask, &wc); */ - - ce.type = ConfigureNotify; ce.event = e->window; ce.window = e->window; @@ -172,9 +136,23 @@ configure_request (XConfigureRequestEvent *e) ce.y = 0; ce.width = win->scr->root_attr.width; ce.height = win->scr->root_attr.height; - ce.border_width = 0; + ce.border_width = 0; ce.above = None; ce.override_redirect = 0; + + if (e->value_mask & CWStackMode && win->state == STATE_MAPPED) + { + if (e->detail == Above) + { + rp_current_window = win; + set_active_window (rp_current_window); + } + else if (e->detail == Below && win == rp_current_window) + { + last_window (); + } + } + XSendEvent(dpy, win->w, False, StructureNotifyMask, (XEvent*)&ce); } } @@ -182,6 +160,7 @@ configure_request (XConfigureRequestEvent *e) static void client_msg (XClientMessageEvent *ev) { + printf ("Recieved client message.\n"); } static void @@ -210,6 +189,13 @@ handle_key (screen_info *s) return; } + if (XLookupKeysym((XKeyEvent *) &ev, 0) >= '0' + && XLookupKeysym((XKeyEvent *) &ev, 0) <= '9') + { + goto_window_number (XLookupKeysym((XKeyEvent *) &ev, 0) - '0'); + return; + } + switch (XLookupKeysym((XKeyEvent *) &ev, 0)) { case KEY_XTERM: @@ -121,6 +121,37 @@ prev_window () } rp_window * +find_window_by_number (int n) +{ + int i; + rp_window *cur; + + for (i=0, cur=rp_window_head; cur; cur=cur->next) + { + if (cur->state != STATE_MAPPED) continue; + + if (i == n) return cur; + else i++; + } + + return NULL; +} + +void +goto_window_number (int n) +{ + rp_window *win; + + if ((win = find_window_by_number (n)) == NULL) + { + return; + } + + rp_current_window = win; + set_active_window (rp_current_window); +} + +rp_window * find_last_accessed_window () { int last_access = 0; @@ -128,7 +159,7 @@ find_last_accessed_window () for (cur=rp_window_head; cur; cur=cur->next) { - if (cur->last_access > last_access + if (cur->last_access >= last_access && cur != rp_current_window && cur->state == STATE_MAPPED) { @@ -13,4 +13,5 @@ rp_window *find_window (Window w); void maximize_current_window (); void set_active_window (rp_window *rp_w); void set_current_window (rp_window *win); +void goto_window_number (int n); #endif /* _LIST_H */ @@ -69,13 +69,17 @@ alrm_handler () int handler (Display *d, XErrorEvent *e) { + char msg[100]; + if (e->request_code == X_ChangeWindowAttributes && e->error_code == BadAccess) { fprintf(stderr, "ratpoison: There can be only ONE.\n"); exit(EXIT_FAILURE); } - fprintf (stderr, "ratpoison: Ya some error happened, but whatever.\n"); - return 0; + XGetErrorText (d, e->error_code, msg, sizeof (msg)); + fprintf (stderr, "ratpoison: %s!\n", msg); + + exit (EXIT_FAILURE); } int @@ -116,11 +120,15 @@ main (int argc, char *argv[]) } /* Setup signal handlers. */ - // XSetErrorHandler(handler); + // XSetErrorHandler(handler); if (signal (SIGALRM, alrm_handler) == SIG_IGN) signal (SIGALRM, SIG_IGN); if (signal (SIGTERM, sighandler) == SIG_IGN) signal (SIGTERM, SIG_IGN); if (signal (SIGINT, sighandler) == SIG_IGN) signal (SIGINT, SIG_IGN); - if (signal (SIGHUP, hup_handler) == SIG_IGN) signal (SIGHUP, SIG_IGN); + if (signal (SIGHUP, hup_handler) == SIG_IGN) + { + printf ("Ignoring HUP.\n"); + signal (SIGHUP, SIG_IGN); + } /* Set our Atoms */ wm_state = XInternAtom(dpy, "WM_STATE", False); @@ -17,6 +17,12 @@ extern Atom wm_state; void grab_keys (screen_info *s) { + int i; + + for (i='0'; i<='9'; i++) + XGrabKey(dpy, XKeysymToKeycode (dpy, i ), AnyModifier, s->key_window, True, + GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_XTERM ), AnyModifier, s->key_window, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_EMACS ), AnyModifier, s->key_window, True, |