add code to grab all modifier combinations, so keybindings work with

2001-10-04  Havoc Pennington  <hp@pobox.com>

	* src/keybindings.c (meta_change_keygrab): add code to grab all
	modifier combinations, so keybindings work with NumLock etc.

	* src/menu.c (meta_window_menu_new): remove newlines from menu
	items

2001-09-27  Havoc Pennington  <hp@pobox.com>

	* src/session.c (save_state): when encoding text for session file,
	escape XML entities
This commit is contained in:
Havoc Pennington 2001-10-05 02:58:48 +00:00 committed by Havoc Pennington
parent 38a878171a
commit 350ecb1dcf
3 changed files with 116 additions and 30 deletions

View File

@ -1,3 +1,16 @@
2001-10-04 Havoc Pennington <hp@pobox.com>
* src/keybindings.c (meta_change_keygrab): add code to grab all
modifier combinations, so keybindings work with NumLock etc.
* src/menu.c (meta_window_menu_new): remove newlines from menu
items
2001-09-27 Havoc Pennington <hp@pobox.com>
* src/session.c (save_state): when encoding text for session file,
escape XML entities
2001-09-21 Alex Graveley <alex@ximian.com> 2001-09-21 Alex Graveley <alex@ximian.com>
* src/Makefile.am (metacity_SOURCES): Add inlinepixbufs.h so * src/Makefile.am (metacity_SOURCES): Add inlinepixbufs.h so

View File

@ -88,7 +88,8 @@ struct _MetaKeyBinding
int keycode; int keycode;
}; };
#define INTERESTING_MODIFIERS (ShiftMask | ControlMask | Mod1Mask) #define IGNORED_MODIFIERS (LockMask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask)
#define INTERESTING_MODIFIERS (~IGNORED_MODIFIERS)
static MetaKeyBinding screen_bindings[] = { static MetaKeyBinding screen_bindings[] = {
{ XK_F1, Mod1Mask, KeyPress, handle_activate_workspace, GINT_TO_POINTER (0), 0 }, { XK_F1, Mod1Mask, KeyPress, handle_activate_workspace, GINT_TO_POINTER (0), 0 },
@ -144,6 +145,88 @@ meta_display_init_keys (MetaDisplay *display)
init_bindings (display, window_bindings); init_bindings (display, window_bindings);
} }
/* Grab/ungrab, ignoring all annoying modifiers like NumLock etc. */
static void
meta_change_keygrab (MetaDisplay *display,
Window xwindow,
gboolean grab,
int keysym,
int keycode,
int modmask)
{
int result;
int ignored_mask;
/* Grab keycode/modmask, together with
* all combinations of IGNORED_MODIFIERS.
* X provides no better way to do this.
*/
/* modmask can't contain any non-interesting modifiers */
g_return_if_fail ((modmask & INTERESTING_MODIFIERS) == modmask);
ignored_mask = 0;
while (ignored_mask < IGNORED_MODIFIERS)
{
if (ignored_mask & INTERESTING_MODIFIERS)
{
/* Not a combination of IGNORED_MODIFIERS
* (it contains some non-ignored modifiers)
*/
++ignored_mask;
continue;
}
meta_error_trap_push (display);
if (grab)
XGrabKey (display->xdisplay, keycode,
modmask | ignored_mask,
xwindow,
True,
GrabModeAsync, GrabModeAsync);
else
XUngrabKey (display->xdisplay, keycode,
modmask | ignored_mask,
xwindow);
result = meta_error_trap_pop (display);
if (grab && result != Success)
{
const char *name;
name = XKeysymToString (keysym);
if (name == NULL)
name = "(unknown)";
if (result == BadAccess)
meta_warning (_("Some other program is already using the key %s with modifiers %x as a binding\n"), name, modmask | ignored_mask);
}
++ignored_mask;
}
}
static void
meta_grab_key (MetaDisplay *display,
Window xwindow,
int keysym,
int keycode,
int modmask)
{
meta_change_keygrab (display, xwindow, TRUE, keysym, keycode, modmask);
}
static void
meta_ungrab_key (MetaDisplay *display,
Window xwindow,
int keysym,
int keycode,
int modmask)
{
meta_change_keygrab (display, xwindow, FALSE, keysym, keycode, modmask);
}
static void static void
grab_keys (MetaKeyBinding *bindings, grab_keys (MetaKeyBinding *bindings,
MetaDisplay *display, MetaDisplay *display,
@ -156,24 +239,10 @@ grab_keys (MetaKeyBinding *bindings,
{ {
if (bindings[i].keycode != 0) if (bindings[i].keycode != 0)
{ {
int result; meta_grab_key (display, xwindow,
bindings[i].keysym,
meta_error_trap_push (display); bindings[i].keycode,
XGrabKey (display->xdisplay, bindings[i].keycode, bindings[i].mask);
bindings[i].mask, xwindow, True,
GrabModeAsync, GrabModeAsync);
result = meta_error_trap_pop (display);
if (result != Success)
{
const char *name;
name = XKeysymToString (bindings[i].keysym);
if (name == NULL)
name = "(unknown)";
if (result == BadAccess)
meta_warning (_("Some other program is already using the key %s as a binding\n"), name);
}
} }
++i; ++i;
@ -192,10 +261,10 @@ ungrab_keys (MetaKeyBinding *bindings,
{ {
if (bindings[i].keycode != 0) if (bindings[i].keycode != 0)
{ {
meta_error_trap_push (display); meta_ungrab_key (display, xwindow,
XUngrabKey (display->xdisplay, bindings[i].keycode, bindings[i].keysym,
bindings[i].mask, xwindow); bindings[i].keycode,
meta_error_trap_pop (display); bindings[i].mask);
} }
++i; ++i;

View File

@ -665,13 +665,14 @@ window_gravity_from_string (const char *str)
} }
static char* static char*
encode_text_as_utf8 (const char *text) encode_text_as_utf8_markup (const char *text)
{ {
/* text can be any encoding, and is nul-terminated. /* text can be any encoding, and is nul-terminated.
* we pretend it's Latin-1 and encode as UTF-8 * we pretend it's Latin-1 and encode as UTF-8
*/ */
GString *str; GString *str;
const char *p; const char *p;
char *escaped;
str = g_string_new (""); str = g_string_new ("");
@ -682,13 +683,16 @@ encode_text_as_utf8 (const char *text)
++p; ++p;
} }
return g_string_free (str, FALSE); escaped = g_markup_escape_text (str->str, str->len);
g_string_free (str, TRUE);
return escaped;
} }
static char* static char*
decode_text_from_utf8 (const char *text) decode_text_from_utf8 (const char *text)
{ {
/* Convert back from the encoded UTF-8 */ /* Convert back from the encoded (but not escaped) UTF-8 */
GString *str; GString *str;
const char *p; const char *p;
@ -803,13 +807,13 @@ save_state (void)
* in practice they are always ascii though.) * in practice they are always ascii though.)
*/ */
sm_client_id = encode_text_as_utf8 (window->sm_client_id); sm_client_id = encode_text_as_utf8_markup (window->sm_client_id);
res_class = window->res_class ? res_class = window->res_class ?
encode_text_as_utf8 (window->res_class) : NULL; encode_text_as_utf8_markup (window->res_class) : NULL;
res_name = window->res_name ? res_name = window->res_name ?
encode_text_as_utf8 (window->res_name) : NULL; encode_text_as_utf8_markup (window->res_name) : NULL;
role = window->role ? role = window->role ?
encode_text_as_utf8 (window->role) : NULL; encode_text_as_utf8_markup (window->role) : NULL;
meta_verbose ("Saving session managed window %s, client ID '%s'\n", meta_verbose ("Saving session managed window %s, client ID '%s'\n",
window->desc, window->sm_client_id); window->desc, window->sm_client_id);