summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsabetts <sabetts>2000-09-06 02:08:40 +0000
committersabetts <sabetts>2000-09-06 02:08:40 +0000
commit33fb61429337fc71292628e9dac1ddf599938304 (patch)
treedaecacc60264a99f20e5fbae757985ef0ebc4bd9
parentd355d02c47ee296064e55520c15252e5fad97ecf (diff)
downloadratpoison-33fb61429337fc71292628e9dac1ddf599938304.zip
added a rename window key.
-rw-r--r--data.h1
-rw-r--r--events.c46
-rw-r--r--list.c2
-rw-r--r--main.c9
-rw-r--r--manage.c56
-rw-r--r--manage.h2
6 files changed, 64 insertions, 52 deletions
diff --git a/data.h b/data.h
index 36c9883..5623a58 100644
--- a/data.h
+++ b/data.h
@@ -40,6 +40,7 @@ struct rp_window
char *name;
int state;
int last_access;
+ int named;
rp_window *next, *prev;
};
diff --git a/events.c b/events.c
index 98180e8..a835eb3 100644
--- a/events.c
+++ b/events.c
@@ -146,12 +146,6 @@ destroy_window (XDestroyWindowEvent *ev)
win = find_window (ev->window);
last_destroy_event = !more_destroy_events();
- if (last_destroy_event && (switch_window_pending || win))
- {
- last_window ();
- switch_window_pending = 0;
- }
-
if (win)
{
/* Goto the last accessed window. */
@@ -159,11 +153,9 @@ destroy_window (XDestroyWindowEvent *ev)
{
printf ("Destroying current window.\n");
- /* If there are more DestroyNotify events, then it is unsafe
- to go to the last window since it could be
- deleted. Therefore, wait until the last DestroyNotify
- event and then switch windows. */
- if (!last_destroy_event) switch_window_pending = 1;
+ /* tell ratpoison to switch to the last window when all the
+ destroy events have been delt with. */
+ switch_window_pending = 1;
unmanage (win);
}
else
@@ -172,6 +164,12 @@ destroy_window (XDestroyWindowEvent *ev)
unmanage (win);
}
}
+
+ if (last_destroy_event && switch_window_pending)
+ {
+ last_window ();
+ switch_window_pending = 0;
+ }
}
void
@@ -262,6 +260,7 @@ handle_key (screen_info *s)
int revert;
Window fwin;
XEvent ev;
+ int keysym;
#ifdef DEBUG
printf ("handling key.\n");
@@ -282,14 +281,25 @@ handle_key (screen_info *s)
return;
}
- if (XLookupKeysym((XKeyEvent *) &ev, 0) >= '0'
- && XLookupKeysym((XKeyEvent *) &ev, 0) <= '9')
+ keysym = XLookupKeysym((XKeyEvent *) &ev, 0);
+
+ if (keysym == KEY_TOGGLEBAR)
+ {
+ toggle_bar (s);
+ return;
+ }
+
+ /* All functions tested for after this point hide the program bar. */
+ hide_bar (s);
+
+ if (keysym >= '0' && keysym <= '9')
{
goto_window_number (XLookupKeysym((XKeyEvent *) &ev, 0) - '0');
+ hide_bar (s);
return;
}
- switch (XLookupKeysym((XKeyEvent *) &ev, 0))
+ switch (keysym)
{
case KEY_XTERM:
spawn (TERM_PROG);
@@ -303,21 +313,21 @@ handle_key (screen_info *s)
case KEY_NEXTWINDOW:
next_window ();
break;
- case KEY_TOGGLEBAR:
- toggle_bar (s);
- break;
case KEY_LASTWINDOW:
last_window ();
break;
case KEY_WINBYNAME:
goto_win_by_name (s);
break;
+ case KEY_RENAME:
+ rename_current_window ();
+ break;
case KEY_DELETE:
if (ev.xkey.state & ShiftMask) kill_window ();
else delete_window ();
break;
default:
- fprintf (stderr, "Unknown key command %c", (char)XKeycodeToKeysym(dpy, ev.xkey.keycode, 0));
+ fprintf (stderr, "Unknown key command '%c'\n", (char)keysym);
break;
}
}
diff --git a/list.c b/list.c
index 51cefd3..ee04b34 100644
--- a/list.c
+++ b/list.c
@@ -44,6 +44,8 @@ add_to_window_list (screen_info *s, Window w)
new_window->prev = NULL;
new_window->state = STATE_UNMAPPED;
new_window->number = -1;
+ new_window->named = 0;
+
if ((new_window->name = malloc (strlen ("Unnamed") + 1)) == NULL)
{
fprintf (stderr, "list.c:add_to_window_list():Out of memory.\n");
diff --git a/main.c b/main.c
index 56f7984..313d7fc 100644
--- a/main.c
+++ b/main.c
@@ -97,7 +97,8 @@ handler (Display *d, XErrorEvent *e)
XGetErrorText (d, e->error_code, error_msg, sizeof (error_msg));
fprintf (stderr, "ratpoison: %s!\n", error_msg);
- exit (EXIT_FAILURE);
+ return 0;
+ // exit (EXIT_FAILURE);
}
int
@@ -114,7 +115,7 @@ 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);
@@ -225,13 +226,13 @@ init_screen (screen_info *s, int screen_num)
s->bar_is_raised = 0;
s->bar_window = XCreateSimpleWindow (dpy, s->root, 0, 0,
1, 1, 1, fg_color.pixel, bg_color.pixel);
+ XSelectInput (dpy, s->bar_window, StructureNotifyMask);
/* Setup the window that will recieve all keystrokes once the prefix
key has been pressed. */
s->key_window = XCreateSimpleWindow (dpy, s->root, 0, 0, 1, 1, 0, WhitePixel (dpy, 0), BlackPixel (dpy, 0));
- XSelectInput (dpy, s->bar_window, StructureNotifyMask);
+ XSelectInput (dpy, s->key_window, KeyPressMask);
XMapWindow (dpy, s->key_window);
- grab_keys (s);
/* Create the input window. */
s->input_window = XCreateSimpleWindow (dpy, s->root, 0, 0,
diff --git a/manage.c b/manage.c
index 6c4881d..592e391 100644
--- a/manage.c
+++ b/manage.c
@@ -32,35 +32,6 @@
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,
- GrabModeAsync, GrabModeAsync);
- XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_PREVWINDOW ), AnyModifier, s->key_window, True,
- GrabModeAsync, GrabModeAsync);
- XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_NEXTWINDOW ), AnyModifier, s->key_window, True,
- GrabModeAsync, GrabModeAsync);
- XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_TOGGLEBAR ), AnyModifier, s->key_window, True,
- GrabModeAsync, GrabModeAsync);
- XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_LASTWINDOW ), AnyModifier, s->key_window, True,
- GrabModeAsync, GrabModeAsync);
- XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_DELETE ), AnyModifier, s->key_window, True,
- GrabModeAsync, GrabModeAsync);
- XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_PREFIX ), AnyModifier, s->key_window, True,
- GrabModeAsync, GrabModeAsync);
- XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_WINBYNAME ), AnyModifier, s->key_window, True,
- GrabModeAsync, GrabModeAsync);
-}
-
static void
grab_prefix_key (Window w)
{
@@ -77,6 +48,9 @@ update_window_name (rp_window *win)
int list_len;
int i;
+ /* Don't overwrite the window name if the user specified one. */
+ if (win->named) return 0;
+
if (!XGetWMName (dpy, win->w, &text))
{
fprintf (stderr, "ratpoison:manage.c: I can't get the WMName.\n");
@@ -122,6 +96,30 @@ update_window_name (rp_window *win)
}
void
+rename_current_window ()
+{
+ char winname[100];
+
+ if (rp_current_window == NULL) return;
+
+ get_input (rp_current_window->scr, "Name: ", winname, 100);
+ printf ("user entered: %s\n", winname);
+
+ free (rp_current_window->name);
+ rp_current_window->name = malloc (sizeof (char) * strlen (winname) + 1);
+ if (rp_current_window->name == NULL)
+ {
+ fprintf (stderr, "ratpoison:rename_window(): Out of memory\n");
+ exit (EXIT_FAILURE);
+ }
+ strcpy (rp_current_window->name, winname);
+ rp_current_window->named = 1;
+
+ /* Update the program bar. */
+ update_window_names (rp_current_window->scr);
+}
+
+void
manage (rp_window *win, screen_info *s)
{
if (!update_window_name (win)) return;
diff --git a/manage.h b/manage.h
index e43bba6..58a5590 100644
--- a/manage.h
+++ b/manage.h
@@ -22,9 +22,9 @@
#include "data.h"
-void grab_keys ();
void scanwins(screen_info *s);
void manage (rp_window *w, screen_info *s);
void unmanage (rp_window *w);
int update_window_name (rp_window *win);
+void rename_current_window ();
#endif /* _MANAGE_H */