2003-11-12 21:58:51 +00:00
|
|
|
|
/* -*- mode: c; style: linux -*- */
|
|
|
|
|
|
|
|
|
|
/* gnome-settings-keyboard-xkb.c
|
|
|
|
|
*
|
|
|
|
|
* Copyright <EFBFBD> 2001 Udaltsoft
|
|
|
|
|
*
|
|
|
|
|
* Written by Sergey V. Oudaltsov <svu@users.sourceforge.net>
|
|
|
|
|
*
|
|
|
|
|
* 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, 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-02-27 19:13:54 +00:00
|
|
|
|
#include <glib/gstrfuncs.h>
|
2003-11-12 21:58:51 +00:00
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
|
#include <gconf/gconf-client.h>
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2004-11-27 16:05:03 +00:00
|
|
|
|
#include <time.h>
|
2003-11-12 21:58:51 +00:00
|
|
|
|
|
2003-11-23 02:44:21 +00:00
|
|
|
|
#include <libgnome/gnome-i18n.h>
|
|
|
|
|
|
2003-11-12 21:58:51 +00:00
|
|
|
|
#include <libxklavier/xklavier.h>
|
2004-01-09 20:43:59 +00:00
|
|
|
|
#include <libxklavier/xklavier_config.h>
|
2003-11-12 21:58:51 +00:00
|
|
|
|
#include <libgswitchit/gswitchit_xkb_config.h>
|
|
|
|
|
|
|
|
|
|
#include "gnome-settings-keyboard-xkb.h"
|
|
|
|
|
#include "gnome-settings-daemon.h"
|
|
|
|
|
|
|
|
|
|
static GSwitchItXkbConfig gswic;
|
|
|
|
|
static gboolean initedOk;
|
|
|
|
|
|
2004-05-25 17:36:44 +00:00
|
|
|
|
static PostActivationCallback paCallback = NULL;
|
|
|
|
|
static void *paCallbackUserData = NULL;
|
|
|
|
|
|
2004-09-03 19:56:16 +00:00
|
|
|
|
static const char DISABLE_XMM_WARNING_KEY[] =
|
|
|
|
|
"/desktop/gnome/peripherals/keyboard/disable_xmm_and_xkb_warning";
|
2004-02-27 19:13:54 +00:00
|
|
|
|
|
2004-05-12 21:54:46 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
RESPONSE_USE_X,
|
|
|
|
|
RESPONSE_USE_GNOME
|
|
|
|
|
} SysConfigChangedMsgResponse;
|
|
|
|
|
|
2004-11-27 16:05:03 +00:00
|
|
|
|
/* #define GSDKX */
|
|
|
|
|
|
|
|
|
|
#ifdef GSDKX
|
|
|
|
|
static FILE *logfile;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gnome_settings_keyboard_log_appender (const char file[], const char function[],
|
|
|
|
|
int level, const char format[], va_list args)
|
|
|
|
|
{
|
|
|
|
|
time_t now = time (NULL);
|
|
|
|
|
fprintf (logfile, "[%08ld,%03d,%s:%s/] \t", now,
|
|
|
|
|
level, file, function);
|
|
|
|
|
vfprintf (logfile, format, args);
|
|
|
|
|
fflush(logfile);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-11-23 02:44:21 +00:00
|
|
|
|
static void
|
|
|
|
|
activation_error (void)
|
|
|
|
|
{
|
|
|
|
|
char *vendor = ServerVendor (GDK_DISPLAY ());
|
|
|
|
|
int release = VendorRelease (GDK_DISPLAY ());
|
|
|
|
|
gboolean badXFree430Release = (!strcmp (vendor,
|
|
|
|
|
"The XFree86 Project, Inc"))
|
2003-11-26 10:15:04 +00:00
|
|
|
|
&& (release / 100000 == 403);
|
2003-11-23 02:44:21 +00:00
|
|
|
|
|
2004-01-22 09:11:22 +00:00
|
|
|
|
GtkWidget *msg = gtk_message_dialog_new_with_markup (NULL,
|
|
|
|
|
0,
|
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
|
_
|
|
|
|
|
("Error activating XKB configuration.\n"
|
|
|
|
|
"Probably internal X server problem.\n\nX server version data:\n%s\n%d\n%s\n"
|
|
|
|
|
"If you report this situation as a bug, please include:\n"
|
|
|
|
|
"- The result of <b>xprop -root | grep XKB</b>\n"
|
|
|
|
|
"- The result of <b>gconftool-2 -R /desktop/gnome/peripherals/keyboard/xkb</b>"),
|
|
|
|
|
vendor,
|
|
|
|
|
release,
|
|
|
|
|
badXFree430Release
|
|
|
|
|
?
|
|
|
|
|
_
|
|
|
|
|
("You are using XFree 4.3.0.\n"
|
|
|
|
|
"There are known problems with complex XKB configurations.\n"
|
|
|
|
|
"Try using simpler configuration or taking more fresh version of XFree software.")
|
|
|
|
|
: "");
|
2003-11-26 22:48:59 +00:00
|
|
|
|
g_signal_connect (msg, "response",
|
|
|
|
|
G_CALLBACK (gtk_widget_destroy), NULL);
|
|
|
|
|
gtk_widget_show (msg);
|
2003-11-23 02:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-12 21:58:51 +00:00
|
|
|
|
static void
|
|
|
|
|
apply_settings (void)
|
|
|
|
|
{
|
|
|
|
|
GConfClient *confClient;
|
|
|
|
|
|
2004-01-09 20:43:59 +00:00
|
|
|
|
if (!initedOk)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-11-12 21:58:51 +00:00
|
|
|
|
confClient = gconf_client_get_default ();
|
|
|
|
|
GSwitchItXkbConfigInit (&gswic, confClient);
|
|
|
|
|
g_object_unref (confClient);
|
|
|
|
|
GSwitchItXkbConfigLoad (&gswic);
|
|
|
|
|
|
2004-01-09 20:43:59 +00:00
|
|
|
|
if (gswic.overrideSettings) {
|
|
|
|
|
/* initialization - from the system settings */
|
2003-11-12 21:58:51 +00:00
|
|
|
|
GSwitchItXkbConfigLoadInitial (&gswic);
|
2004-01-09 20:43:59 +00:00
|
|
|
|
gswic.overrideSettings = FALSE;
|
|
|
|
|
GSwitchItXkbConfigSave (&gswic);
|
|
|
|
|
} else {
|
2004-05-25 17:36:44 +00:00
|
|
|
|
if (GSwitchItXkbConfigActivate (&gswic)) {
|
|
|
|
|
if (paCallback != NULL) {
|
|
|
|
|
(*paCallback) (paCallbackUserData);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2004-01-09 20:43:59 +00:00
|
|
|
|
g_warning
|
|
|
|
|
("Could not activate the XKB configuration");
|
|
|
|
|
activation_error ();
|
|
|
|
|
}
|
2003-11-23 02:44:21 +00:00
|
|
|
|
}
|
2003-11-12 21:58:51 +00:00
|
|
|
|
|
|
|
|
|
GSwitchItXkbConfigTerm (&gswic);
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-12 21:54:46 +00:00
|
|
|
|
static void
|
|
|
|
|
gnome_settings_keyboard_xkb_sysconfig_changed_response (GtkDialog * dialog,
|
|
|
|
|
SysConfigChangedMsgResponse
|
|
|
|
|
what2do,
|
|
|
|
|
GSwitchItXkbConfig
|
|
|
|
|
* pgswicNow)
|
|
|
|
|
{
|
|
|
|
|
switch (what2do) {
|
|
|
|
|
case RESPONSE_USE_X:
|
|
|
|
|
GSwitchItXkbConfigSave (pgswicNow);
|
|
|
|
|
break;
|
|
|
|
|
case RESPONSE_USE_GNOME:
|
|
|
|
|
/* Do absolutely nothing - just keep things the way they are */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (dialog));
|
|
|
|
|
GSwitchItXkbConfigTerm (pgswicNow);
|
|
|
|
|
g_free (pgswicNow);
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-08 03:08:51 +00:00
|
|
|
|
static void
|
|
|
|
|
gnome_settings_keyboard_xkb_analyze_sysconfig (void)
|
|
|
|
|
{
|
|
|
|
|
GConfClient *confClient;
|
2004-05-12 21:54:46 +00:00
|
|
|
|
GSwitchItXkbConfig gswicWas, *pgswicNow;
|
2004-09-27 22:33:49 +00:00
|
|
|
|
gboolean isConfigChanged;
|
2004-05-08 03:08:51 +00:00
|
|
|
|
|
|
|
|
|
if (!initedOk)
|
|
|
|
|
return;
|
2004-05-12 21:54:46 +00:00
|
|
|
|
pgswicNow = g_new (GSwitchItXkbConfig, 1);
|
2004-05-08 03:08:51 +00:00
|
|
|
|
confClient = gconf_client_get_default ();
|
|
|
|
|
GSwitchItXkbConfigInit (&gswicWas, confClient);
|
2004-05-12 21:54:46 +00:00
|
|
|
|
GSwitchItXkbConfigInit (pgswicNow, confClient);
|
2004-05-08 03:08:51 +00:00
|
|
|
|
g_object_unref (confClient);
|
|
|
|
|
GSwitchItXkbConfigLoadSysBackup (&gswicWas);
|
2004-05-12 21:54:46 +00:00
|
|
|
|
GSwitchItXkbConfigLoadInitial (pgswicNow);
|
2004-05-08 03:08:51 +00:00
|
|
|
|
|
2004-09-27 22:33:49 +00:00
|
|
|
|
isConfigChanged = g_slist_length (gswicWas.layouts) &&
|
|
|
|
|
!GSwitchItXkbConfigEquals (pgswicNow, &gswicWas);
|
2004-05-10 19:10:16 +00:00
|
|
|
|
/* config was changed!!! */
|
2004-09-27 22:33:49 +00:00
|
|
|
|
if (isConfigChanged) {
|
2004-05-08 03:08:51 +00:00
|
|
|
|
GtkWidget *msg = gtk_message_dialog_new_with_markup (NULL,
|
|
|
|
|
0,
|
2004-05-08 22:57:52 +00:00
|
|
|
|
GTK_MESSAGE_INFO,
|
2004-05-12 21:54:46 +00:00
|
|
|
|
GTK_BUTTONS_NONE,
|
2004-05-10 19:10:16 +00:00
|
|
|
|
/* !! temporary one */
|
2004-05-08 03:08:51 +00:00
|
|
|
|
_
|
2004-05-12 21:54:46 +00:00
|
|
|
|
("The X system keyboard settings differ from your current GNOME "
|
|
|
|
|
"keyboard settings. Which set would you like to use?"));
|
|
|
|
|
gtk_dialog_add_buttons (GTK_DIALOG (msg),
|
|
|
|
|
_("Use X settings"),
|
|
|
|
|
RESPONSE_USE_X,
|
|
|
|
|
_("Use GNOME settings"),
|
|
|
|
|
RESPONSE_USE_GNOME, NULL);
|
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (msg),
|
|
|
|
|
RESPONSE_USE_GNOME);
|
2004-05-08 03:08:51 +00:00
|
|
|
|
g_signal_connect (msg, "response",
|
2004-05-12 21:54:46 +00:00
|
|
|
|
G_CALLBACK
|
|
|
|
|
(gnome_settings_keyboard_xkb_sysconfig_changed_response),
|
|
|
|
|
pgswicNow);
|
2004-05-08 03:08:51 +00:00
|
|
|
|
gtk_widget_show (msg);
|
|
|
|
|
}
|
2004-05-12 21:54:46 +00:00
|
|
|
|
GSwitchItXkbConfigSaveSysBackup (pgswicNow);
|
2004-09-27 22:33:49 +00:00
|
|
|
|
if (!isConfigChanged)
|
|
|
|
|
g_free (pgswicNow);
|
2004-05-08 03:08:51 +00:00
|
|
|
|
GSwitchItXkbConfigTerm (&gswicWas);
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-27 19:13:54 +00:00
|
|
|
|
static void
|
|
|
|
|
gnome_settings_keyboard_xkb_chk_lcl_xmm_response (GtkDialog * dlg,
|
|
|
|
|
gint response)
|
|
|
|
|
{
|
|
|
|
|
GConfClient *gcc = gconf_client_get_default ();
|
|
|
|
|
switch (response) {
|
|
|
|
|
case GTK_RESPONSE_OK:
|
|
|
|
|
gconf_client_set_bool (gcc, DISABLE_XMM_WARNING_KEY, TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
g_object_unref (G_OBJECT (gcc));
|
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (dlg));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gnome_settings_keyboard_xkb_chk_lcl_xmm (void)
|
|
|
|
|
{
|
|
|
|
|
GConfClient *gcc = gconf_client_get_default ();
|
|
|
|
|
gboolean disableWarning =
|
|
|
|
|
gconf_client_get_bool (gcc, DISABLE_XMM_WARNING_KEY, NULL);
|
|
|
|
|
GDir *homeDir;
|
|
|
|
|
G_CONST_RETURN gchar *fname;
|
|
|
|
|
g_object_unref (G_OBJECT (gcc));
|
|
|
|
|
if (disableWarning)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
homeDir = g_dir_open (g_get_home_dir (), 0, NULL);
|
|
|
|
|
if (homeDir == NULL)
|
|
|
|
|
return;
|
|
|
|
|
while ((fname = g_dir_read_name (homeDir)) != NULL)
|
2004-09-03 19:56:16 +00:00
|
|
|
|
if (strlen (fname) >= 8
|
|
|
|
|
&& !g_ascii_strncasecmp (fname, ".xmodmap", 8)) {
|
|
|
|
|
GtkWidget *msg =
|
|
|
|
|
gtk_message_dialog_new_with_markup (NULL, 0,
|
|
|
|
|
GTK_MESSAGE_WARNING,
|
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
|
_
|
|
|
|
|
("You have a keyboard remapping file (%s) in your home directory whose contents will now be ignored."
|
|
|
|
|
" You can use the keyboard preferences to restore them."),
|
2004-08-28 01:42:25 +00:00
|
|
|
|
fname);
|
2004-02-27 19:13:54 +00:00
|
|
|
|
g_signal_connect (msg, "response",
|
|
|
|
|
G_CALLBACK
|
|
|
|
|
(gnome_settings_keyboard_xkb_chk_lcl_xmm_response),
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_widget_show (msg);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
g_dir_close (homeDir);
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-25 17:36:44 +00:00
|
|
|
|
void
|
|
|
|
|
gnome_settings_keyboard_xkb_set_post_activation_callback
|
|
|
|
|
(PostActivationCallback fun, void *userData)
|
|
|
|
|
{
|
|
|
|
|
paCallback = fun;
|
|
|
|
|
paCallbackUserData = userData;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-12 21:58:51 +00:00
|
|
|
|
void
|
|
|
|
|
gnome_settings_keyboard_xkb_init (GConfClient * client)
|
|
|
|
|
{
|
2004-11-27 16:05:03 +00:00
|
|
|
|
#ifdef GSDKX
|
|
|
|
|
XklSetDebugLevel (200);
|
|
|
|
|
logfile = fopen ("/tmp/gsdkx.log", "a");
|
|
|
|
|
XklSetLogAppender (gnome_settings_keyboard_log_appender);
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-11-12 21:58:51 +00:00
|
|
|
|
if (!XklInit (GDK_DISPLAY ())) {
|
|
|
|
|
initedOk = TRUE;
|
2004-05-08 03:08:51 +00:00
|
|
|
|
XklBackupNamesProp ();
|
|
|
|
|
gnome_settings_keyboard_xkb_analyze_sysconfig ();
|
2004-02-27 19:13:54 +00:00
|
|
|
|
gnome_settings_keyboard_xkb_chk_lcl_xmm ();
|
2003-11-12 21:58:51 +00:00
|
|
|
|
gnome_settings_daemon_register_callback
|
|
|
|
|
("/desktop/gnome/peripherals/keyboard/xkb",
|
|
|
|
|
(KeyCallbackFunc) apply_settings);
|
2004-11-27 16:05:03 +00:00
|
|
|
|
|
|
|
|
|
if (XklGetBackendFeatures() &
|
|
|
|
|
XKLF_REQUIRES_MANUAL_LAYOUT_MANAGEMENT)
|
|
|
|
|
{
|
|
|
|
|
gdk_window_add_filter (NULL,
|
|
|
|
|
(GdkFilterFunc) XklFilterEvents,
|
|
|
|
|
NULL);
|
|
|
|
|
gdk_window_add_filter (gdk_get_default_root_window(),
|
|
|
|
|
(GdkFilterFunc) XklFilterEvents,
|
|
|
|
|
NULL);
|
|
|
|
|
XklStartListen (XKLL_MANAGE_LAYOUTS);
|
|
|
|
|
}
|
2003-11-12 21:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gnome_settings_keyboard_xkb_load (GConfClient * client)
|
|
|
|
|
{
|
2004-01-09 20:43:59 +00:00
|
|
|
|
apply_settings ();
|
2003-11-12 21:58:51 +00:00
|
|
|
|
}
|