=== modified file 'lib-src/emacsclient.c' --- lib-src/emacsclient.c 2014-06-17 16:09:19 +0000 +++ lib-src/emacsclient.c 2014-07-09 05:30:11 +0000 @@ -82,6 +82,8 @@ #include #include +#include + #ifndef VERSION #define VERSION "unspecified" #endif @@ -1517,6 +1519,31 @@ #endif /* WINDOWSNT */ } +/* Return the canonical HOST:SEQUENCE.SCREEN name of DISPLAY. + For some weird reason, this is important for XIM (Bug#17975). */ + +static char * +x_canonical_display (char *display) +{ + char host[256]; /* Max. FQDN length is 255. */ + int sequence, screen; + + if (sscanf (display, "%s:%d.%d", host, &sequence, &screen) == 3) + /* canonical */ ; + else if (sscanf (display, "%d:%d", &sequence, &screen) == 2 + || sscanf (display, ":%d:%d", &sequence, &screen) == 2) + { + display = xmalloc (4 + INT_BUFSIZE_BOUND (int) * 2 + 3); + sprintf (display, "unix:%d.%d", sequence, screen); + } + else if (sscanf (display, ":%d", &sequence) == 1) + { + display = xmalloc (4 + INT_BUFSIZE_BOUND (int) + 4); + sprintf (display, "unix:%d.0", sequence); + } + return display; +} + int main (int argc, char **argv) { @@ -1585,6 +1612,9 @@ w32_give_focus (); #endif /* HAVE_NTGUI */ + if (display) + display = x_canonical_display ((char *) display); + /* Send over our environment and current directory. */ if (!current_frame) {