[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: alternate keymaps



   From: OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
   Date: Sun, 07 Mar 1999 16:56:56 +0900

   From: Ryan Yeske <rcyeske@sfu.ca>
   Subject: alternate keymaps
   Date: Sat, 6 Mar 1999 16:40:51 -0800

   > Is it possible to install a dvorak keymap under the Hurd as it stands?

     No, the keyboard driver of gnumach doesn't provide the interface to
   change the keymap. But it is not too difficult to modify the driver
   for that. If you'd like to do that, see i386/i386at/kd.[ch].

The gnumach keyboard driver DOES support changing the keymap.  See the
example code at the end of the message.  You also need
i386/i386at/kd.h from the gnumach sources and of course you'll have to
find out what to put in the map.  The program has to be run as root.

Mark

#include <errno.h>
#include <error.h>
#include <stdlib.h>

#include <mach.h>
#include <device/device.h>
#include <hurd.h>

#define	IOCPARM_MASK	0x1fff		/* parameter length, at most 13 bits */
#define	IOC_VOID	0x20000000	/* no parameters */
#define	IOC_OUT		0x40000000	/* copy out parameters */
#define	IOC_IN		0x80000000U	/* copy in parameters */
#define	IOC_INOUT	(IOC_IN|IOC_OUT)

#define _IOC(inout,group,num,len) \
	(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
#define	_IO(g,n)	_IOC(IOC_VOID,	(g), (n), 0)
#define	_IOR(g,n,t)	_IOC(IOC_OUT,	(g), (n), sizeof(t))
#define	_IOW(g,n,t)	_IOC(IOC_IN,	(g), (n), sizeof(t))
#define	_IOWR(g,n,t)	_IOC(IOC_INOUT,	(g), (n), sizeof(t))

/* Prevent inclusion of <sys/ioctl.h>.  */
#define _SYS_IOCTL_H 1
#include "kd.h"

#define K_PUPSC		0x49
#define K_ENDSC		0x4f
#define K_PDNSC		0x51
#define K_INSSC		0x52

struct kbentry map[] =
{
  { ALT_STATE, K_qSC, { K_ESC, K_q, K_DONE } },
  { ALT_STATE, K_wSC, { K_ESC, K_w, K_DONE } },
  { ALT_STATE, K_eSC, { K_ESC, K_e, K_DONE } },
  { ALT_STATE, K_rSC, { K_ESC, K_r, K_DONE } },
  { ALT_STATE, K_tSC, { K_ESC, K_t, K_DONE } },
  { ALT_STATE, K_ySC, { K_ESC, K_y, K_DONE } },
  { ALT_STATE, K_uSC, { K_ESC, K_u, K_DONE } },
  { ALT_STATE, K_iSC, { K_ESC, K_i, K_DONE } },
  { ALT_STATE, K_oSC, { K_ESC, K_o, K_DONE } },
  { ALT_STATE, K_pSC, { K_ESC, K_p, K_DONE } },
  { ALT_STATE, K_aSC, { K_ESC, K_a, K_DONE } },
  { ALT_STATE, K_sSC, { K_ESC, K_s, K_DONE } },
  { ALT_STATE, K_dSC, { K_ESC, K_d, K_DONE } },
  { ALT_STATE, K_fSC, { K_ESC, K_f, K_DONE } },
  { ALT_STATE, K_gSC, { K_ESC, K_g, K_DONE } },
  { ALT_STATE, K_hSC, { K_ESC, K_h, K_DONE } },
  { ALT_STATE, K_jSC, { K_ESC, K_j, K_DONE } },
  { ALT_STATE, K_kSC, { K_ESC, K_k, K_DONE } },
  { ALT_STATE, K_lSC, { K_ESC, K_l, K_DONE } },
  { ALT_STATE, K_zSC, { K_ESC, K_z, K_DONE } },
  { ALT_STATE, K_xSC, { K_ESC, K_x, K_DONE } },
  { ALT_STATE, K_cSC, { K_ESC, K_c, K_DONE } },
  { ALT_STATE, K_vSC, { K_ESC, K_v, K_DONE } },
  { ALT_STATE, K_bSC, { K_ESC, K_b, K_DONE } },
  { ALT_STATE, K_nSC, { K_ESC, K_n, K_DONE } },
  { ALT_STATE, K_mSC, { K_ESC, K_m, K_DONE } },
  { NORM_STATE, K_PUPSC, { K_ESC, K_LBRKT, K_I } },
  { NORM_STATE, K_ENDSC, { K_ESC, K_LBRKT, K_F } },
  { NORM_STATE, K_PDNSC, { K_ESC, K_LBRKT, K_G } },
  { NORM_STATE, K_INSSC, { K_ESC, K_LBRKT, K_L } },
  { K_DONE }
};

int
main (void)
{
  error_t err;
  mach_port_t device, consdev;
  struct kbentry *entry;
  
  err = get_privileged_ports (NULL, &device);
  if (err)
    error (EXIT_FAILURE, err, "cannot get device master port");

  err = device_open (device, D_READ|D_WRITE, "console", &consdev);
  mach_port_deallocate (mach_task_self (), device);
  if (err)
    error (EXIT_FAILURE, err, "console");

  for (entry = map; entry->kb_state != K_DONE; entry++)
    {
      err = device_set_status (consdev, KDSKBENT, entry,
			       (sizeof (struct kbentry)
			        + sizeof (natural_t) - 1)
			       / sizeof (natural_t) + 1);
      if (err)
	error (EXIT_FAILURE, err, "console (ioctl)");
    }

  exit (EXIT_SUCCESS);
}


Reply to: