Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/vt/vt_core.c
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | |||||
static int signal_vt_acq(struct vt_window *); | static int signal_vt_acq(struct vt_window *); | ||||
static int finish_vt_rel(struct vt_window *, int, int *); | static int finish_vt_rel(struct vt_window *, int, int *); | ||||
static int finish_vt_acq(struct vt_window *); | static int finish_vt_acq(struct vt_window *); | ||||
static int vt_window_switch(struct vt_window *); | static int vt_window_switch(struct vt_window *); | ||||
static int vt_late_window_switch(struct vt_window *); | static int vt_late_window_switch(struct vt_window *); | ||||
static int vt_proc_alive(struct vt_window *); | static int vt_proc_alive(struct vt_window *); | ||||
static void vt_resize(struct vt_device *); | static void vt_resize(struct vt_device *); | ||||
static void vt_update_static(void *); | static void vt_update_static(void *); | ||||
static void vt_mouse_paste(); | |||||
SET_DECLARE(vt_drv_set, struct vt_driver); | SET_DECLARE(vt_drv_set, struct vt_driver); | ||||
#define _VTDEFH MAX(100, PIXEL_HEIGHT(VT_FB_DEFAULT_HEIGHT)) | #define _VTDEFH MAX(100, PIXEL_HEIGHT(VT_FB_DEFAULT_HEIGHT)) | ||||
#define _VTDEFW MAX(200, PIXEL_WIDTH(VT_FB_DEFAULT_WIDTH)) | #define _VTDEFW MAX(200, PIXEL_WIDTH(VT_FB_DEFAULT_WIDTH)) | ||||
static struct terminal vt_consterm; | static struct terminal vt_consterm; | ||||
static struct vt_window vt_conswindow; | static struct vt_window vt_conswindow; | ||||
static struct vt_device vt_consdev = { | static struct vt_device vt_consdev = { | ||||
.vd_driver = NULL, | .vd_driver = NULL, | ||||
.vd_softc = NULL, | .vd_softc = NULL, | ||||
.vd_flags = VDF_INVALID, | .vd_flags = VDF_INVALID, | ||||
.vd_windows = { [VT_CONSWINDOW] = &vt_conswindow, }, | .vd_windows = { [VT_CONSWINDOW] = &vt_conswindow, }, | ||||
.vd_curwindow = &vt_conswindow, | .vd_curwindow = &vt_conswindow, | ||||
.vd_markedwin = NULL, | |||||
.vd_kbstate = 0, | .vd_kbstate = 0, | ||||
#ifndef SC_NO_CUTPASTE | #ifndef SC_NO_CUTPASTE | ||||
.vd_pastebuf = { | |||||
.vpb_buf = NULL, | |||||
.vpb_bufsz = 0, | |||||
.vpb_len = 0 | |||||
}, | |||||
.vd_mcursor = &vt_default_mouse_pointer, | .vd_mcursor = &vt_default_mouse_pointer, | ||||
.vd_mcursor_fg = TC_WHITE, | .vd_mcursor_fg = TC_WHITE, | ||||
.vd_mcursor_bg = TC_BLACK, | .vd_mcursor_bg = TC_BLACK, | ||||
#endif | #endif | ||||
}; | }; | ||||
static term_char_t vt_constextbuf[(_VTDEFW) * (VBF_DEFAULT_HISTORY_SIZE)]; | static term_char_t vt_constextbuf[(_VTDEFW) * (VBF_DEFAULT_HISTORY_SIZE)]; | ||||
static term_char_t *vt_constextbufrows[VBF_DEFAULT_HISTORY_SIZE]; | static term_char_t *vt_constextbufrows[VBF_DEFAULT_HISTORY_SIZE]; | ||||
static struct vt_window vt_conswindow = { | static struct vt_window vt_conswindow = { | ||||
▲ Show 20 Lines • Show All 312 Lines • ▼ Show 20 Lines | case SPCLKEY | DBG: /* kbdmap(5) keyword `debug`. */ | ||||
return (1); | return (1); | ||||
case SPCLKEY | HALT: /* kbdmap(5) keyword `halt`. */ | case SPCLKEY | HALT: /* kbdmap(5) keyword `halt`. */ | ||||
if (vt_kbd_halt) | if (vt_kbd_halt) | ||||
shutdown_nice(RB_HALT); | shutdown_nice(RB_HALT); | ||||
return (1); | return (1); | ||||
case SPCLKEY | PASTE: /* kbdmap(5) keyword `paste`. */ | case SPCLKEY | PASTE: /* kbdmap(5) keyword `paste`. */ | ||||
#ifndef SC_NO_CUTPASTE | #ifndef SC_NO_CUTPASTE | ||||
/* Insert text from cut-paste buffer. */ | /* Insert text from cut-paste buffer. */ | ||||
/* TODO */ | vt_mouse_paste(); | ||||
#endif | #endif | ||||
break; | break; | ||||
case SPCLKEY | PDWN: /* kbdmap(5) keyword `pdwn`. */ | case SPCLKEY | PDWN: /* kbdmap(5) keyword `pdwn`. */ | ||||
if (vt_kbd_poweroff) | if (vt_kbd_poweroff) | ||||
shutdown_nice(RB_HALT|RB_POWEROFF); | shutdown_nice(RB_HALT|RB_POWEROFF); | ||||
return (1); | return (1); | ||||
case SPCLKEY | PNC: /* kbdmap(5) keyword `panic`. */ | case SPCLKEY | PNC: /* kbdmap(5) keyword `panic`. */ | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 1,051 Lines • ▼ Show 20 Lines | vt_mouse_terminput_button(struct vt_device *vd, int button) | ||||
/* Avoid overflow. */ | /* Avoid overflow. */ | ||||
x = MIN(x, 255 - '!'); | x = MIN(x, 255 - '!'); | ||||
y = MIN(y, 255 - '!'); | y = MIN(y, 255 - '!'); | ||||
mouseb[3] = ' ' + button; | mouseb[3] = ' ' + button; | ||||
mouseb[4] = '!' + x; | mouseb[4] = '!' + x; | ||||
mouseb[5] = '!' + y; | mouseb[5] = '!' + y; | ||||
for (i = 0; i < sizeof(mouseb); i++ ) | for (i = 0; i < sizeof(mouseb); i++) | ||||
terminal_input_char(vw->vw_terminal, mouseb[i]); | terminal_input_char(vw->vw_terminal, mouseb[i]); | ||||
} | } | ||||
static void | static void | ||||
vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event, | vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event, | ||||
int cnt) | int cnt) | ||||
{ | { | ||||
Show All 21 Lines | if (mouse->u.data.z < 0) { | ||||
/* Scroll down. */ | /* Scroll down. */ | ||||
sc_mouse_input_button(vd, 65); | sc_mouse_input_button(vd, 65); | ||||
} | } | ||||
break; | break; | ||||
#endif | #endif | ||||
} | } | ||||
} | } | ||||
static void | |||||
vt_mouse_paste() | |||||
{ | |||||
term_char_t *buf; | |||||
int i, len; | |||||
len = VD_PASTEBUFLEN(main_vd); | |||||
buf = VD_PASTEBUF(main_vd); | |||||
len /= sizeof(term_char_t); | |||||
for (i = 0; i < len; i++) { | |||||
if (buf[i] == '\0') | |||||
continue; | |||||
terminal_input_char(main_vd->vd_curwindow->vw_terminal, | |||||
buf[i]); | |||||
} | |||||
} | |||||
void | void | ||||
vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel) | vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel) | ||||
{ | { | ||||
struct vt_device *vd; | struct vt_device *vd; | ||||
struct vt_window *vw; | struct vt_window *vw; | ||||
struct vt_font *vf; | struct vt_font *vf; | ||||
term_pos_t size; | term_pos_t size; | ||||
term_char_t *buf; | int len, mark; | ||||
int i, len, mark; | |||||
vd = main_vd; | vd = main_vd; | ||||
vw = vd->vd_curwindow; | vw = vd->vd_curwindow; | ||||
vf = vw->vw_font; | vf = vw->vw_font; | ||||
mark = 0; | mark = 0; | ||||
if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS)) | if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS)) | ||||
/* | /* | ||||
Show All 26 Lines | case MOUSE_MOTION_EVENT: | ||||
/* Apply limits. */ | /* Apply limits. */ | ||||
x = MAX(x, 0); | x = MAX(x, 0); | ||||
y = MAX(y, 0); | y = MAX(y, 0); | ||||
x = MIN(x, (size.tp_col * vf->vf_width) - 1); | x = MIN(x, (size.tp_col * vf->vf_width) - 1); | ||||
y = MIN(y, (size.tp_row * vf->vf_height) - 1); | y = MIN(y, (size.tp_row * vf->vf_height) - 1); | ||||
vd->vd_mx = x; | vd->vd_mx = x; | ||||
vd->vd_my = y; | vd->vd_my = y; | ||||
if ((vd->vd_mstate & MOUSE_BUTTON1DOWN) && | if (vd->vd_mstate & MOUSE_BUTTON1DOWN) | ||||
(vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE, | vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE, | ||||
vd->vd_mx / vf->vf_width, | vd->vd_mx / vf->vf_width, | ||||
vd->vd_my / vf->vf_height) == 1)) { | vd->vd_my / vf->vf_height); | ||||
/* | |||||
* We have something marked to copy, so update pointer | |||||
* to window with selection. | |||||
*/ | |||||
vd->vd_markedwin = vw; | |||||
} | |||||
vt_resume_flush_timer(vw->vw_device, 0); | vt_resume_flush_timer(vw->vw_device, 0); | ||||
return; /* Done */ | return; /* Done */ | ||||
case MOUSE_BUTTON_EVENT: | case MOUSE_BUTTON_EVENT: | ||||
/* Buttons */ | /* Buttons */ | ||||
break; | break; | ||||
default: | default: | ||||
return; /* Done */ | return; /* Done */ | ||||
} | } | ||||
Show All 15 Lines | case 3: /* triple click: cut a line */ | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case VT_MOUSE_PASTEBUTTON: | case VT_MOUSE_PASTEBUTTON: | ||||
switch (cnt) { | switch (cnt) { | ||||
case 0: /* up */ | case 0: /* up */ | ||||
break; | break; | ||||
default: | default: | ||||
if (vd->vd_markedwin == NULL) | vt_mouse_paste(); | ||||
return; | |||||
/* Get current selecton size in bytes. */ | |||||
len = vtbuf_get_marked_len(&vd->vd_markedwin->vw_buf); | |||||
if (len <= 0) | |||||
return; | |||||
buf = malloc(len, M_VT, M_WAITOK | M_ZERO); | |||||
/* Request copy/paste buffer data, no more than `len' */ | |||||
vtbuf_extract_marked(&vd->vd_markedwin->vw_buf, buf, | |||||
len); | |||||
len /= sizeof(term_char_t); | |||||
for (i = 0; i < len; i++ ) { | |||||
if (buf[i] == '\0') | |||||
continue; | |||||
terminal_input_char(vw->vw_terminal, buf[i]); | |||||
} | |||||
/* Done, so cleanup. */ | |||||
free(buf, M_VT); | |||||
break; | break; | ||||
} | } | ||||
return; /* Done */ | return; /* Done */ | ||||
case VT_MOUSE_EXTENDBUTTON: | case VT_MOUSE_EXTENDBUTTON: | ||||
switch (cnt) { | switch (cnt) { | ||||
case 0: /* up */ | case 0: /* up */ | ||||
if (!(vd->vd_mstate & MOUSE_BUTTON1DOWN)) | if (!(vd->vd_mstate & MOUSE_BUTTON1DOWN)) | ||||
mark = VTB_MARK_EXTEND; | mark = VTB_MARK_EXTEND; | ||||
Show All 16 Lines | else | ||||
vd->vd_mstate &= ~event; | vd->vd_mstate &= ~event; | ||||
if (vtbuf_set_mark(&vw->vw_buf, mark, vd->vd_mx / vf->vf_width, | if (vtbuf_set_mark(&vw->vw_buf, mark, vd->vd_mx / vf->vf_width, | ||||
vd->vd_my / vf->vf_height) == 1) { | vd->vd_my / vf->vf_height) == 1) { | ||||
/* | /* | ||||
* We have something marked to copy, so update pointer to | * We have something marked to copy, so update pointer to | ||||
* window with selection. | * window with selection. | ||||
*/ | */ | ||||
vd->vd_markedwin = vw; | |||||
vt_resume_flush_timer(vw->vw_device, 0); | vt_resume_flush_timer(vw->vw_device, 0); | ||||
switch (mark) { | |||||
case VTB_MARK_END: | |||||
case VTB_MARK_WORD: | |||||
case VTB_MARK_ROW: | |||||
case VTB_MARK_EXTEND: | |||||
break; | |||||
default: | |||||
/* Other types of mark do not require to copy data. */ | |||||
return; | |||||
} | |||||
/* Get current selection size in bytes. */ | |||||
len = vtbuf_get_marked_len(&vw->vw_buf); | |||||
if (len <= 0) | |||||
return; | |||||
/* Reallocate buffer only if old one is too small. */ | |||||
if (len > VD_PASTEBUFSZ(vd)) { | |||||
VD_PASTEBUF(vd) = realloc(VD_PASTEBUF(vd), len, M_VT, | |||||
M_WAITOK | M_ZERO); | |||||
/* Update buffer size. */ | |||||
VD_PASTEBUFSZ(vd) = len; | |||||
} | |||||
/* Request copy/paste buffer data, no more than `len' */ | |||||
vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd), | |||||
VD_PASTEBUFSZ(vd)); | |||||
VD_PASTEBUFLEN(vd) = len; | |||||
/* XXX VD_PASTEBUF(vd) have to be freed on shutdown/unload. */ | |||||
} | } | ||||
} | } | ||||
void | void | ||||
vt_mouse_state(int show) | vt_mouse_state(int show) | ||||
{ | { | ||||
struct vt_device *vd; | struct vt_device *vd; | ||||
struct vt_window *vw; | struct vt_window *vw; | ||||
▲ Show 20 Lines • Show All 676 Lines • Show Last 20 Lines |