From 47f67eb270c093004a2ae9f1c68a082ffa0bbc91 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 27 Sep 2002 01:40:17 +0000 Subject: [PATCH] use MetaAccelLabel to display accelerators for the menu items 2002-09-26 Havoc Pennington * src/menu.c (meta_window_menu_new): use MetaAccelLabel to display accelerators for the menu items * src/metaaccellabel.c: cut-and-paste GtkAccelLabel and port to use virtual modifiers * src/Makefile.am (metacity_SOURCES): add metaaccellabel.[hc] * src/prefs.c (meta_prefs_get_window_binding): new function * src/core.c (meta_core_get_menu_accelerator): new function --- ChangeLog | 14 ++ src/Makefile.am | 2 + src/core.c | 97 ++++++++++ src/core.h | 5 + src/menu.c | 47 ++++- src/metaaccellabel.c | 439 +++++++++++++++++++++++++++++++++++++++++++ src/metaaccellabel.h | 104 ++++++++++ src/prefs.c | 22 +++ src/prefs.h | 4 + 9 files changed, 729 insertions(+), 5 deletions(-) create mode 100644 src/metaaccellabel.c create mode 100644 src/metaaccellabel.h diff --git a/ChangeLog b/ChangeLog index 497cdf5db..851fdaded 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2002-09-26 Havoc Pennington + + * src/menu.c (meta_window_menu_new): use MetaAccelLabel to display + accelerators for the menu items + + * src/metaaccellabel.c: cut-and-paste GtkAccelLabel and port to + use virtual modifiers + + * src/Makefile.am (metacity_SOURCES): add metaaccellabel.[hc] + + * src/prefs.c (meta_prefs_get_window_binding): new function + + * src/core.c (meta_core_get_menu_accelerator): new function + 2002-09-25 Havoc Pennington * src/metacity.schemas.in: Change short desc of switch_windows and diff --git a/src/Makefile.am b/src/Makefile.am index 4355317b1..649ae0591 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,8 @@ metacity_SOURCES= \ main.h \ menu.c \ menu.h \ + metaaccellabel.c \ + metaaccellabel.h \ place.c \ place.h \ prefs.c \ diff --git a/src/core.c b/src/core.c index abcaf9d8c..fb3a185d8 100644 --- a/src/core.c +++ b/src/core.c @@ -22,6 +22,7 @@ #include "core.h" #include "frame.h" #include "workspace.h" +#include "prefs.h" void meta_core_get_client_size (Display *xdisplay, @@ -509,6 +510,102 @@ meta_core_show_window_menu (Display *xdisplay, meta_window_show_menu (window, root_x, root_y, button, timestamp); } +void +meta_core_get_menu_accelerator (MetaMenuOp menu_op, + int workspace, + unsigned int *keysym, + MetaVirtualModifier *modifiers) +{ + const char *name; + + name = NULL; + + switch (menu_op) + { + case META_MENU_OP_DELETE: + name = META_KEYBINDING_CLOSE; + break; + case META_MENU_OP_MINIMIZE: + name = META_KEYBINDING_MINIMIZE; + break; + case META_MENU_OP_UNMAXIMIZE: + name = META_KEYBINDING_UNMAXIMIZE; + break; + case META_MENU_OP_MAXIMIZE: + name = META_KEYBINDING_MAXIMIZE; + break; + case META_MENU_OP_UNSHADE: + name = META_KEYBINDING_TOGGLE_SHADE; + break; + case META_MENU_OP_SHADE: + name = META_KEYBINDING_TOGGLE_SHADE; + break; + case META_MENU_OP_UNSTICK: + name = META_KEYBINDING_TOGGLE_STICKY; + break; + case META_MENU_OP_STICK: + name = META_KEYBINDING_TOGGLE_STICKY; + break; + case META_MENU_OP_WORKSPACES: + switch (workspace) + { + case 1: + name = META_KEYBINDING_MOVE_WORKSPACE_1; + break; + case 2: + name = META_KEYBINDING_MOVE_WORKSPACE_2; + break; + case 3: + name = META_KEYBINDING_MOVE_WORKSPACE_3; + break; + case 4: + name = META_KEYBINDING_MOVE_WORKSPACE_4; + break; + case 5: + name = META_KEYBINDING_MOVE_WORKSPACE_5; + break; + case 6: + name = META_KEYBINDING_MOVE_WORKSPACE_6; + break; + case 7: + name = META_KEYBINDING_MOVE_WORKSPACE_7; + break; + case 8: + name = META_KEYBINDING_MOVE_WORKSPACE_8; + break; + case 9: + name = META_KEYBINDING_MOVE_WORKSPACE_9; + break; + case 10: + name = META_KEYBINDING_MOVE_WORKSPACE_10; + break; + case 11: + name = META_KEYBINDING_MOVE_WORKSPACE_11; + break; + case 12: + name = META_KEYBINDING_MOVE_WORKSPACE_12; + break; + } + break; + case META_MENU_OP_MOVE: + name = META_KEYBINDING_BEGIN_MOVE; + break; + case META_MENU_OP_RESIZE: + name = META_KEYBINDING_BEGIN_RESIZE; + break; + } + + if (name) + { + meta_prefs_get_window_binding (name, keysym, modifiers); + } + else + { + *keysym = 0; + *modifiers = 0; + } +} + char * meta_core_get_workspace_name_with_index (Display *xdisplay, int index) diff --git a/src/core.h b/src/core.h index 63b254dbf..80c9263c5 100644 --- a/src/core.h +++ b/src/core.h @@ -116,6 +116,11 @@ void meta_core_show_window_menu (Display *xdisplay, int button, Time timestamp); +void meta_core_get_menu_accelerator (MetaMenuOp menu_op, + int workspace, + unsigned int *keysym, + MetaVirtualModifier *modifiers); + gboolean meta_core_begin_grab_op (Display *xdisplay, Window frame_xwindow, MetaGrabOp op, diff --git a/src/menu.c b/src/menu.c index 783183cf8..1dc35f52e 100644 --- a/src/menu.c +++ b/src/menu.c @@ -27,6 +27,7 @@ #include "util.h" #include "core.h" #include "themewidget.h" +#include "metaaccellabel.h" typedef struct _MenuItem MenuItem; typedef struct _MenuData MenuData; @@ -185,6 +186,31 @@ get_workspace_name_with_accel (Display *display, } } +static GtkWidget* +menu_item_new (const char *label, + gboolean with_image, + unsigned int key, + MetaVirtualModifier mods) +{ + GtkWidget *menu_item; + GtkWidget *accel_label; + + if (with_image) + menu_item = gtk_image_menu_item_new (); + else + menu_item = gtk_menu_item_new (); + accel_label = meta_accel_label_new_with_mnemonic (label); + gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5); + + gtk_container_add (GTK_CONTAINER (menu_item), accel_label); + gtk_widget_show (accel_label); + + meta_accel_label_set_accelerator (META_ACCEL_LABEL (accel_label), + key, mods); + + return menu_item; +} + MetaWindowMenu* meta_window_menu_new (MetaFrames *frames, MetaMenuOp ops, @@ -218,7 +244,9 @@ meta_window_menu_new (MetaFrames *frames, { GtkWidget *mi; MenuData *md; - + unsigned int key; + MetaVirtualModifier mods; + if (menuitems[i].op == 0) { mi = gtk_separator_menu_item_new (); @@ -235,17 +263,20 @@ meta_window_menu_new (MetaFrames *frames, GTK_ICON_SIZE_MENU); } + + meta_core_get_menu_accelerator (menuitems[i].op, -1, + &key, &mods); if (image) { - mi = gtk_image_menu_item_new_with_mnemonic (_(menuitems[i].label)); + mi = menu_item_new (_(menuitems[i].label), TRUE, key, mods); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image); gtk_widget_show (image); } else { - mi = gtk_menu_item_new_with_mnemonic (_(menuitems[i].label)); + mi = menu_item_new (_(menuitems[i].label), FALSE, key, mods); } if (insensitive & menuitems[i].op) @@ -289,13 +320,19 @@ meta_window_menu_new (MetaFrames *frames, { char *label, *name; MenuData *md; - + unsigned int key; + MetaVirtualModifier mods; + + meta_core_get_menu_accelerator (META_MENU_OP_WORKSPACES, + i + 1, + &key, &mods); + name = get_workspace_name_with_accel (display, i); if (ops & META_MENU_OP_UNSTICK) label = g_strdup_printf (_("Only on %s"), name); else label = g_strdup_printf(_("Move to %s"), name); - mi = gtk_menu_item_new_with_mnemonic (label); + mi = menu_item_new (label, FALSE, key, mods); g_free (name); g_free (label); diff --git a/src/metaaccellabel.c b/src/metaaccellabel.c new file mode 100644 index 000000000..e6fbf6f63 --- /dev/null +++ b/src/metaaccellabel.c @@ -0,0 +1,439 @@ +/* Metacity hacked-up GtkAccelLabel */ +/* Copyright (C) 2002 Red Hat, Inc. */ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * MetaAccelLabel: GtkLabel with accelerator monitoring facilities. + * Copyright (C) 1998 Tim Janik + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the GTK+ Team and others 1997-2001. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +#include +#include "metaaccellabel.h" +#include +#include +#include +#include "util.h" + +static void meta_accel_label_class_init (MetaAccelLabelClass *klass); +static void meta_accel_label_init (MetaAccelLabel *accel_label); +static void meta_accel_label_destroy (GtkObject *object); +static void meta_accel_label_finalize (GObject *object); +static void meta_accel_label_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static gboolean meta_accel_label_expose_event (GtkWidget *widget, + GdkEventExpose *event); + +static void meta_accel_label_update (MetaAccelLabel *accel_label); +static int meta_accel_label_get_accel_width (MetaAccelLabel *accel_label); + + +static MetaAccelLabelClass *accel_label_class = NULL; +static GtkLabelClass *parent_class = NULL; + + +GtkType +meta_accel_label_get_type (void) +{ + static GtkType accel_label_type = 0; + + if (!accel_label_type) + { + static const GtkTypeInfo accel_label_info = + { + "MetaAccelLabel", + sizeof (MetaAccelLabel), + sizeof (MetaAccelLabelClass), + (GtkClassInitFunc) meta_accel_label_class_init, + (GtkObjectInitFunc) meta_accel_label_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + accel_label_type = gtk_type_unique (GTK_TYPE_LABEL, &accel_label_info); + } + + return accel_label_type; +} + +static void +meta_accel_label_class_init (MetaAccelLabelClass *class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + GtkObjectClass *object_class = GTK_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + + accel_label_class = class; + parent_class = g_type_class_peek_parent (class); + + gobject_class->finalize = meta_accel_label_finalize; + + object_class->destroy = meta_accel_label_destroy; + + widget_class->size_request = meta_accel_label_size_request; + widget_class->expose_event = meta_accel_label_expose_event; + + class->signal_quote1 = g_strdup ("<:"); + class->signal_quote2 = g_strdup (":>"); + /* This is the text that should appear next to menu accelerators + * that use the shift key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_shift = g_strdup (_("Shift")); + /* This is the text that should appear next to menu accelerators + * that use the control key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_control = g_strdup (_("Ctrl")); + /* This is the text that should appear next to menu accelerators + * that use the alt key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_alt = g_strdup (_("Alt")); + /* This is the text that should appear next to menu accelerators + * that use the meta key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_meta = g_strdup (_("Meta")); + /* This is the text that should appear next to menu accelerators + * that use the super key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_super = g_strdup (_("Super")); + /* This is the text that should appear next to menu accelerators + * that use the hyper key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_hyper = g_strdup (_("Hyper")); + /* This is the text that should appear next to menu accelerators + * that use the mod2 key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_mod2 = g_strdup (_("Mod2")); + /* This is the text that should appear next to menu accelerators + * that use the mod3 key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_mod3 = g_strdup (_("Mod3")); + /* This is the text that should appear next to menu accelerators + * that use the mod4 key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_mod4 = g_strdup (_("Mod4")); + /* This is the text that should appear next to menu accelerators + * that use the mod5 key. If the text on this key isn't typically + * translated on keyboards used for your language, don't translate + * this. + */ + class->mod_name_mod5 = g_strdup (_("Mod5")); + + class->mod_separator = g_strdup ("+"); + class->accel_seperator = g_strdup (" / "); + class->latin1_to_char = TRUE; +} + +static void +meta_accel_label_init (MetaAccelLabel *accel_label) +{ + accel_label->accel_padding = 3; + accel_label->accel_string = NULL; + + meta_accel_label_update (accel_label); +} + +GtkWidget* +meta_accel_label_new_with_mnemonic (const gchar *string) +{ + MetaAccelLabel *accel_label; + + g_return_val_if_fail (string != NULL, NULL); + + accel_label = g_object_new (META_TYPE_ACCEL_LABEL, NULL); + + gtk_label_set_text_with_mnemonic (GTK_LABEL (accel_label), string); + + return GTK_WIDGET (accel_label); +} + +static void +meta_accel_label_destroy (GtkObject *object) +{ + MetaAccelLabel *accel_label = META_ACCEL_LABEL (object); + + + g_free (accel_label->accel_string); + accel_label->accel_string = NULL; + + accel_label->accel_mods = 0; + accel_label->accel_key = 0; + + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} + +static void +meta_accel_label_finalize (GObject *object) +{ + MetaAccelLabel *accel_label = META_ACCEL_LABEL (object); + + g_free (accel_label->accel_string); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +void +meta_accel_label_set_accelerator (MetaAccelLabel *accel_label, + guint accelerator_key, + MetaVirtualModifier accelerator_mods) +{ + g_return_if_fail (META_IS_ACCEL_LABEL (accel_label)); + + if (accelerator_key != accel_label->accel_key || + accelerator_mods != accel_label->accel_mods) + { + accel_label->accel_mods = accelerator_mods; + accel_label->accel_key = accelerator_key; + + meta_accel_label_update (accel_label); + } +} + +static int +meta_accel_label_get_accel_width (MetaAccelLabel *accel_label) +{ + g_return_val_if_fail (META_IS_ACCEL_LABEL (accel_label), 0); + + return (accel_label->accel_string_width + + (accel_label->accel_string_width ? accel_label->accel_padding : 0)); +} + +static void +meta_accel_label_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + MetaAccelLabel *accel_label = META_ACCEL_LABEL (widget); + PangoLayout *layout; + gint width; + + if (GTK_WIDGET_CLASS (parent_class)->size_request) + GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition); + + layout = gtk_widget_create_pango_layout (widget, accel_label->accel_string); + pango_layout_get_pixel_size (layout, &width, NULL); + accel_label->accel_string_width = width; + + g_object_unref (G_OBJECT (layout)); +} + +static gboolean +meta_accel_label_expose_event (GtkWidget *widget, + GdkEventExpose *event) +{ + MetaAccelLabel *accel_label = META_ACCEL_LABEL (widget); + GtkMisc *misc = GTK_MISC (accel_label); + PangoLayout *layout; + + if (GTK_WIDGET_DRAWABLE (accel_label)) + { + int ac_width; + + ac_width = meta_accel_label_get_accel_width (accel_label); + + if (widget->allocation.width >= widget->requisition.width + ac_width) + { + int x; + int y; + + widget->allocation.width -= ac_width; + if (GTK_WIDGET_CLASS (parent_class)->expose_event) + GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event); + widget->allocation.width += ac_width; + + x = widget->allocation.x + widget->allocation.width - misc->xpad - ac_width; + + y = (widget->allocation.y * (1.0 - misc->yalign) + + (widget->allocation.y + widget->allocation.height - + (widget->requisition.height - misc->ypad * 2)) * + misc->yalign) + 1.5; + + layout = gtk_widget_create_pango_layout (widget, accel_label->accel_string); + + gtk_paint_layout (widget->style, + widget->window, + GTK_WIDGET_STATE (widget), + FALSE, + &event->area, + widget, + "accellabel", + x, y, + layout); + + g_object_unref (G_OBJECT (layout)); + } + else + { + if (GTK_WIDGET_CLASS (parent_class)->expose_event) + GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event); + } + } + + return FALSE; +} + +static void +meta_accel_label_update (MetaAccelLabel *accel_label) +{ + MetaAccelLabelClass *class; + GString *gstring; + gboolean seen_mod = FALSE; + gunichar ch; + + g_return_if_fail (META_IS_ACCEL_LABEL (accel_label)); + + class = META_ACCEL_LABEL_GET_CLASS (accel_label); + + g_free (accel_label->accel_string); + accel_label->accel_string = NULL; + + gstring = g_string_new (accel_label->accel_string); + g_string_append (gstring, gstring->len ? class->accel_seperator : " "); + + if (accel_label->accel_mods & META_VIRTUAL_SHIFT_MASK) + { + g_string_append (gstring, class->mod_name_shift); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_CONTROL_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_control); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_ALT_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_alt); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_META_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_meta); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_SUPER_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_super); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_HYPER_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_hyper); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_MOD2_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_mod2); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_MOD3_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_mod3); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_MOD4_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_mod4); + seen_mod = TRUE; + } + if (accel_label->accel_mods & META_VIRTUAL_MOD5_MASK) + { + if (seen_mod) + g_string_append (gstring, class->mod_separator); + g_string_append (gstring, class->mod_name_mod5); + seen_mod = TRUE; + } + + if (seen_mod) + g_string_append (gstring, class->mod_separator); + + ch = gdk_keyval_to_unicode (accel_label->accel_key); + if (ch && (g_unichar_isgraph (ch) || ch == ' ') && + (ch < 0x80 || class->latin1_to_char)) + { + switch (ch) + { + case ' ': + g_string_append (gstring, "Space"); + break; + case '\\': + g_string_append (gstring, "Backslash"); + break; + default: + g_string_append_unichar (gstring, g_unichar_toupper (ch)); + break; + } + } + else + { + gchar *tmp; + + tmp = gtk_accelerator_name (accel_label->accel_key, 0); + if (tmp[0] != 0 && tmp[1] == 0) + tmp[0] = g_ascii_toupper (tmp[0]); + g_string_append (gstring, tmp); + g_free (tmp); + } + + g_free (accel_label->accel_string); + accel_label->accel_string = gstring->str; + g_string_free (gstring, FALSE); + + g_assert (accel_label->accel_string); + /* accel_label->accel_string = g_strdup ("-/-"); */ + + gtk_widget_queue_resize (GTK_WIDGET (accel_label)); +} diff --git a/src/metaaccellabel.h b/src/metaaccellabel.h new file mode 100644 index 000000000..abaf7e689 --- /dev/null +++ b/src/metaaccellabel.h @@ -0,0 +1,104 @@ +/* Metacity hacked-up GtkAccelLabel */ +/* Copyright (C) 2002 Red Hat, Inc. */ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * MetaAccelLabel: GtkLabel with accelerator monitoring facilities. + * Copyright (C) 1998 Tim Janik + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the GTK+ Team and others 1997-2001. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +#ifndef __META_ACCEL_LABEL_H__ +#define __META_ACCEL_LABEL_H__ + +#include +#include "common.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define META_TYPE_ACCEL_LABEL (meta_accel_label_get_type ()) +#define META_ACCEL_LABEL(obj) (GTK_CHECK_CAST ((obj), META_TYPE_ACCEL_LABEL, MetaAccelLabel)) +#define META_ACCEL_LABEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), META_TYPE_ACCEL_LABEL, MetaAccelLabelClass)) +#define META_IS_ACCEL_LABEL(obj) (GTK_CHECK_TYPE ((obj), META_TYPE_ACCEL_LABEL)) +#define META_IS_ACCEL_LABEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), META_TYPE_ACCEL_LABEL)) +#define META_ACCEL_LABEL_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), META_TYPE_ACCEL_LABEL, MetaAccelLabelClass)) + + +typedef struct _MetaAccelLabel MetaAccelLabel; +typedef struct _MetaAccelLabelClass MetaAccelLabelClass; + +struct _MetaAccelLabel +{ + GtkLabel label; + + MetaVirtualModifier accel_mods; + guint accel_key; + guint accel_padding; + gchar *accel_string; + guint16 accel_string_width; +}; + +struct _MetaAccelLabelClass +{ + GtkLabelClass parent_class; + + gchar *signal_quote1; + gchar *signal_quote2; + gchar *mod_name_shift; + gchar *mod_name_control; + gchar *mod_name_alt; + gchar *mod_name_meta; + gchar *mod_name_super; + gchar *mod_name_hyper; + gchar *mod_name_mod2; + gchar *mod_name_mod3; + gchar *mod_name_mod4; + gchar *mod_name_mod5; + gchar *mod_separator; + gchar *accel_seperator; + guint latin1_to_char : 1; + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); +}; + +GtkType meta_accel_label_get_type (void) G_GNUC_CONST; +GtkWidget* meta_accel_label_new_with_mnemonic (const gchar *string); +void meta_accel_label_set_accelerator (MetaAccelLabel *accel_label, + guint accelerator_key, + MetaVirtualModifier accelerator_mods); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __META_ACCEL_LABEL_H__ */ diff --git a/src/prefs.c b/src/prefs.c index 7cccde038..afabef650 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -1188,3 +1188,25 @@ meta_prefs_get_keybinding_action (const char *name) return META_KEYBINDING_ACTION_NONE; } +void +meta_prefs_get_window_binding (const char *name, + unsigned int *keysym, + MetaVirtualModifier *modifiers) +{ + int i; + + i = G_N_ELEMENTS (window_bindings) - 2; /* -2 for dummy entry at end */ + while (i >= 0) + { + if (strcmp (window_bindings[i].name, name) == 0) + { + *keysym = window_bindings[i].keysym; + *modifiers = window_bindings[i].modifiers; + return; + } + + --i; + } + + g_assert_not_reached (); +} diff --git a/src/prefs.h b/src/prefs.h index 243e9cbef..8769bceea 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -187,6 +187,10 @@ void meta_prefs_get_window_bindings (const MetaKeyPref **bindings, MetaKeyBindingAction meta_prefs_get_keybinding_action (const char *name); +void meta_prefs_get_window_binding (const char *name, + unsigned int *keysym, + MetaVirtualModifier *modifiers); + #endif