summaryrefslogtreecommitdiff
path: root/hw/xfree86/utils/kbd_mode/bsd-kbd_mode.c
blob: 3c3c535acf565175847430c250a3191e0966d22a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* $XFree86: xc/programs/Xserver/hw/xfree86/etc/kbd_mode.c,v 3.5 1996/12/23 06:47:13 dawes Exp $ */


/* Keyboard mode control program for 386BSD */


/* $XConsortium: kbd_mode.c /main/7 1996/03/11 10:46:12 kaleb $ */

#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

#include "X.h"
#include "input.h"
#include "scrnintstr.h"

#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"

static int fd;

void
msg (char* s)
{
  perror (s);
  close (fd);
  exit (-1);
}

int
main(int argc, char** argv)
{
#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
    vtmode_t vtmode;
#endif
    Bool syscons = FALSE;

    if ((fd = open("/dev/vga",O_RDONLY,0)) <0)
      msg ("Cannot open /dev/vga");

#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
    /* Check if syscons */
    if (ioctl(fd, VT_GETMODE, &vtmode) >= 0)
      syscons = TRUE;
#endif
    
    if (0 == strcmp (argv[1], "-u"))
      {
	if (syscons)
	  {
#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
	    ioctl (fd, KDSKBMODE, K_RAW);
#endif
	  }
	else
	  {
	    if (ioctl (fd, CONSOLE_X_MODE_ON, 0) < 0)
	      {
	        close (fd);
	        exit (0);  /* Assume codrv, so nothing to do */
	      }
          }
      }
    else if (0 == strcmp (argv[1], "-a"))
      {
	if (syscons)
	  {
#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
	    ioctl (fd, KDSKBMODE, K_XLATE);
#endif
	  }
	else
	  {
	    if (ioctl (fd, CONSOLE_X_MODE_OFF, 0) < 0)
	      {
	        close (fd);
	        exit (0);  /* Assume codrv, so nothing to do */
	      }
          }
      }
    else
      {
	close (fd);
	fprintf (stderr,"Usage: %s [-u|-a]\n",argv[0]);
	fprintf (stderr,"-u for sending up down key events in x mode.\n");
	fprintf (stderr,"-a for sending ascii keys in normal use.\n");
	exit (-1);
      }
    close (fd);
    exit (0);
}