2008-09-06 18:01:56 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Thomas Thurman
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file Schema bindings generator.
|
|
|
|
*
|
|
|
|
* This program simply takes the items given in the binding lists in
|
2008-10-05 20:24:07 -04:00
|
|
|
* window-bindings.h and scheme-bindings.h and turns them into a portion of
|
2008-09-06 18:01:56 -04:00
|
|
|
* the GConf .schemas file.
|
2008-10-05 20:24:07 -04:00
|
|
|
*
|
|
|
|
* FIXME: also need to make 50-metacity-desktop-key.xml
|
2008-09-06 18:01:56 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-10-12 19:29:09 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2008-10-18 00:33:14 -04:00
|
|
|
|
2008-09-06 18:01:56 -04:00
|
|
|
#include <glib.h>
|
2008-10-18 00:33:14 -04:00
|
|
|
#include "config.h"
|
2008-09-06 18:01:56 -04:00
|
|
|
|
|
|
|
#define _(x) x
|
|
|
|
|
2008-10-18 00:33:14 -04:00
|
|
|
static void single_stanza (gboolean is_window, const char *name,
|
|
|
|
const char *default_value,
|
|
|
|
gboolean can_reverse,
|
|
|
|
const char *description);
|
2008-10-12 19:29:09 -04:00
|
|
|
|
2008-10-18 00:33:14 -04:00
|
|
|
char *about_keybindings, *about_reversible_keybindings;
|
2008-09-06 18:01:56 -04:00
|
|
|
|
|
|
|
const char* window_string = \
|
|
|
|
" <schema>\n" \
|
|
|
|
" <key>/schemas/apps/metacity/%s_keybindings/%s%s</key>\n" \
|
|
|
|
" <applyto>/apps/metacity/%s_keybindings/%s%s</applyto>\n" \
|
|
|
|
" <owner>metacity</owner>\n" \
|
|
|
|
" <type>string</type>\n" \
|
|
|
|
" <default>%s</default>\n" \
|
|
|
|
" <locale name=\"C\">\n" \
|
|
|
|
" <short>%s</short>\n" \
|
|
|
|
" <long>\n" \
|
|
|
|
" %s %s\n" \
|
|
|
|
" </long>\n" \
|
|
|
|
" </locale>\n" \
|
|
|
|
" </schema>\n\n\n";
|
|
|
|
|
2008-10-12 19:29:09 -04:00
|
|
|
static void
|
2008-10-18 00:33:14 -04:00
|
|
|
single_stanza (gboolean is_window, const char *name,
|
|
|
|
const char *default_value,
|
|
|
|
gboolean can_reverse,
|
|
|
|
const char *description)
|
2008-09-06 18:01:56 -04:00
|
|
|
{
|
2008-10-05 20:24:07 -04:00
|
|
|
char *keybinding_type = is_window? "window": "global";
|
2008-10-18 00:33:14 -04:00
|
|
|
char *escaped_default_value, *escaped_description;
|
2008-10-05 20:24:07 -04:00
|
|
|
|
2008-10-18 00:33:14 -04:00
|
|
|
if (description==NULL)
|
|
|
|
return; /* it must be undocumented, so it can't go in this table */
|
2008-10-05 20:24:07 -04:00
|
|
|
|
2008-10-18 00:33:14 -04:00
|
|
|
escaped_description = g_markup_escape_text (description, -1);
|
|
|
|
escaped_default_value = default_value==NULL? "disabled":
|
|
|
|
g_markup_escape_text (description, -1);
|
2008-10-05 20:24:07 -04:00
|
|
|
|
|
|
|
printf (" <schema>\n");
|
|
|
|
printf (" <key>/schemas/apps/metacity/%s_keybindings/%s</key>\n",
|
|
|
|
keybinding_type, name);
|
|
|
|
printf (" <applyto>/apps/metacity/%s_keybindings/%s</applyto>\n",
|
|
|
|
keybinding_type, name);
|
|
|
|
printf (" <owner>metacity</owner>\n");
|
|
|
|
printf (" <type>string</type>\n");
|
|
|
|
printf (" <default>%s</default>\n", escaped_default_value);
|
2008-10-18 00:33:14 -04:00
|
|
|
|
2008-10-05 20:24:07 -04:00
|
|
|
printf (" <locale name=\"C\">\n");
|
2008-10-18 00:33:14 -04:00
|
|
|
printf (" <short>%s</short>\n", description);
|
|
|
|
printf (" <long>%s</long>\n",
|
|
|
|
can_reverse? about_reversible_keybindings:
|
|
|
|
about_keybindings);
|
|
|
|
printf (" </locale>\n");
|
|
|
|
printf (" </schema>\n\n");
|
2008-10-05 20:24:07 -04:00
|
|
|
|
2008-10-18 00:33:14 -04:00
|
|
|
g_free (escaped_description);
|
2008-10-12 19:29:09 -04:00
|
|
|
|
2008-10-18 00:33:14 -04:00
|
|
|
if (default_value!=NULL)
|
|
|
|
g_free (escaped_default_value);
|
2008-10-05 20:24:07 -04:00
|
|
|
}
|
2008-09-06 18:01:56 -04:00
|
|
|
|
2008-10-12 19:29:09 -04:00
|
|
|
static void produce_bindings ();
|
|
|
|
|
|
|
|
static void
|
2008-10-05 20:24:07 -04:00
|
|
|
produce_bindings ()
|
|
|
|
{
|
2008-10-12 19:29:09 -04:00
|
|
|
FILE *metacity_schemas_in_in = fopen("metacity.schemas.in.in", "r");
|
|
|
|
|
|
|
|
if (!metacity_schemas_in_in)
|
|
|
|
{
|
|
|
|
g_error ("Cannot compile without metacity.schemas.in.in: %s\n",
|
|
|
|
strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!feof (metacity_schemas_in_in))
|
|
|
|
{
|
|
|
|
/* 10240 is ridiculous overkill; we're writing the input file and
|
|
|
|
* the lines are always 80 chars or less.
|
|
|
|
*/
|
|
|
|
char buffer[10240];
|
|
|
|
|
|
|
|
fgets (buffer, sizeof (buffer), metacity_schemas_in_in);
|
|
|
|
|
|
|
|
if (strstr (buffer, "<!-- GENERATED -->"))
|
|
|
|
break;
|
|
|
|
|
|
|
|
printf ("%s", buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!feof (metacity_schemas_in_in))
|
|
|
|
{
|
2008-10-21 21:02:45 -04:00
|
|
|
#define keybind(name, handler, param, flags, stroke, description) \
|
2008-10-18 00:33:14 -04:00
|
|
|
single_stanza ( \
|
|
|
|
flags & BINDING_PER_WINDOW, \
|
2008-10-21 21:02:45 -04:00
|
|
|
#name, \
|
|
|
|
stroke, \
|
2008-10-05 20:24:07 -04:00
|
|
|
flags & BINDING_REVERSES, \
|
2008-10-18 00:33:14 -04:00
|
|
|
description);
|
|
|
|
#include "window-bindings.h"
|
2008-10-05 20:24:07 -04:00
|
|
|
#include "screen-bindings.h"
|
2008-10-21 21:02:45 -04:00
|
|
|
#undef keybind
|
2008-10-12 19:29:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!feof (metacity_schemas_in_in))
|
|
|
|
{
|
|
|
|
char buffer[10240];
|
|
|
|
|
|
|
|
fgets (buffer, sizeof (buffer), metacity_schemas_in_in);
|
|
|
|
|
|
|
|
printf ("%s", buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (metacity_schemas_in_in);
|
2008-09-06 18:01:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main ()
|
|
|
|
{
|
2008-10-12 19:29:09 -04:00
|
|
|
/* Translators: Please don't translate "Control", "Shift", etc, since these
|
|
|
|
* are hardcoded (in gtk/gtkaccelgroup.c; it's not metacity's fault).
|
|
|
|
* "disabled" must also stay as it is.
|
2008-10-05 20:24:07 -04:00
|
|
|
*/
|
2008-10-18 00:33:14 -04:00
|
|
|
about_keybindings = g_markup_escape_text(_( \
|
|
|
|
"The format looks like \"<Control>a\" or <Shift><Alt>F1\".\n\n"\
|
2008-10-12 19:29:09 -04:00
|
|
|
"The parser is fairly liberal and allows "\
|
2008-09-06 18:01:56 -04:00
|
|
|
"lower or upper case, and also abbreviations such as \"<Ctl>\" and " \
|
|
|
|
"\"<Ctrl>\". If you set the option to the special string " \
|
2008-10-18 00:33:14 -04:00
|
|
|
"\"disabled\", then there will be no keybinding for this action."),
|
|
|
|
-1);
|
2008-10-05 20:24:07 -04:00
|
|
|
|
2008-10-18 00:33:14 -04:00
|
|
|
about_reversible_keybindings = g_markup_escape_text(_( \
|
|
|
|
"The format looks like \"<Control>a\" or <Shift><Alt>F1\".\n\n"\
|
|
|
|
"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.\n\n"\
|
|
|
|
"This keybinding may be reversed by holding down the \"shift\" key; "
|
|
|
|
"therefore, \"shift\" cannot be one of the keys it uses."),
|
|
|
|
-1);
|
2008-10-05 20:24:07 -04:00
|
|
|
|
|
|
|
produce_bindings ();
|
2008-10-18 00:33:14 -04:00
|
|
|
|
|
|
|
g_free (about_keybindings);
|
|
|
|
g_free (about_reversible_keybindings);
|
2008-10-12 19:29:09 -04:00
|
|
|
|
|
|
|
return 0;
|
2008-09-06 18:01:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* eof schema-bindings.c */
|
|
|
|
|