My hack for reading .Xmodmap
Hi, I was doing some experimenting with the latest servers, and found that the only way to get my custom .Xmodmap to be loaded automatically at startup was to force it to be read at the end of the DarwinKeyboardReloadHandler routine. Is it safe to call xmodmap at the end of the DarwinKeyboardReloadHandler routine? Using xmodmap is much easier than trying to parse the .Xmodmap files and then calling XkbApplyMappingChange. I had to background the calls to xmodmap or else the server would hang waiting for the xmodmap processes. I also only call xmodmap on the second (or any subsequent) calls to DarwinKeyboardReloadHandler. Here is my ugly hack to quartzKeyboard.c that seems to be working for me: diff -up xorg-server-1.4.2-apple49/hw/xquartz/quartzKeyboard.c.orig xorg-server-1.4.2-apple49/hw/xquartz/quartzKeyboard.c --- xorg-server-1.4.2-apple49/hw/xquartz/quartzKeyboard.c.orig 2009-10-14 11:06:49.000000000 -0400 +++ xorg-server-1.4.2-apple49/hw/xquartz/quartzKeyboard.c 2009-10-14 00:07:14.000000000 -0400 @@ -172,6 +172,7 @@ const static struct { darwinKeyboardInfo keyInfo; pthread_mutex_t keyInfo_mutex = PTHREAD_MUTEX_INITIALIZER; +int ran_darwin_kbdreload = 0; static void DarwinChangeKeyboardControl(DeviceIntPtr device, KeybdCtrl *ctrl) { // FIXME: to be implemented @@ -372,6 +373,9 @@ void DarwinKeyboardReloadHandler(void) { CFIndex initialKeyRepeatValue, keyRepeatValue; BOOL ok; DeviceIntPtr pDev = darwinKeyboard; + const char *xmodmap = PROJECTROOT "/bin/xmodmap"; + const char *sysmodmap = PROJECTROOT "/lib/X11/xinit/.Xmodmap"; + char *homedir, usermodmap[1024], cmd[1024]; DEBUG_LOG("DarwinKeyboardReloadHandler\n"); @@ -415,6 +419,28 @@ void DarwinKeyboardReloadHandler(void) { } XkbUpdateCoreDescription(darwinKeyboard, 0); } pthread_mutex_unlock(&keyInfo_mutex); + + if (ran_darwin_kbdreload > 0 && access(xmodmap, F_OK) == 0) { + + /* Check for system .Xmodmap */ + if (access(sysmodmap, F_OK) == 0) { + snprintf (cmd, sizeof(cmd), "exec %s %s &", xmodmap, sysmodmap); + System(cmd); + } + + /* Check for user's local .Xmodmap */ + homedir = getenv("HOME"); + if (homedir != NULL) { + snprintf (usermodmap, sizeof(usermodmap), "%s/.Xmodmap", homedir); + if (access(usermodmap, F_OK) == 0) { + snprintf (cmd, sizeof(cmd), "exec %s %s &", xmodmap, usermodmap); + System(cmd); + } + } + + } else + ran_darwin_kbdreload++; + } //----------------------------------------------------------------------------- Thanks, Martin
Here's the change I went with based on your original patch: http://cgit.freedesktop.org/~jeremyhu/xserver/commit/?id=5e79976c13c5b94b123... comments on yours: 1) hardcoded 1024... use PATH_MAX instead. 2) You only used ~/.Xmodmap if you also had a system one. --Jeremy On Oct 18, 2009, at 19:45, Martin Otte wrote:
Hi,
I was doing some experimenting with the latest servers, and found that the only way to get my custom .Xmodmap to be loaded automatically at startup was to force it to be read at the end of the DarwinKeyboardReloadHandler routine.
Is it safe to call xmodmap at the end of the DarwinKeyboardReloadHandler routine? Using xmodmap is much easier than trying to parse the .Xmodmap files and then calling XkbApplyMappingChange. I had to background the calls to xmodmap or else the server would hang waiting for the xmodmap processes. I also only call xmodmap on the second (or any subsequent) calls to DarwinKeyboardReloadHandler. Here is my ugly hack to quartzKeyboard.c that seems to be working for me:
diff -up xorg-server-1.4.2-apple49/hw/xquartz/quartzKeyboard.c.orig xorg-server-1.4.2-apple49/hw/xquartz/quartzKeyboard.c --- xorg-server-1.4.2-apple49/hw/xquartz/quartzKeyboard.c.orig 2009-10-14 11:06:49.000000000 -0400 +++ xorg-server-1.4.2-apple49/hw/xquartz/quartzKeyboard.c 2009-10-14 00:07:14.000000000 -0400 @@ -172,6 +172,7 @@ const static struct {
darwinKeyboardInfo keyInfo; pthread_mutex_t keyInfo_mutex = PTHREAD_MUTEX_INITIALIZER; +int ran_darwin_kbdreload = 0;
static void DarwinChangeKeyboardControl(DeviceIntPtr device, KeybdCtrl *ctrl) { // FIXME: to be implemented @@ -372,6 +373,9 @@ void DarwinKeyboardReloadHandler(void) { CFIndex initialKeyRepeatValue, keyRepeatValue; BOOL ok; DeviceIntPtr pDev = darwinKeyboard; + const char *xmodmap = PROJECTROOT "/bin/xmodmap"; + const char *sysmodmap = PROJECTROOT "/lib/X11/xinit/.Xmodmap"; + char *homedir, usermodmap[1024], cmd[1024];
DEBUG_LOG("DarwinKeyboardReloadHandler\n");
@@ -415,6 +419,28 @@ void DarwinKeyboardReloadHandler(void) { } XkbUpdateCoreDescription(darwinKeyboard, 0); } pthread_mutex_unlock(&keyInfo_mutex); + + if (ran_darwin_kbdreload > 0 && access(xmodmap, F_OK) == 0) { + + /* Check for system .Xmodmap */ + if (access(sysmodmap, F_OK) == 0) { + snprintf (cmd, sizeof(cmd), "exec %s %s &", xmodmap, sysmodmap); + System(cmd); + } + + /* Check for user's local .Xmodmap */ + homedir = getenv("HOME"); + if (homedir != NULL) { + snprintf (usermodmap, sizeof(usermodmap), "%s/.Xmodmap", homedir); + if (access(usermodmap, F_OK) == 0) { + snprintf (cmd, sizeof(cmd), "exec %s %s &", xmodmap, usermodmap); + System(cmd); + } + } + + } else + ran_darwin_kbdreload++; + }
//-----------------------------------------------------------------------------
Thanks, Martin <xquartz-force-xmodmap.patch>
_______________________________________________ Xquartz-dev mailing list Xquartz-dev@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/xquartz-dev
On 03Nov2009 16:48, Jeremy Huddleston <jeremyhu@apple.com> wrote: | Here's the change I went with based on your original patch: | http://cgit.freedesktop.org/~jeremyhu/xserver/commit/?id=5e79976c13c5b94b123... | | comments on yours: | 1) hardcoded 1024... use PATH_MAX instead. | 2) You only used ~/.Xmodmap if you also had a system one. [...] | > + /* Check for system .Xmodmap */ | > + if (access(sysmodmap, F_OK) == 0) { | > + snprintf (cmd, sizeof(cmd), "exec %s %s &", xmodmap, sysmodmap); | > + System(cmd); [...] Isn't there a decent performance/resouce gain from a direct fork/exec rather than System() (which goes fork, exec-/bin/sh, then /bin/sh forks and then execs xmodmap because of the "&). And it would be prudent to close stdin in the child, too. Cheers, -- Cameron Simpson <cs@zip.com.au> DoD#743 http://www.cskk.ezoshosting.com/cs/ UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. - Doug Gwyn
On Nov 3, 2009, at 19:05, Cameron Simpson wrote:
On 03Nov2009 16:48, Jeremy Huddleston <jeremyhu@apple.com> wrote: | Here's the change I went with based on your original patch: | http://cgit.freedesktop.org/~jeremyhu/xserver/commit/?id=5e79976c13c5b94b123...
Isn't there a decent performance/resouce gain from a direct fork/exec rather than System() (which goes fork, exec-/bin/sh, then /bin/sh forks and then execs xmodmap because of the "&). And it would be prudent to close stdin in the child, too.
Yeah, that's all done in X11Controller.m's -launch_client: which additionally sets DISPLAY if it is not set correctly.
participants (3)
-
Cameron Simpson
-
Jeremy Huddleston
-
Martin Otte