From 84ee56d66b889363903eddd81a8b2a07f180656f Mon Sep 17 00:00:00 2001 From: sabetts Date: Wed, 26 Mar 2003 02:42:05 +0000 Subject: * src/split.h (show_frame_message): new prototype * src/split.c (show_frame_message): new function * src/main.c (init_screen): listen for key release events in the key_window and input_window. * src/input.c (read_key): new argument, gobble_rel. All callers updated. * src/actions.c (cmd_remove): only remove the current frame if it isn't the ONLY one. (cmd_remove): display a message informing the user if the frame cannot be removed. (cmd_resize): clean up resize loop. (cmd_resize): display a window indicating which frame is being resized. --- ChangeLog | 20 ++++++++++++++++++++ NEWS | 3 +++ src/actions.c | 18 +++++++++++++----- src/events.c | 2 +- src/input.c | 21 ++++++++++++++++++--- src/input.h | 2 +- src/main.c | 4 ++-- src/split.c | 13 +++++++++---- src/split.h | 2 ++ 9 files changed, 69 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9cf6192..f8fbd8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2003-03-25 Shawn Betts + + * src/split.h (show_frame_message): new prototype + + * src/split.c (show_frame_message): new function + + * src/main.c (init_screen): listen for key release events in the + key_window and input_window. + + * src/input.c (read_key): new argument, gobble_rel. All callers + updated. + + * src/actions.c (cmd_remove): only remove the current frame if it + isn't the ONLY one. + (cmd_remove): display a message informing the user if the frame + cannot be removed. + (cmd_resize): clean up resize loop. + (cmd_resize): display a window indicating which frame is being + resized. + 2003-03-23 Shawn Betts * src/split.c (resize_frame_vertically): fix typo error (frame_top diff --git a/NEWS b/NEWS index 0ff7c52..bcfe6e0 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,9 @@ ratpoison NEWS --- history of user-visible changes. -*- outline -*- * Changes since 1.1.1 +** key presses +All actions now occur after the user has released the key. + ** keybinding changes fselect is bound to C-t C-f and C-t f, curframe is now bound to C-t F, and resize is bound to C-t C-r and C-t r. diff --git a/src/actions.c b/src/actions.c index 82fac46..8e18bf2 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1381,9 +1381,16 @@ cmd_only (int interactive, void *data) char * cmd_remove (int interactive, void *data) { + screen_info *s = current_screen(); rp_window_frame *frame; - frame = find_frame_next (current_screen()->rp_current_frame); + if (num_frames(s) <= 1) + { + message (" remove: cannot remove only frame "); + return NULL; + } + + frame = find_frame_next (s->rp_current_frame); if (frame) { @@ -1425,9 +1432,11 @@ cmd_resize (int interactive, void *data) XGetInputFocus (dpy, &fwin, &revert); XSetInputFocus (dpy, s->key_window, RevertToPointerRoot, CurrentTime); - nbytes = read_key (&c, &mod, buffer, sizeof (buffer)); while (1) { + show_frame_message (" Resize frame "); + nbytes = read_key (&c, &mod, buffer, sizeof (buffer), 1); + if (c == RESIZE_VGROW_KEY && mod == RESIZE_VGROW_MODIFIER) resize_frame_vertically (s->rp_current_frame, defaults.frame_resize_unit); else if (c == RESIZE_VSHRINK_KEY && mod == RESIZE_VSHRINK_MODIFIER) @@ -1441,10 +1450,9 @@ cmd_resize (int interactive, void *data) resize_shrink_to_window (s->rp_current_frame); else if (c == RESIZE_END_KEY && mod == RESIZE_END_MODIFIER) break; - - nbytes = read_key (&c, &mod, buffer, sizeof (buffer)); } + hide_frame_indicator (); XSetInputFocus (dpy, fwin, RevertToPointerRoot, CurrentTime); } else @@ -2914,7 +2922,7 @@ cmd_fselect (int interactive, void *data) /* Read a key. */ XGetInputFocus (dpy, &fwin, &revert); XSetInputFocus (dpy, s->key_window, RevertToPointerRoot, CurrentTime); - read_key (&c, &mod, NULL, 0); + read_key (&c, &mod, NULL, 0, 1); XSetInputFocus (dpy, fwin, RevertToPointerRoot, CurrentTime); /* Destroy our number windows and free the array. */ diff --git a/src/events.c b/src/events.c index dd998b5..b656f16 100644 --- a/src/events.c +++ b/src/events.c @@ -375,7 +375,7 @@ handle_key (screen_info *s) rat_grabbed = 1; } - read_key (&keysym, &mod, NULL, 0); + read_key (&keysym, &mod, NULL, 0, 1); XSetInputFocus (dpy, fwin, revert, CurrentTime); if (rat_grabbed) diff --git a/src/input.c b/src/input.c index 6064d93..a5d5461 100644 --- a/src/input.c +++ b/src/input.c @@ -258,18 +258,33 @@ cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_nam } int -read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len) +read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len, int gobble_rel) { + int key_presses = 0; XEvent ev; int nbytes; + unsigned int keycode; + /* Read a key from the keyboard. */ do { XMaskEvent (dpy, KeyPressMask, &ev); + /* Store the keycode so we can wait for it's corresponding key + release event. */ + keycode = ev.xkey.keycode; *modifiers = ev.xkey.state; nbytes = cook_keycode (&ev.xkey, keysym, modifiers, keysym_name, len, 0); } while (IsModifierKey (*keysym)); + PRINT_DEBUG (("key press events: %d\n", key_presses)); + + /* Gobble the release event for the key we pressed. */ + if (gobble_rel) + do + { + XMaskEvent (dpy, KeyReleaseMask, &ev); + } while (ev.xkey.keycode != keycode); + return nbytes; } @@ -357,7 +372,7 @@ get_more_input (char *prompt, char *preinput) /* XSync (dpy, False); */ - nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize); + nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize, 0); while (ch != XK_Return) { PRINT_DEBUG (("key %ld\n", ch)); @@ -429,7 +444,7 @@ get_more_input (char *prompt, char *preinput) update_input_window(s, prompt, str, cur_len); } - nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize); + nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize, 0); } str[cur_len] = 0; diff --git a/src/input.h b/src/input.h index 0544f37..631d4d4 100644 --- a/src/input.h +++ b/src/input.h @@ -26,7 +26,7 @@ char *keysym_to_string (KeySym keysym, unsigned int modifier); int cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_name, int len, int ignore_bad_mods); char *get_input (char *prompt); char *get_more_input (char *prompt, char *preinput); -int read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len); +int read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len, int gobble_rel); unsigned int x11_mask_to_rp_mask (unsigned int mask); unsigned int rp_mask_to_x11_mask (unsigned int mask); void update_modifier_map (); diff --git a/src/main.c b/src/main.c index ed89e3a..b34cd6e 100644 --- a/src/main.c +++ b/src/main.c @@ -680,14 +680,14 @@ init_screen (screen_info *s, int screen_num) s->key_window = XCreateSimpleWindow (dpy, s->root, 0, 0, 1, 1, 0, WhitePixel (dpy, s->screen_num), BlackPixel (dpy, s->screen_num)); - XSelectInput (dpy, s->key_window, KeyPressMask ); + XSelectInput (dpy, s->key_window, KeyPressMask | KeyReleaseMask); XMapWindow (dpy, s->key_window); /* Create the input window. */ s->input_window = XCreateSimpleWindow (dpy, s->root, 0, 0, 1, 1, defaults.bar_border_width, s->fg_color, s->bg_color); - XSelectInput (dpy, s->input_window, KeyPressMask ); + XSelectInput (dpy, s->input_window, KeyPressMask | KeyReleaseMask); /* Create the frame indicator window */ s->frame_window = XCreateSimpleWindow (dpy, s->root, 1, 1, 1, 1, defaults.bar_border_width, diff --git a/src/split.c b/src/split.c index fe1565c..b0d6ff1 100644 --- a/src/split.c +++ b/src/split.c @@ -787,11 +787,18 @@ hide_frame_indicator () void show_frame_indicator () +{ + show_frame_message (MESSAGE_FRAME_STRING); + alarm (defaults.frame_indicator_timeout); +} + +void +show_frame_message (char *msg) { screen_info *s = current_screen (); int width, height; - width = defaults.bar_x_padding * 2 + XTextWidth (defaults.font, MESSAGE_FRAME_STRING, strlen (MESSAGE_FRAME_STRING)); + width = defaults.bar_x_padding * 2 + XTextWidth (defaults.font, msg, strlen (msg)); height = (FONT_HEIGHT (defaults.font) + defaults.bar_y_padding * 2); XMoveResizeWindow (dpy, current_screen()->frame_window, @@ -808,9 +815,7 @@ show_frame_indicator () XDrawString (dpy, s->frame_window, s->normal_gc, defaults.bar_x_padding, defaults.bar_y_padding + defaults.font->max_bounds.ascent, - MESSAGE_FRAME_STRING, strlen (MESSAGE_FRAME_STRING)); - - alarm (defaults.frame_indicator_timeout); + msg, strlen (msg)); } rp_window_frame * diff --git a/src/split.h b/src/split.h index a9e952d..d7ce710 100644 --- a/src/split.h +++ b/src/split.h @@ -45,6 +45,8 @@ void blank_frame (rp_window_frame *frame); void show_frame_indicator (); void hide_frame_indicator (); +void show_frame_message (char *msg); + rp_window_frame *find_frame_right (rp_window_frame *frame); rp_window_frame *find_frame_left (rp_window_frame *frame); rp_window_frame *find_frame_down (rp_window_frame *frame); -- cgit v1.2.3