2006-11-15 Björn Lindqvist <bjourne@gmail.com>

2006-11-15  Bruno Boaventura  <brunoboaventura@gmail.com>
2006-11-15  Björn Lindqvist   <bjourne@gmail.com>

        * src/menu.c: added MetaMenuItemType enum; added it
        to MenuItem; added values of this type to menuitems
        array.
        * src/menu.c (menu_item_new): rewrite to take a MenuItem
        instead of a set of parameters describing the menu item.
        * src/menu.c (meta_window_menu_new): use proper checkboxes
        or radio buttons on the window menu.
        * src/window.c (meta_window_show_menu): unstick and stick
        are always shown.
This commit is contained in:
Bruno Boaventura 2006-11-15 13:16:32 +00:00 committed by Thomas James Alexander Thurman
parent c065a5df5d
commit a3e309bab8
3 changed files with 127 additions and 92 deletions

View File

@ -1,3 +1,16 @@
2006-11-15 Bruno Boaventura <brunoboaventura@gmail.com>
2006-11-15 Björn Lindqvist <bjourne@gmail.com>
* src/menu.c: added MetaMenuItemType enum; added it
to MenuItem; added values of this type to menuitems
array.
* src/menu.c (menu_item_new): rewrite to take a MenuItem
instead of a set of parameters describing the menu item.
* src/menu.c (meta_window_menu_new): use proper checkboxes
or radio buttons on the window menu.
* src/window.c (meta_window_show_menu): unstick and stick
are always shown.
2006-11-06 Thomas Thurman <thomas@thurman.org.uk> 2006-11-06 Thomas Thurman <thomas@thurman.org.uk>
* configure.in: post-release bump to 2.17.3. * configure.in: post-release bump to 2.17.3.

View File

@ -32,13 +32,23 @@
#include "core.h" #include "core.h"
#include "themewidget.h" #include "themewidget.h"
#include "metaaccellabel.h" #include "metaaccellabel.h"
#include "window.h"
typedef struct _MenuItem MenuItem; typedef struct _MenuItem MenuItem;
typedef struct _MenuData MenuData; typedef struct _MenuData MenuData;
typedef enum
{
MENU_ITEM_SEPARATOR = 0,
MENU_ITEM_NORMAL,
MENU_ITEM_IMAGE,
MENU_ITEM_CHECKBOX,
} MetaMenuItemType;
struct _MenuItem struct _MenuItem
{ {
MetaMenuOp op; MetaMenuOp op;
MetaMenuItemType type;
const char *stock_id; const char *stock_id;
const gboolean checked; const gboolean checked;
const char *label; const char *label;
@ -55,41 +65,41 @@ static void activate_cb (GtkWidget *menuitem, gpointer data);
static MenuItem menuitems[] = { static MenuItem menuitems[] = {
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_MINIMIZE, METACITY_STOCK_MINIMIZE, FALSE, N_("Mi_nimize") }, { META_MENU_OP_MINIMIZE, MENU_ITEM_IMAGE, METACITY_STOCK_MINIMIZE, FALSE, N_("Mi_nimize") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_MAXIMIZE, METACITY_STOCK_MAXIMIZE, FALSE, N_("Ma_ximize") }, { META_MENU_OP_MAXIMIZE, MENU_ITEM_IMAGE, METACITY_STOCK_MAXIMIZE, FALSE, N_("Ma_ximize") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_UNMAXIMIZE, NULL, FALSE, N_("Unma_ximize") }, { META_MENU_OP_UNMAXIMIZE, MENU_ITEM_NORMAL, NULL, FALSE, N_("Unma_ximize") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_SHADE, NULL, FALSE, N_("Roll _Up") }, { META_MENU_OP_SHADE, MENU_ITEM_NORMAL, NULL, FALSE, N_("Roll _Up") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_UNSHADE, NULL, FALSE, N_("_Unroll") }, { META_MENU_OP_UNSHADE, MENU_ITEM_NORMAL, NULL, FALSE, N_("_Unroll") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_ABOVE, NULL, FALSE, N_("On _Top") }, { META_MENU_OP_ABOVE, MENU_ITEM_CHECKBOX, NULL, FALSE, N_("On _Top") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_UNABOVE, NULL, TRUE, N_("On _Top") }, { META_MENU_OP_UNABOVE, MENU_ITEM_CHECKBOX, NULL, TRUE, N_("On _Top") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_MOVE, NULL, FALSE, N_("_Move") }, { META_MENU_OP_MOVE, MENU_ITEM_NORMAL, NULL, FALSE, N_("_Move") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_RESIZE, NULL, FALSE, N_("_Resize") }, { META_MENU_OP_RESIZE, MENU_ITEM_NORMAL, NULL, FALSE, N_("_Resize") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_RECOVER, NULL, FALSE, N_("Move Titlebar On_screen") }, { META_MENU_OP_RECOVER, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move Titlebar On_screen") },
{ 0, NULL, FALSE, NULL }, /* separator */ { 0, MENU_ITEM_SEPARATOR, NULL, FALSE, NULL }, /* separator */
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_DELETE, METACITY_STOCK_DELETE, FALSE, N_("_Close") }, { META_MENU_OP_DELETE, MENU_ITEM_IMAGE, METACITY_STOCK_DELETE, FALSE, N_("_Close") },
{ META_MENU_OP_WORKSPACES, NULL, FALSE, NULL }, /* separator */ { META_MENU_OP_WORKSPACES, MENU_ITEM_SEPARATOR, NULL, FALSE, NULL }, /* separator */
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_STICK, NULL, FALSE, N_("_Always on Visible Workspace") }, { META_MENU_OP_STICK, MENU_ITEM_CHECKBOX, NULL, FALSE, N_("_Always on Visible Workspace") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_UNSTICK, NULL, FALSE, N_("_Only on This Workspace") }, { META_MENU_OP_UNSTICK, MENU_ITEM_CHECKBOX, NULL, FALSE, N_("_Only on This Workspace") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_MOVE_LEFT, NULL, FALSE, N_("Move to Workspace _Left") }, { META_MENU_OP_MOVE_LEFT, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Workspace _Left") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_MOVE_RIGHT, NULL, FALSE, N_("Move to Workspace R_ight") }, { META_MENU_OP_MOVE_RIGHT, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Workspace R_ight") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_MOVE_UP, NULL, FALSE, N_("Move to Workspace _Up") }, { META_MENU_OP_MOVE_UP, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Workspace _Up") },
/* Translators: Translate this string the same way as you do in libwnck! */ /* Translators: Translate this string the same way as you do in libwnck! */
{ META_MENU_OP_MOVE_DOWN, NULL, FALSE, N_("Move to Workspace _Down") } { META_MENU_OP_MOVE_DOWN, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Workspace _Down") }
}; };
static void static void
@ -97,7 +107,7 @@ popup_position_func (GtkMenu *menu,
gint *x, gint *x,
gint *y, gint *y,
gboolean *push_in, gboolean *push_in,
gpointer user_data) gpointer user_data)
{ {
GtkRequisition req; GtkRequisition req;
GdkPoint *pos; GdkPoint *pos;
@ -125,7 +135,7 @@ menu_closed (GtkMenu *widget,
meta_frames_notify_menu_hide (menu->frames); meta_frames_notify_menu_hide (menu->frames);
(* menu->func) (menu, gdk_display, (* menu->func) (menu, gdk_display,
menu->client_xwindow, menu->client_xwindow,
gtk_get_current_event_time (), gtk_get_current_event_time (),
0, 0, 0, 0,
menu->data); menu->data);
@ -144,7 +154,7 @@ activate_cb (GtkWidget *menuitem, gpointer data)
meta_frames_notify_menu_hide (md->menu->frames); meta_frames_notify_menu_hide (md->menu->frames);
(* md->menu->func) (md->menu, gdk_display, (* md->menu->func) (md->menu, gdk_display,
md->menu->client_xwindow, md->menu->client_xwindow,
gtk_get_current_event_time (), gtk_get_current_event_time (),
md->op, md->op,
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem),
"workspace")), "workspace")),
@ -239,36 +249,57 @@ get_workspace_name_with_accel (Display *display,
} }
} }
static GtkWidget* static GtkWidget *
menu_item_new (const char *label, menu_item_new (MenuItem *menuitem, int workspace_id)
gboolean with_image,
gboolean with_check,
unsigned int key,
MetaVirtualModifier mods)
{ {
GtkWidget *menu_item; unsigned int key;
MetaVirtualModifier mods;
const char *i18n_label;
GtkWidget *mi;
GtkWidget *accel_label; GtkWidget *accel_label;
if (with_check) if (menuitem->type == MENU_ITEM_NORMAL)
{ {
menu_item = gtk_check_menu_item_new (); mi = gtk_menu_item_new ();
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), }
TRUE); else if (menuitem->type == MENU_ITEM_IMAGE)
{
GtkWidget *image;
image = gtk_image_new_from_stock (menuitem->stock_id, GTK_ICON_SIZE_MENU);
mi = gtk_image_menu_item_new ();
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image);
gtk_widget_show (image);
}
else if (menuitem->type == MENU_ITEM_CHECKBOX)
{
mi = gtk_check_menu_item_new ();
if (menuitem->op == META_MENU_OP_STICK || menuitem->op == META_MENU_OP_UNSTICK)
{
gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (mi),
TRUE);
}
else
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), menuitem->checked);
} }
else if (with_image)
menu_item = gtk_image_menu_item_new ();
else else
menu_item = gtk_menu_item_new (); return gtk_separator_menu_item_new ();
accel_label = meta_accel_label_new_with_mnemonic (label);
i18n_label = _(menuitem->label);
meta_core_get_menu_accelerator (menuitem->op, workspace_id, &key, &mods);
accel_label = meta_accel_label_new_with_mnemonic (i18n_label);
gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5); gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (menu_item), accel_label); gtk_container_add (GTK_CONTAINER (mi), accel_label);
gtk_widget_show (accel_label); gtk_widget_show (accel_label);
meta_accel_label_set_accelerator (META_ACCEL_LABEL (accel_label), meta_accel_label_set_accelerator (META_ACCEL_LABEL (accel_label),
key, mods); key, mods);
return menu_item; return mi;
} }
MetaWindowMenu* MetaWindowMenu*
@ -301,58 +332,48 @@ meta_window_menu_new (MetaFrames *frames,
menu->menu = gtk_menu_new (); menu->menu = gtk_menu_new ();
gtk_menu_set_screen (GTK_MENU (menu->menu), gtk_menu_set_screen (GTK_MENU (menu->menu),
gtk_widget_get_screen (GTK_WIDGET (frames))); gtk_widget_get_screen (GTK_WIDGET (frames)));
i = 0; for (i = 0; i < (int) G_N_ELEMENTS (menuitems); i++)
while (i < (int) G_N_ELEMENTS (menuitems))
{ {
if (ops & menuitems[i].op || menuitems[i].op == 0) MenuItem menuitem = menuitems[i];
if (ops & menuitem.op || menuitem.op == 0)
{ {
GtkWidget *mi; GtkWidget *mi;
MenuData *md; MenuData *md;
unsigned int key; unsigned int key;
MetaVirtualModifier mods; MetaVirtualModifier mods;
if (menuitems[i].label == NULL) mi = menu_item_new (&menuitem, -1);
if (menuitem.op == META_MENU_OP_STICK || menuitem.op == META_MENU_OP_UNSTICK)
{ {
mi = gtk_separator_menu_item_new (); Display *xdisplay;
MetaDisplay *display;
MetaWindow *window;
xdisplay = gdk_x11_drawable_get_xdisplay (GTK_WIDGET (frames)->window);
display = meta_display_for_x_display (xdisplay);
window = meta_display_lookup_x_window (display, client_xwindow);
if (menuitem.op == META_MENU_OP_STICK)
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), window->on_all_workspaces);
else
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), !window->on_all_workspaces);
} }
else
if (menuitem.type != MENU_ITEM_SEPARATOR)
{ {
GtkWidget *image;
image = NULL;
if (menuitems[i].stock_id)
{
image = gtk_image_new_from_stock (menuitems[i].stock_id,
GTK_ICON_SIZE_MENU);
}
meta_core_get_menu_accelerator (menuitems[i].op, -1, meta_core_get_menu_accelerator (menuitems[i].op, -1,
&key, &mods); &key, &mods);
if (image) if (insensitive & menuitem.op)
{
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,
menuitems[i].checked, key, mods);
}
if (insensitive & menuitems[i].op)
gtk_widget_set_sensitive (mi, FALSE); gtk_widget_set_sensitive (mi, FALSE);
md = g_new (MenuData, 1); md = g_new (MenuData, 1);
md->menu = menu; md->menu = menu;
md->op = menuitems[i].op; md->op = menuitem.op;
gtk_signal_connect_full (GTK_OBJECT (mi), gtk_signal_connect_full (GTK_OBJECT (mi),
"activate", "activate",
@ -362,24 +383,26 @@ meta_window_menu_new (MetaFrames *frames,
g_free, FALSE, FALSE); g_free, FALSE, FALSE);
} }
gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), mi);
mi);
gtk_widget_show (mi); gtk_widget_show (mi);
} }
++i;
} }
if (ops & META_MENU_OP_WORKSPACES) if (ops & META_MENU_OP_WORKSPACES)
{ {
GtkWidget *mi;
Display *display; Display *display;
Window xroot; Window xroot;
GdkScreen *screen; GdkScreen *screen;
GtkWidget *submenu; GtkWidget *submenu;
GtkWidget *submenuitem; GtkWidget *submenuitem;
MenuItem to_another_workspace = {
0, MENU_ITEM_NORMAL,
NULL, FALSE,
N_("Move to Another _Workspace")
};
meta_verbose ("Creating %d-workspace menu current space %d\n", meta_verbose ("Creating %d-workspace menu current space %d\n",
n_workspaces, active_workspace); n_workspaces, active_workspace);
@ -389,26 +412,30 @@ meta_window_menu_new (MetaFrames *frames,
xroot = GDK_DRAWABLE_XID (gdk_screen_get_root_window (screen)); xroot = GDK_DRAWABLE_XID (gdk_screen_get_root_window (screen));
submenu = gtk_menu_new (); submenu = gtk_menu_new ();
submenuitem = menu_item_new (_("Move to Another _Workspace"), FALSE, FALSE, 0, 0); submenuitem = menu_item_new (&to_another_workspace, -1);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenuitem), submenu); gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenuitem), submenu);
gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), submenuitem);
submenuitem);
gtk_widget_show (submenuitem); gtk_widget_show (submenuitem);
i = 0; for (i = 0; i < n_workspaces; i++)
while (i < n_workspaces)
{ {
char *label; char *label;
MenuData *md; MenuData *md;
unsigned int key; unsigned int key;
MetaVirtualModifier mods; MetaVirtualModifier mods;
MenuItem moveitem;
GtkWidget *mi;
meta_core_get_menu_accelerator (META_MENU_OP_WORKSPACES, meta_core_get_menu_accelerator (META_MENU_OP_WORKSPACES,
i + 1, i + 1,
&key, &mods); &key, &mods);
label = get_workspace_name_with_accel (display, xroot, i); label = get_workspace_name_with_accel (display, xroot, i);
mi = menu_item_new (label, FALSE, FALSE, key, mods);
moveitem.type = MENU_ITEM_NORMAL;
moveitem.op = META_MENU_OP_WORKSPACES;
moveitem.label = label;
mi = menu_item_new (&moveitem, i + 1);
g_free (label); g_free (label);
@ -434,12 +461,9 @@ meta_window_menu_new (MetaFrames *frames,
md, md,
g_free, FALSE, FALSE); g_free, FALSE, FALSE);
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
mi);
gtk_widget_show (mi); gtk_widget_show (mi);
++i;
} }
} }
else else

View File

@ -6359,9 +6359,7 @@ meta_window_show_menu (MetaWindow *window,
ops |= META_MENU_OP_SHADE; ops |= META_MENU_OP_SHADE;
#endif #endif
if (window->on_all_workspaces)
ops |= META_MENU_OP_UNSTICK; ops |= META_MENU_OP_UNSTICK;
else
ops |= META_MENU_OP_STICK; ops |= META_MENU_OP_STICK;
if (window->wm_state_above) if (window->wm_state_above)