Add a keybinding to launch a terminal

2004-10-13  Vincent Untz  <vincent@vuntz.net>

	Add a keybinding to launch a terminal

	* src/keybindings.c: (handle_run_terminal): new function,
	(error_on_generic_command): new function, (error_on_command): wrapper
	around error_on_generic_command(), (error_on_terminal_command): new
	function

	* src/metacity.schemas.in: add run_command_terminal key

	* src/prefs.[ch]: (meta_prefs_init): cache the terminal command and
	register a gconf callback to update it, (change_notify): handle the
	notification of terminal command changes, (meta_preference_to_string):
	add the terminal command case, (update_terminal_command): new function,
	(meta_prefs_get_terminal_command): new function,
	(meta_prefs_get_gconf_key_for_terminal_command): new function
This commit is contained in:
Vincent Untz 2004-10-13 08:32:10 +00:00 committed by Vincent Untz
parent 278b5807f1
commit b03558dc4d
5 changed files with 200 additions and 11 deletions

View File

@ -1,3 +1,21 @@
2004-10-13 Vincent Untz <vincent@vuntz.net>
Add a keybinding to launch a terminal
* src/keybindings.c: (handle_run_terminal): new function,
(error_on_generic_command): new function, (error_on_command): wrapper
around error_on_generic_command(), (error_on_terminal_command): new
function
* src/metacity.schemas.in: add run_command_terminal key
* src/prefs.[ch]: (meta_prefs_init): cache the terminal command and
register a gconf callback to update it, (change_notify): handle the
notification of terminal command changes, (meta_preference_to_string):
add the terminal command case, (update_terminal_command): new function,
(meta_prefs_get_terminal_command): new function,
(meta_prefs_get_gconf_key_for_terminal_command): new function
2004-10-11 Rob Adams <readams@readams.net>
* configure.in: bump version to 2.9.0. Add UNSTABLE warning.

View File

@ -184,6 +184,11 @@ static void handle_maximize_horiz (MetaDisplay *display,
MetaWindow *window,
XEvent *event,
MetaKeyBinding *binding);
static void handle_run_terminal (MetaDisplay *display,
MetaScreen *screen,
MetaWindow *window,
XEvent *event,
MetaKeyBinding *binding);
/* debug */
static void handle_spew_mark (MetaDisplay *display,
@ -357,6 +362,8 @@ static const MetaKeyHandler screen_handlers[] = {
GINT_TO_POINTER (32) },
{ META_KEYBINDING_COMMAND_WIN_SCREENSHOT, handle_run_command,
GINT_TO_POINTER (33) },
{ META_KEYBINDING_RUN_COMMAND_TERMINAL, handle_run_terminal,
NULL },
{ NULL, NULL, NULL }
};
@ -2483,7 +2490,7 @@ handle_activate_workspace (MetaDisplay *display,
}
static void
error_on_command (int command_index,
error_on_generic_command (const char *key,
const char *command,
const char *message,
int screen_number,
@ -2491,15 +2498,9 @@ error_on_command (int command_index,
{
GError *err;
char *argv[10];
char *key;
char numbuf[32];
char timestampbuf[32];
meta_warning ("Error on command %d \"%s\": %s\n",
command_index, command, message);
key = meta_prefs_get_gconf_key_for_command (command_index);
sprintf (numbuf, "%d", screen_number);
sprintf (timestampbuf, "%lu", timestamp);
@ -2530,10 +2531,41 @@ error_on_command (int command_index,
err->message);
g_error_free (err);
}
}
static void
error_on_command (int command_index,
const char *command,
const char *message,
int screen_number,
Time timestamp)
{
char *key;
meta_warning ("Error on command %d \"%s\": %s\n",
command_index, command, message);
key = meta_prefs_get_gconf_key_for_command (command_index);
error_on_generic_command (key, command, message, screen_number, timestamp);
g_free (key);
}
error_on_terminal_command (const char *command,
const char *message,
int screen_number,
Time timestamp)
{
char *key;
meta_warning ("Error on terminal command \"%s\": %s\n", command, message);
key = meta_prefs_get_gconf_key_for_terminal_command ();
error_on_generic_command (key, command, message, screen_number, timestamp);
}
static void
set_display_setup_func (void *data)
{
@ -3409,3 +3441,40 @@ meta_set_keybindings_disabled (gboolean setting)
meta_topic (META_DEBUG_KEYBINDINGS,
"Keybindings %s\n", all_bindings_disabled ? "disabled" : "enabled");
}
static void
handle_run_terminal (MetaDisplay *display,
MetaScreen *screen,
MetaWindow *window,
XEvent *event,
MetaKeyBinding *binding)
{
const char *command;
GError *err;
command = meta_prefs_get_terminal_command ();
if (command == NULL)
{
char *s;
meta_topic (META_DEBUG_KEYBINDINGS,
"No terminal command to run in response to "
"keybinding press\n");
s = g_strdup_printf (_("No terminal command has been defined.\n"));
error_on_terminal_command (NULL, s, screen->number, event->xkey.time);
g_free (s);
return;
}
err = NULL;
if (!meta_spawn_command_line_async_on_screen (command, screen, &err))
{
error_on_terminal_command (command, err->message, screen->number,
event->xkey.time);
g_error_free (err);
}
}

View File

@ -1735,6 +1735,29 @@ you set
</locale>
</schema>
<schema>
<key>/schemas/apps/metacity/global_keybindings/run_command_terminal</key>
<applyto>/apps/metacity/global_keybindings/run_command_terminal</applyto>
<owner>metacity</owner>
<type>string</type>
<default>disabled</default>
<locale name="C">
<short>Run a terminal</short>
<long>
The keybinding which invokes a terminal.
The format looks like "&lt;Control&gt;a" or
"&lt;Shift&gt;&lt;Alt&gt;F1".
The parser is fairly liberal and allows lower or upper case,
and also abbreviations such as "&lt;Ctl&gt;" and
"&lt;Ctrl&gt;". If you set the option to the special string
"disabled", then there will be no keybinding for this
action.
</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/metacity/global_keybindings/run_command</key>
<applyto>/apps/metacity/global_keybindings/run_command_1</applyto>

View File

@ -54,6 +54,9 @@
#define KEY_REDUCED_RESOURCES "/apps/metacity/general/reduced_resources"
#define KEY_COMMAND_PREFIX "/apps/metacity/keybinding_commands/command_"
#define KEY_TERMINAL_COMMAND "/desktop/gnome/applications/terminal/exec"
#define KEY_SCREEN_BINDINGS_PREFIX "/apps/metacity/global_keybindings"
#define KEY_WINDOW_BINDINGS_PREFIX "/apps/metacity/window_keybindings"
@ -105,6 +108,8 @@ static MetaButtonLayout button_layout = {
/* The screenshot commands are at the end */
static char *commands[MAX_COMMANDS] = { NULL, };
static char *terminal_command = NULL;
static char *workspace_names[MAX_REASONABLE_WORKSPACES] = { NULL, };
#ifdef HAVE_GCONF
@ -130,6 +135,7 @@ static gboolean update_binding (MetaKeyPref *binding,
const char *value);
static gboolean update_command (const char *name,
const char *value);
static gboolean update_terminal_command (const char *value);
static gboolean update_workspace_name (const char *name,
const char *value);
static gboolean update_reduced_resources (gboolean value);
@ -395,6 +401,12 @@ meta_prefs_init (void)
&err);
cleanup_error (&err);
update_reduced_resources (bool_val);
str_val = gconf_client_get_string (default_client, KEY_TERMINAL_COMMAND,
&err);
cleanup_error (&err);
update_terminal_command (str_val);
g_free (str_val);
#endif /* HAVE_GCONF */
/* Load keybindings prefs */
@ -412,6 +424,11 @@ meta_prefs_init (void)
NULL,
NULL,
&err);
gconf_client_notify_add (default_client, KEY_TERMINAL_COMMAND,
change_notify,
NULL,
NULL,
&err);
cleanup_error (&err);
#endif /* HAVE_GCONF */
}
@ -679,6 +696,22 @@ change_notify (GConfClient *client,
if (update_command (key, str))
queue_changed (META_PREF_COMMANDS);
}
else if (strcmp (key, KEY_TERMINAL_COMMAND) == 0)
{
const char *str;
if (value && value->type != GCONF_VALUE_STRING)
{
meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
KEY_TERMINAL_COMMAND);
goto out;
}
str = value ? gconf_value_get_string (value) : NULL;
if (update_terminal_command (str))
queue_changed (META_PREF_TERMINAL_COMMAND);
}
else if (str_has_prefix (key, KEY_WORKSPACE_NAME_PREFIX))
{
const char *str;
@ -1335,6 +1368,9 @@ meta_preference_to_string (MetaPreference pref)
case META_PREF_COMMANDS:
return "COMMANDS";
case META_PREF_TERMINAL_COMMAND:
return "TERMINAL_COMMAND";
case META_PREF_BUTTON_LAYOUT:
return "BUTTON_LAYOUT";
break;
@ -1457,6 +1493,7 @@ static MetaKeyPref screen_bindings[] = {
{ META_KEYBINDING_COMMAND_32, 0, 0, FALSE },
{ META_KEYBINDING_COMMAND_SCREENSHOT, 0, 0, FALSE },
{ META_KEYBINDING_COMMAND_WIN_SCREENSHOT, 0, 0, FALSE },
{ META_KEYBINDING_RUN_COMMAND_TERMINAL, 0, 0, FALSE },
{ NULL, 0, 0, FALSE}
};
@ -1776,6 +1813,31 @@ update_command (const char *name,
return TRUE;
}
static gboolean
update_terminal_command (const char *value)
{
char *old_terminal_command;
gboolean changed;
old_terminal_command = terminal_command;
if (value != NULL && *value)
{
terminal_command = g_strdup (value);
}
changed = TRUE;
if ((old_terminal_command && terminal_command &&
strcmp (old_terminal_command, terminal_command) == 0) ||
(old_terminal_command == NULL && terminal_command == NULL))
changed = FALSE;
if (old_terminal_command != terminal_command)
g_free (old_terminal_command);
return changed;
}
#endif /* HAVE_GCONF */
const char*
@ -1807,6 +1869,18 @@ meta_prefs_get_gconf_key_for_command (int i)
return key;
}
const char*
meta_prefs_get_terminal_command (void)
{
return terminal_command;
}
const char*
meta_prefs_get_gconf_key_for_terminal_command (void)
{
return KEY_TERMINAL_COMMAND;
}
#ifdef HAVE_GCONF
static gboolean
update_workspace_name (const char *name,

View File

@ -41,6 +41,7 @@ typedef enum
META_PREF_SCREEN_KEYBINDINGS,
META_PREF_DISABLE_WORKAROUNDS,
META_PREF_COMMANDS,
META_PREF_TERMINAL_COMMAND,
META_PREF_BUTTON_LAYOUT,
META_PREF_WORKSPACE_NAMES,
META_PREF_VISUAL_BELL,
@ -76,6 +77,9 @@ const char* meta_prefs_get_command (int i);
char* meta_prefs_get_gconf_key_for_command (int i);
const char* meta_prefs_get_terminal_command (void);
const char* meta_prefs_get_gconf_key_for_terminal_command (void);
void meta_prefs_get_button_layout (MetaButtonLayout *button_layout);
MetaActionDoubleClickTitlebar meta_prefs_get_action_double_click_titlebar (void);
@ -147,6 +151,7 @@ void meta_prefs_change_workspace_name (int i,
#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"
#define META_KEYBINDING_RUN_COMMAND_TERMINAL "run_command_terminal"
/* Window bindings */
#define META_KEYBINDING_WINDOW_MENU "activate_window_menu"