summaryrefslogtreecommitdiff
path: root/src/menu.c
diff options
context:
space:
mode:
authorRob Adams <readams@readams.net>2003-12-21 06:31:40 +0000
committerRob Adams <readams@src.gnome.org>2003-12-21 06:31:40 +0000
commit690100f1ad494022dbecb0730e63f9a250d032f4 (patch)
treed9fe8f63c035cc3b118c9f575369bbd5e22394c8 /src/menu.c
parent95b0ee480e2e7d6e6029dd9382076c2adcb6ebd9 (diff)
downloadmetacity-690100f1ad494022dbecb0730e63f9a250d032f4.tar.gz
Reorganize the window menu according to discussion on #110904. The
2003-12-20 Rob Adams <readams@readams.net> Reorganize the window menu according to discussion on #110904. The workspace name mnemonic chunk of the patch is thanks to Jonathan Blandford. * src/common.h: add MENU_OP_ABOVE, MENU_OP_UNABOVE, MENU_UP_MOVE_TO_* menu ops. * src/core.c (meta_core_get_menu_accelerator): add accelerator for the new menu ops. * src/menu.c: add checked attribute in _MenuItem struct to display a checkmark next to a menu item. Add the new menu items to menuitems. (get_workspace_name_with_accel): Add mnemonics even to renamed workspaces. (menu_item_new): provide support for the checked attribute (meta_window_menu_new): construct new submenu for workspace switching. * src/window.c (menu_callback): implement support for the new menu ops. (meta_window_show_menu): don't use the OP_*SHAPE operations, and compute which of the OP_MOVE_TO_* ops should be used for the current workspace and workspace layout. Add the OP_*ABOVE operations.
Diffstat (limited to 'src/menu.c')
-rw-r--r--src/menu.c101
1 files changed, 67 insertions, 34 deletions
diff --git a/src/menu.c b/src/menu.c
index 4ffc5e76..958bbe2e 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -36,6 +36,7 @@ struct _MenuItem
{
MetaMenuOp op;
const char *stock_id;
+ const gboolean checked;
const char *label;
};
@@ -49,18 +50,24 @@ struct _MenuData
static void activate_cb (GtkWidget *menuitem, gpointer data);
static MenuItem menuitems[] = {
- { META_MENU_OP_MINIMIZE, METACITY_STOCK_MINIMIZE, N_("Mi_nimize") },
- { META_MENU_OP_MAXIMIZE, METACITY_STOCK_MAXIMIZE, N_("Ma_ximize") },
- { META_MENU_OP_UNMAXIMIZE, NULL, N_("Unma_ximize") },
- { META_MENU_OP_SHADE, NULL, N_("Roll _Up") },
- { META_MENU_OP_UNSHADE, NULL, N_("_Unroll") },
- { META_MENU_OP_MOVE, NULL, N_("_Move") },
- { META_MENU_OP_RESIZE, NULL, N_("_Resize") },
- { 0, NULL, NULL }, /* separator */
- { META_MENU_OP_DELETE, METACITY_STOCK_DELETE, N_("_Close") },
- { 0, NULL, NULL }, /* separator */
- { META_MENU_OP_STICK, NULL, N_("Put on _All Workspaces") },
- { META_MENU_OP_UNSTICK, NULL, N_("Only on _This Workspace") }
+ { META_MENU_OP_MINIMIZE, METACITY_STOCK_MINIMIZE, FALSE, N_("Mi_nimize") },
+ { META_MENU_OP_MAXIMIZE, METACITY_STOCK_MAXIMIZE, FALSE, N_("Ma_ximize") },
+ { META_MENU_OP_UNMAXIMIZE, NULL, FALSE, N_("Unma_ximize") },
+ { META_MENU_OP_SHADE, NULL, FALSE, N_("Roll _Up") },
+ { META_MENU_OP_UNSHADE, NULL, FALSE, N_("_Unroll") },
+ { META_MENU_OP_ABOVE, NULL, FALSE, N_("On _Top") },
+ { META_MENU_OP_UNABOVE, NULL, TRUE, N_("On _Top") },
+ { META_MENU_OP_MOVE, NULL, FALSE, N_("_Move") },
+ { META_MENU_OP_RESIZE, NULL, FALSE, N_("_Resize") },
+ { 0, NULL, FALSE, NULL }, /* separator */
+ { META_MENU_OP_DELETE, METACITY_STOCK_DELETE, FALSE, N_("_Close") },
+ { 0, NULL, FALSE, NULL }, /* separator */
+ { META_MENU_OP_STICK, NULL, FALSE, N_("Put on _All Workspaces") },
+ { META_MENU_OP_UNSTICK, NULL, FALSE, N_("Only on _This Workspace") },
+ { META_MENU_OP_MOVE_LEFT, NULL, FALSE, N_("Move to Workspace _Left") },
+ { META_MENU_OP_MOVE_RIGHT, NULL, FALSE, N_("Move to Workspace R_ight") },
+ { META_MENU_OP_MOVE_UP, NULL, FALSE, N_("Move to Workspace _Up") },
+ { META_MENU_OP_MOVE_DOWN, NULL, FALSE, N_("Move to Workspace _Down") }
};
static void
@@ -157,26 +164,30 @@ get_workspace_name_with_accel (Display *display,
* Above name is a pointer into the Workspace struct. Here we make
* a copy copy so we can have our wicked way with it.
*/
- new_name = g_strdup_printf (_("Workspace %s%d"),
- number < 10 ? "_" : "",
- number);
+ if (number == 10)
+ new_name = g_strdup_printf (_("Workspace 1_0"));
+ else
+ new_name = g_strdup_printf (_("Workspace %s%d"),
+ number < 10 ? "_" : "",
+ number);
return new_name;
}
else
{
/*
- * Otherwise this is just a normal name to which we cannot really
- * add accelerators. Escape any _ characters so that the user's
- * workspace names do not get mangled.
+ * Otherwise this is just a normal name. Escape any _ characters so that
+ * the user's workspace names do not get mangled. If the number is less
+ * than 10 we provide an accelerator.
*/
char *new_name;
const char *source;
char *dest;
/*
- * Assume the worst case, that every character is a _
+ * Assume the worst case, that every character is a _. We also
+ * provide memory for " (_#)"
*/
- new_name = g_malloc0 (strlen (name) * 2 + 1);
+ new_name = g_malloc0 (strlen (name) * 2 + 6 + 1);
/*
* Now iterate down the strings, adding '_' to escape as we go
@@ -190,6 +201,16 @@ get_workspace_name_with_accel (Display *display,
*dest++ = *source++;
}
+ /* People don't start at workstation 0, but workstation 1 */
+ if (index < 9)
+ {
+ g_snprintf (dest, 6, " (_%d)", index + 1);
+ }
+ else if (index == 9)
+ {
+ g_snprintf (dest, 6, " (_0)");
+ }
+
return new_name;
}
}
@@ -197,13 +218,20 @@ get_workspace_name_with_accel (Display *display,
static GtkWidget*
menu_item_new (const char *label,
gboolean with_image,
+ gboolean with_check,
unsigned int key,
MetaVirtualModifier mods)
{
GtkWidget *menu_item;
GtkWidget *accel_label;
- if (with_image)
+ if (with_check)
+ {
+ menu_item = gtk_check_menu_item_new ();
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
+ TRUE);
+ }
+ else if (with_image)
menu_item = gtk_image_menu_item_new ();
else
menu_item = gtk_menu_item_new ();
@@ -277,17 +305,18 @@ meta_window_menu_new (MetaFrames *frames,
meta_core_get_menu_accelerator (menuitems[i].op, -1,
&key, &mods);
-
+
if (image)
{
- mi = menu_item_new (_(menuitems[i].label), TRUE, key, mods);
+ mi = menu_item_new (_(menuitems[i].label), TRUE, FALSE, key, mods);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
image);
gtk_widget_show (image);
}
else
{
- mi = menu_item_new (_(menuitems[i].label), FALSE, key, mods);
+ mi = menu_item_new (_(menuitems[i].label), FALSE,
+ menuitems[i].checked, key, mods);
}
if (insensitive & menuitems[i].op)
@@ -321,6 +350,8 @@ meta_window_menu_new (MetaFrames *frames,
Display *display;
Window xroot;
GdkScreen *screen;
+ GtkWidget *submenu;
+ GtkWidget *submenuitem;
meta_verbose ("Creating %d-workspace menu current space %d\n",
n_workspaces, active_workspace);
@@ -329,11 +360,18 @@ meta_window_menu_new (MetaFrames *frames,
screen = gdk_drawable_get_screen (GTK_WIDGET (frames)->window);
xroot = GDK_DRAWABLE_XID (gdk_screen_get_root_window (screen));
-
+
+ submenu = gtk_menu_new ();
+ submenuitem = menu_item_new (N_("Move to Another _Workspace"), FALSE, FALSE, 0, 0);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenuitem), submenu);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu),
+ submenuitem);
+ gtk_widget_show (submenuitem);
+
i = 0;
while (i < n_workspaces)
{
- char *label, *name;
+ char *label;
MenuData *md;
unsigned int key;
MetaVirtualModifier mods;
@@ -342,14 +380,9 @@ meta_window_menu_new (MetaFrames *frames,
i + 1,
&key, &mods);
- name = get_workspace_name_with_accel (display, xroot, 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 = menu_item_new (label, FALSE, key, mods);
+ label = get_workspace_name_with_accel (display, xroot, i);
+ mi = menu_item_new (label, FALSE, FALSE, key, mods);
- g_free (name);
g_free (label);
if (!(ops & META_MENU_OP_UNSTICK) &&
@@ -374,7 +407,7 @@ meta_window_menu_new (MetaFrames *frames,
md,
g_free, FALSE, FALSE);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu),
+ gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
mi);
gtk_widget_show (mi);