2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer as
12 * the first lines of this file unmodified.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_syscons.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/consio.h>
39 #include <sys/limits.h>
41 #include <sys/malloc.h>
42 #include <sys/mouse.h>
43 #include <sys/mutex.h>
45 #include <sys/random.h>
46 #include <sys/signalvar.h>
49 #include <dev/syscons/syscons.h>
51 #ifdef SC_TWOBUTTON_MOUSE
52 #define SC_MOUSE_PASTEBUTTON MOUSE_BUTTON3DOWN /* right button */
53 #define SC_MOUSE_EXTENDBUTTON MOUSE_BUTTON2DOWN /* not really used */
55 #define SC_MOUSE_PASTEBUTTON MOUSE_BUTTON2DOWN /* middle button */
56 #define SC_MOUSE_EXTENDBUTTON MOUSE_BUTTON3DOWN /* right button */
57 #endif /* SC_TWOBUTTON_MOUSE */
59 #define SC_WAKEUP_DELTA 20
61 /* for backward compatibility */
62 #define OLD_CONS_MOUSECTL _IOWR('c', 10, old_mouse_info_t)
64 typedef struct old_mouse_data {
70 typedef struct old_mouse_info {
73 struct old_mouse_data data;
74 struct mouse_mode mode;
78 #ifndef SC_NO_SYSMOUSE
81 #ifndef SC_NO_CUTPASTE
82 static int cut_buffer_size;
83 static u_char *cut_buffer;
87 static void set_mouse_pos(scr_stat *scp);
88 #ifndef SC_NO_CUTPASTE
89 static int skip_spc_right(scr_stat *scp, int p);
90 static int skip_spc_left(scr_stat *scp, int p);
91 static void mouse_cut(scr_stat *scp);
92 static void mouse_cut_start(scr_stat *scp);
93 static void mouse_cut_end(scr_stat *scp);
94 static void mouse_cut_word(scr_stat *scp);
95 static void mouse_cut_line(scr_stat *scp);
96 static void mouse_cut_extend(scr_stat *scp);
97 #endif /* SC_NO_CUTPASTE */
99 #ifndef SC_NO_CUTPASTE
100 /* allocate a cut buffer */
102 sc_alloc_cut_buffer(scr_stat *scp, int wait)
106 if ((cut_buffer == NULL)
107 || (cut_buffer_size < scp->xsize * scp->ysize + 1)) {
112 cut_buffer_size = scp->xsize * scp->ysize + 1;
113 p = (u_char *)malloc(cut_buffer_size,
114 M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT);
120 #endif /* SC_NO_CUTPASTE */
123 sc_mouse_input_button(scr_stat *scp, int button)
125 char mouseb[6] = "\x1B[M";
127 mouseb[3] = ' ' + button;
128 mouseb[4] = '!' + scp->mouse_pos % scp->xsize;
129 mouseb[5] = '!' + scp->mouse_pos / scp->xsize;
130 sc_respond(scp, mouseb, sizeof mouseb, 1);
134 sc_mouse_input(scr_stat *scp, mouse_info_t *mouse)
137 switch (mouse->operation) {
138 case MOUSE_BUTTON_EVENT:
139 if (mouse->u.event.value > 0) {
140 /* Mouse button pressed. */
141 if (mouse->u.event.id & MOUSE_BUTTON1DOWN)
142 sc_mouse_input_button(scp, 0);
143 if (mouse->u.event.id & MOUSE_BUTTON2DOWN)
144 sc_mouse_input_button(scp, 1);
145 if (mouse->u.event.id & MOUSE_BUTTON3DOWN)
146 sc_mouse_input_button(scp, 2);
148 /* Mouse button released. */
149 sc_mouse_input_button(scp, 3);
152 case MOUSE_MOTION_EVENT:
153 if (mouse->u.data.z < 0) {
155 sc_mouse_input_button(scp, 64);
156 } else if (mouse->u.data.z > 0) {
158 sc_mouse_input_button(scp, 65);
166 sc_mouse_move(scr_stat *scp, int x, int y)
171 scp->mouse_xpos = scp->mouse_oldxpos = x;
172 scp->mouse_ypos = scp->mouse_oldypos = y;
173 if (scp->font_size <= 0 || scp->font_width <= 0)
174 scp->mouse_pos = scp->mouse_oldpos = 0;
176 scp->mouse_pos = scp->mouse_oldpos =
177 (y/scp->font_size - scp->yoff)*scp->xsize + x/scp->font_width -
179 scp->status |= MOUSE_MOVED;
183 /* adjust mouse position */
185 set_mouse_pos(scr_stat *scp)
187 if (scp->mouse_xpos < scp->xoff*scp->font_width)
188 scp->mouse_xpos = scp->xoff*scp->font_width;
189 if (scp->mouse_ypos < scp->yoff*scp->font_size)
190 scp->mouse_ypos = scp->yoff*scp->font_size;
191 if (ISGRAPHSC(scp)) {
192 if (scp->mouse_xpos > scp->xpixel-1)
193 scp->mouse_xpos = scp->xpixel-1;
194 if (scp->mouse_ypos > scp->ypixel-1)
195 scp->mouse_ypos = scp->ypixel-1;
198 if (scp->mouse_xpos > (scp->xsize + scp->xoff)*scp->font_width - 1)
199 scp->mouse_xpos = (scp->xsize + scp->xoff)*scp->font_width - 1;
200 if (scp->mouse_ypos > (scp->ysize + scp->yoff)*scp->font_size - 1)
201 scp->mouse_ypos = (scp->ysize + scp->yoff)*scp->font_size - 1;
204 if ((scp->mouse_xpos != scp->mouse_oldxpos || scp->mouse_ypos != scp->mouse_oldypos)
205 && (scp->font_size != 0 && scp->font_width != 0)) {
206 scp->status |= MOUSE_MOVED;
208 (scp->mouse_ypos/scp->font_size - scp->yoff)*scp->xsize
209 + scp->mouse_xpos/scp->font_width - scp->xoff;
210 #ifndef SC_NO_CUTPASTE
211 if ((scp->status & MOUSE_VISIBLE) && (scp->status & MOUSE_CUTTING))
217 #ifndef SC_NO_CUTPASTE
220 sc_draw_mouse_image(scr_stat *scp)
225 SC_VIDEO_LOCK(scp->sc);
226 (*scp->rndr->draw_mouse)(scp, scp->mouse_xpos, scp->mouse_ypos, TRUE);
227 scp->mouse_oldpos = scp->mouse_pos;
228 scp->mouse_oldxpos = scp->mouse_xpos;
229 scp->mouse_oldypos = scp->mouse_ypos;
230 scp->status |= MOUSE_VISIBLE;
231 SC_VIDEO_UNLOCK(scp->sc);
235 sc_remove_mouse_image(scr_stat *scp)
242 SC_VIDEO_LOCK(scp->sc);
243 (*scp->rndr->draw_mouse)(scp, scp->mouse_oldxpos, scp->mouse_oldypos,
246 * To simplify the renderer and ensure undrawing with correct
247 * attributes, mark for update a region containing the cursor
248 * (usually 2x2 character cells joined by almost a full line o
251 * The renderer should only undraw any pixels outside of the text
252 * window (e.g., ones in borders and hardware cursors).
254 i = scp->mouse_oldpos;
255 mark_for_update(scp, i);
256 mark_for_update(scp, i);
257 cols = 1 + howmany(10 - 1, scp->font_width); /* up to VGA cursor width 9 */
258 cols = imax(cols, 2); /* in case it is text mode 2x2 char cells */
259 cols = imin(cols, scp->xsize - i % scp->xsize);
260 rows = 1 + howmany(16 - 1, scp->font_size); /* up to VGA cursor height 16 */
261 rows = imax(rows, 2); /* don't bother reducing 3 to 2 if text */
262 rows = imin(rows, scp->ysize - i / scp->xsize);
263 mark_for_update(scp, i + (rows - 1) * scp->xsize + cols - 1);
264 scp->status &= ~MOUSE_VISIBLE;
265 SC_VIDEO_UNLOCK(scp->sc);
269 sc_inside_cutmark(scr_stat *scp, int pos)
274 if (scp->mouse_cut_end < 0)
276 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
277 start = scp->mouse_cut_start;
278 end = scp->mouse_cut_end;
280 start = scp->mouse_cut_end;
281 end = scp->mouse_cut_start - 1;
283 return ((start <= pos) && (pos <= end));
287 sc_remove_cutmarking(scr_stat *scp)
292 if (scp->mouse_cut_end >= 0) {
293 mark_for_update(scp, scp->mouse_cut_start);
294 mark_for_update(scp, scp->mouse_cut_end);
296 scp->mouse_cut_start = scp->xsize*scp->ysize;
297 scp->mouse_cut_end = -1;
299 scp->status &= ~MOUSE_CUTTING;
303 sc_remove_all_cutmarkings(sc_softc_t *sc)
308 /* delete cut markings in all vtys */
309 for (i = 0; i < sc->vtys; ++i) {
310 scp = SC_STAT(sc->dev[i]);
313 sc_remove_cutmarking(scp);
318 sc_remove_all_mouse(sc_softc_t *sc)
323 for (i = 0; i < sc->vtys; ++i) {
324 scp = SC_STAT(sc->dev[i]);
327 if (scp->status & MOUSE_VISIBLE) {
328 scp->status &= ~MOUSE_VISIBLE;
334 #define IS_SPACE_CHAR(c) (((c) & 0xff) == ' ')
336 #ifdef SC_CUT_SPACES2TABS
337 #define IS_BLANK_CHAR(c) (((c) & 0xff) == ' ' || ((c) & 0xff) == '\t')
339 #define IS_BLANK_CHAR(c) IS_SPACE_CHAR(c)
340 #endif /* SC_CUT_SPACES2TABS */
342 #ifdef SC_CUT_SEPCHARS
343 #define IS_SEP_CHAR(c) (index(SC_CUT_SEPCHARS, (c) & 0xff) != NULL)
345 #define IS_SEP_CHAR(c) IS_SPACE_CHAR(c)
346 #endif /* SC_CUT_SEPCHARS */
348 /* skip spaces to right */
350 skip_spc_right(scr_stat *scp, int p)
355 for (i = p % scp->xsize; i < scp->xsize; ++i) {
356 c = sc_vtb_getc(&scp->vtb, p);
357 if (!IS_SPACE_CHAR(c))
364 /* skip spaces to left */
366 skip_spc_left(scr_stat *scp, int p)
371 for (i = p-- % scp->xsize - 1; i >= 0; --i) {
372 c = sc_vtb_getc(&scp->vtb, p);
373 if (!IS_SPACE_CHAR(c))
381 mouse_do_cut(scr_stat *scp, int from, int to)
389 for (p = from, i = blank = leadspaces = 0; p <= to; ++p) {
390 cut_buffer[i] = sc_vtb_getc(&scp->vtb, p);
391 /* Be prepared that sc_vtb_getc() can return '\0' */
392 if (cut_buffer[i] == '\0')
394 #ifdef SC_CUT_SPACES2TABS
395 if (leadspaces != -1) {
396 if (IS_SPACE_CHAR(cut_buffer[i])) {
398 /* Check that we are at tabstop position */
399 if ((p % scp->xsize) % 8 == 7) {
401 cut_buffer[i] = '\t';
408 #endif /* SC_CUT_SPACES2TABS */
409 /* remember the position of the last non-space char */
410 if (!IS_BLANK_CHAR(cut_buffer[i]))
411 blank = i + 1; /* the first space after the last non-space */
413 /* trim trailing blank when crossing lines */
414 if ((p % scp->xsize) == (scp->xsize - 1)) {
415 cut_buffer[blank++] = '\r';
420 cut_buffer[i] = '\0';
422 /* remove the current marking */
424 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
425 mark_for_update(scp, scp->mouse_cut_start);
426 mark_for_update(scp, scp->mouse_cut_end);
427 } else if (scp->mouse_cut_end >= 0) {
428 mark_for_update(scp, scp->mouse_cut_end);
429 mark_for_update(scp, scp->mouse_cut_start);
432 /* mark the new region */
433 scp->mouse_cut_start = from;
434 scp->mouse_cut_end = to;
435 mark_for_update(scp, from);
436 mark_for_update(scp, to);
440 /* copy marked region to the cut buffer */
442 mouse_cut(scr_stat *scp)
453 start = scp->mouse_cut_start;
454 end = scp->mouse_cut_end;
455 if (scp->mouse_pos >= start) {
457 to = end = scp->mouse_pos;
459 from = end = scp->mouse_pos;
463 for (i = p % scp->xsize; i < scp->xsize; ++i) {
464 c = sc_vtb_getc(&scp->vtb, p);
465 if (!IS_SPACE_CHAR(c))
469 /* if there is nothing but blank chars, trim them, but mark towards eol */
470 if (i == scp->xsize) {
476 mouse_do_cut(scp, from, to);
478 scp->mouse_cut_start = start;
479 scp->mouse_cut_end = end;
483 /* a mouse button is pressed, start cut operation */
485 mouse_cut_start(scr_stat *scp)
490 if (scp->status & MOUSE_VISIBLE) {
491 sc_remove_all_cutmarkings(scp->sc);
492 if ((scp->mouse_pos == scp->mouse_cut_start) &&
493 (scp->mouse_pos == scp->mouse_cut_end)) {
494 cut_buffer[0] = '\0';
496 } else if (skip_spc_right(scp, scp->mouse_pos) >= scp->xsize) {
497 /* if the pointer is on trailing blank chars, mark towards eol */
498 i = skip_spc_left(scp, scp->mouse_pos) + 1;
500 scp->mouse_cut_start =
501 rounddown(scp->mouse_pos, scp->xsize) + i;
503 (scp->mouse_pos / scp->xsize + 1) * scp->xsize - 1;
505 cut_buffer[0] = '\r';
508 scp->mouse_cut_start = scp->mouse_pos;
509 scp->mouse_cut_end = scp->mouse_cut_start;
511 cut_buffer[0] = sc_vtb_getc(&scp->vtb, scp->mouse_cut_start);
513 cut_buffer[1] = '\0';
514 scp->status |= MOUSE_CUTTING;
515 mark_all(scp); /* this is probably overkill XXX */
519 /* end of cut operation */
521 mouse_cut_end(scr_stat *scp)
523 if (scp->status & MOUSE_VISIBLE)
524 scp->status &= ~MOUSE_CUTTING;
527 /* copy a word under the mouse pointer */
529 mouse_cut_word(scr_stat *scp)
540 * Because we don't have locale information in the kernel,
541 * we only distinguish space char and non-space chars. Punctuation
542 * chars, symbols and other regular chars are all treated alike
543 * unless user specified SC_CUT_SEPCHARS in his kernel config file.
545 if (scp->status & MOUSE_VISIBLE) {
546 sol = rounddown(scp->mouse_pos, scp->xsize);
547 eol = sol + scp->xsize;
548 c = sc_vtb_getc(&scp->vtb, scp->mouse_pos);
549 if (IS_SEP_CHAR(c)) {
551 for (j = scp->mouse_pos; j >= sol; --j) {
552 c = sc_vtb_getc(&scp->vtb, j);
557 for (j = scp->mouse_pos; j < eol; ++j) {
558 c = sc_vtb_getc(&scp->vtb, j);
565 for (j = scp->mouse_pos; j >= sol; --j) {
566 c = sc_vtb_getc(&scp->vtb, j);
571 for (j = scp->mouse_pos; j < eol; ++j) {
572 c = sc_vtb_getc(&scp->vtb, j);
579 /* copy the found word */
580 mouse_do_cut(scp, start, end);
581 len = strlen(cut_buffer);
582 if (cut_buffer[len - 1] == '\r')
583 cut_buffer[len - 1] = '\0';
587 /* copy a line under the mouse pointer */
589 mouse_cut_line(scr_stat *scp)
594 if (scp->status & MOUSE_VISIBLE) {
595 from = rounddown(scp->mouse_pos, scp->xsize);
596 mouse_do_cut(scp, from, from + scp->xsize - 1);
597 len = strlen(cut_buffer);
598 if (cut_buffer[len - 1] == '\r')
599 cut_buffer[len - 1] = '\0';
600 scp->status |= MOUSE_CUTTING;
604 /* extend the marked region to the mouse pointer position */
606 mouse_cut_extend(scr_stat *scp)
612 if ((scp->status & MOUSE_VISIBLE) && !(scp->status & MOUSE_CUTTING)
613 && (scp->mouse_cut_end >= 0)) {
614 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
615 start = scp->mouse_cut_start;
616 end = scp->mouse_cut_end;
618 start = scp->mouse_cut_end;
619 end = scp->mouse_cut_start - 1;
622 if (scp->mouse_pos > end) {
623 scp->mouse_cut_start = start;
624 scp->mouse_cut_end = end;
625 } else if (scp->mouse_pos < start) {
626 scp->mouse_cut_start = end + 1;
627 scp->mouse_cut_end = start;
629 if (scp->mouse_pos - start > end + 1 - scp->mouse_pos) {
630 scp->mouse_cut_start = start;
631 scp->mouse_cut_end = end;
633 scp->mouse_cut_start = end + 1;
634 scp->mouse_cut_end = start;
639 scp->status |= MOUSE_CUTTING;
643 /* paste cut buffer contents into the current vty */
645 sc_mouse_paste(scr_stat *scp)
647 sc_paste(scp, cut_buffer, strlen(cut_buffer));
650 #endif /* SC_NO_CUTPASTE */
653 sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
667 case CONS_MOUSECTL: /* control mouse arrow */
668 case OLD_CONS_MOUSECTL:
670 mouse = (mouse_info_t*)data;
672 random_harvest_queue(mouse, sizeof(mouse_info_t), RANDOM_MOUSE);
674 if (cmd == OLD_CONS_MOUSECTL) {
675 static u_char swapb[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
676 old_mouse_info_t *old_mouse = (old_mouse_info_t *)data;
679 mouse->operation = old_mouse->operation;
680 switch (mouse->operation) {
682 mouse->u.mode = old_mouse->u.mode;
690 mouse->u.data.x = old_mouse->u.data.x;
691 mouse->u.data.y = old_mouse->u.data.y;
693 mouse->u.data.buttons = swapb[old_mouse->u.data.buttons & 0x7];
696 old_mouse->u.data.x = scp->mouse_xpos;
697 old_mouse->u.data.y = scp->mouse_ypos;
698 old_mouse->u.data.buttons = swapb[scp->mouse_buttons & 0x7];
705 cur_scp = scp->sc->cur_scp;
707 switch (mouse->operation) {
709 if (ISSIGVALID(mouse->u.mode.signal)) {
710 scp->mouse_signal = mouse->u.mode.signal;
711 scp->mouse_proc = td->td_proc;
712 scp->mouse_pid = td->td_proc->p_pid;
715 scp->mouse_signal = 0;
716 scp->mouse_proc = NULL;
723 if (!(scp->sc->flags & SC_MOUSE_ENABLED)) {
724 scp->sc->flags |= SC_MOUSE_ENABLED;
725 cur_scp->status &= ~MOUSE_HIDDEN;
726 if (!ISGRAPHSC(cur_scp))
735 if (scp->sc->flags & SC_MOUSE_ENABLED) {
736 scp->sc->flags &= ~SC_MOUSE_ENABLED;
737 sc_remove_all_mouse(scp->sc);
745 scp->mouse_xpos = mouse->u.data.x;
746 scp->mouse_ypos = mouse->u.data.y;
753 scp->mouse_xpos += mouse->u.data.x;
754 scp->mouse_ypos += mouse->u.data.y;
760 mouse->u.data.x = scp->mouse_xpos;
761 mouse->u.data.y = scp->mouse_ypos;
763 mouse->u.data.buttons = scp->mouse_buttons;
767 case MOUSE_MOTION_EVENT:
768 /* send out mouse event on /dev/sysmouse */
770 /* this should maybe only be settable from /dev/consolectl SOS */
771 if (SC_VTY(tp->t_dev) != SC_CONSOLECTL)
775 if (mouse->u.data.x != 0 || mouse->u.data.y != 0) {
776 cur_scp->mouse_xpos += mouse->u.data.x;
777 cur_scp->mouse_ypos += mouse->u.data.y;
778 set_mouse_pos(cur_scp);
781 if (mouse->operation == MOUSE_ACTION) {
782 f = cur_scp->mouse_buttons ^ mouse->u.data.buttons;
783 cur_scp->mouse_buttons = mouse->u.data.buttons;
787 if (sysmouse_event(mouse) == 0)
791 * If any buttons are down or the mouse has moved a lot,
792 * stop the screen saver.
794 if (((mouse->operation == MOUSE_ACTION) && mouse->u.data.buttons)
795 || (mouse->u.data.x*mouse->u.data.x
796 + mouse->u.data.y*mouse->u.data.y
797 >= SC_WAKEUP_DELTA*SC_WAKEUP_DELTA)) {
798 sc_touch_scrn_saver();
801 cur_scp->status &= ~MOUSE_HIDDEN;
803 if (cur_scp->mouse_level > 0) {
804 sc_mouse_input(scp, mouse);
808 if (cur_scp->mouse_signal && cur_scp->mouse_proc) {
809 /* has controlling process died? */
810 if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))) {
811 cur_scp->mouse_signal = 0;
812 cur_scp->mouse_proc = NULL;
813 cur_scp->mouse_pid = 0;
817 kern_psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
818 PROC_UNLOCK(cur_scp->mouse_proc);
823 #ifndef SC_NO_CUTPASTE
824 if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
827 if ((mouse->operation == MOUSE_ACTION) && f) {
828 /* process button presses */
829 if (cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN)
830 mouse_cut_start(cur_scp);
832 mouse_cut_end(cur_scp);
833 if (cur_scp->mouse_buttons & MOUSE_BUTTON2DOWN ||
834 cur_scp->mouse_buttons & MOUSE_BUTTON3DOWN)
835 sc_mouse_paste(cur_scp);
837 #endif /* SC_NO_CUTPASTE */
840 case MOUSE_BUTTON_EVENT:
841 if ((mouse->u.event.id & MOUSE_BUTTONS) == 0)
843 if (mouse->u.event.value < 0)
846 /* this should maybe only be settable from /dev/consolectl SOS */
847 if (SC_VTY(tp->t_dev) != SC_CONSOLECTL)
850 if (mouse->u.event.value > 0)
851 cur_scp->mouse_buttons |= mouse->u.event.id;
853 cur_scp->mouse_buttons &= ~mouse->u.event.id;
855 if (sysmouse_event(mouse) == 0)
858 /* if a button is held down, stop the screen saver */
859 if (mouse->u.event.value > 0)
860 sc_touch_scrn_saver();
862 cur_scp->status &= ~MOUSE_HIDDEN;
864 if (cur_scp->mouse_level > 0) {
865 sc_mouse_input(scp, mouse);
869 if (cur_scp->mouse_signal && cur_scp->mouse_proc) {
870 if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))){
871 cur_scp->mouse_signal = 0;
872 cur_scp->mouse_proc = NULL;
873 cur_scp->mouse_pid = 0;
877 kern_psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
878 PROC_UNLOCK(cur_scp->mouse_proc);
883 #ifndef SC_NO_CUTPASTE
884 if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
887 switch (mouse->u.event.id) {
888 case MOUSE_BUTTON1DOWN:
889 switch (mouse->u.event.value % 4) {
891 mouse_cut_end(cur_scp);
893 case 1: /* single click: start cut operation */
894 mouse_cut_start(cur_scp);
896 case 2: /* double click: cut a word */
897 mouse_cut_word(cur_scp);
898 mouse_cut_end(cur_scp);
900 case 3: /* triple click: cut a line */
901 mouse_cut_line(cur_scp);
902 mouse_cut_end(cur_scp);
906 case SC_MOUSE_PASTEBUTTON:
907 switch (mouse->u.event.value) {
911 sc_mouse_paste(cur_scp);
915 case SC_MOUSE_EXTENDBUTTON:
916 switch (mouse->u.event.value) {
918 if (!(cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN))
919 mouse_cut_end(cur_scp);
922 mouse_cut_extend(cur_scp);
927 #endif /* SC_NO_CUTPASTE */
930 case MOUSE_MOUSECHAR:
931 if (mouse->u.mouse_char < 0) {
932 mouse->u.mouse_char = scp->sc->mouse_char;
934 if (mouse->u.mouse_char > UCHAR_MAX - 3)
937 sc_remove_all_mouse(scp->sc);
938 #ifndef SC_NO_FONT_LOADING
939 if (ISTEXTSC(cur_scp) && (cur_scp->font != NULL))
940 sc_load_font(cur_scp, 0, cur_scp->font_size,
942 cur_scp->font + cur_scp->font_size
943 * cur_scp->sc->mouse_char,
944 cur_scp->sc->mouse_char, 4);
946 scp->sc->mouse_char = mouse->u.mouse_char;
961 #endif /* SC_NO_SYSMOUSE */