diff --git a/src/Makefile.am b/src/Makefile.am index e2b342e65..5e6b710f4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -191,10 +191,6 @@ libmutter_la_SOURCES = \ ui/ui.h \ ui/frames.c \ ui/frames.h \ - ui/menu.c \ - ui/menu.h \ - ui/metaaccellabel.c \ - ui/metaaccellabel.h \ ui/resizepopup.c \ ui/resizepopup.h \ ui/theme-parser.c \ diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c index e5e7756e6..b5e3b8c1e 100644 --- a/src/compositor/compositor.c +++ b/src/compositor/compositor.c @@ -1356,3 +1356,10 @@ meta_compositor_hide_tile_preview (MetaCompositor *compositor) { meta_plugin_manager_hide_tile_preview (compositor->plugin_mgr); } + +void +meta_compositor_show_window_menu (MetaCompositor *compositor, + MetaWindow *window) +{ + meta_plugin_manager_show_window_menu (compositor->plugin_mgr, window); +} diff --git a/src/compositor/meta-plugin-manager.c b/src/compositor/meta-plugin-manager.c index 8987e219d..076f31583 100644 --- a/src/compositor/meta-plugin-manager.c +++ b/src/compositor/meta-plugin-manager.c @@ -356,3 +356,18 @@ meta_plugin_manager_hide_tile_preview (MetaPluginManager *plugin_mgr) return FALSE; } + +void +meta_plugin_manager_show_window_menu (MetaPluginManager *plugin_mgr, + MetaWindow *window) +{ + MetaPlugin *plugin = plugin_mgr->plugin; + MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin); + MetaDisplay *display = plugin_mgr->compositor->display; + + if (display->display_opening) + return; + + if (klass->show_window_menu) + klass->show_window_menu (plugin, window); +} diff --git a/src/compositor/meta-plugin-manager.h b/src/compositor/meta-plugin-manager.h index d814ee677..224f353e5 100644 --- a/src/compositor/meta-plugin-manager.h +++ b/src/compositor/meta-plugin-manager.h @@ -80,4 +80,8 @@ gboolean meta_plugin_manager_show_tile_preview (MetaPluginManager *mgr, MetaRectangle *tile_rect, int tile_monitor_number); gboolean meta_plugin_manager_hide_tile_preview (MetaPluginManager *mgr); + +void meta_plugin_manager_show_window_menu (MetaPluginManager *mgr, + MetaWindow *window); + #endif diff --git a/src/core/core.c b/src/core/core.c index 303cd1ec0..e42947eb3 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -398,9 +398,6 @@ meta_core_change_workspace (Display *xdisplay, void meta_core_show_window_menu (Display *xdisplay, Window frame_xwindow, - int root_x, - int root_y, - int button, guint32 timestamp) { MetaWindow *window = get_window (xdisplay, frame_xwindow); @@ -409,121 +406,7 @@ meta_core_show_window_menu (Display *xdisplay, meta_window_raise (window); meta_window_focus (window, timestamp); - 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_NONE: - /* No keybinding for this one */ - break; - case META_MENU_OP_DELETE: - name = "close"; - break; - case META_MENU_OP_MINIMIZE: - name = "minimize"; - break; - case META_MENU_OP_UNMAXIMIZE: - name = "unmaximize"; - break; - case META_MENU_OP_MAXIMIZE: - name = "maximize"; - break; - case META_MENU_OP_UNSHADE: - case META_MENU_OP_SHADE: - name = "toggle_shaded"; - break; - case META_MENU_OP_UNSTICK: - case META_MENU_OP_STICK: - name = "toggle-on-all-workspaces"; - break; - case META_MENU_OP_ABOVE: - case META_MENU_OP_UNABOVE: - name = "toggle-above"; - break; - case META_MENU_OP_WORKSPACES: - switch (workspace) - { - case 1: - name = "move-to-workspace-1"; - break; - case 2: - name = "move-to-workspace-2"; - break; - case 3: - name = "move-to-workspace-3"; - break; - case 4: - name = "move-to-workspace-4"; - break; - case 5: - name = "move-to-workspace-5"; - break; - case 6: - name = "move-to-workspace-6"; - break; - case 7: - name = "move-to-workspace-7"; - break; - case 8: - name = "move-to-workspace-8"; - break; - case 9: - name = "move-to-workspace-9"; - break; - case 10: - name = "move-to-workspace-10"; - break; - case 11: - name = "move-to-workspace-11"; - break; - case 12: - name = "move-to-workspace-12"; - break; - } - break; - case META_MENU_OP_MOVE: - name = "begin-move"; - break; - case META_MENU_OP_RESIZE: - name = "begin-resize"; - break; - case META_MENU_OP_MOVE_LEFT: - name = "move-to-workspace-left"; - break; - case META_MENU_OP_MOVE_RIGHT: - name = "move-to-workspace-right"; - break; - case META_MENU_OP_MOVE_UP: - name = "move-to-workspace-up"; - break; - case META_MENU_OP_MOVE_DOWN: - name = "move-to-workspace-down"; - break; - case META_MENU_OP_RECOVER: - /* No keybinding for this one */ - break; - } - - if (name) - { - meta_prefs_get_window_binding (name, keysym, modifiers); - } - else - { - *keysym = 0; - *modifiers = 0; - } + meta_window_show_menu (window); } const char* diff --git a/src/core/core.h b/src/core/core.h index cd08233ff..97a48815a 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -142,15 +142,8 @@ const char* meta_core_get_workspace_name_with_index (Display *xdisplay, void meta_core_show_window_menu (Display *xdisplay, Window frame_xwindow, - int root_x, - int root_y, - int button, guint32 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, diff --git a/src/core/display-private.h b/src/core/display-private.h index 451f94ae9..b63ca0da9 100644 --- a/src/core/display-private.h +++ b/src/core/display-private.h @@ -247,10 +247,6 @@ struct _MetaDisplay /* Managed by group.c */ GHashTable *groups_by_leader; - /* currently-active window menu if any */ - MetaWindowMenu *window_menu; - MetaWindow *window_with_menu; - /* Managed by window-props.c */ MetaWindowPropHooks *prop_hooks_table; GHashTable *prop_hooks; diff --git a/src/core/display.c b/src/core/display.c index f740779f7..193567274 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -518,9 +518,6 @@ meta_display_open (void) the_display->groups_by_leader = NULL; - the_display->window_with_menu = NULL; - the_display->window_menu = NULL; - the_display->screen = NULL; #ifdef HAVE_STARTUP_NOTIFICATION diff --git a/src/core/keybindings.c b/src/core/keybindings.c index abf5cd815..01d310af7 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -2732,20 +2732,7 @@ handle_activate_window_menu (MetaDisplay *display, gpointer dummy) { if (display->focus_window) - { - int x, y; - - meta_window_get_position (display->focus_window, - &x, &y); - - if (meta_ui_get_direction() == META_UI_DIRECTION_RTL) - x += display->focus_window->rect.width; - - meta_window_show_menu (display->focus_window, - x, y, - 0, - event->time); - } + meta_window_show_menu (display->focus_window); } static void diff --git a/src/core/prefs.c b/src/core/prefs.c index ac761305a..4847de6be 100644 --- a/src/core/prefs.c +++ b/src/core/prefs.c @@ -2262,43 +2262,6 @@ meta_prefs_get_keybinding_action (const char *name) : META_KEYBINDING_ACTION_NONE; } -/* This is used by the menu system to decide what key binding - * to display next to an option. We return the first non-disabled - * binding, if any. - */ -void -meta_prefs_get_window_binding (const char *name, - unsigned int *keysym, - MetaVirtualModifier *modifiers) -{ - MetaKeyPref *pref = g_hash_table_lookup (key_bindings, name); - - if (pref->per_window) - { - GSList *s = pref->combos; - - while (s) - { - MetaKeyCombo *c = s->data; - - if (c->keysym != 0 || c->modifiers != 0) - { - *keysym = c->keysym; - *modifiers = c->modifiers; - return; - } - - s = s->next; - } - - /* Not found; return the disabled value */ - *keysym = *modifiers = 0; - return; - } - - g_assert_not_reached (); -} - gint meta_prefs_get_mouse_button_resize (void) { diff --git a/src/core/window-private.h b/src/core/window-private.h index 77b8c3998..d6c82a6f4 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -622,11 +622,7 @@ void meta_window_set_current_workspace_hint (MetaWindow *window); unsigned long meta_window_get_net_wm_desktop (MetaWindow *window); -void meta_window_show_menu (MetaWindow *window, - int root_x, - int root_y, - int button, - guint32 timestamp); +void meta_window_show_menu (MetaWindow *window); gboolean meta_window_handle_mouse_grab_op_event (MetaWindow *window, const ClutterEvent *event); diff --git a/src/core/window.c b/src/core/window.c index 5ead25358..47b9ceb4f 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -1305,13 +1305,6 @@ meta_window_unmanage (MetaWindow *window, meta_compositor_remove_window (window->display->compositor, window); window->known_to_compositor = FALSE; - if (window->display->window_with_menu == window) - { - meta_ui_window_menu_free (window->display->window_menu); - window->display->window_menu = NULL; - window->display->window_with_menu = NULL; - } - if (destroying_windows_disallowed > 0) meta_bug ("Tried to destroy window %s while destruction was not allowed\n", window->desc); @@ -5495,268 +5488,11 @@ meta_window_recalc_features (MetaWindow *window) */ } -static void -menu_callback (MetaWindowMenu *menu, - Display *xdisplay, - Window client_xwindow, - guint32 timestamp, - MetaMenuOp op, - int workspace_index, - gpointer data) -{ - MetaDisplay *display; - MetaWindow *window; - MetaWorkspace *workspace; - - display = meta_display_for_x_display (xdisplay); - window = meta_display_lookup_x_window (display, client_xwindow); - workspace = NULL; - - if (window != NULL) /* window can be NULL */ - { - meta_verbose ("Menu op %u on %s\n", op, window->desc); - - switch (op) - { - case META_MENU_OP_NONE: - /* nothing */ - break; - - case META_MENU_OP_DELETE: - meta_window_delete (window, timestamp); - break; - - case META_MENU_OP_MINIMIZE: - meta_window_minimize (window); - break; - - case META_MENU_OP_UNMAXIMIZE: - meta_window_unmaximize (window, META_MAXIMIZE_BOTH); - break; - - case META_MENU_OP_MAXIMIZE: - meta_window_maximize (window, META_MAXIMIZE_BOTH); - break; - - case META_MENU_OP_UNSHADE: - meta_window_unshade (window, timestamp); - break; - - case META_MENU_OP_SHADE: - meta_window_shade (window, timestamp); - break; - - case META_MENU_OP_MOVE_LEFT: - workspace = meta_workspace_get_neighbor (window->screen->active_workspace, - META_MOTION_LEFT); - break; - - case META_MENU_OP_MOVE_RIGHT: - workspace = meta_workspace_get_neighbor (window->screen->active_workspace, - META_MOTION_RIGHT); - break; - - case META_MENU_OP_MOVE_UP: - workspace = meta_workspace_get_neighbor (window->screen->active_workspace, - META_MOTION_UP); - break; - - case META_MENU_OP_MOVE_DOWN: - workspace = meta_workspace_get_neighbor (window->screen->active_workspace, - META_MOTION_DOWN); - break; - - case META_MENU_OP_WORKSPACES: - workspace = meta_screen_get_workspace_by_index (window->screen, - workspace_index); - break; - - case META_MENU_OP_STICK: - meta_window_stick (window); - break; - - case META_MENU_OP_UNSTICK: - meta_window_unstick (window); - break; - - case META_MENU_OP_ABOVE: - case META_MENU_OP_UNABOVE: - if (window->wm_state_above == FALSE) - meta_window_make_above (window); - else - meta_window_unmake_above (window); - break; - - case META_MENU_OP_MOVE: - meta_window_begin_grab_op (window, - META_GRAB_OP_KEYBOARD_MOVING, - FALSE, - timestamp); - break; - - case META_MENU_OP_RESIZE: - meta_window_begin_grab_op (window, - META_GRAB_OP_KEYBOARD_RESIZING_UNKNOWN, - FALSE, - timestamp); - break; - - case META_MENU_OP_RECOVER: - meta_window_shove_titlebar_onscreen (window); - break; - - default: - meta_warning (G_STRLOC": Unknown window op\n"); - break; - } - - if (workspace) - { - meta_window_change_workspace (window, - workspace); - } - } - else - { - meta_verbose ("Menu callback on nonexistent window\n"); - } - - if (display->window_menu == menu) - { - display->window_menu = NULL; - display->window_with_menu = NULL; - } - - meta_ui_window_menu_free (menu); -} - void -meta_window_show_menu (MetaWindow *window, - int root_x, - int root_y, - int button, - guint32 timestamp) +meta_window_show_menu (MetaWindow *window) { - MetaMenuOp ops; - MetaMenuOp insensitive; - MetaWindowMenu *menu; - MetaWorkspaceLayout layout; - int n_workspaces; - gboolean ltr; - g_return_if_fail (!window->override_redirect); - - if (window->display->window_menu) - { - meta_ui_window_menu_free (window->display->window_menu); - window->display->window_menu = NULL; - window->display->window_with_menu = NULL; - } - - ops = META_MENU_OP_NONE; - insensitive = META_MENU_OP_NONE; - - ops |= (META_MENU_OP_DELETE | META_MENU_OP_MINIMIZE | META_MENU_OP_MOVE | META_MENU_OP_RESIZE); - - if (!meta_window_titlebar_is_onscreen (window) && - window->type != META_WINDOW_DOCK && - window->type != META_WINDOW_DESKTOP) - ops |= META_MENU_OP_RECOVER; - - if (!meta_prefs_get_workspaces_only_on_primary () || - meta_window_is_on_primary_monitor (window)) - { - n_workspaces = meta_screen_get_n_workspaces (window->screen); - - if (n_workspaces > 1) - ops |= META_MENU_OP_WORKSPACES; - - meta_screen_calc_workspace_layout (window->screen, - n_workspaces, - meta_workspace_index ( window->screen->active_workspace), - &layout); - - if (!window->on_all_workspaces) - { - ltr = meta_ui_get_direction() == META_UI_DIRECTION_LTR; - - if (layout.current_col > 0) - ops |= ltr ? META_MENU_OP_MOVE_LEFT : META_MENU_OP_MOVE_RIGHT; - if ((layout.current_col < layout.cols - 1) && - (layout.current_row * layout.cols + (layout.current_col + 1) < n_workspaces)) - ops |= ltr ? META_MENU_OP_MOVE_RIGHT : META_MENU_OP_MOVE_LEFT; - if (layout.current_row > 0) - ops |= META_MENU_OP_MOVE_UP; - if ((layout.current_row < layout.rows - 1) && - ((layout.current_row + 1) * layout.cols + layout.current_col < n_workspaces)) - ops |= META_MENU_OP_MOVE_DOWN; - } - - meta_screen_free_workspace_layout (&layout); - - ops |= META_MENU_OP_UNSTICK; - ops |= META_MENU_OP_STICK; - } - - if (META_WINDOW_MAXIMIZED (window)) - ops |= META_MENU_OP_UNMAXIMIZE; - else - ops |= META_MENU_OP_MAXIMIZE; - - if (window->wm_state_above) - ops |= META_MENU_OP_UNABOVE; - else - ops |= META_MENU_OP_ABOVE; - - if (!window->has_maximize_func) - insensitive |= META_MENU_OP_UNMAXIMIZE | META_MENU_OP_MAXIMIZE; - - if (!window->has_minimize_func) - insensitive |= META_MENU_OP_MINIMIZE; - - if (!window->has_close_func) - insensitive |= META_MENU_OP_DELETE; - - if (!window->has_shade_func) - insensitive |= META_MENU_OP_SHADE | META_MENU_OP_UNSHADE; - - if (!META_WINDOW_ALLOWS_MOVE (window)) - insensitive |= META_MENU_OP_MOVE; - - if (!META_WINDOW_ALLOWS_RESIZE (window)) - insensitive |= META_MENU_OP_RESIZE; - - if (window->always_sticky) - insensitive |= META_MENU_OP_STICK | META_MENU_OP_UNSTICK | META_MENU_OP_WORKSPACES; - - if ((window->type == META_WINDOW_DESKTOP) || - (window->type == META_WINDOW_DOCK) || - (window->type == META_WINDOW_SPLASHSCREEN || - META_WINDOW_MAXIMIZED (window))) - insensitive |= META_MENU_OP_ABOVE | META_MENU_OP_UNABOVE; - - /* If all operations are disabled, just quit without showing the menu. - * This is the case, for example, with META_WINDOW_DESKTOP windows. - */ - if ((ops & ~insensitive) == 0) - return; - - menu = - meta_ui_window_menu_new (window->screen->ui, - window->xwindow, - ops, - insensitive, - meta_window_get_net_wm_desktop (window), - meta_screen_get_n_workspaces (window->screen), - menu_callback, - NULL); - - window->display->window_menu = menu; - window->display->window_with_menu = window; - - meta_verbose ("Popping up window menu for %s\n", window->desc); - - meta_ui_window_menu_popup (menu, root_x, root_y, button, timestamp); + meta_compositor_show_window_menu (window->display->compositor, window); } void @@ -8373,11 +8109,7 @@ meta_window_handle_ungrabbed_event (MetaWindow *window, { if (meta_prefs_get_raise_on_click ()) meta_window_raise (window); - meta_window_show_menu (window, - event->button.x, - event->button.y, - event->button.button, - event->any.time); + meta_window_show_menu (window); return TRUE; } else if (fully_modified && (int) event->button.button == 1) diff --git a/src/meta/common.h b/src/meta/common.h index 0b58678e4..bbfa77e5f 100644 --- a/src/meta/common.h +++ b/src/meta/common.h @@ -86,61 +86,6 @@ typedef enum META_FRAME_TILED_RIGHT = 1 << 16 } MetaFrameFlags; -/** - * MetaMenuOp: - * @META_MENU_OP_NONE: No menu operation - * @META_MENU_OP_DELETE: Menu operation delete - * @META_MENU_OP_MINIMIZE: Menu operation minimize - * @META_MENU_OP_UNMAXIMIZE: Menu operation unmaximize - * @META_MENU_OP_MAXIMIZE: Menu operation maximize - * @META_MENU_OP_UNSHADE: Menu operation unshade - * @META_MENU_OP_SHADE: Menu operation shade - * @META_MENU_OP_UNSTICK: Menu operation unstick - * @META_MENU_OP_STICK: Menu operation stick - * @META_MENU_OP_WORKSPACES: Menu operation workspaces - * @META_MENU_OP_MOVE: Menu operation move - * @META_MENU_OP_RESIZE: Menu operation resize - * @META_MENU_OP_ABOVE: Menu operation above - * @META_MENU_OP_UNABOVE: Menu operation unabove - * @META_MENU_OP_MOVE_LEFT: Menu operation left - * @META_MENU_OP_MOVE_RIGHT: Menu operation right - * @META_MENU_OP_MOVE_UP: Menu operation up - * @META_MENU_OP_MOVE_DOWN: Menu operation down - * @META_MENU_OP_RECOVER: Menu operation recover - */ -typedef enum -{ - META_MENU_OP_NONE = 0, - META_MENU_OP_DELETE = 1 << 0, - META_MENU_OP_MINIMIZE = 1 << 1, - META_MENU_OP_UNMAXIMIZE = 1 << 2, - META_MENU_OP_MAXIMIZE = 1 << 3, - META_MENU_OP_UNSHADE = 1 << 4, - META_MENU_OP_SHADE = 1 << 5, - META_MENU_OP_UNSTICK = 1 << 6, - META_MENU_OP_STICK = 1 << 7, - META_MENU_OP_WORKSPACES = 1 << 8, - META_MENU_OP_MOVE = 1 << 9, - META_MENU_OP_RESIZE = 1 << 10, - META_MENU_OP_ABOVE = 1 << 11, - META_MENU_OP_UNABOVE = 1 << 12, - META_MENU_OP_MOVE_LEFT = 1 << 13, - META_MENU_OP_MOVE_RIGHT = 1 << 14, - META_MENU_OP_MOVE_UP = 1 << 15, - META_MENU_OP_MOVE_DOWN = 1 << 16, - META_MENU_OP_RECOVER = 1 << 17 -} MetaMenuOp; - -typedef struct _MetaWindowMenu MetaWindowMenu; - -typedef void (* MetaWindowMenuFunc) (MetaWindowMenu *menu, - Display *xdisplay, - Window client_xwindow, - guint32 timestamp, - MetaMenuOp op, - int workspace, - gpointer user_data); - /** * MetaGrabOp: * @META_GRAB_OP_NONE: None diff --git a/src/meta/compositor.h b/src/meta/compositor.h index 57be80afd..b5d7a5428 100644 --- a/src/meta/compositor.h +++ b/src/meta/compositor.h @@ -122,5 +122,7 @@ void meta_compositor_show_tile_preview (MetaCompositor *compositor, MetaRectangle *tile_rect, int tile_monitor_number); void meta_compositor_hide_tile_preview (MetaCompositor *compositor); +void meta_compositor_show_window_menu (MetaCompositor *compositor, + MetaWindow *window); #endif /* META_COMPOSITOR_H */ diff --git a/src/meta/meta-plugin.h b/src/meta/meta-plugin.h index 983db7a47..a2666d05b 100644 --- a/src/meta/meta-plugin.h +++ b/src/meta/meta-plugin.h @@ -164,6 +164,9 @@ struct _MetaPluginClass int tile_monitor_number); void (*hide_tile_preview) (MetaPlugin *plugin); + void (*show_window_menu) (MetaPlugin *plugin, + MetaWindow *window); + /** * MetaPluginClass::kill_window_effects: * @actor: a #MetaWindowActor diff --git a/src/meta/prefs.h b/src/meta/prefs.h index ced3ddd90..0db03d082 100644 --- a/src/meta/prefs.h +++ b/src/meta/prefs.h @@ -399,10 +399,6 @@ GType meta_key_binding_get_type (void); MetaKeyBindingAction meta_prefs_get_keybinding_action (const char *name); -void meta_prefs_get_window_binding (const char *name, - unsigned int *keysym, - MetaVirtualModifier *modifiers); - gboolean meta_prefs_get_visual_bell (void); gboolean meta_prefs_bell_is_audible (void); GDesktopVisualBellType meta_prefs_get_visual_bell_type (void); diff --git a/src/ui/frames.c b/src/ui/frames.c index 55e005a9d..3ba21dd0e 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -1102,9 +1102,6 @@ meta_frame_titlebar_event (MetaUIFrame *frame, case G_DESKTOP_TITLEBAR_ACTION_MENU: meta_core_show_window_menu (display, frame->xwindow, - event->x_root, - event->y_root, - event->button, event->time); break; } @@ -1214,30 +1211,9 @@ meta_frames_button_press_event (GtkWidget *widget, redraw_control (frames, frame, control); if (control == META_FRAME_CONTROL_MENU) - { - MetaFrameGeometry fgeom; - GdkRectangle *rect; - int dx, dy; - - meta_frames_calc_geometry (frames, frame, &fgeom); - - rect = control_rect (META_FRAME_CONTROL_MENU, &fgeom); - - /* get delta to convert to root coords */ - dx = event->x_root - event->x; - dy = event->y_root - event->y; - - /* Align to the right end of the menu rectangle if RTL */ - if (meta_ui_get_direction() == META_UI_DIRECTION_RTL) - dx += rect->width; - - meta_core_show_window_menu (display, - frame->xwindow, - rect->x + dx, - rect->y + rect->height + dy, - event->button, - event->time); - } + meta_core_show_window_menu (display, + frame->xwindow, + event->time); } else if (event->button == 1 && (control == META_FRAME_CONTROL_RESIZE_SE || diff --git a/src/ui/menu.c b/src/ui/menu.c deleted file mode 100644 index c22f778b7..000000000 --- a/src/ui/menu.c +++ /dev/null @@ -1,516 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* Mutter window menu */ - -/* - * Copyright (C) 2001 Havoc Pennington - * Copyright (C) 2004 Rob Adams - * Copyright (C) 2005 Elijah Newren - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#include -#include -#include -#include "menu.h" -#include -#include "util-private.h" -#include "core.h" -#include "metaaccellabel.h" -#include "ui.h" - -typedef struct _MenuItem MenuItem; -typedef struct _MenuData MenuData; - -typedef enum -{ - MENU_ITEM_SEPARATOR = 0, - MENU_ITEM_NORMAL, - MENU_ITEM_CHECKBOX, - MENU_ITEM_RADIOBUTTON, - MENU_ITEM_WORKSPACE_LIST, -} MetaMenuItemType; - -struct _MenuItem -{ - MetaMenuOp op; - MetaMenuItemType type; - const gboolean checked; - const char *label; -}; - - -struct _MenuData -{ - MetaWindowMenu *menu; - MetaMenuOp op; -}; - -static void activate_cb (GtkWidget *menuitem, gpointer data); - -static MenuItem menuitems[] = { - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_MINIMIZE, MENU_ITEM_NORMAL, FALSE, N_("Mi_nimize") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_MAXIMIZE, MENU_ITEM_NORMAL, FALSE, N_("Ma_ximize") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_UNMAXIMIZE, MENU_ITEM_NORMAL, FALSE, N_("Unma_ximize") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_SHADE, MENU_ITEM_NORMAL, FALSE, N_("Roll _Up") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_UNSHADE, MENU_ITEM_NORMAL, FALSE, N_("_Unroll") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_MOVE, MENU_ITEM_NORMAL, FALSE, N_("_Move") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_RESIZE, MENU_ITEM_NORMAL, FALSE, N_("_Resize") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_RECOVER, MENU_ITEM_NORMAL, FALSE, N_("Move Titlebar On_screen") }, - { META_MENU_OP_WORKSPACES, MENU_ITEM_SEPARATOR, FALSE, NULL }, /* separator */ - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_ABOVE, MENU_ITEM_CHECKBOX, FALSE, N_("Always on _Top") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_UNABOVE, MENU_ITEM_CHECKBOX, TRUE, N_("Always on _Top") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_STICK, MENU_ITEM_RADIOBUTTON, FALSE, N_("_Always on Visible Workspace") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_UNSTICK, MENU_ITEM_RADIOBUTTON, FALSE, N_("_Only on This Workspace") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_MOVE_LEFT, MENU_ITEM_NORMAL, FALSE, N_("Move to Workspace _Left") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_MOVE_RIGHT, MENU_ITEM_NORMAL, FALSE, N_("Move to Workspace R_ight") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_MOVE_UP, MENU_ITEM_NORMAL, FALSE, N_("Move to Workspace _Up") }, - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_MOVE_DOWN, MENU_ITEM_NORMAL, FALSE, N_("Move to Workspace _Down") }, - { 0, MENU_ITEM_WORKSPACE_LIST, FALSE, NULL }, - { 0, MENU_ITEM_SEPARATOR, FALSE, NULL }, /* separator */ - /* Translators: Translate this string the same way as you do in libwnck! */ - { META_MENU_OP_DELETE, MENU_ITEM_NORMAL, FALSE, N_("_Close") } -}; - -static void -popup_position_func (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data) -{ - GtkRequisition req; - GdkPoint *pos; - - pos = user_data; - - gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); - - *x = pos->x; - *y = pos->y; - - if (meta_ui_get_direction() == META_UI_DIRECTION_RTL) - *x = MAX (0, *x - req.width); - - /* Ensure onscreen */ - *x = CLAMP (*x, 0, MAX (0, gdk_screen_width () - req.width)); - *y = CLAMP (*y, 0, MAX (0, gdk_screen_height () - req.height)); -} - -static void -menu_closed (GtkMenu *widget, - gpointer data) -{ - MetaWindowMenu *menu; - - menu = data; - - (* menu->func) (menu, - GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), - menu->client_xwindow, - gtk_get_current_event_time (), - 0, 0, - menu->data); - - /* menu may now be freed */ -} - -static void -activate_cb (GtkWidget *menuitem, gpointer data) -{ - MenuData *md; - - g_return_if_fail (GTK_IS_WIDGET (menuitem)); - - md = data; - - (* md->menu->func) (md->menu, - GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), - md->menu->client_xwindow, - gtk_get_current_event_time (), - md->op, - GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), - "workspace")), - md->menu->data); - - /* menu may now be freed */ -} - -/* - * Given a Display and an index, get the workspace name and add any - * accelerators. At the moment this means adding a _ if the name is of - * the form "Workspace n" where n is less than 10, and escaping any - * other '_'s so they do not create inadvertant accelerators. - * - * The calling code owns the string, and is reponsible to free the - * memory after use. - * - * See also http://mail.gnome.org/archives/gnome-i18n/2008-March/msg00380.html - * which discusses possible i18n concerns. - */ -static char* -get_workspace_name_with_accel (Display *display, - Window xroot, - int index) -{ - const char *name; - int number; - int charcount=0; - - name = meta_core_get_workspace_name_with_index (display, xroot, index); - - g_assert (name != NULL); - - /* - * If the name is of the form "Workspace x" where x is an unsigned - * integer, insert a '_' before the number if it is less than 10 and - * return it - */ - number = 0; - if (sscanf (name, _("Workspace %d%n"), &number, &charcount) != 0 && - *(name + charcount)=='\0') - { - char *new_name; - - /* - * Above name is a pointer into the Workspace struct. Here we make - * a copy copy so we can have our wicked way with it. - */ - 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. 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 _. We also - * provide memory for " (_#)" - */ - new_name = g_malloc0 (strlen (name) * 2 + 6 + 1); - - /* - * Now iterate down the strings, adding '_' to escape as we go - */ - dest = new_name; - source = name; - while (*source != '\0') - { - if (*source == '_') - *dest++ = '_'; - *dest++ = *source++; - } - - /* People don't start at workspace 0, but workspace 1 */ - if (index < 9) - { - g_snprintf (dest, 6, " (_%d)", index + 1); - } - else if (index == 9) - { - g_snprintf (dest, 6, " (_0)"); - } - - return new_name; - } -} - -static GtkWidget * -menu_item_new (MenuItem *menuitem, int workspace_id) -{ - unsigned int key; - MetaVirtualModifier mods; - const char *i18n_label; - GtkWidget *mi; - GtkWidget *accel_label; - - if (menuitem->type == MENU_ITEM_NORMAL) - { - mi = gtk_menu_item_new (); - } - else if (menuitem->type == MENU_ITEM_CHECKBOX) - { - mi = gtk_check_menu_item_new (); - - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), - menuitem->checked); - } - else if (menuitem->type == MENU_ITEM_RADIOBUTTON) - { - mi = gtk_check_menu_item_new (); - - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (mi), - TRUE); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), - menuitem->checked); - } - else if (menuitem->type == MENU_ITEM_WORKSPACE_LIST) - return NULL; - else - return gtk_separator_menu_item_new (); - - 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_container_add (GTK_CONTAINER (mi), accel_label); - gtk_widget_show (accel_label); - - meta_accel_label_set_accelerator (META_ACCEL_LABEL (accel_label), - key, mods); - - return mi; -} - -MetaWindowMenu* -meta_window_menu_new (MetaFrames *frames, - MetaMenuOp ops, - MetaMenuOp insensitive, - Window client_xwindow, - unsigned long active_workspace, - int n_workspaces, - MetaWindowMenuFunc func, - gpointer data) -{ - int i; - MetaWindowMenu *menu; - - /* FIXME: Modifications to 'ops' should happen in meta_window_show_menu */ - if (n_workspaces < 2) - ops &= ~(META_MENU_OP_STICK | META_MENU_OP_UNSTICK | META_MENU_OP_WORKSPACES); - else if (n_workspaces == 2) - /* #151183: If we only have two workspaces, disable the menu listing them. */ - ops &= ~(META_MENU_OP_WORKSPACES); - - menu = g_new (MetaWindowMenu, 1); - menu->frames = frames; - menu->client_xwindow = client_xwindow; - menu->func = func; - menu->data = data; - menu->ops = ops; - menu->insensitive = insensitive; - - menu->menu = gtk_menu_new (); - - gtk_menu_set_screen (GTK_MENU (menu->menu), - gtk_widget_get_screen (GTK_WIDGET (frames))); - - for (i = 0; i < (int) G_N_ELEMENTS (menuitems); i++) - { - MenuItem menuitem = menuitems[i]; - if (ops & menuitem.op || menuitem.op == 0) - { - GtkWidget *mi; - MenuData *md; - unsigned int key; - MetaVirtualModifier mods; - - mi = menu_item_new (&menuitem, -1); - - /* Set the activeness of radiobuttons. */ - switch (menuitem.op) - { - case META_MENU_OP_STICK: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), - active_workspace == 0xFFFFFFFF); - break; - case META_MENU_OP_UNSTICK: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), - active_workspace != 0xFFFFFFFF); - break; - default: - break; - } - - if (menuitem.type == MENU_ITEM_WORKSPACE_LIST) - { - if (ops & META_MENU_OP_WORKSPACES) - { - Display *display; - Window xroot; - GdkScreen *screen; - GdkWindow *window; - GtkWidget *submenu; - int j; - - MenuItem to_another_workspace = { - 0, MENU_ITEM_NORMAL, FALSE, - N_("Move to Another _Workspace") - }; - - meta_verbose ("Creating %d-workspace menu current space %lu\n", - n_workspaces, active_workspace); - - window = gtk_widget_get_window (GTK_WIDGET (frames)); - display = GDK_WINDOW_XDISPLAY (window); - - screen = gdk_window_get_screen (window); - xroot = GDK_WINDOW_XID (gdk_screen_get_root_window (screen)); - - submenu = gtk_menu_new (); - - g_assert (mi==NULL); - mi = menu_item_new (&to_another_workspace, -1); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), submenu); - - for (j = 0; j < n_workspaces; j++) - { - char *label; - MenuData *md; - unsigned int key; - MetaVirtualModifier mods; - MenuItem moveitem; - GtkWidget *submi; - - meta_core_get_menu_accelerator (META_MENU_OP_WORKSPACES, - j + 1, - &key, &mods); - - label = get_workspace_name_with_accel (display, xroot, j); - - moveitem.type = MENU_ITEM_NORMAL; - moveitem.op = META_MENU_OP_WORKSPACES; - moveitem.label = label; - submi = menu_item_new (&moveitem, j + 1); - - g_free (label); - - if ((active_workspace == (unsigned)j) && (ops & META_MENU_OP_UNSTICK)) - gtk_widget_set_sensitive (submi, FALSE); - - md = g_new (MenuData, 1); - - md->menu = menu; - md->op = META_MENU_OP_WORKSPACES; - - g_object_set_data (G_OBJECT (submi), - "workspace", - GINT_TO_POINTER (j)); - - g_signal_connect_data (G_OBJECT (submi), - "activate", - G_CALLBACK (activate_cb), - md, - (GClosureNotify) g_free, 0); - - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), submi); - - gtk_widget_show (submi); - } - } - else - meta_verbose ("not creating workspace menu\n"); - } - else if (menuitem.type != MENU_ITEM_SEPARATOR) - { - meta_core_get_menu_accelerator (menuitems[i].op, -1, - &key, &mods); - - if (insensitive & menuitem.op) - gtk_widget_set_sensitive (mi, FALSE); - - md = g_new (MenuData, 1); - - md->menu = menu; - md->op = menuitem.op; - - g_signal_connect_data (G_OBJECT (mi), - "activate", - G_CALLBACK (activate_cb), - md, - (GClosureNotify) g_free, 0); - } - - if (mi) - { - gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), mi); - - gtk_widget_show (mi); - } - } - } - - - g_signal_connect (menu->menu, "selection_done", - G_CALLBACK (menu_closed), menu); - - return menu; -} - -void -meta_window_menu_popup (MetaWindowMenu *menu, - int root_x, - int root_y, - int button, - guint32 timestamp) -{ - GdkPoint *pt; - - pt = g_new (GdkPoint, 1); - - g_object_set_data_full (G_OBJECT (menu->menu), - "destroy-point", - pt, - g_free); - - pt->x = root_x; - pt->y = root_y; - - gtk_menu_popup (GTK_MENU (menu->menu), - NULL, NULL, - popup_position_func, pt, - button, - timestamp); - - if (!gtk_widget_get_visible (menu->menu)) - meta_warning ("GtkMenu failed to grab the pointer\n"); -} - -void -meta_window_menu_free (MetaWindowMenu *menu) -{ - gtk_widget_destroy (menu->menu); - g_free (menu); -} diff --git a/src/ui/menu.h b/src/ui/menu.h deleted file mode 100644 index f75832849..000000000 --- a/src/ui/menu.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* Mutter window menu */ - -/* - * Copyright (C) 2001 Havoc Pennington - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#ifndef META_MENU_H -#define META_MENU_H - -#include -#include "frames.h" - -struct _MetaWindowMenu -{ - MetaFrames *frames; - Window client_xwindow; - GtkWidget *menu; - MetaWindowMenuFunc func; - gpointer data; - MetaMenuOp ops; - MetaMenuOp insensitive; -}; - -MetaWindowMenu* meta_window_menu_new (MetaFrames *frames, - MetaMenuOp ops, - MetaMenuOp insensitive, - Window client_xwindow, - unsigned long active_workspace, - int n_workspaces, - MetaWindowMenuFunc func, - gpointer data); -void meta_window_menu_popup (MetaWindowMenu *menu, - int root_x, - int root_y, - int button, - guint32 timestamp); -void meta_window_menu_free (MetaWindowMenu *menu); - - -#endif diff --git a/src/ui/metaaccellabel.c b/src/ui/metaaccellabel.c deleted file mode 100644 index 27491bf99..000000000 --- a/src/ui/metaaccellabel.c +++ /dev/null @@ -1,451 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* 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, see . - */ - -/* - * 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 "util-private.h" - -static void meta_accel_label_destroy (GtkWidget *object); -static void meta_accel_label_finalize (GObject *object); -static void meta_accel_label_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural); -static void meta_accel_label_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural); -static gboolean meta_accel_label_draw (GtkWidget *widget, - cairo_t *cr); - -static void meta_accel_label_update (MetaAccelLabel *accel_label); -static int meta_accel_label_get_accel_width (MetaAccelLabel *accel_label); - -G_DEFINE_TYPE (MetaAccelLabel, meta_accel_label, GTK_TYPE_LABEL); - -static void -meta_accel_label_class_init (MetaAccelLabelClass *class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); - - gobject_class->finalize = meta_accel_label_finalize; - - widget_class->destroy = meta_accel_label_destroy; - - widget_class->get_preferred_width = meta_accel_label_get_preferred_width; - widget_class->get_preferred_height = meta_accel_label_get_preferred_height; - widget_class->draw = meta_accel_label_draw; - - 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 (GtkWidget *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_WIDGET_CLASS (meta_accel_label_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 (meta_accel_label_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_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - MetaAccelLabel *accel_label = META_ACCEL_LABEL (widget); - PangoLayout *layout; - gint width; - - GTK_WIDGET_CLASS (meta_accel_label_parent_class)->get_preferred_width (widget, minimum, natural); - - 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 void -meta_accel_label_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - GTK_WIDGET_CLASS (meta_accel_label_parent_class)->get_preferred_height (widget, minimum, natural); -} - -/* Mostly taken from GTK3. */ -static gboolean -meta_accel_label_draw (GtkWidget *widget, - cairo_t *cr) -{ - MetaAccelLabel *accel_label = META_ACCEL_LABEL (widget); - GtkMisc *misc = GTK_MISC (accel_label); - GtkTextDirection direction; - int ac_width; - GtkAllocation allocation; - GtkRequisition requisition; - - direction = gtk_widget_get_direction (widget); - ac_width = meta_accel_label_get_accel_width (accel_label); - gtk_widget_get_allocation (widget, &allocation); - gtk_widget_get_preferred_size (widget, - &requisition, NULL); - - if (allocation.width >= requisition.width + ac_width) - { - GtkStyleContext *style; - PangoLayout *label_layout; - PangoLayout *accel_layout; - GtkLabel *label = GTK_LABEL (widget); - gint x, y, xpad, ypad; - gfloat xalign, yalign; - - label_layout = gtk_label_get_layout (GTK_LABEL (accel_label)); - gtk_misc_get_alignment (misc, &xalign, &yalign); - - cairo_save (cr); - - /* XXX: Mad hack: We modify the label's width so it renders - * properly in its draw function that we chain to. */ - if (direction == GTK_TEXT_DIR_RTL) - cairo_translate (cr, ac_width, 0); - if (gtk_label_get_ellipsize (label)) - pango_layout_set_width (label_layout, - pango_layout_get_width (label_layout) - - ac_width * PANGO_SCALE); - - allocation.width -= ac_width; - gtk_widget_set_allocation (widget, &allocation); - if (GTK_WIDGET_CLASS (meta_accel_label_parent_class)->draw) - GTK_WIDGET_CLASS (meta_accel_label_parent_class)->draw (widget, - cr); - allocation.width += ac_width; - gtk_widget_set_allocation (widget, &allocation); - if (gtk_label_get_ellipsize (label)) - pango_layout_set_width (label_layout, - pango_layout_get_width (label_layout) - + ac_width * PANGO_SCALE); - - cairo_restore (cr); - - gtk_misc_get_padding (misc, &xpad, &ypad); - - if (direction == GTK_TEXT_DIR_RTL) - x = xpad; - else - x = gtk_widget_get_allocated_width (widget) - xpad - ac_width; - - gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y); - - accel_layout = gtk_widget_create_pango_layout (widget, accel_label->accel_string); - - y = (allocation.height - (requisition.height - ypad * 2)) * yalign + 1.5; - - style = gtk_widget_get_style_context (widget); - gtk_style_context_save (style); - gtk_style_context_set_state (style, - gtk_widget_get_state_flags (widget)); - gtk_render_layout (gtk_widget_get_style_context (widget), - cr, - x, y, - accel_layout); - gtk_style_context_restore (style); - - g_object_unref (accel_layout); - } - else - { - if (GTK_WIDGET_CLASS (meta_accel_label_parent_class)->draw) - GTK_WIDGET_CLASS (meta_accel_label_parent_class)->draw (widget, cr); - } - - 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/ui/metaaccellabel.h b/src/ui/metaaccellabel.h deleted file mode 100644 index cebd6eb77..000000000 --- a/src/ui/metaaccellabel.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* 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, see . - */ - -/* - * 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 - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define META_TYPE_ACCEL_LABEL (meta_accel_label_get_type ()) -#define META_ACCEL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_ACCEL_LABEL, MetaAccelLabel)) -#define META_ACCEL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_ACCEL_LABEL, MetaAccelLabelClass)) -#define META_IS_ACCEL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_ACCEL_LABEL)) -#define META_IS_ACCEL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_ACCEL_LABEL)) -#define META_ACCEL_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_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); -}; - -GType 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/ui/ui.c b/src/ui/ui.c index a412602e3..b0300518b 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -487,40 +487,6 @@ meta_ui_set_frame_title (MetaUI *ui, meta_frames_set_title (ui->frames, xwindow, title); } -MetaWindowMenu* -meta_ui_window_menu_new (MetaUI *ui, - Window client_xwindow, - MetaMenuOp ops, - MetaMenuOp insensitive, - unsigned long active_workspace, - int n_workspaces, - MetaWindowMenuFunc func, - gpointer data) -{ - return meta_window_menu_new (ui->frames, - ops, insensitive, - client_xwindow, - active_workspace, - n_workspaces, - func, data); -} - -void -meta_ui_window_menu_popup (MetaWindowMenu *menu, - int root_x, - int root_y, - int button, - guint32 timestamp) -{ - meta_window_menu_popup (menu, root_x, root_y, button, timestamp); -} - -void -meta_ui_window_menu_free (MetaWindowMenu *menu) -{ - meta_window_menu_free (menu); -} - GdkPixbuf* meta_gdk_pixbuf_get_from_pixmap (Pixmap xpixmap, int src_x, diff --git a/src/ui/ui.h b/src/ui/ui.h index a79bc0f45..af0e72a82 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -113,21 +113,6 @@ void meta_ui_update_frame_style (MetaUI *ui, void meta_ui_repaint_frame (MetaUI *ui, Window xwindow); -MetaWindowMenu* meta_ui_window_menu_new (MetaUI *ui, - Window client_xwindow, - MetaMenuOp ops, - MetaMenuOp insensitive, - unsigned long active_workspace, - int n_workspaces, - MetaWindowMenuFunc func, - gpointer data); -void meta_ui_window_menu_popup (MetaWindowMenu *menu, - int root_x, - int root_y, - int button, - guint32 timestamp); -void meta_ui_window_menu_free (MetaWindowMenu *menu); - /* FIXME these lack a display arg */ GdkPixbuf* meta_gdk_pixbuf_get_from_pixmap (Pixmap xpixmap,