summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Betts <sabetts@gmail.com>2008-02-11 23:13:39 -0800
committerShawn Betts <sabetts@gmail.com>2008-02-11 23:13:39 -0800
commit6ef6c4ddce5eec679d81c48c0f5b72ab04a388f2 (patch)
tree785ae87eb9cdf4429af86a59648b47598689c1a8
parenta45a3c2cba130c6164088884d51af7545b7c671a (diff)
parent42459044340ce1cb016a9a7d85e8c784f7e36979 (diff)
downloadratpoison-6ef6c4ddce5eec679d81c48c0f5b72ab04a388f2.zip
Merge branch 'master' of sabetts@git.sv.gnu.org:/srv/git/ratpoison
-rw-r--r--.gitignore3
-rw-r--r--src/actions.c36
-rw-r--r--src/events.c2
-rw-r--r--src/input.c40
-rw-r--r--src/input.h2
5 files changed, 53 insertions, 30 deletions
diff --git a/.gitignore b/.gitignore
index c0c4872..d0e29b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,4 +12,5 @@ depcomp
install-sh
missing
ratpoison-*.tar.gz
-ratpoison-*.tar.gz.sig \ No newline at end of file
+ratpoison-*.tar.gz.sig
+TAGS
diff --git a/src/actions.c b/src/actions.c
index 62107bb..84fdd49 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -1742,9 +1742,7 @@ read_frame (struct argspec *spec, struct sbuf *s, struct cmdarg **arg)
XSync (dpy, False);
/* Read a key. */
- XGrabKeyboard (dpy, current_screen()->key_window, False, GrabModeSync, GrabModeAsync, CurrentTime);
- read_key (&c, &mod, keysym_buf, keysym_bufsize);
- XUngrabKeyboard (dpy, CurrentTime);
+ read_single_key (&c, &mod, keysym_buf, keysym_bufsize);
/* Destroy our number windows and free the array. */
for (i=0; i<frames; i++)
@@ -2969,17 +2967,21 @@ cmd_resize (int interactive, struct cmdarg **args)
unsigned int mod;
KeySym c;
struct list_head *bk;
+ Window focus;
+ int revert;
/* If we haven't got at least 2 frames, there isn't anything to
scale. */
if (num_frames (s) < 2)
return cmdret_new (RET_FAILURE, NULL);
- XGrabKeyboard (dpy, s->key_window, False, GrabModeSync, GrabModeAsync, CurrentTime);
-
/* Save the frameset in case the user aborts. */
bk = screen_copy_frameset (s);
+ /* Get ready to read keys. */
+ XGetInputFocus (dpy, &focus, &revert);
+ set_window_focus (s->key_window);
+
while (1)
{
struct resize_binding *binding;
@@ -3028,7 +3030,7 @@ cmd_resize (int interactive, struct cmdarg **args)
free (bk);
hide_frame_indicator ();
- XUngrabKeyboard (dpy, CurrentTime);
+ set_window_focus (focus);
}
else
{
@@ -3155,7 +3157,6 @@ cmdret *
cmd_license (int interactive, struct cmdarg **args)
{
rp_screen *s = current_screen();
- XEvent ev;
int x = 10;
int y = 10;
int i;
@@ -3192,7 +3193,6 @@ cmd_license (int interactive, struct cmdarg **args)
XInstallColormap (dpy, s->def_cmap);
XMapRaised (dpy, s->help_window);
- XGrabKeyboard (dpy, s->help_window, False, GrabModeSync, GrabModeAsync, CurrentTime);
/* Find the longest line. */
for(i=0; license_text[i]; i++)
@@ -3221,10 +3221,7 @@ cmd_license (int interactive, struct cmdarg **args)
}
/* Wait for a key press. */
- XMaskEvent (dpy, KeyPressMask, &ev);
-
- /* Revert focus. */
- XUngrabKeyboard (dpy, CurrentTime);
+ read_any_key ();
XUnmapWindow (dpy, s->help_window);
/* Possibly restore colormap. */
@@ -3254,7 +3251,6 @@ cmd_help (int interactive, struct cmdarg **args)
if (interactive)
{
rp_screen *s = current_screen();
- XEvent ev;
int i, old_i;
int x = 10;
int y = 0;
@@ -3268,7 +3264,6 @@ cmd_help (int interactive, struct cmdarg **args)
XInstallColormap (dpy, s->def_cmap);
XMapRaised (dpy, s->help_window);
- XGrabKeyboard (dpy, s->help_window, False, GrabModeSync, GrabModeAsync, CurrentTime);
XmbDrawString (dpy, s->help_window, defaults.font, s->normal_gc,
10, y + rp_font_ascent,
@@ -3353,8 +3348,7 @@ cmd_help (int interactive, struct cmdarg **args)
}
}
- XMaskEvent (dpy, KeyPressMask, &ev);
- XUngrabKeyboard (dpy, CurrentTime);
+ read_any_key();
XUnmapWindow (dpy, s->help_window);
/* Possibly restore colormap. */
@@ -4964,8 +4958,6 @@ cmd_readkey (int interactive, struct cmdarg **args)
map = ARG(0,keymap);
- XGrabKeyboard (dpy, current_screen()->key_window, False, GrabModeSync, GrabModeAsync, CurrentTime);
-
/* Change the mouse icon to indicate to the user we are waiting for
more keystrokes */
if (defaults.wait_for_key_cursor)
@@ -4974,8 +4966,7 @@ cmd_readkey (int interactive, struct cmdarg **args)
rat_grabbed = 1;
}
- read_key (&keysym, &mod, NULL, 0);
- XUngrabKeyboard (dpy, CurrentTime);
+ read_single_key (&keysym, &mod, NULL, 0);
if (rat_grabbed)
ungrab_rat();
@@ -5517,8 +5508,6 @@ cmd_describekey (int interactive, struct cmdarg **args)
map = ARG(0,keymap);
- XGrabKeyboard (dpy, current_screen()->key_window, False, GrabModeSync, GrabModeAsync, CurrentTime);
-
/* Change the mouse icon to indicate to the user we are waiting for
more keystrokes */
if (defaults.wait_for_key_cursor)
@@ -5527,8 +5516,7 @@ cmd_describekey (int interactive, struct cmdarg **args)
rat_grabbed = 1;
}
- read_key (&keysym, &mod, NULL, 0);
- XUngrabKeyboard (dpy, CurrentTime);
+ read_single_key (&keysym, &mod, NULL, 0);
if (rat_grabbed)
ungrab_rat();
diff --git a/src/events.c b/src/events.c
index 25f7c1c..e52acf4 100644
--- a/src/events.c
+++ b/src/events.c
@@ -433,6 +433,8 @@ handle_key (KeySym ks, unsigned int mod, rp_screen *s)
{
PRINT_DEBUG(("Impossible: No matching key"));
}
+
+ /* All keys have been read so now we let the keyboard go. */
XAllowEvents (dpy, AsyncKeyboard, CurrentTime);
}
diff --git a/src/input.c b/src/input.c
index 3350341..3297ac7 100644
--- a/src/input.c
+++ b/src/input.c
@@ -377,6 +377,30 @@ cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_nam
return nbytes;
}
+/* Wait for a key and discard it. */
+void
+read_any_key ()
+{
+ char buffer[513];
+ unsigned int mod;
+ KeySym c;
+
+ read_single_key (&c, &mod, buffer, sizeof (buffer));
+}
+
+/* The same as read_key, but handle focusing the key_window and reverting focus. */
+int
+read_single_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len)
+{
+ Window focus;
+ int revert;
+
+ XGetInputFocus (dpy, &focus, &revert);
+ set_window_focus (current_screen()->key_window);
+ read_key (keysym, modifiers, keysym_name, len);
+ set_window_focus (focus);
+}
+
int
read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len)
{
@@ -386,10 +410,13 @@ read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len)
/* Read a key from the keyboard. */
do
{
- XMaskEvent (dpy, KeyPressMask, &ev);
+ /* The keyboard is frozen, so unfreeze it and allow another key to come in. */
+ XAllowEvents (dpy, SyncKeyboard, CurrentTime);
+
+ XMaskEvent (dpy, KeyPressMask|KeyRelease, &ev);
*modifiers = ev.xkey.state;
nbytes = cook_keycode (&ev.xkey, keysym, modifiers, keysym_name, len, 0);
- } while (IsModifierKey (*keysym));
+ } while (IsModifierKey (*keysym) || ev.xkey.type == KeyRelease);
return nbytes;
}
@@ -503,6 +530,8 @@ get_more_input (char *prompt, char *preinput,
rp_input_line *line;
char *final_input;
edit_status status;
+ Window focus;
+ int revert;
#ifdef HAVE_HISTORY
history_reset();
@@ -522,12 +551,13 @@ get_more_input (char *prompt, char *preinput,
XMapWindow (dpy, s->input_window);
XRaiseWindow (dpy, s->input_window);
XClearWindow (dpy, s->input_window);
+ /* Switch focus to our input window to read the next key events. */
+ XGetInputFocus (dpy, &focus, &revert);
+ set_window_focus (s->input_window);
XSync (dpy, False);
update_input_window (s, line);
- XGrabKeyboard (dpy, s->input_window, False, GrabModeSync, GrabModeAsync, CurrentTime);
-
for (;;)
{
nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize);
@@ -566,7 +596,7 @@ get_more_input (char *prompt, char *preinput,
input_line_free (line);
/* Revert focus. */
- XUngrabKeyboard (dpy, CurrentTime);
+ set_window_focus (focus);
XUnmapWindow (dpy, s->input_window);
/* Possibly restore colormap. */
diff --git a/src/input.h b/src/input.h
index f3da6bc..676c6e7 100644
--- a/src/input.h
+++ b/src/input.h
@@ -26,6 +26,8 @@ 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, completion_fn fn);
char *get_more_input (char *prompt, char *preinput, completion_fn fn);
+void read_any_key ();
+int read_single_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len);
int read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len);
unsigned int x11_mask_to_rp_mask (unsigned int mask);
unsigned int rp_mask_to_x11_mask (unsigned int mask);