diff options
Diffstat (limited to 'nx-X11/programs/Xserver/hw/xfree86/os-support/usl')
12 files changed, 2211 insertions, 0 deletions
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/Imakefile new file mode 100644 index 000000000..034c9c7d6 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/Imakefile @@ -0,0 +1,40 @@ +XCOMM $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/Imakefile,v 1.2 2005/11/08 06:33:29 jkj Exp $ +XCOMM $XConsortium$ + +#include <Server.tmpl> + +SRCS = usl_init.c usl_video.c usl_io.c usl_iop.c usl_mouse.c usl_vtsw.c \ + usl_xqueue.c std_kbdEv.c posix_tty.c bios_mmap.c vidmem.c \ + libc_wrapper.c stdResource.c stdPci.c sigiostubs.c pm_noop.c \ + kmod_noop.c agp_noop.c usl_kbd.c at_scancode.c usl_KbdMap.c + +OBJS = usl_init.o usl_video.o usl_io.o usl_iop.o usl_mouse.o usl_vtsw.o \ + usl_xqueue.o std_kbdEv.o posix_tty.o bios_mmap.o vidmem.o \ + libc_wrapper.o stdResource.o stdPci.o sigiostubs.o pm_noop.o \ + kmod_noop.o agp_noop.o usl_kbd.o at_scancode.o usl_KbdMap.o + +INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \ + -I$(SERVERSRC)/mi -I$(XINCLUDESRC) -I$(EXTINCSRC) + +RESDEFINES = -DUSESTDRES + +DEFINES = $(RESDEFINES) + +SubdirLibraryRule($(OBJS)) +NormalLibraryObjectRule() + +LinkSourceFile(bios_mmap.c,../shared) +LinkSourceFile(std_kbdEv.c,../shared) +LinkSourceFile(at_scancode.c,../shared) +LinkSourceFile(posix_tty.c,../shared) +LinkSourceFile(libc_wrapper.c,../shared) +LinkSourceFile(stdResource.c,../shared) +LinkSourceFile(stdPci.c,../shared) +LinkSourceFile(sigiostubs.c,../shared) +LinkSourceFile(pm_noop.c,../shared) +LinkSourceFile(kmod_noop.c,../shared) +LinkSourceFile(agp_noop.c,../shared) +LinkSourceFile(vidmem.c,../shared) + +DependTarget() + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c new file mode 100644 index 000000000..57c73f07a --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c @@ -0,0 +1,304 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c,v 1.2 2005/11/08 06:33:29 jkj Exp $ */ +/* + * Copyright 2005 by J. Kean Johnston <jkj@sco.com> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name J. Kean Johnston not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. J. Kean Johnston makes no + * representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Based on xf86KbdMap.c, which is + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. + * Copyright (c) 1992-2003 by The XFree86 Project, Inc. + */ + +#include "X.h" +#include "Xmd.h" +#include "input.h" +#include "scrnintstr.h" + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86Xinput.h" +#include "xf86OSKbd.h" +#include "atKeynames.h" +#include "xf86Keymap.h" + +#include "usl_kbd.h" + +#define KD_GET_ENTRY(i,n) \ + eascii_to_x[((priv->keymap.key[i].spcl << (n+1)) & 0x100) + priv->keymap.key[i].map[n]] + +/* + * NOTE: Not all possible remappable symbols are remapped. There are two main + * reasons: + * a) The mapping between scancode and SYSV/386 - symboltable + * is inconsistent between different versions and has some + * BIG mistakes. + * b) In X-Windows there is a difference between numpad-keys + * and normal keys. SYSV/386 uses for both kinds of keys + * the same symbol. + * + * Thus only the alpha keypad and the function keys are translated. + * Also CapsLock, NumLock, ScrollLock, Shift, Control & Alt. + */ + +static unsigned char remap[128] = { + 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */ + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */ + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */ + 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */ + 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */ + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */ + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */ + 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */ + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */ +}; + +static KeySym eascii_to_x[512] = { + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol, + NoSymbol, XK_Return, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, XK_Escape, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + XK_space, XK_exclam, XK_quotedbl, XK_numbersign, + XK_dollar, XK_percent, XK_ampersand, XK_apostrophe, + XK_parenleft, XK_parenright, XK_asterisk, XK_plus, + XK_comma, XK_minus, XK_period, XK_slash, + XK_0, XK_1, XK_2, XK_3, + XK_4, XK_5, XK_6, XK_7, + XK_8, XK_9, XK_colon, XK_semicolon, + XK_less, XK_equal, XK_greater, XK_question, + XK_at, XK_A, XK_B, XK_C, + XK_D, XK_E, XK_F, XK_G, + XK_H, XK_I, XK_J, XK_K, + XK_L, XK_M, XK_N, XK_O, + XK_P, XK_Q, XK_R, XK_S, + XK_T, XK_U, XK_V, XK_W, + XK_X, XK_Y, XK_Z, XK_bracketleft, + XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore, + XK_grave, XK_a, XK_b, XK_c, + XK_d, XK_e, XK_f, XK_g, + XK_h, XK_i, XK_j, XK_k, + XK_l, XK_m, XK_n, XK_o, + XK_p, XK_q, XK_r, XK_s, + XK_t, XK_u, XK_v, XK_w, + XK_x, XK_y, XK_z, XK_braceleft, + XK_bar, XK_braceright, XK_asciitilde, XK_Delete, + XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex, + XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla, + XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis, + XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring, + XK_Eacute, XK_ae, XK_AE, XK_ocircumflex, + XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave, + XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent, + XK_sterling, XK_yen, XK_paragraph, XK_section, + XK_aacute, XK_iacute, XK_oacute, XK_uacute, + XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine, + XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf, + XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi, + XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau, + XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta, + XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection, + XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal, + XK_topintegral, XK_botintegral, XK_division, XK_similarequal, + XK_degree, NoSymbol, NoSymbol, XK_radical, + XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol, + + /* + * special marked entries (256 + x) + */ + + NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R, + XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L, + NoSymbol, XK_Control_L, XK_Alt_L, XK_Alt_R, + XK_Control_L, XK_Control_R, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, XK_F1, + XK_F2, XK_F3, XK_F4, XK_F5, + XK_F6, XK_F7, XK_F8, XK_F9, + XK_F10, XK_F11, XK_F12, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + }; + +/* + * KbdGetMapping -- + * Get the national keyboard mapping. The keyboard type is set, a new map + * and the modifiermap is computed. + */ + +void +KbdGetMapping (InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private; + KeySym *k; + int i; + KeySym *pMap = map; + + for (i = 0; i < priv->keymap.n_keys && i < NUM_KEYCODES; i++) { + if (remap[i]) { + k = pMap + (remap[i] << 2); + + k[0] = KD_GET_ENTRY(i,0); /* non-shifed */ + k[1] = KD_GET_ENTRY(i,1); /* shifted */ + k[2] = KD_GET_ENTRY(i,4); /* alt */ + k[3] = KD_GET_ENTRY(i,5); /* alt - shifted */ + + if (k[3] == k[2]) k[3] = NoSymbol; + if (k[2] == k[1]) k[2] = NoSymbol; + if (k[1] == k[0]) k[1] = NoSymbol; + if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol; + } + } + + /* + * compute the modifier map + */ + for (i = 0; i < MAP_LENGTH; i++) + pModMap[i] = NoSymbol; /* make sure it is restored */ + + for (k = pMap, i = MIN_KEYCODE; + i < (NUM_KEYCODES + MIN_KEYCODE); + i++, k += 4) { + + switch(*k) { + case XK_Shift_L: + case XK_Shift_R: + pModMap[i] = ShiftMask; + break; + + case XK_Control_L: + case XK_Control_R: + pModMap[i] = ControlMask; + break; + + case XK_Caps_Lock: + pModMap[i] = LockMask; + break; + + case XK_Alt_L: + case XK_Alt_R: + pModMap[i] = AltMask; + break; + + case XK_Num_Lock: + pModMap[i] = NumLockMask; + break; + + case XK_Scroll_Lock: + pModMap[i] = ScrollLockMask; + break; + + /* kana support */ + case XK_Kana_Lock: + case XK_Kana_Shift: + pModMap[i] = KanaMask; + break; + + /* alternate toggle for multinational support */ + case XK_Mode_switch: + pModMap[i] = AltLangMask; + break; + } + } + + pKeySyms->map = pMap; + pKeySyms->mapWidth = GLYPHS_PER_KEY; + pKeySyms->minKeyCode = MIN_KEYCODE; + pKeySyms->maxKeyCode = MAX_KEYCODE; +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c new file mode 100644 index 000000000..35410b688 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c @@ -0,0 +1,359 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c,v 1.2 2005/11/08 06:33:29 jkj Exp $ */ +/* + * Copyright 2001-2005 by Kean Johnston <jkj@sco.com> + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany + * Copyright 1993 by David Wexelblat <dwex@goblin.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of Thomas Roell, David Wexelblat + * and Kean Johnston not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Thomas Roell, David Wexelblat and Kean Johnston make no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THOMAS ROELL, DAVID WEXELBLAT AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT + * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + * + */ +/* $XConsortium$ */ + +#include "X.h" +#include "Xmd.h" + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +#include <sys/utsname.h> + +static Bool KeepTty = FALSE; +static Bool Protect0 = FALSE; +static Bool CRTSpecified = FALSE; +static int VTnum = -1; +static char vtdevice[48]; + +int usl_is_osr6 = -1; + +static Bool +IsConsoleDevice(const char *dev) +{ + if ((!strcmp (dev, "/dev/console")) || + (!strcmp (dev, "/dev/syscon")) || + (!strcmp (dev, "/dev/systty"))) + return TRUE; + + return FALSE; +} + +static int +is_osr6 (void) +{ + struct utsname uts; + + if (usl_is_osr6 == -1) { + if (uname (&uts) < 0) { + FatalError ("get_usl_ver: Failed to determine UNIX name (%s)\n", + strerror (errno)); + } + + if (uts.version[0] == '6') + usl_is_osr6 = 1; + else + usl_is_osr6 = 0; + } + + return usl_is_osr6; +} + + +void +xf86OpenConsole(void) +{ + int fd, i, ioctl_ret; + struct vt_mode VT; + struct vt_stat vts; + MessageType from = X_PROBED; + struct sigaction sigvtsw; + char *ttn; + + if (serverGeneration == 1) { + int isconsole = 0, consdev = 0; + + /* check if we're run with euid==0 */ + if (geteuid() != 0) { + FatalError("xf86OpenConsole: Server must be suid root\n"); + } + + /* If we are run in the background we will get SIGTTOU. Ignore it. */ + OsSignal (SIGTTOU, SIG_IGN); + + /* Protect page 0 to help find NULL dereferencing */ + /* mprotect() doesn't seem to work */ + if (Protect0) { + int fd = -1; + + if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0) { + xf86Msg(X_WARNING, "xf86OpenConsole: cannot open /dev/zero (%s)\n", + strerror(errno)); + } else { + if ((int)mmap(0, 0x1000, PROT_NONE, + MAP_FIXED | MAP_SHARED, fd, 0) == -1) { + xf86Msg(X_WARNING, "xf86OpenConsole: failed to protect page 0 (%s)\n", + strerror(errno)); + } + close(fd); + } + } + + /* + * setup the virtual terminal manager + */ + if (VTnum == -1) { + /* + * No device was specified. We need to query the kernel to see which + * console device we are on (and in fact if we are on a console at all). + */ + if (ioctl (0, VT_GETSTATE, &vts) < 0) { + FatalError("xf86OpenConsole: Could not query active VT: %s\n", + strerror(errno)); + } + VTnum = vts.v_active; + if (is_osr6()) + snprintf (vtdevice, sizeof(vtdevice), "/dev/tty%02d", VTnum + 1); + else + snprintf (vtdevice, sizeof(vtdevice), "/dev/vt%02d", VTnum); + } else { + from = X_CMDLINE; + if (is_osr6()) + snprintf (vtdevice, sizeof(vtdevice), "/dev/tty%02d", VTnum + 1); + else + snprintf (vtdevice, sizeof(vtdevice), "/dev/vt%02d", VTnum); + } + + if (IsConsoleDevice(vtdevice)) { + isconsole = 1; + CRTSpecified = FALSE; /* Dont honour -crt /dev/console */ + } + + if (ioctl (0, KIOCINFO, 0) >= 0) + consdev = 1 + isconsole; + + if ((!CRTSpecified) && (isconsole || (!consdev))) { + /* + * Need to find a free VT + */ + if ((fd = open ("/dev/console", O_WRONLY | O_NOCTTY)) < 0) { + FatalError ("xf86OpenConsole: Could not open /dev/console: %s\n", + strerror (errno)); + } + + if (ioctl (fd, VT_OPENQRY, &VTnum) < 0) { + FatalError ("xf86OpenConsole: Cannot find a free VT: %s\n", + strerror(errno)); + } + close (fd); + if (usl_is_osr6) + snprintf (vtdevice, sizeof(vtdevice), "/dev/tty%02d", VTnum + 1); + else + snprintf (vtdevice, sizeof(vtdevice), "/dev/vt%02d", VTnum); + } + + /* + * Now we can dispose of stdin/stdout + */ + fclose (stdin); + fclose (stdout); + + if (CRTSpecified || isconsole || consdev != 1) { + if (!KeepTty) { + setpgrp(); + } + } + + if ((xf86Info.consoleFd = open(vtdevice, O_RDWR | O_NONBLOCK, 0)) < 0) { + FatalError("xf86OpenConsole: Cannot open %s: %s\n", vtdevice, + strerror(errno)); + } + + xf86Msg (from, "using VT number %d (%s)\n\n", VTnum, vtdevice); + xf86Info.vtno = VTnum; + + /* change ownership of the vt */ + chown(vtdevice, getuid(), getgid()); + + /* + * now get the VT + */ + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) { + FatalError("xf86OpenConsole: VT_ACTIVATE failed: %s\n", + strerror(errno)); + } + if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0) { + FatalError("xf86OpenConsole: VT_WAITACTIVE failed: %s\n",strerror(errno)); + } + + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) { + FatalError("xf86OpenConsole: VT_GETMODE failed: %s\n", strerror(errno)); + } + + sigvtsw.sa_handler = xf86VTRequest; + sigfillset(&sigvtsw.sa_mask); + sigvtsw.sa_flags = 0; + sigaction(SIGUSR1, &sigvtsw, NULL); + + VT.mode = VT_PROCESS; + VT.relsig = SIGUSR1; + VT.acqsig = SIGUSR1; + + ioctl_ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); + if (ioctl_ret < 0) { + FatalError("xf86OpenConsole: VT_SETMODE failed: %s\n", strerror(errno)); + } + + if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) { + FatalError("xf86OpenConsole: KD_GRAPHICS failed: %s\n", strerror(errno)); + } + } else { /* serverGeneration != 1 */ + /* + * now get the VT + */ + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) { + FatalError("xf86OpenConsole: VT_ACTIVATE failed: %s\n", strerror(errno)); + } + if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0) { + FatalError("xf86OpenConsole: VT_WAITACTIVE failed: %s\n",strerror(errno)); + } + /* + * If the server doesn't have the VT when the reset occurs, + * this is to make sure we don't continue until the activate + * signal is received. + */ + if (!xf86Screens[0]->vtSema) + sleep(5); + } + return; +} + +void +xf86CloseConsole(void) +{ + struct vt_mode VT; + struct sigaction sigvtsw; + + ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */ + + sigvtsw.sa_handler = SIG_DFL; + sigfillset(&sigvtsw.sa_mask); + sigvtsw.sa_flags = 0; + sigaction(SIGUSR1, &sigvtsw, NULL); + + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) { + VT.mode = VT_AUTO; + VT.waitv = 0; + ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */ + } + close(xf86Info.consoleFd); /* make the vt-manager happy */ + return; +} + +int +xf86ProcessArgument(int argc, char *argv[], int i) +{ + /* + * Keep server from detaching from controlling tty. This is useful + * when debugging (so the server can receive keyboard signals. + */ + if (!strcmp(argv[i], "-keeptty")) { + KeepTty = TRUE; + return(1); + } + + /* + * Undocumented flag to protect page 0 from read/write to help + * catch NULL pointer dereferences. This is purely a debugging + * flag. + */ + if (!strcmp(argv[i], "-protect0")) { + Protect0 = TRUE; + return(1); + } + + if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { + if (sscanf(argv[i], "vt%2d", &VTnum) == 0) { + UseMsg(); + VTnum = -1; + return(0); + } + VTnum -= is_osr6(); + CRTSpecified = TRUE; + return(1); + } + + /* + * Use a device the user specifies. + */ + if (!strcmp(argv[i], "-crt")) { + if (++i > argc) { + UseMsg(); + VTnum = -1; + return(0); + } else { + char *mytty = ttyname(0); + char *arg = argv[i]; + + if (!mytty) + mytty = "\1"; + if (!arg[0]) + arg = "\2"; /* Prevent idiots from using -crt "" */ + + if (strcmp (mytty, arg) != 0) { + char *fmt; + + if (is_osr6()) + fmt = "/dev/tty%02d"; + else + fmt = "/dev/vt%02d"; + + if (sscanf(arg, fmt, &VTnum) == 0) { + UseMsg(); + VTnum = -1; + return(0); + } + + /* OSR6 devices start names at 1, UW7 starts at 0 */ + VTnum -= is_osr6(); + CRTSpecified = TRUE; + } + return(2); + } + } + return(0); +} + +void +xf86UseMsg(void) +{ + if (is_osr6()) { + ErrorF("-crt /dev/ttyXX use the specified VT device\n"); + ErrorF("vtXX use the specified VT number (01-16)\n"); + } else { + ErrorF("-crt /dev/vtXX use the specified VT device\n"); + ErrorF("vtXX use the specified VT number (00-15)\n"); + } + + ErrorF("-keeptty "); + ErrorF("don't detach controlling tty (for debugging only)\n"); + return; +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c new file mode 100644 index 000000000..c93e8058e --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c @@ -0,0 +1,172 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */ +/* + * Copyright 2001-2005 by Kean Johnston <jkj@sco.com> + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany + * Copyright 1993 by David Dawes <dawes@xfree86.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of Thomas Roell, David Dawes + * and Kean Johnston not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Thomas Roell, David Dawes and Kean Johnston make no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THOMAS ROELL, DAVID DAWES AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT + * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + * + */ +/* $XConsortium$ */ + +#include "X.h" + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +void +xf86SoundKbdBell(int loudness, int pitch, int duration) +{ + if (loudness && pitch) { + ioctl(xf86Info.consoleFd, KIOCSOUND, 1193180 / pitch); + usleep(xf86Info.bell_duration * loudness * 20); + ioctl(xf86Info.consoleFd, KIOCSOUND, 0); + } +} + +void +xf86SetKbdLeds(int leds) +{ + ioctl(xf86Info.consoleFd, KDSETLED, leds); +} + +int +xf86GetKbdLeds(void) +{ + int leds; + + ioctl(xf86Info.consoleFd, KDGETLED, &leds); + return(leds); +} + +/* + * Much of the code in this function is duplicated from the Linux code + * by Orest Zborowski <obz@Kodak.com> and David Dawes <dawes@xfree86.org>. + * Please see the file ../linux/lnx_io.c for full copyright information. + */ +void +xf86SetKbdRepeat(char rad) +{ + int i; + int value = 0x7f; /* Maximum delay with slowest rate */ + int delay = 250; /* Default delay */ + int rate = 300; /* Default repeat rate */ + + static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150, + 133, 120, 109, 100, 92, 86, 80, 75, 67, + 60, 55, 50, 46, 43, 40, 37, 33, 30, 27, + 25, 23, 21, 20 }; +#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int )) + + static int valid_delays[] = { 250, 500, 750, 1000 }; +#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int )) + + if (xf86Info.kbdRate >= 0) + rate = xf86Info.kbdRate * 10; + if (xf86Info.kbdDelay >= 0) + delay = xf86Info.kbdDelay; + + for (i = 0; i < RATE_COUNT; i++) + if (rate >= valid_rates[i]) { + value &= 0x60; + value |= i; + break; + } + + for (i = 0; i < DELAY_COUNT; i++) + if (delay <= valid_delays[i]) { + value &= 0x1f; + value |= i << 5; + break; + } + + ioctl (xf86Info.consoleFd, KDSETTYPEMATICS, value); +} + +static int orig_kbm; +static struct termio orig_termio; +static keymap_t keymap, noledmap; + +void +xf86KbdInit(void) +{ + ioctl (xf86Info.consoleFd, KDGKBMODE, &orig_kbm); + ioctl (xf86Info.consoleFd, TCGETA, &orig_termio); + /* + * We need to get the original keyboard map and NUL out the lock + * modifiers. This prevents the scancode API from messing with + * the keyboard LED's. We restore the original map when we exit. + */ + if (ioctl (xf86Info.consoleFd, GIO_KEYMAP, &keymap) < 0) { + FatalError ("xf86KbdInit: Failed to get keyboard map (%s)\n", + strerror(errno)); + } + if (ioctl (xf86Info.consoleFd, GIO_KEYMAP, &noledmap) < 0) { + FatalError ("xf86KbdInit: Failed to get keyboard map (%s)\n", + strerror(errno)); + } else { + int i, j; + + for (i = 0; i < noledmap.n_keys; i++) { + for (j = 0; j < NUM_STATES; j++) { + if (IS_SPECKEY(&noledmap, i, j) && + ((noledmap.key[i].map[j] == K_CLK) || + (noledmap.key[i].map[j] == K_NLK) || + (noledmap.key[i].map[j] == K_SLK))) { + noledmap.key[i].map[j] = K_NOP; + } + } + } + } +} + +int +xf86KbdOn(void) +{ + struct termio newtio; + + newtio = orig_termio; /* structure copy */ + newtio.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); + newtio.c_oflag = 0; + newtio.c_cflag = CREAD | CS8 | B9600; + newtio.c_lflag = 0; + newtio.c_cc[VTIME]=0; + newtio.c_cc[VMIN]=1; + ioctl(xf86Info.consoleFd, TCSETA, &newtio); + + ioctl (xf86Info.consoleFd, KDSKBMODE, K_RAW); + ioctl (xf86Info.consoleFd, PIO_KEYMAP, &noledmap); + + return(xf86Info.consoleFd); +} + +int +xf86KbdOff(void) +{ + ioctl (xf86Info.consoleFd, KDSKBMODE, orig_kbm); + ioctl (xf86Info.consoleFd, PIO_KEYMAP, &keymap); + ioctl(xf86Info.consoleFd, TCSETA, &orig_termio); + + return(xf86Info.consoleFd); +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c new file mode 100644 index 000000000..362ac369e --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c @@ -0,0 +1,108 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */ +/* + * Copyright 2001,2005 by Kean Johnston <jkj@sco.com> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name Kean Johnston not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Kean Johnston makes no + * representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ +/* $XConsortium$ */ + + +#include "X.h" + +#include "compiler.h" + +#define _NEED_SYSI86 +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86OSpriv.h" +#include "xf86_OSlib.h" + + +/***************************************************************************/ +/* I/O Permissions section */ +/***************************************************************************/ + +static Bool IOEnabled = FALSE; + +Bool +xf86EnableIO(void) +{ + if (IOEnabled) + return TRUE; + + if (sysi86(SI86IOPL, 3) < 0) + FatalError("Failed to set IOPL for extended I/O\n"); + IOEnabled = TRUE; + return TRUE; +} + +void +xf86DisableIO(void) +{ + if (!IOEnabled) + return; + + sysi86(SI86IOPL, 0); + IOEnabled = FALSE; +} + +/***************************************************************************/ +/* Interrupt Handling section */ +/***************************************************************************/ + +Bool +xf86DisableInterrupts(void) +{ + if (!IOEnabled) { + if (sysi86(SI86IOPL, 3) < 0) + return FALSE; + } + +#ifdef __GNUC__ + __asm__ __volatile__("cli"); +#else + asm("cli"); +#endif /* __GNUC__ */ + + if (!IOEnabled) { + sysi86(SI86IOPL, 0); + } + + return(TRUE); +} + +void +xf86EnableInterrupts(void) +{ + if (!IOEnabled) { + if (sysi86(SI86IOPL, 3) < 0) + return; + } + +#ifdef __GNUC__ + __asm__ __volatile__("sti"); +#else + asm("sti"); +#endif /* __GNUC__ */ + + if (!IOEnabled) { + sysi86(SI86IOPL, 0); + } +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c new file mode 100644 index 000000000..c6e089db8 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c @@ -0,0 +1,456 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */ +/* + * Copyright 2005 by Kean Johnston <jkj@sco.com> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name Kean Johnston not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Kean Johnston makes no + * representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ +/* $XConsortium$ */ + +/* + * Based on sco_io.c which is + * (C) Copyright 2003 Kean Johnston <jkj@sco.com> + * + * Based on lnx_kbd.c which is + * Copyright (c) 2002 by The XFree86 Project, Inc. + * + * Based on the code from lnx_io.c which is + * Copyright 1992 by Orest Zborowski <obz@Kodak.com> + * Copyright 1993 by David Dawes <dawes@xfree86.org> + */ + +#define NEED_EVENTS +#include "X.h" + +#include "compiler.h" + +#define _NEED_SYSI86 +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86OSpriv.h" +#include "xf86_OSlib.h" + +#include "xf86Xinput.h" +#include "xf86OSKbd.h" +#include "atKeynames.h" +#include "usl_kbd.h" +#include "usl_xqueue.h" + +#include <sys/param.h> + +static KbdProtocolRec protocols[] = { + { "standard", PROT_STD }, + { "Xqueue", PROT_XQUEUE }, + { NULL, PROT_UNKNOWN_KBD } +}; + +extern Bool VTSwitchEnabled; +#ifdef USE_VT_SYSREQ +extern Bool VTSysreqToggle; +#endif + +static void +SoundBell(InputInfoPtr pInfo, int loudness, int pitch, int duration) +{ + if (loudness && pitch) { + ioctl(pInfo->fd, KIOCSOUND, 1193180 / pitch); + usleep(duration * loudness * 20); + ioctl(pInfo->fd, KIOCSOUND, 0); + } +} + +static void +SetKbdLeds(InputInfoPtr pInfo, int leds) +{ + int real_leds = 0; + + if (leds & XLED1) + real_leds |= LED_CAP; + if (leds & XLED2) + real_leds |= LED_NUM; + if (leds & XLED3) + real_leds |= LED_SCR; + ioctl(pInfo->fd, KDSETLED, real_leds); +} + +static int +GetKbdLeds(InputInfoPtr pInfo) +{ + int real_leds, leds = 0; + + ioctl(pInfo->fd, KDGETLED, &real_leds); + + if (real_leds & LED_CAP) leds |= XLED1; + if (real_leds & LED_NUM) leds |= XLED2; + if (real_leds & LED_SCR) leds |= XLED3; + + return(leds); +} + +static void +SetKbdRepeat(InputInfoPtr pInfo, char rad) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + int i; + int value = 0x7f; /* Maximum delay with slowest rate */ + int delay = 250; /* Default delay */ + int rate = 300; /* Default repeat rate */ + + static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150, + 133, 120, 109, 100, 92, 86, 80, 75, 67, + 60, 55, 50, 46, 43, 40, 37, 33, 30, 27, + 25, 23, 21, 20 }; +#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int )) + + static int valid_delays[] = { 250, 500, 750, 1000 }; +#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int )) + + if (pKbd->rate >= 0) + rate = pKbd->rate * 10; + if (pKbd->delay >= 0) + delay = pKbd->delay; + + for (i = 0; i < RATE_COUNT; i++) + if (rate >= valid_rates[i]) { + value &= 0x60; + value |= i; + break; + } + + for (i = 0; i < DELAY_COUNT; i++) + if (delay <= valid_delays[i]) { + value &= 0x1f; + value |= i << 5; + break; + } + + ioctl (pInfo->fd, KDSETTYPEMATICS, value); +} + +static int +KbdInit(InputInfoPtr pInfo, int what) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private; + + if (pKbd->isConsole) { + if (ioctl (pInfo->fd, KDGKBMODE, &priv->orig_kbm) < 0) { + xf86Msg (X_ERROR, "KbdInit: Could not determine keyboard mode\n"); + return !Success; + } + + /* + * We need to get the original keyboard map and NUL out the lock + * modifiers. This prevents the kernel from messing with + * the keyboard LED's. We restore the original map when we exit. + * Note that we also have to eliminate screen switch sequences + * else the VT manager will switch for us, which we don't want. + * For example, lets say you had changed the VT manager to switch + * on Alt-Fx instead of Ctrl-Alt-Fx. This means that while inside + * X, you cant use, for example, Alt-F4, which is a pain in the + * fundamental when you're using CDE-like thingies. + */ + if (ioctl (pInfo->fd, GIO_KEYMAP, &priv->keymap) < 0) { + xf86Msg (X_ERROR, "KbdInit: Failed to get keyboard map (%s)\n", + strerror(errno)); + return !Success; + } + if (ioctl (pInfo->fd, GIO_KEYMAP, &priv->noledmap) < 0) { + xf86Msg (X_ERROR, "KbdInit: Failed to get keyboard map (%s)\n", + strerror(errno)); + return !Success; + } else { + int i, j; + + for (i = 0; i < priv->noledmap.n_keys; i++) { + for (j = 0; j < NUM_STATES; j++) { + if (IS_SPECKEY(&priv->noledmap, i, j) && + ((priv->noledmap.key[i].map[j] == K_CLK) || + (priv->noledmap.key[i].map[j] == K_NLK) || + (priv->noledmap.key[i].map[j] == K_SLK) || + (priv->noledmap.key[i].map[j] == K_FRCNEXT) || + (priv->noledmap.key[i].map[j] == K_FRCPREV) || + ((priv->noledmap.key[i].map[j] >= K_VTF) && + (priv->noledmap.key[i].map[j] <= K_VTL)) )) { + priv->noledmap.key[i].map[j] = K_NOP; + } + } + } + } + + if (ioctl (pInfo->fd, TCGETA, &priv->kbdtty) < 0) { + xf86Msg (X_ERROR, "KbdInit: Failed to get terminal modes (%s)\n", + strerror(errno)); + return !Success; + } + } /* End of if we are on a console */ + + return Success; +} + +static int +KbdOn(InputInfoPtr pInfo, int what) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private; + struct termio newtio; + + if (pKbd->isConsole) { + /* + * Use the calculated keyboard map that does not have active + * LED lock handling (we track LEDs ourselves). + */ + ioctl (pInfo->fd, PIO_KEYMAP, &priv->noledmap); + +#ifdef NOTYET + newtio = priv->kbdtty; /* structure copy */ + newtio.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); + newtio.c_oflag = 0; + newtio.c_cflag = CREAD | CS8 | B9600; + newtio.c_lflag = 0; + newtio.c_cc[VTIME]=0; + newtio.c_cc[VMIN]=1; + ioctl(pInfo->fd, TCSETA, &newtio); + + if (priv->xq == 0) + ioctl (pInfo->fd, KDSKBMODE, K_RAW); + else +#endif + XqKbdOnOff (pInfo, 1); + } + + return Success; +} + +static int +KbdOff(InputInfoPtr pInfo, int what) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private; + + if (pKbd->isConsole) { + /* Revert back to original translate scancode mode */ +#ifdef NOTYET + if (priv->xq == 0) + ioctl (pInfo->fd, KDSKBMODE, priv->orig_kbm); + else +#endif + XqKbdOnOff (pInfo, 0); + + ioctl (pInfo->fd, PIO_KEYMAP, &priv->keymap); + ioctl(pInfo->fd, TCSETA, &priv->kbdtty); + } + + return Success; +} + +#define ModifierSet(k) ((modifiers & (k)) == (k)) + +static Bool +SpecialKey(InputInfoPtr pInfo, int key, Bool down, int modifiers) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + + if(!pKbd->vtSwitchSupported) + return FALSE; + + if ((!ModifierSet(ShiftMask)) && ((ModifierSet(ControlMask | AltMask)) || + (ModifierSet(ControlMask | AltLangMask)))) { + if (VTSwitchEnabled && !xf86Info.vtSysreq) { + switch (key) { + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + if (down) { + int sts = key - KEY_F1; + if (sts != xf86Info.vtno) { + ioctl(pInfo->fd, VT_SWITCH, sts); + } + return TRUE; + } + case KEY_F11: + case KEY_F12: + if (down) { + int sts = key - KEY_F11 + 10; + if (sts != xf86Info.vtno) { + ioctl(pInfo->fd, VT_SWITCH, sts); + } + return TRUE; + } + } + } + } +#ifdef USE_VT_SYSREQ + if (VTSwitchEnabled && xf86Info.vtSysreq) { + switch (key) { + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + if (VTSysreqToggle && down) { + ioctl(pInfo->fd, VT_ACTIVATE, key - KEY_F1); + VTSysreqToggle = FALSE; + return TRUE; + } + break; + case KEY_F11: + case KEY_F12: + if (VTSysreqToggle && down) { + ioctl(pInfo->fd, VT_ACTIVATE, key - KEY_F11 + 10); + VTSysreqToggle = FALSE; + return TRUE; + } + break; + /* Ignore these keys -- ie don't let them cancel an alt-sysreq */ + case KEY_Alt: + case KEY_AltLang: + break; + case KEY_SysReqest: + if (!(ModifierSet(ShiftMask) || ModifierSet(ControlMask))) { + if ((ModifierSet(AltMask) || ModifierSet(AltLangMask)) && down) + VTSysreqToggle = TRUE; + } + break; + default: + /* + * We only land here when Alt-SysReq is followed by a + * non-switching key. + */ + if (VTSysreqToggle) + VTSysreqToggle = FALSE; + } + } +#endif /* USE_VT_SYSREQ */ + return FALSE; +} + +#ifdef NOTYET +static void +stdReadInput(InputInfoPtr pInfo) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + unsigned char rBuf[64]; + int nBytes, i; + + if ((nBytes = read( pInfo->fd, (char *)rBuf, sizeof(rBuf))) > 0) { + for (i = 0; i < nBytes; i++) { + pKbd->PostEvent(pInfo, rBuf[i] & 0x7f, rBuf[i] & 0x80 ? FALSE : TRUE); + } + } +} +#endif + +static Bool +OpenKeyboard(InputInfoPtr pInfo) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private; + int i; + KbdProtocolId prot = PROT_UNKNOWN_KBD; + char *s; + + s = xf86SetStrOption(pInfo->options, "Protocol", NULL); + for (i = 0; protocols[i].name; i++) { + if (xf86NameCmp(s, protocols[i].name) == 0) { + prot = protocols[i].id; + break; + } + } + + switch (prot) { + case PROT_STD: +#ifdef NOTYET + pInfo->read_input = stdReadInput; + priv->xq = 0; + break; +#endif + case PROT_XQUEUE: + pInfo->read_input = NULL; /* Handled by the XQUEUE signal handler */ + priv->xq = 1; + break; + default: + xf86Msg(X_ERROR,"\"%s\" is not a valid keyboard protocol name\n", s); + xfree(s); + return FALSE; + } + + xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, s); + xfree(s); + + s = xf86SetStrOption(pInfo->options, "Device", NULL); + if (s == NULL) { + pInfo->fd = xf86Info.consoleFd; + pKbd->isConsole = TRUE; + } else { + pInfo->fd = open(s, O_RDONLY | O_NONBLOCK | O_EXCL); + if (pInfo->fd == -1) { + xf86Msg(X_ERROR, "%s: cannot open \"%s\"\n", pInfo->name, s); + xfree(s); + return FALSE; + } + pKbd->isConsole = FALSE; + xfree(s); + } + + if (pKbd->isConsole) + pKbd->vtSwitchSupported = TRUE; + + return TRUE; +} + +Bool +xf86OSKbdPreInit(InputInfoPtr pInfo) +{ + KbdDevPtr pKbd = pInfo->private; + + pKbd->KbdInit = KbdInit; + pKbd->KbdOn = KbdOn; + pKbd->KbdOff = KbdOff; + pKbd->Bell = SoundBell; + pKbd->SetLeds = SetKbdLeds; + pKbd->GetLeds = GetKbdLeds; + pKbd->SetKbdRepeat = SetKbdRepeat; + pKbd->KbdGetMapping = KbdGetMapping; + pKbd->SpecialKey = SpecialKey; + pKbd->OpenKeyboard = OpenKeyboard; + + pKbd->GetSpecialKey = NULL; + pKbd->RemapScanCode = ATScancode; + pKbd->vtSwitchSupported = FALSE; + + pKbd->private = xcalloc(sizeof(USLKbdPrivRec), 1); + if (pKbd->private == NULL) { + xf86Msg(X_ERROR,"can't allocate keyboard OS private data\n"); + return FALSE; + } + + return TRUE; +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h new file mode 100644 index 000000000..a65986fe5 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h @@ -0,0 +1,14 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h,v 1.2 2005/11/08 06:33:30 jkj Exp $ */ +#ifndef SCO_KBD_HDR +#define SCO_KBD_HDR + +typedef struct { + int orig_kbm; + struct termio kbdtty; + keymap_t keymap, noledmap; + int xq; +} USLKbdPrivRec, *USLKbdPrivPtr; + +extern void KbdGetMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms, + CARD8 *pModMap); +#endif /* SCO_KBD_HDR */ diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c new file mode 100644 index 000000000..708a08e11 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c @@ -0,0 +1,181 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c,v 1.3 2005/11/10 02:41:20 jkj Exp $ */ + +/* + * Copyright 2005 Kean Johnston + * Copyright 1999 by The XFree86 Project, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of The XFree86 Project, Inc + * and Kean Johnston not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * The XFree86 Project, Inc and Kean Johnston make no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THE XFREE86 PROJECT, INC AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT + * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + * + */ + +#include "X.h" +#include "compiler.h" +#include "xf86.h" +#include "xf86Xinput.h" +#include "xf86OSmouse.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "mipointer.h" +#include "usl_xqueue.h" + +static int +SupportedInterfaces(void) +{ + return MSE_MISC; +} + +static const char *internalNames[] = { + "Xqueue", + NULL +}; + +static const char ** +BuiltinNames(void) +{ + return internalNames; +} + +static const char * +DefaultProtocol (void) +{ + return "Xqueue"; +} + +static Bool +CheckProtocol(const char *protocol) +{ + int i; + + for (i = 0; internalNames[i]; i++) + if (xf86NameCmp(protocol, internalNames[i]) == 0) + return TRUE; + return FALSE; +} + +static int +OsMouseProc(DeviceIntPtr pPointer, int what) +{ + InputInfoPtr pInfo; + MouseDevPtr pMse; + unsigned char map[9]; + int ret; + + pInfo = pPointer->public.devicePrivate; + pMse = pInfo->private; + pMse->device = pPointer; + + switch (what) { + case DEVICE_INIT: + pPointer->public.on = FALSE; + + for (ret = 0; ret <= 8; ret++) + map[ret] = ret; + + InitPointerDeviceStruct((DevicePtr)pPointer, map, 8, + miPointerGetMotionEvents, pMse->Ctrl, + miPointerGetMotionBufferSize()); + /* X valuator */ + xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1); + xf86InitValuatorDefaults(pPointer, 0); + + /* Y valuator */ + xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1); + xf86InitValuatorDefaults(pPointer, 1); + + xf86MotionHistoryAllocate(pInfo); + break; + + case DEVICE_ON: + pMse->lastButtons = 0; + pMse->emulateState = 0; + pPointer->public.on = TRUE; + XqMseOnOff (pInfo, 1); + break; + + case DEVICE_CLOSE: + case DEVICE_OFF: + pPointer->public.on = FALSE; + XqMseOnOff (pInfo, 0); + break; + } + return Success; +} + +static Bool +OsMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags) +{ + /* This is called when the protocol is "Xqueue" */ + MouseDevPtr pMse; + + pMse = pInfo->private; + pMse->protocol = protocol; + xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol); + + /* Collect the options, and process the common options. */ + xf86CollectInputOptions(pInfo, NULL, NULL); + xf86ProcessCommonOptions(pInfo, pInfo->options); + + pInfo->fd = -1; +#if 0 + /* Make sure we can open the mouse */ + pInfo->fd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK); + + if (pInfo->fd < 0) { + if (xf86GetAllowMouseOpenFail()) { + xf86Msg(X_WARNING, "%s: cannot open /dev/mouse (%s)\n", + pInfo->name, strerror(errno)); + } else { + xf86Msg(X_ERROR, "%s: cannot open /dev/mouse (%s)\n", + pInfo->name, strerror(errno)); + xfree(pMse); + return FALSE; + } + } +#endif + + /* Process common mouse options (like Emulate3Buttons, etc). */ + pMse->CommonOptions(pInfo); + + /* Setup the local procs. */ + pInfo->device_control = OsMouseProc; + pInfo->read_input = NULL; /* Handled by the XQUEUE signal handler */ + + pInfo->flags |= XI86_CONFIGURED; + return TRUE; +} + +OSMouseInfoPtr +xf86OSMouseInit(int flags) +{ + OSMouseInfoPtr p; + + p = xcalloc(sizeof(OSMouseInfoRec), 1); + if (!p) + return NULL; + + p->SupportedInterfaces = SupportedInterfaces; + p->BuiltinNames = BuiltinNames; + p->DefaultProtocol = DefaultProtocol; + p->CheckProtocol = CheckProtocol; + p->PreInit = OsMousePreInit; + return p; +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c new file mode 100644 index 000000000..2c85ea92c --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c @@ -0,0 +1,111 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */ +/* + * Copyrught 2005 Kean Johnston <jkj@sco.com> + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany + * Copyright 1993 by David Wexelblat <dwex@goblin.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of Thomas Roell, David Dawes + * and Kean Johnston not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Thomas Roell, David Dawes and Kean Johnston make no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THOMAS ROELL, DAVID DAWES AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT + * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + * + */ +/* $XConsortium$ */ + +#include "X.h" + +#define _NEED_SYSI86 +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +static Bool +linearVidMem(void) +{ + return TRUE; +} + +static pointer +mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +{ + pointer base; + int fd; + + fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR); + if (fd < 0) { + FatalError("xf86MapVidMem: failed to open %s (%s)\n", + DEV_MEM, strerror(errno)); + } + base = mmap((caddr_t)0, Size, (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_SHARED, fd, (off_t)Base); + close(fd); + + if (base == MAP_FAILED) { + FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n", + "xf86MapVidMem", Size, Base, strerror(errno)); + } + return(base); +} + +/* ARGSUSED */ +static void +unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) +{ + munmap(Base, Size); +} + +/* + * For some SVR4 versions, a 32-bit read is done for the first location + * in each page when the page is first mapped. If this is done while + * memory access is enabled for regions that have read side-effects, + * this can cause unexpected results, including lockups on some hardware. + * This function is called to make sure each page is mapped while it is + * safe to do so. + */ + +#define X_PAGE_SIZE 4096 + +static void +readSideEffects(int ScreenNum, pointer Base, unsigned long Size) +{ + unsigned long base, end, addr; + CARD32 val; + + base = (unsigned long)Base; + end = base + Size; + + for (addr = base; addr < end; addr += X_PAGE_SIZE) + val = *(volatile CARD32 *)addr; +} + +void +xf86OSInitVidMem(VidMemInfoPtr pVidMem) +{ + pVidMem->linearSupported = linearVidMem(); + pVidMem->mapMem = mapVidMem; + pVidMem->unmapMem = unmapVidMem; + pVidMem->readSideEffects = readSideEffects; + pVidMem->initialised = TRUE; +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c new file mode 100644 index 000000000..d15a24149 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c @@ -0,0 +1,97 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */ +/* + * Copyright 2005 by Kean Johnston <jkj@sco.com> + * Copyright 1993 by David Wexelblat <dwex@goblin.org> + * Copyright 1993 by David McCullough <davidm@stallion.oz.au> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of David Wexelblat not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. David Wexelblat makes no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + */ +/* $XConsortium$ */ + +#include "X.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +/* + * Handle the VT-switching interface for SCO UnixWare / OpenServer 6 + */ + +/* + * This function is the signal handler for the VT-switching signal. It + * is only referenced inside the OS-support layer. NOTE: we do NOT need + * to re-arm the signal here, since we used sigaction() to set the signal + * disposition in usl_init.c. If we had used signal(), we would need to + * re-arm the signal here. All we need to do now is record the fact that + * we got the signal. XFree86 handles the rest. + */ +void +xf86VTRequest(int sig) +{ + xf86Info.vtRequestsPending = TRUE; + return; +} + +Bool +xf86VTSwitchPending(void) +{ + return(xf86Info.vtRequestsPending ? TRUE : FALSE); +} + +static int usl_ledstatus = -1; +static unsigned int usl_ledstate = 0; + +Bool +xf86VTSwitchAway(void) +{ + usl_ledstatus = ioctl(xf86Info.consoleFd, KDGETLED, &usl_ledstate); + + xf86Info.vtRequestsPending = FALSE; + if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0) { + return(FALSE); + } else { + return(TRUE); + } +} + +Bool +xf86VTSwitchTo(void) +{ + xf86Info.vtRequestsPending = FALSE; + if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) { + return(FALSE); + } else { + if (usl_ledstatus >= 0) { + ioctl (xf86Info.consoleFd, KDSETLED, usl_ledstate); + } + usl_ledstatus = -1; + + /* + * Convince the console driver this screen is in graphics mode, + * otherwise it assumes it can do more to the screen than it should. + */ + if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) { + ErrorF("Failed to set graphics mode (%s)\n", strerror(errno)); + } + + return TRUE; + } +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c new file mode 100644 index 000000000..8b66ee1f8 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c @@ -0,0 +1,360 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c,v 1.3 2005/11/10 02:41:20 jkj Exp $ */ +/* + * Copyright 2005 by Kean Johnston <jkj@sco.com> + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany + * Copyright 1993-1999 by The XFree86 Project, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The copyright holders make no + * representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + */ +/* $XConsortium$ */ + +#include "X.h" +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86Xinput.h" +#include "xf86OSmouse.h" +#include "xf86OSKbd.h" +#include "usl_xqueue.h" + +#ifdef XKB +#include "inputstr.h" +#include <X11/extensions/XKB.h> +#include <X11/extensions/XKBstr.h> +#include <X11/extensions/XKBsrv.h> +extern Bool noXkbExtension; +#endif + +#include "xf86Xinput.h" +#include "mipointer.h" + +#if !defined(XQ_WHEEL) +# define XQ_WHEEL 4 +#endif + +/* + * Implementation notes + * + * This code is based on a mixture of the original XFree86 sysv/xqueue.c + * and information gathered from the SCO X server code (no actual code + * was used, just the principles). + * + * The XFree86 XQUEUE code went to some considerable lengths to implement + * what it calls "asynchronous XQUEUE". This involved creating a pipe, + * and writing to that pipe each time an XQUEUE signal is received. The + * one end of that pipe was then added to the list of selectable file + * descriptors with AddEnabledDevice(). I completely fail to see the need + * for this, and this code does not implement that mechanism. The server + * will be interrupted anyway by the XQUEUE driver, so whether we pull the + * events off the queue at the time we receive the signal or whether we + * write to a pipe and then have the main select() loop stop and call us, + * it makes no difference I can fathom. + * + * The code also differs from the original XFree86 code in that it maintains + * local variables for the number of devices initialized. The original code + * stored that information in the private data pointer of the mouse structure, + * but this same code is used for both the keyboard and the mouse, so that + * was changed. + * + * Part of the difficulty in dealing with XQUEUE is that it is a single + * interface to two devices. The recent changes in XFree86/Xorg try to + * treat the mouse and keyboard as discrete devices, and the code is + * structured in such a way that they should be able to be independently + * opened and closed. But we can't do that with XQUEUE, so we have to + * centralize XQUEUE access here in this module. + */ + +static xqEventQueue *xqQaddr = NULL; +static int xqSigEnable = 1; +static int xqEnableCount = 0; +static struct kd_quemode xqMode; + +/* + * These two pointers are set when the keyboard/mouse handler procs + * are called to turn them on or off. This is so that we can call the + * correct PostEvent for the device. + */ +static InputInfoPtr xqMouse = NULL; +static InputInfoPtr xqKeyboard = NULL; + +static void XqSignalHandler (int signo); + +/* + * Private functions + */ +static void +XqReset (void) +{ + if (xqEnableCount > 0) { + xqQaddr->xq_head = xqQaddr->xq_tail; + xqQaddr->xq_sigenable = xqSigEnable; + } +} + +#ifdef NOTNEEDED +static void +XqLock (void) +{ + xqSigEnable = 0; + if (xqEnableCount > 0) { + xqQaddr->xq_sigenable = xqSigEnable; + } +} + +static void +XqUnlock (void) +{ + xqSigEnable = 1; + if (xqEnableCount > 0) { + xqQaddr->xq_sigenable = xqSigEnable; + } +} +#endif /* NOTNEEDED */ + +/* + * Since this code is shared between two devices, we need to keep track + * of how many times we've been enabled or disabled. For example, if the + * keyboard has been turned off, but the mouse hasn't, then we do not + * want the whole queue off. Only when both devices are turned off do we + * actually disable Xqueue mode. When either device is turned on, we + * enable it. + */ +static int +XqEnable (InputInfoPtr pInfo) +{ + struct sigaction xqsig; + static int msefd = -1; + + if (msefd == -1) { + msefd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK); +#if 0 + msefd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK | O_NOCTTY); + if (msefd < 0) { + /* + * Try giving it a controlling tty + */ + msefd = open (ttyname(xf86Info.consoleFd), O_RDWR | O_NONBLOCK); + if (msefd >= 0) + close (msefd); + msefd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK | O_NOCTTY); + if (msefd < 0) + sleep(2); + } +#endif + } + + if (msefd < 0) { + if (xf86GetAllowMouseOpenFail()) { + ErrorF("%s: cannot open /dev/mouse (%s)\n", + ttyname(xf86Info.consoleFd), strerror(errno)); + } else { + sleep(5); + FatalError ("%s: cannot open /dev/mouse (%s)\n", + ttyname(xf86Info.consoleFd), strerror(errno)); + } + } + + if (xqEnableCount++ == 0) { + xqMode.qaddr = 0; + ioctl (xf86Info.consoleFd, KDQUEMODE, NULL); + + /* + * Note: We need to make sure the signal is armed before we enable + * XQUEUE mode, so that if we get events immediately after the ioctl + * we dont have an unhandled signal coming to the Xserver. + * Also note that we use sigaction, so that we do not have to re-arm + * the signal every time it is delivered, which just slows things + * down (setting a signal is a fairly expensive operation). + */ + + xqsig.sa_handler = XqSignalHandler; + sigfillset (&xqsig.sa_mask); + xqsig.sa_flags = 0; + sigaction (SIGUSR2, &xqsig, NULL); + + /* + * This is a fairly large queue size. Since we are reacting to events + * asynchronously, its best for performance if we deal with as many + * events as possible, and high resolution mice generate a lot of + * events. + */ + xqMode.qsize = 64; + xqMode.signo = SIGUSR2; + xqMode.qaddr = 0; + if (ioctl (xf86Info.consoleFd, KDQUEMODE, &xqMode) < 0) { + xf86Msg (X_ERROR, "%s: could not set XQUEUE mode (%s)", pInfo->name, + strerror(errno)); + xqEnableCount--; + + xqsig.sa_handler = SIG_DFL; + sigfillset (&xqsig.sa_mask); + xqsig.sa_flags = 0; + sigaction (SIGUSR2, &xqsig, NULL); + + return !Success; + } + + /* + * We're in business. The workstation is now in XQUEUE mode. + */ + xqQaddr = (xqEventQueue *)xqMode.qaddr; + xqQaddr->xq_sigenable = 0; /* LOCK */ + nap(500); + XqReset(); + } + return Success; +} + +static int +XqDisable (InputInfoPtr pInfo) +{ + struct sigaction xqsig; + + if (xqEnableCount-- == 1) { + xqQaddr->xq_sigenable = 0; /* LOCK */ + + if (ioctl (xf86Info.consoleFd, KDQUEMODE, NULL) < 0) { + xf86Msg (X_ERROR, "%s: could not unset XQUEUE mode (%s)", pInfo->name, + strerror(errno)); + xqEnableCount++; + return !Success; + } + + xqsig.sa_handler = SIG_DFL; + sigfillset (&xqsig.sa_mask); + xqsig.sa_flags = 0; + sigaction (SIGUSR2, &xqsig, NULL); + } + + return Success; +} + +/* + * XQUEUE signal handler. This is what goes through the list of events + * we've already received and dispatches them to either the keyboard or + * mouse event poster. + */ +static void +XqSignalHandler (int signo) +{ + xqEvent *xqEvents = xqQaddr->xq_events; + int xqHead = xqQaddr->xq_head; + xEvent xE; + MouseDevPtr pMse = NULL; + KbdDevPtr pKbd = NULL; + signed char dx, dy; + + if (xqMouse) + pMse = (MouseDevPtr)xqMouse->private; + if (xqKeyboard) + pKbd = (KbdDevPtr)xqKeyboard->private; + + while (xqHead != xqQaddr->xq_tail) { + + switch (xqEvents[xqHead].xq_type) { + case XQ_MOTION: + dx = (signed char)xqEvents[xqHead].xq_x; + dy = (signed char)xqEvents[xqHead].xq_y; + if (pMse) + pMse->PostEvent(xqMouse, ~(xqEvents[xqHead].xq_code) & 0x07, + (int)dx, (int)dy, 0, 0); + break; + + case XQ_BUTTON: + if (pMse) + pMse->PostEvent(xqMouse, ~(xqEvents[xqHead].xq_code) & 0x07, + 0, 0, 0, 0); + break; + + case XQ_WHEEL: + if (pMse) { + int wbut = pMse->lastButtons, dz; + if (xqEvents[xqHead].xq_code == 1) + dz = 1; + else + dz = -1; + pMse->PostEvent(xqMouse, wbut, 0, 0, dz, 0); + } + break; + + case XQ_KEY: + if (pKbd) + pKbd->PostEvent(xqKeyboard, xqEvents[xqHead].xq_code & 0x7f, + xqEvents[xqHead].xq_code & 0x80 ? FALSE : TRUE); + break; + + default: + xf86Msg(X_WARNING, "XQUEUE: unknown event type %d\n", + xqEvents[xqHead].xq_type); + break; + } + + xqHead++; + if (xqHead == xqQaddr->xq_size) + xqHead = 0; + xf86Info.inputPending = TRUE; + } + + XqReset(); +} + +/* + * Public functions + */ +int +XqMseOnOff (InputInfoPtr pInfo, int on) +{ + if (on) { + if (xqMouse) { + if (xqMouse != pInfo) + xf86Msg(X_WARNING, "XqMseOnOff: mouse pointer structure changed!\n"); + xqMouse = pInfo; + } else { + xqMouse = pInfo; + return XqEnable(pInfo); + } + } else { + xqMouse = NULL; + return XqDisable(pInfo); + } + return Success; +} + +int +XqKbdOnOff (InputInfoPtr pInfo, int on) +{ + if (on) { + if (xqKeyboard) { + if (xqKeyboard != pInfo) + xf86Msg(X_WARNING, "XqKbdOnOff: keyboard pointer structure changed!\n"); + xqKeyboard = pInfo; + } else { + xqKeyboard = pInfo; + return XqEnable(pInfo); + } + } else { + xqKeyboard = NULL; + return XqDisable(pInfo); + } + return Success; +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h new file mode 100644 index 000000000..2a777accf --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h @@ -0,0 +1,9 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h,v 1.2 2005/11/08 06:33:30 jkj Exp $ */ + +#ifndef _XF86_USL_XQUEUE_H_ +#define _XF86_USL_XQUEUE_H_ + +extern int XqMseOnOff (InputInfoPtr pInfo, int on); +extern int XqKbdOnOff (InputInfoPtr pInfo, int on); + +#endif |