From 60767d1215233461273d4d16df8ff52cf15b4010 Mon Sep 17 00:00:00 2001 From: sabetts Date: Thu, 7 Sep 2000 16:49:23 +0000 Subject: restructured tree, added automake and autoconf to the build process. --- src/input.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/input.c (limited to 'src/input.c') diff --git a/src/input.c b/src/input.c new file mode 100644 index 0000000..ad8f093 --- /dev/null +++ b/src/input.c @@ -0,0 +1,75 @@ +/* for reading kdb input from the user. Currently only used to read in + the name of a window to jump to. */ + +#include +#include +#include + +#include "ratpoison.h" + + +static int +read_key () +{ + XEvent ev; + + XMaskEvent (dpy, KeyPressMask, &ev); + return XLookupKeysym ((XKeyEvent *)&ev, 0); +} + +/* pass in a pointer a string and how much room we have, and fill it + in with text from the user. */ +void +get_input (screen_info *s, char *prompt, char *str, int len) +{ + int cur_len; /* Current length of the string. */ + int ch; + int revert; + Window fwin; + int prompt_width = XTextWidth (s->font, prompt, strlen (prompt)); + int width = 100 + prompt_width; + + /* We don't want to draw overtop of the program bar. */ + hide_bar (s); + + XMapWindow (dpy, s->input_window); + XMoveResizeWindow (dpy, s->input_window, + bar_x (s, width), bar_y (s), width, (FONT_HEIGHT (s->font) + BAR_PADDING * 2)); + XClearWindow (dpy, s->input_window); + XRaiseWindow (dpy, s->input_window); + + /* draw the window prompt. */ + XDrawString (dpy, s->input_window, s->bold_gc, 5, + BAR_PADDING + s->font->max_bounds.ascent, prompt, strlen (prompt)); + + XGetInputFocus (dpy, &fwin, &revert); + XSetInputFocus (dpy, s->input_window, RevertToPointerRoot, CurrentTime); + + cur_len = 0; + while ((ch = read_key ()) != XK_Return) + { + printf ("key %d\n", ch); + if (ch == XK_BackSpace) + { + if (cur_len > 0) cur_len--; + XClearWindow (dpy, s->input_window); + XDrawString (dpy, s->input_window, s->bold_gc, 5, + BAR_PADDING + s->font->max_bounds.ascent, prompt, strlen (prompt)); + XDrawString (dpy, s->input_window, s->bold_gc, 5 + prompt_width, + BAR_PADDING + s->font->max_bounds.ascent, str, cur_len); + } + else if (ch >= ' ') + { + str[cur_len] = ch; + if (cur_len < len - 1) cur_len++; + + XDrawString (dpy, s->input_window, s->bold_gc, 5 + prompt_width, + BAR_PADDING + s->font->max_bounds.ascent, str, cur_len); + } + } + + str[cur_len] = 0; + XSetInputFocus (dpy, fwin, RevertToPointerRoot, CurrentTime); + XUnmapWindow (dpy, s->input_window); +} + -- cgit v1.2.3