Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/vt/vt_core.c
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
#include <dev/kbd/kbdreg.h> | #include <dev/kbd/kbdreg.h> | ||||
#include <dev/vt/vt.h> | #include <dev/vt/vt.h> | ||||
#if defined(__i386__) || defined(__amd64__) | #if defined(__i386__) || defined(__amd64__) | ||||
#include <machine/psl.h> | #include <machine/psl.h> | ||||
#include <machine/frame.h> | #include <machine/frame.h> | ||||
#endif | #endif | ||||
static int vtterm_cngrab_noswitch(struct vt_device *, struct vt_window *); | |||||
static int vtterm_cnungrab_noswitch(struct vt_device *, struct vt_window *); | |||||
static tc_bell_t vtterm_bell; | static tc_bell_t vtterm_bell; | ||||
static tc_cursor_t vtterm_cursor; | static tc_cursor_t vtterm_cursor; | ||||
static tc_putchar_t vtterm_putchar; | static tc_putchar_t vtterm_putchar; | ||||
static tc_fill_t vtterm_fill; | static tc_fill_t vtterm_fill; | ||||
static tc_copy_t vtterm_copy; | static tc_copy_t vtterm_copy; | ||||
static tc_pre_input_t vtterm_pre_input; | static tc_pre_input_t vtterm_pre_input; | ||||
static tc_post_input_t vtterm_post_input; | static tc_post_input_t vtterm_post_input; | ||||
static tc_param_t vtterm_param; | static tc_param_t vtterm_param; | ||||
▲ Show 20 Lines • Show All 944 Lines • ▼ Show 20 Lines | vt_allocate_keyboard(struct vt_device *vd) | ||||
* If vt_upgrade() happens while the console is grabbed, we are | * If vt_upgrade() happens while the console is grabbed, we are | ||||
* potentially going to switch keyboard devices while the keyboard is in | * potentially going to switch keyboard devices while the keyboard is in | ||||
* use. Unwind the grabbing of the current keyboard first, then we will | * use. Unwind the grabbing of the current keyboard first, then we will | ||||
* re-grab the new keyboard below, before we return. | * re-grab the new keyboard below, before we return. | ||||
*/ | */ | ||||
if (vd->vd_curwindow == &vt_conswindow) { | if (vd->vd_curwindow == &vt_conswindow) { | ||||
grabbed = vd->vd_curwindow->vw_grabbed; | grabbed = vd->vd_curwindow->vw_grabbed; | ||||
for (i = 0; i < grabbed; ++i) | for (i = 0; i < grabbed; ++i) | ||||
vtterm_cnungrab(vd->vd_curwindow->vw_terminal); | vtterm_cnungrab_noswitch(vd, vd->vd_curwindow); | ||||
} | } | ||||
idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd); | idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd); | ||||
if (idx0 >= 0) { | if (idx0 >= 0) { | ||||
DPRINTF(20, "%s: kbdmux allocated, idx = %d\n", __func__, idx0); | DPRINTF(20, "%s: kbdmux allocated, idx = %d\n", __func__, idx0); | ||||
k0 = kbd_get_keyboard(idx0); | k0 = kbd_get_keyboard(idx0); | ||||
for (idx = kbd_find_keyboard2("*", -1, 0); | for (idx = kbd_find_keyboard2("*", -1, 0); | ||||
Show All 21 Lines | if (idx0 >= 0) { | ||||
k0 = kbd_get_keyboard(idx0); | k0 = kbd_get_keyboard(idx0); | ||||
} | } | ||||
vd->vd_keyboard = k0; | vd->vd_keyboard = k0; | ||||
DPRINTF(20, "%s: vd_keyboard = %d\n", __func__, | DPRINTF(20, "%s: vd_keyboard = %d\n", __func__, | ||||
vd->vd_keyboard->kb_index); | vd->vd_keyboard->kb_index); | ||||
if (vd->vd_curwindow == &vt_conswindow) { | if (vd->vd_curwindow == &vt_conswindow) { | ||||
for (i = 0; i < grabbed; ++i) | for (i = 0; i < grabbed; ++i) | ||||
vtterm_cngrab(vd->vd_curwindow->vw_terminal); | vtterm_cngrab_noswitch(vd, vd->vd_curwindow); | ||||
} | } | ||||
return (idx0); | return (idx0); | ||||
} | } | ||||
static void | static void | ||||
vtterm_bell(struct terminal *tm) | vtterm_bell(struct terminal *tm) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 529 Lines • ▼ Show 20 Lines | vtterm_cngetc(struct terminal *tm) | ||||
} | } | ||||
if (vw->vw_kbdsq && *vw->vw_kbdsq) | if (vw->vw_kbdsq && *vw->vw_kbdsq) | ||||
return (*vw->vw_kbdsq++); | return (*vw->vw_kbdsq++); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
static void | /* | ||||
vtterm_cngrab(struct terminal *tm) | * These two do most of what we want to do in vtterm_cnungrab, but without | ||||
* actually switching windows. This is necessary for, e.g., | |||||
* vt_allocate_keyboard() to get the current keyboard into the state it needs to | |||||
* be in without damaging the device's window state. | |||||
* | |||||
* Both return the current grab count, though it's only used in vtterm_cnungrab. | |||||
*/ | |||||
static int | |||||
vtterm_cngrab_noswitch(struct vt_device *vd, struct vt_window *vw) | |||||
{ | { | ||||
struct vt_device *vd; | |||||
struct vt_window *vw; | |||||
keyboard_t *kbd; | keyboard_t *kbd; | ||||
vw = tm->tm_softc; | if (vw->vw_grabbed++ > 0) | ||||
vd = vw->vw_device; | return (vw->vw_grabbed); | ||||
if (!cold) | |||||
vt_window_switch(vw); | |||||
if ((kbd = vd->vd_keyboard) == NULL) | if ((kbd = vd->vd_keyboard) == NULL) | ||||
return; | return (1); | ||||
if (vw->vw_grabbed++ > 0) | |||||
return; | |||||
/* | /* | ||||
* Make sure the keyboard is accessible even when the kbd device | * Make sure the keyboard is accessible even when the kbd device | ||||
* driver is disabled. | * driver is disabled. | ||||
*/ | */ | ||||
kbdd_enable(kbd); | kbdd_enable(kbd); | ||||
/* We shall always use the keyboard in the XLATE mode here. */ | /* We shall always use the keyboard in the XLATE mode here. */ | ||||
vw->vw_prev_kbdmode = vw->vw_kbdmode; | vw->vw_prev_kbdmode = vw->vw_kbdmode; | ||||
vw->vw_kbdmode = K_XLATE; | vw->vw_kbdmode = K_XLATE; | ||||
vt_update_kbd_mode(vw, kbd); | vt_update_kbd_mode(vw, kbd); | ||||
kbdd_poll(kbd, TRUE); | kbdd_poll(kbd, TRUE); | ||||
return (1); | |||||
} | } | ||||
static int | |||||
vtterm_cnungrab_noswitch(struct vt_device *vd, struct vt_window *vw) | |||||
{ | |||||
keyboard_t *kbd; | |||||
if (--vw->vw_grabbed > 0) | |||||
return (vw->vw_grabbed); | |||||
if ((kbd = vd->vd_keyboard) == NULL) | |||||
return (0); | |||||
kbdd_poll(kbd, FALSE); | |||||
vw->vw_kbdmode = vw->vw_prev_kbdmode; | |||||
vt_update_kbd_mode(vw, kbd); | |||||
kbdd_disable(kbd); | |||||
return (0); | |||||
} | |||||
static void | static void | ||||
vtterm_cngrab(struct terminal *tm) | |||||
{ | |||||
struct vt_device *vd; | |||||
struct vt_window *vw; | |||||
vw = tm->tm_softc; | |||||
vd = vw->vw_device; | |||||
/* To be restored after we ungrab. */ | |||||
if (vd->vd_grabwindow == NULL) | |||||
vd->vd_grabwindow = vd->vd_curwindow; | |||||
if (!cold) | |||||
vt_window_switch(vw); | |||||
vtterm_cngrab_noswitch(vd, vw); | |||||
} | |||||
static void | |||||
vtterm_cnungrab(struct terminal *tm) | vtterm_cnungrab(struct terminal *tm) | ||||
{ | { | ||||
struct vt_device *vd; | struct vt_device *vd; | ||||
struct vt_window *vw; | struct vt_window *vw; | ||||
keyboard_t *kbd; | |||||
vw = tm->tm_softc; | vw = tm->tm_softc; | ||||
vd = vw->vw_device; | vd = vw->vw_device; | ||||
if ((kbd = vd->vd_keyboard) == NULL) | MPASS(vd->vd_grabwindow != NULL); | ||||
if (vtterm_cnungrab_noswitch(vd, vw) != 0) | |||||
return; | return; | ||||
if (--vw->vw_grabbed > 0) | if (!cold && vd->vd_grabwindow != vw) | ||||
return; | vt_window_switch(vd->vd_grabwindow); | ||||
kbdd_poll(kbd, FALSE); | vd->vd_grabwindow = NULL; | ||||
vw->vw_kbdmode = vw->vw_prev_kbdmode; | |||||
vt_update_kbd_mode(vw, kbd); | |||||
kbdd_disable(kbd); | |||||
} | } | ||||
static void | static void | ||||
vtterm_opened(struct terminal *tm, int opened) | vtterm_opened(struct terminal *tm, int opened) | ||||
{ | { | ||||
struct vt_window *vw = tm->tm_softc; | struct vt_window *vw = tm->tm_softc; | ||||
struct vt_device *vd = vw->vw_device; | struct vt_device *vd = vw->vw_device; | ||||
▲ Show 20 Lines • Show All 1,318 Lines • Show Last 20 Lines |