From 73cce3b17406d72235073f47b62953c0894f276b Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 24 Feb 2003 02:16:09 +0000 Subject: [PATCH] Take control of the panel's global keybindings. The screenshot utility is 2003-02-24 Mark McLoughlin Take control of the panel's global keybindings. The screenshot utility is hooked up using a special case run_command and the menu and run dialog bindings are done using the _GNOME_PANEL_ACTION ClientMessage protocol. * src/display.[ch]: (meta_display_open): add some atoms. * src/keybindings.c: (handle_panel_keybinding): impl to handle a keybinding by sending an action message to the panel. * src/metacity.schemas.in: add schemas for the panel and screenshot keybindings and the screenshot commands. * src/prefs.[ch]: (update_command), (meta_prefs_get_gconf_key_for_command): impl special case handling for the screenshot commands. They are stored at the the end of the commands array but have named keys. --- ChangeLog | 22 +++++++ src/display.c | 8 ++- src/display.h | 3 + src/keybindings.c | 55 ++++++++++++++++++ src/metacity.schemas.in | 126 ++++++++++++++++++++++++++++++++++++++++ src/prefs.c | 56 ++++++++++++++---- src/prefs.h | 6 ++ 7 files changed, 265 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e516a58d..1845ec9a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2003-02-24 Mark McLoughlin + + Take control of the panel's global keybindings. The + screenshot utility is hooked up using a special case + run_command and the menu and run dialog bindings are + done using the _GNOME_PANEL_ACTION ClientMessage + protocol. + + * src/display.[ch]: (meta_display_open): add some atoms. + + * src/keybindings.c: + (handle_panel_keybinding): impl to handle a keybinding + by sending an action message to the panel. + + * src/metacity.schemas.in: add schemas for the panel and + screenshot keybindings and the screenshot commands. + + * src/prefs.[ch]: (update_command), + (meta_prefs_get_gconf_key_for_command): impl special case + handling for the screenshot commands. They are stored at + the the end of the commands array but have named keys. + 2003-02-23 Havoc Pennington Patch from Rob Adams addresses #95014 (placement issues), diff --git a/src/display.c b/src/display.c index 1fe4be493..21daa9e4e 100644 --- a/src/display.c +++ b/src/display.c @@ -266,7 +266,10 @@ meta_display_open (const char *name) "_NET_STARTUP_ID", "_METACITY_TOGGLE_VERBOSE", "_METACITY_UPDATE_COUNTER", - "SYNC_COUNTER" + "SYNC_COUNTER", + "_GNOME_PANEL_ACTION", + "_GNOME_PANEL_ACTION_MAIN_MENU", + "_GNOME_PANEL_ACTION_RUN_DIALOG" }; Atom atoms[G_N_ELEMENTS(atom_names)]; @@ -406,6 +409,9 @@ meta_display_open (const char *name) display->atom_metacity_toggle_verbose = atoms[78]; display->atom_metacity_update_counter = atoms[79]; display->atom_sync_counter = atoms[80]; + display->atom_gnome_panel_action = atoms[81]; + display->atom_gnome_panel_action_main_menu = atoms[82]; + display->atom_gnome_panel_action_run_dialog = atoms[83]; display->prop_hooks = NULL; meta_display_init_window_prop_hooks (display); diff --git a/src/display.h b/src/display.h index 44381b909..3f2cb3a47 100644 --- a/src/display.h +++ b/src/display.h @@ -169,6 +169,9 @@ struct _MetaDisplay Atom atom_metacity_toggle_verbose; Atom atom_metacity_update_counter; Atom atom_sync_counter; + Atom atom_gnome_panel_action; + Atom atom_gnome_panel_action_main_menu; + Atom atom_gnome_panel_action_run_dialog; /* This is the actual window from focus events, * not the one we last set diff --git a/src/keybindings.c b/src/keybindings.c index 713e4242a..be9fe533b 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -79,6 +79,11 @@ static void handle_toggle_desktop (MetaDisplay *display, MetaWindow *window, XEvent *event, MetaKeyBinding *binding); +static void handle_panel_keybinding (MetaDisplay *display, + MetaScreen *screen, + MetaWindow *window, + XEvent *event, + MetaKeyBinding *binding); static void handle_toggle_maximize (MetaDisplay *display, MetaScreen *screen, MetaWindow *window, @@ -265,6 +270,10 @@ static const MetaKeyHandler screen_handlers[] = { GINT_TO_POINTER (META_TAB_LIST_DOCKS) }, { META_KEYBINDING_SHOW_DESKTOP, handle_toggle_desktop, NULL }, + { META_KEYBINDING_PANEL_MAIN_MENU, handle_panel_keybinding, + GINT_TO_POINTER (META_KEYBINDING_ACTION_PANEL_MAIN_MENU) }, + { META_KEYBINDING_PANEL_RUN_DIALOG, handle_panel_keybinding, + GINT_TO_POINTER (META_KEYBINDING_ACTION_PANEL_RUN_DIALOG) }, { META_KEYBINDING_COMMAND_1, handle_run_command, GINT_TO_POINTER (0) }, { META_KEYBINDING_COMMAND_2, handle_run_command, @@ -329,6 +338,10 @@ static const MetaKeyHandler screen_handlers[] = { GINT_TO_POINTER (30) }, { META_KEYBINDING_COMMAND_32, handle_run_command, GINT_TO_POINTER (31) }, + { META_KEYBINDING_COMMAND_SCREENSHOT, handle_run_command, + GINT_TO_POINTER (32) }, + { META_KEYBINDING_COMMAND_WIN_SCREENSHOT, handle_run_command, + GINT_TO_POINTER (33) }, { NULL, NULL, NULL } }; @@ -2571,6 +2584,48 @@ handle_toggle_desktop (MetaDisplay *display, meta_screen_show_desktop (screen); } +static void +handle_panel_keybinding (MetaDisplay *display, + MetaScreen *screen, + MetaWindow *window, + XEvent *event, + MetaKeyBinding *binding) +{ + MetaKeyBindingAction action; + Atom action_atom; + XClientMessageEvent ev; + + action = GPOINTER_TO_INT (binding->handler->data); + + action_atom = None; + switch (action) + { + case META_KEYBINDING_ACTION_PANEL_MAIN_MENU: + action_atom = display->atom_gnome_panel_action_main_menu; + break; + case META_KEYBINDING_ACTION_PANEL_RUN_DIALOG: + action_atom = display->atom_gnome_panel_action_run_dialog; + break; + default: + return; + } + + ev.type = ClientMessage; + ev.window = screen->xroot; + ev.message_type = display->atom_gnome_panel_action; + ev.format = 32; + ev.data.l[0] = action_atom; + ev.data.l[1] = event->xkey.time; + + meta_error_trap_push (display); + XSendEvent (display->xdisplay, + screen->xroot, + False, + StructureNotifyMask, + (XEvent*) &ev); + meta_error_trap_pop (display, FALSE); +} + static void handle_activate_menu (MetaDisplay *display, MetaScreen *screen, diff --git a/src/metacity.schemas.in b/src/metacity.schemas.in index c52cf7a0a..bd55b88a0 100644 --- a/src/metacity.schemas.in +++ b/src/metacity.schemas.in @@ -1599,6 +1599,100 @@ you set + + /schemas/apps/metacity/global_keybindings/panel_main_menu + /apps/metacity/global_keybindings/panel_main_menu + metacity + string + <Alt>F1 + + Show the panel menu + + The keybinding which shows the panel's main menu. + + The format looks like "<Control>a" or + "<Shift><Alt>F1. + + The parser is fairly liberal and allows lower or upper case, + and also abbreviations such as "<Ctl>" and + "<Ctrl>". If you set the option to the special string + "disabled", then there will be no keybinding for this + action. + + + + + + /schemas/apps/metacity/global_keybindings/panel_run_dialog + /apps/metacity/global_keybindings/panel_run_dialog + metacity + string + <Alt>F2 + + Show the panel run dialog + + The keybinding which display's the panel's "Run Program" dialog + box. + + The format looks like "<Control>a" or + "<Shift><Alt>F1. + + The parser is fairly liberal and allows lower or upper case, + and also abbreviations such as "<Ctl>" and + "<Ctrl>". If you set the option to the special string + "disabled", then there will be no keybinding for this + action. + + + + + + /schemas/apps/metacity/global_keybindings/run_command_screenshot + /apps/metacity/global_keybindings/run_command_screenshot + metacity + string + Print + + Take a screenshot + + The keybinding which invokes the panel's screenshot utility. + + The format looks like "<Control>a" or + "<Shift><Alt>F1. + + The parser is fairly liberal and allows lower or upper case, + and also abbreviations such as "<Ctl>" and + "<Ctrl>". If you set the option to the special string + "disabled", then there will be no keybinding for this + action. + + + + + + /schemas/apps/metacity/global_keybindings/run_command_window_screenshot + /apps/metacity/global_keybindings/run_command_window_screenshot + metacity + string + <Alt>Print + + Take a screenshot of a window + + The keybinding which invokes the panel's screenshot utility + to take a screenshot of a window. + + The format looks like "<Control>a" or + "<Shift><Alt>F1. + + The parser is fairly liberal and allows lower or upper case, + and also abbreviations such as "<Ctl>" and + "<Ctrl>". If you set the option to the special string + "disabled", then there will be no keybinding for this + action. + + + + /schemas/apps/metacity/global_keybindings/run_command /apps/metacity/global_keybindings/run_command_1 @@ -1636,6 +1730,38 @@ you set + + /schemas/apps/metacity/keybinding_commands/command_screenshot + /apps/metacity/keybinding_commands/command_screenshot + metacity + string + gnome-panel-screenshot + + The screenshot command + + The /apps/metacity/global_keybindings/run_command_screenshot + key defines a keybinding which causes the command specified + by this setting to be invoked. + + + + + + /schemas/apps/metacity/keybinding_commands/command_window_screenshot + /apps/metacity/keybinding_commands/command_window_screenshot + metacity + string + gnome-panel-screenshot --window + + The window screenshot command + + The /apps/metacity/global_keybindings/run_command_window_screenshot + key defines a keybinding which causes the command specified + by this setting to be invoked. + + + + /schemas/apps/metacity/keybinding_commands/command /apps/metacity/keybinding_commands/command_1 diff --git a/src/prefs.c b/src/prefs.c index 5977bc755..e2efa47a4 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -30,7 +30,11 @@ #include #define MAX_REASONABLE_WORKSPACES 36 -#define MAX_COMMANDS 32 + +#define MAX_COMMANDS (32 + NUM_EXTRA_COMMANDS) +#define NUM_EXTRA_COMMANDS 2 +#define SCREENSHOT_COMMAND_IDX (MAX_COMMANDS - 2) +#define WIN_SCREENSHOT_COMMAND_IDX (MAX_COMMANDS - 1) /* If you add a key, it needs updating in init() and in the gconf * notify listener and of course in the .schemas file @@ -95,6 +99,7 @@ static MetaButtonLayout button_layout = { } }; +/* The screenshot commands are at the end */ static char *commands[MAX_COMMANDS] = { NULL, }; static char *workspace_names[MAX_REASONABLE_WORKSPACES] = { NULL, }; @@ -1363,6 +1368,8 @@ static MetaKeyPref screen_bindings[] = { { META_KEYBINDING_CYCLE_PANELS, 0, 0, TRUE }, { META_KEYBINDING_CYCLE_PANELS_BACKWARD, 0, 0, TRUE }, { META_KEYBINDING_SHOW_DESKTOP, 0, 0, FALSE }, + { META_KEYBINDING_PANEL_MAIN_MENU, 0, 0, FALSE }, + { META_KEYBINDING_PANEL_RUN_DIALOG, 0, 0, FALSE }, { META_KEYBINDING_COMMAND_1, 0, 0, FALSE }, { META_KEYBINDING_COMMAND_2, 0, 0, FALSE }, { META_KEYBINDING_COMMAND_3, 0, 0, FALSE }, @@ -1395,6 +1402,8 @@ static MetaKeyPref screen_bindings[] = { { META_KEYBINDING_COMMAND_30, 0, 0, FALSE }, { META_KEYBINDING_COMMAND_31, 0, 0, FALSE }, { META_KEYBINDING_COMMAND_32, 0, 0, FALSE }, + { META_KEYBINDING_COMMAND_SCREENSHOT, 0, 0, FALSE }, + { META_KEYBINDING_COMMAND_WIN_SCREENSHOT, 0, 0, FALSE }, { NULL, 0, 0, FALSE} }; @@ -1663,15 +1672,31 @@ update_command (const char *name, ++p; - if (!g_ascii_isdigit (*p)) + if (g_ascii_isdigit (*p)) { - meta_topic (META_DEBUG_KEYBINDINGS, - "Command %s doesn't end in number?\n", name); - return FALSE; + i = atoi (p); + i -= 1; /* count from 0 not 1 */ + } + else + { + p = strrchr (name, '/'); + ++p; + + if (strcmp (p, "command_screenshot") == 0) + { + i = SCREENSHOT_COMMAND_IDX; + } + else if (strcmp (p, "command_window_screenshot") == 0) + { + i = WIN_SCREENSHOT_COMMAND_IDX; + } + else + { + meta_topic (META_DEBUG_KEYBINDINGS, + "Command %s doesn't end in number?\n", name); + return FALSE; + } } - - i = atoi (p); - i -= 1; /* count from 0 not 1 */ if (i >= MAX_COMMANDS) { @@ -1711,8 +1736,19 @@ char* meta_prefs_get_gconf_key_for_command (int i) { char *key; - - key = g_strdup_printf (KEY_COMMAND_PREFIX"%d", i + 1); + + switch (i) + { + case SCREENSHOT_COMMAND_IDX: + key = g_strdup (KEY_COMMAND_PREFIX "screenshot"); + break; + case WIN_SCREENSHOT_COMMAND_IDX: + key = g_strdup (KEY_COMMAND_PREFIX "window_screenshot"); + break; + default: + key = g_strdup_printf (KEY_COMMAND_PREFIX"%d", i + 1); + break; + } return key; } diff --git a/src/prefs.h b/src/prefs.h index 8a607f697..60376df2d 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -109,6 +109,8 @@ void meta_prefs_change_workspace_name (int i, #define META_KEYBINDING_CYCLE_PANELS "cycle_panels" #define META_KEYBINDING_CYCLE_PANELS_BACKWARD "cycle_panels_backward" #define META_KEYBINDING_SHOW_DESKTOP "show_desktop" +#define META_KEYBINDING_PANEL_MAIN_MENU "panel_main_menu" +#define META_KEYBINDING_PANEL_RUN_DIALOG "panel_run_dialog" #define META_KEYBINDING_COMMAND_1 "run_command_1" #define META_KEYBINDING_COMMAND_2 "run_command_2" #define META_KEYBINDING_COMMAND_3 "run_command_3" @@ -141,6 +143,8 @@ void meta_prefs_change_workspace_name (int i, #define META_KEYBINDING_COMMAND_30 "run_command_30" #define META_KEYBINDING_COMMAND_31 "run_command_31" #define META_KEYBINDING_COMMAND_32 "run_command_32" +#define META_KEYBINDING_COMMAND_SCREENSHOT "run_command_screenshot" +#define META_KEYBINDING_COMMAND_WIN_SCREENSHOT "run_command_window_screenshot" /* Window bindings */ #define META_KEYBINDING_WINDOW_MENU "activate_window_menu" @@ -204,6 +208,8 @@ typedef enum _MetaKeyBindingAction META_KEYBINDING_ACTION_CYCLE_PANELS, META_KEYBINDING_ACTION_CYCLE_PANELS_BACKWARD, META_KEYBINDING_ACTION_SHOW_DESKTOP, + META_KEYBINDING_ACTION_PANEL_MAIN_MENU, + META_KEYBINDING_ACTION_PANEL_RUN_DIALOG, META_KEYBINDING_ACTION_COMMAND_1, META_KEYBINDING_ACTION_COMMAND_2, META_KEYBINDING_ACTION_COMMAND_3,