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>
|
2008-10-23 00:01:14 -04:00
|
|
|
#include <stdlib.h>
|
2008-10-12 19:29:09 -04:00
|
|
|
#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
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
char *source_filename, *target_filename;
|
|
|
|
FILE *source_file, *target_file;
|
|
|
|
|
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
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
fprintf (target_file, " <schema>\n");
|
|
|
|
fprintf (target_file, " <key>/schemas/apps/metacity/%s_keybindings/%s</key>\n",
|
2008-10-05 20:24:07 -04:00
|
|
|
keybinding_type, name);
|
2008-10-23 00:01:14 -04:00
|
|
|
fprintf (target_file, " <applyto>/apps/metacity/%s_keybindings/%s</applyto>\n",
|
2008-10-05 20:24:07 -04:00
|
|
|
keybinding_type, name);
|
2008-10-23 00:01:14 -04:00
|
|
|
fprintf (target_file, " <owner>metacity</owner>\n");
|
|
|
|
fprintf (target_file, " <type>string</type>\n");
|
|
|
|
fprintf (target_file, " <default>%s</default>\n", escaped_default_value);
|
2008-10-18 00:33:14 -04:00
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
fprintf (target_file, " <locale name=\"C\">\n");
|
|
|
|
fprintf (target_file, " <short>%s</short>\n", description);
|
|
|
|
fprintf (target_file, " <long>%s</long>\n",
|
2008-10-18 00:33:14 -04:00
|
|
|
can_reverse? about_reversible_keybindings:
|
|
|
|
about_keybindings);
|
2008-10-23 00:01:14 -04:00
|
|
|
fprintf (target_file, " </locale>\n");
|
|
|
|
fprintf (target_file, " </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-23 00:01:14 -04:00
|
|
|
source_file = fopen(source_filename, "r");
|
|
|
|
|
|
|
|
if (!source_file)
|
|
|
|
{
|
|
|
|
g_error ("Cannot compile without %s: %s\n",
|
|
|
|
source_filename, strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
target_file = fopen(target_filename, "w");
|
2008-10-12 19:29:09 -04:00
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
if (!target_file)
|
2008-10-12 19:29:09 -04:00
|
|
|
{
|
2008-10-23 00:01:14 -04:00
|
|
|
g_error ("Cannot create %s: %s\n",
|
|
|
|
target_filename, strerror (errno));
|
2008-10-12 19:29:09 -04:00
|
|
|
}
|
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
while (!feof (source_file))
|
2008-10-12 19:29:09 -04:00
|
|
|
{
|
|
|
|
/* 10240 is ridiculous overkill; we're writing the input file and
|
|
|
|
* the lines are always 80 chars or less.
|
|
|
|
*/
|
|
|
|
char buffer[10240];
|
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
fgets (buffer, sizeof (buffer), source_file);
|
2008-10-12 19:29:09 -04:00
|
|
|
|
|
|
|
if (strstr (buffer, "<!-- GENERATED -->"))
|
|
|
|
break;
|
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
fprintf (target_file, "%s", buffer);
|
2008-10-12 19:29:09 -04:00
|
|
|
}
|
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
if (!feof (source_file))
|
2008-10-12 19:29:09 -04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
while (!feof (source_file))
|
2008-10-12 19:29:09 -04:00
|
|
|
{
|
|
|
|
char buffer[10240];
|
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
fgets (buffer, sizeof (buffer), source_file);
|
2008-10-12 19:29:09 -04:00
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
fprintf (target_file, "%s", buffer);
|
2008-10-12 19:29:09 -04:00
|
|
|
}
|
|
|
|
|
2008-10-23 00:01:14 -04:00
|
|
|
if (fclose (source_file)!=0)
|
|
|
|
g_error ("Cannot close %s: %s\n",
|
|
|
|
source_filename, strerror (errno));
|
|
|
|
|
|
|
|
if (fclose (target_file)!=0)
|
|
|
|
g_error ("Cannot close %s: %s\n",
|
|
|
|
target_filename, strerror (errno));
|
2008-09-06 18:01:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-10-23 00:01:14 -04:00
|
|
|
main (int argc, char **argv)
|
2008-09-06 18:01:56 -04:00
|
|
|
{
|
2008-10-23 00:01:14 -04:00
|
|
|
if (argc!=3)
|
|
|
|
{
|
|
|
|
g_error ("Syntax: %s <source.in.in> <target.in>\n", argv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
source_filename = argv[1];
|
|
|
|
target_filename = argv[2];
|
|
|
|
|
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 */
|
|
|
|
|