diff options
| author | Huang Peng <shawn.p.huang@gmail.com> | 2008-09-12 08:42:37 +0800 |
|---|---|---|
| committer | Huang Peng <shawn.p.huang@gmail.com> | 2008-09-12 08:42:37 +0800 |
| commit | ad00c89cd9c4f975b2124e857fdbe24214cfd8cd (patch) | |
| tree | 4a01790080788e35fad849c09c670e3385799509 | |
| parent | bd9b695b5c81130f04f7315fcbef8a56a3c8291e (diff) | |
| download | ibus-ad00c89cd9c4f975b2124e857fdbe24214cfd8cd.tar.gz ibus-ad00c89cd9c4f975b2124e857fdbe24214cfd8cd.tar.xz ibus-ad00c89cd9c4f975b2124e857fdbe24214cfd8cd.zip | |
Fix problem when start a program with usermode-helper.
| -rw-r--r-- | client/qt4/ibus-client.cpp | 15 | ||||
| -rw-r--r-- | lib/gtk2/ibusimclient.c | 19 |
2 files changed, 32 insertions, 2 deletions
diff --git a/client/qt4/ibus-client.cpp b/client/qt4/ibus-client.cpp index 2f75d5a..32b6d97 100644 --- a/client/qt4/ibus-client.cpp +++ b/client/qt4/ibus-client.cpp @@ -26,6 +26,8 @@ #include <QDBusMessage> #include <QDBusArgument> +#include <pwd.h> + #include "ibus-client.h" #include "ibus-input-context.h" @@ -47,6 +49,19 @@ IBusClient::IBusClient () username = getlogin (); if (username.isEmpty ()) username = getenv ("SUDO_USER"); + if (username.isEmpty ()) { + QString uid = getenv ("USERHELPER_UID"); + if (!uid.isEmpty ()) { + bool ok; + uid_t id = uid.toInt (&ok); + if (ok) { + struct passwd *pw = getpwuid (id); + if ( pw != NULL) + username = pw->pw_name; + } + } + } + if (username.isEmpty ()) username = getenv ("USERNAME"); if (username.isEmpty ()) diff --git a/lib/gtk2/ibusimclient.c b/lib/gtk2/ibusimclient.c index 6c60dc4..71f99e8 100644 --- a/lib/gtk2/ibusimclient.c +++ b/lib/gtk2/ibusimclient.c @@ -25,6 +25,8 @@ #include <sys/un.h> #include <string.h> #include <stdarg.h> +#include <stdlib.h> +#include <pwd.h> #include <glib/gstdio.h> #include <gdk/gdk.h> #include <gdk/gdkx.h> @@ -376,6 +378,19 @@ _ibus_im_client_ibus_open (IBusIMClient *client) username = g_strdup (getlogin()); if (username == NULL) username = g_strdup (g_getenv("SUDO_USER")); + if (username == NULL) { + const gchar *uid = g_getenv ("USERHELPER_UID"); + if (uid != NULL) { + gchar *end; + uid_t id = (uid_t)strtol(uid, &end, 10); + if (uid != end) { + struct passwd *pw = getpwuid (id); + if (pw != NULL) { + username = g_strdup (pw->pw_name); + } + } + } + } if (username == NULL) username = g_strdup (g_getenv("USERNAME")); if (username == NULL) @@ -557,7 +572,7 @@ ibus_im_client_init (IBusIMClient *obj) g_object_ref (priv->keymap); _keymap_find_japan_groups (client); _keymap_find_yen_bar_keys (client); - g_debug ("japan_groups = 0x%x", priv->japan_groups); + g_debug ("japan_groups = 0x%lx", priv->japan_groups); priv->keymap_handler_id = g_signal_connect (priv->keymap, "keys-changed", @@ -1002,7 +1017,7 @@ _keymap_keys_changed_cb (GdkKeymap *keymap, IBusIMClient *client) { _keymap_find_japan_groups (client); _keymap_find_yen_bar_keys (client); - g_debug ("keymap changed japan_groups = 0x%x", + g_debug ("keymap changed japan_groups = 0x%lx", client->priv->japan_groups); } |
