2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "opt_syscons.h"
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/consio.h>
37 #include <sys/limits.h>
39 #include <sys/malloc.h>
40 #include <sys/mouse.h>
41 #include <sys/mutex.h>
43 #include <sys/random.h>
44 #include <sys/signalvar.h>
47 #include <dev/syscons/syscons.h>
49 #ifdef SC_TWOBUTTON_MOUSE
50 #define SC_MOUSE_PASTEBUTTON MOUSE_BUTTON3DOWN /* right button */
51 #define SC_MOUSE_EXTENDBUTTON MOUSE_BUTTON2DOWN /* not really used */
53 #define SC_MOUSE_PASTEBUTTON MOUSE_BUTTON2DOWN /* middle button */
54 #define SC_MOUSE_EXTENDBUTTON MOUSE_BUTTON3DOWN /* right button */
55 #endif /* SC_TWOBUTTON_MOUSE */
57 #define SC_WAKEUP_DELTA 20
59 /* for backward compatibility */
60 #define OLD_CONS_MOUSECTL _IOWR('c', 10, old_mouse_info_t)
62 typedef struct old_mouse_data {
68 typedef struct old_mouse_info {
71 struct old_mouse_data data;
72 struct mouse_mode mode;
76 #ifndef SC_NO_SYSMOUSE
79 #ifndef SC_NO_CUTPASTE
80 static int cut_buffer_size;
81 static u_char *cut_buffer;
85 static void set_mouse_pos(scr_stat *scp);
86 #ifndef SC_NO_CUTPASTE
87 static int skip_spc_right(scr_stat *scp, int p);
88 static int skip_spc_left(scr_stat *scp, int p);
89 static void mouse_cut(scr_stat *scp);
90 static void mouse_cut_start(scr_stat *scp);
91 static void mouse_cut_end(scr_stat *scp);
92 static void mouse_cut_word(scr_stat *scp);
93 static void mouse_cut_line(scr_stat *scp);
94 static void mouse_cut_extend(scr_stat *scp);
95 #endif /* SC_NO_CUTPASTE */
97 #ifndef SC_NO_CUTPASTE
98 /* allocate a cut buffer */
100 sc_alloc_cut_buffer(scr_stat *scp, int wait)
104 if ((cut_buffer == NULL)
105 || (cut_buffer_size < scp->xsize * scp->ysize + 1)) {
110 cut_buffer_size = scp->xsize * scp->ysize + 1;
111 p = (u_char *)malloc(cut_buffer_size,
112 M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT);
118 #endif /* SC_NO_CUTPASTE */
121 sc_mouse_input_button(scr_stat *scp, int button)
123 char mouseb[6] = "\x1B[M";
125 mouseb[3] = ' ' + button;
126 mouseb[4] = '!' + scp->mouse_pos % scp->xsize;
127 mouseb[5] = '!' + scp->mouse_pos / scp->xsize;
128 sc_respond(scp, mouseb, sizeof mouseb, 1);
132 sc_mouse_input(scr_stat *scp, mouse_info_t *mouse)
135 switch (mouse->operation) {
136 case MOUSE_BUTTON_EVENT:
137 if (mouse->u.event.value > 0) {
138 /* Mouse button pressed. */
139 if (mouse->u.event.id & MOUSE_BUTTON1DOWN)
140 sc_mouse_input_button(scp, 0);
141 if (mouse->u.event.id & MOUSE_BUTTON2DOWN)
142 sc_mouse_input_button(scp, 1);
143 if (mouse->u.event.id & MOUSE_BUTTON3DOWN)
144 sc_mouse_input_button(scp, 2);
146 /* Mouse button released. */
147 sc_mouse_input_button(scp, 3);
150 case MOUSE_MOTION_EVENT:
151 if (mouse->u.data.z < 0) {
153 sc_mouse_input_button(scp, 64);
154 } else if (mouse->u.data.z > 0) {
156 sc_mouse_input_button(scp, 65);
164 sc_mouse_move(scr_stat *scp, int x, int y)
169 scp->mouse_xpos = scp->mouse_oldxpos = x;
170 scp->mouse_ypos = scp->mouse_oldypos = y;
171 if (scp->font_size <= 0 || scp->font_width <= 0)
172 scp->mouse_pos = scp->mouse_oldpos = 0;
174 scp->mouse_pos = scp->mouse_oldpos =
175 (y/scp->font_size - scp->yoff)*scp->xsize + x/scp->font_width -
177 scp->status |= MOUSE_MOVED;
181 /* adjust mouse position */
183 set_mouse_pos(scr_stat *scp)
185 if (scp->mouse_xpos < scp->xoff*scp->font_width)
186 scp->mouse_xpos = scp->xoff*scp->font_width;
187 if (scp->mouse_ypos < scp->yoff*scp->font_size)
188 scp->mouse_ypos = scp->yoff*scp->font_size;
189 if (ISGRAPHSC(scp)) {
190 if (scp->mouse_xpos > scp->xpixel-1)
191 scp->mouse_xpos = scp->xpixel-1;
192 if (scp->mouse_ypos > scp->ypixel-1)
193 scp->mouse_ypos = scp->ypixel-1;
196 if (scp->mouse_xpos > (scp->xsize + scp->xoff)*scp->font_width - 1)
197 scp->mouse_xpos = (scp->xsize + scp->xoff)*scp->font_width - 1;
198 if (scp->mouse_ypos > (scp->ysize + scp->yoff)*scp->font_size - 1)
199 scp->mouse_ypos = (scp->ysize + scp->yoff)*scp->font_size - 1;
202 if ((scp->mouse_xpos != scp->mouse_oldxpos || scp->mouse_ypos != scp->mouse_oldypos)
203 && (scp->font_size != 0 && scp->font_width != 0)) {
204 scp->status |= MOUSE_MOVED;
206 (scp->mouse_ypos/scp->font_size - scp->yoff)*scp->xsize
207 + scp->mouse_xpos/scp->font_width - scp->xoff;
208 #ifndef SC_NO_CUTPASTE
209 if ((scp->status & MOUSE_VISIBLE) && (scp->status & MOUSE_CUTTING))
215 #ifndef SC_NO_CUTPASTE
218 sc_draw_mouse_image(scr_stat *scp)
223 SC_VIDEO_LOCK(scp->sc);
224 (*scp->rndr->draw_mouse)(scp, scp->mouse_xpos, scp->mouse_ypos, TRUE);
225 scp->mouse_oldpos = scp->mouse_pos;
226 scp->mouse_oldxpos = scp->mouse_xpos;
227 scp->mouse_oldypos = scp->mouse_ypos;
228 scp->status |= MOUSE_VISIBLE;
229 SC_VIDEO_UNLOCK(scp->sc);
233 sc_remove_mouse_image(scr_stat *scp)
241 SC_VIDEO_LOCK(scp->sc);
242 (*scp->rndr->draw_mouse)(scp,
243 (scp->mouse_oldpos%scp->xsize + scp->xoff)
245 (scp->mouse_oldpos/scp->xsize + scp->yoff)
248 size = scp->xsize*scp->ysize;
249 i = scp->mouse_oldpos;
250 mark_for_update(scp, i);
251 mark_for_update(scp, i);
253 if (i + scp->xsize + 1 < size) {
254 mark_for_update(scp, i + scp->xsize + 1);
255 } else if (i + scp->xsize < size) {
256 mark_for_update(scp, i + scp->xsize);
257 } else if (i + 1 < size) {
258 mark_for_update(scp, i + 1);
261 scp->status &= ~MOUSE_VISIBLE;
262 SC_VIDEO_UNLOCK(scp->sc);
266 sc_inside_cutmark(scr_stat *scp, int pos)
271 if (scp->mouse_cut_end < 0)
273 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
274 start = scp->mouse_cut_start;
275 end = scp->mouse_cut_end;
277 start = scp->mouse_cut_end;
278 end = scp->mouse_cut_start - 1;
280 return ((start <= pos) && (pos <= end));
284 sc_remove_cutmarking(scr_stat *scp)
289 if (scp->mouse_cut_end >= 0) {
290 mark_for_update(scp, scp->mouse_cut_start);
291 mark_for_update(scp, scp->mouse_cut_end);
293 scp->mouse_cut_start = scp->xsize*scp->ysize;
294 scp->mouse_cut_end = -1;
296 scp->status &= ~MOUSE_CUTTING;
300 sc_remove_all_cutmarkings(sc_softc_t *sc)
305 /* delete cut markings in all vtys */
306 for (i = 0; i < sc->vtys; ++i) {
307 scp = SC_STAT(sc->dev[i]);
310 sc_remove_cutmarking(scp);
315 sc_remove_all_mouse(sc_softc_t *sc)
320 for (i = 0; i < sc->vtys; ++i) {
321 scp = SC_STAT(sc->dev[i]);
324 if (scp->status & MOUSE_VISIBLE) {
325 scp->status &= ~MOUSE_VISIBLE;
331 #define IS_SPACE_CHAR(c) (((c) & 0xff) == ' ')
333 #ifdef SC_CUT_SPACES2TABS
334 #define IS_BLANK_CHAR(c) (((c) & 0xff) == ' ' || ((c) & 0xff) == '\t')
336 #define IS_BLANK_CHAR(c) IS_SPACE_CHAR(c)
337 #endif /* SC_CUT_SPACES2TABS */
339 #ifdef SC_CUT_SEPCHARS
340 #define IS_SEP_CHAR(c) (index(SC_CUT_SEPCHARS, (c) & 0xff) != NULL)
342 #define IS_SEP_CHAR(c) IS_SPACE_CHAR(c)
343 #endif /* SC_CUT_SEPCHARS */
345 /* skip spaces to right */
347 skip_spc_right(scr_stat *scp, int p)
352 for (i = p % scp->xsize; i < scp->xsize; ++i) {
353 c = sc_vtb_getc(&scp->vtb, p);
354 if (!IS_SPACE_CHAR(c))
361 /* skip spaces to left */
363 skip_spc_left(scr_stat *scp, int p)
368 for (i = p-- % scp->xsize - 1; i >= 0; --i) {
369 c = sc_vtb_getc(&scp->vtb, p);
370 if (!IS_SPACE_CHAR(c))
378 mouse_do_cut(scr_stat *scp, int from, int to)
386 for (p = from, i = blank = leadspaces = 0; p <= to; ++p) {
387 cut_buffer[i] = sc_vtb_getc(&scp->vtb, p);
388 /* Be prepared that sc_vtb_getc() can return '\0' */
389 if (cut_buffer[i] == '\0')
391 #ifdef SC_CUT_SPACES2TABS
392 if (leadspaces != -1) {
393 if (IS_SPACE_CHAR(cut_buffer[i])) {
395 /* Check that we are at tabstop position */
396 if ((p % scp->xsize) % 8 == 7) {
398 cut_buffer[i] = '\t';
405 #endif /* SC_CUT_SPACES2TABS */
406 /* remember the position of the last non-space char */
407 if (!IS_BLANK_CHAR(cut_buffer[i]))
408 blank = i + 1; /* the first space after the last non-space */
410 /* trim trailing blank when crossing lines */
411 if ((p % scp->xsize) == (scp->xsize - 1)) {
412 cut_buffer[blank++] = '\r';
417 cut_buffer[i] = '\0';
419 /* remove the current marking */
421 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
422 mark_for_update(scp, scp->mouse_cut_start);
423 mark_for_update(scp, scp->mouse_cut_end);
424 } else if (scp->mouse_cut_end >= 0) {
425 mark_for_update(scp, scp->mouse_cut_end);
426 mark_for_update(scp, scp->mouse_cut_start);
429 /* mark the new region */
430 scp->mouse_cut_start = from;
431 scp->mouse_cut_end = to;
432 mark_for_update(scp, from);
433 mark_for_update(scp, to);
437 /* copy marked region to the cut buffer */
439 mouse_cut(scr_stat *scp)
450 start = scp->mouse_cut_start;
451 end = scp->mouse_cut_end;
452 if (scp->mouse_pos >= start) {
454 to = end = scp->mouse_pos;
456 from = end = scp->mouse_pos;
460 for (i = p % scp->xsize; i < scp->xsize; ++i) {
461 c = sc_vtb_getc(&scp->vtb, p);
462 if (!IS_SPACE_CHAR(c))
466 /* if there is nothing but blank chars, trim them, but mark towards eol */
467 if (i == scp->xsize) {
473 mouse_do_cut(scp, from, to);
475 scp->mouse_cut_start = start;
476 scp->mouse_cut_end = end;
480 /* a mouse button is pressed, start cut operation */
482 mouse_cut_start(scr_stat *scp)
487 if (scp->status & MOUSE_VISIBLE) {
488 sc_remove_all_cutmarkings(scp->sc);
489 if ((scp->mouse_pos == scp->mouse_cut_start) &&
490 (scp->mouse_pos == scp->mouse_cut_end)) {
491 cut_buffer[0] = '\0';
493 } else if (skip_spc_right(scp, scp->mouse_pos) >= scp->xsize) {
494 /* if the pointer is on trailing blank chars, mark towards eol */
495 i = skip_spc_left(scp, scp->mouse_pos) + 1;
497 scp->mouse_cut_start =
498 (scp->mouse_pos / scp->xsize) * scp->xsize + i;
500 (scp->mouse_pos / scp->xsize + 1) * scp->xsize - 1;
502 cut_buffer[0] = '\r';
505 scp->mouse_cut_start = scp->mouse_pos;
506 scp->mouse_cut_end = scp->mouse_cut_start;
508 cut_buffer[0] = sc_vtb_getc(&scp->vtb, scp->mouse_cut_start);
510 cut_buffer[1] = '\0';
511 scp->status |= MOUSE_CUTTING;
512 mark_all(scp); /* this is probably overkill XXX */
516 /* end of cut operation */
518 mouse_cut_end(scr_stat *scp)
520 if (scp->status & MOUSE_VISIBLE)
521 scp->status &= ~MOUSE_CUTTING;
524 /* copy a word under the mouse pointer */
526 mouse_cut_word(scr_stat *scp)
537 * Because we don't have locale information in the kernel,
538 * we only distinguish space char and non-space chars. Punctuation
539 * chars, symbols and other regular chars are all treated alike
540 * unless user specified SC_CUT_SEPCHARS in his kernel config file.
542 if (scp->status & MOUSE_VISIBLE) {
543 sol = (scp->mouse_pos / scp->xsize) * scp->xsize;
544 eol = sol + scp->xsize;
545 c = sc_vtb_getc(&scp->vtb, scp->mouse_pos);
546 if (IS_SEP_CHAR(c)) {
548 for (j = scp->mouse_pos; j >= sol; --j) {
549 c = sc_vtb_getc(&scp->vtb, j);
554 for (j = scp->mouse_pos; j < eol; ++j) {
555 c = sc_vtb_getc(&scp->vtb, j);
562 for (j = scp->mouse_pos; j >= sol; --j) {
563 c = sc_vtb_getc(&scp->vtb, j);
568 for (j = scp->mouse_pos; j < eol; ++j) {
569 c = sc_vtb_getc(&scp->vtb, j);
576 /* copy the found word */
577 mouse_do_cut(scp, start, end);
578 len = strlen(cut_buffer);
579 if (cut_buffer[len - 1] == '\r')
580 cut_buffer[len - 1] = '\0';
584 /* copy a line under the mouse pointer */
586 mouse_cut_line(scr_stat *scp)
591 if (scp->status & MOUSE_VISIBLE) {
592 from = (scp->mouse_pos / scp->xsize) * scp->xsize;
593 mouse_do_cut(scp, from, from + scp->xsize - 1);
594 len = strlen(cut_buffer);
595 if (cut_buffer[len - 1] == '\r')
596 cut_buffer[len - 1] = '\0';
597 scp->status |= MOUSE_CUTTING;
601 /* extend the marked region to the mouse pointer position */
603 mouse_cut_extend(scr_stat *scp)
609 if ((scp->status & MOUSE_VISIBLE) && !(scp->status & MOUSE_CUTTING)
610 && (scp->mouse_cut_end >= 0)) {
611 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
612 start = scp->mouse_cut_start;
613 end = scp->mouse_cut_end;
615 start = scp->mouse_cut_end;
616 end = scp->mouse_cut_start - 1;
619 if (scp->mouse_pos > end) {
620 scp->mouse_cut_start = start;
621 scp->mouse_cut_end = end;
622 } else if (scp->mouse_pos < start) {
623 scp->mouse_cut_start = end + 1;
624 scp->mouse_cut_end = start;
626 if (scp->mouse_pos - start > end + 1 - scp->mouse_pos) {
627 scp->mouse_cut_start = start;
628 scp->mouse_cut_end = end;
630 scp->mouse_cut_start = end + 1;
631 scp->mouse_cut_end = start;
636 scp->status |= MOUSE_CUTTING;
640 /* paste cut buffer contents into the current vty */
642 sc_mouse_paste(scr_stat *scp)
644 sc_paste(scp, cut_buffer, strlen(cut_buffer));
647 #endif /* SC_NO_CUTPASTE */
650 sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
664 case CONS_MOUSECTL: /* control mouse arrow */
665 case OLD_CONS_MOUSECTL:
667 mouse = (mouse_info_t*)data;
669 random_harvest(mouse, sizeof(mouse_info_t), 2, 0, RANDOM_MOUSE);
671 if (cmd == OLD_CONS_MOUSECTL) {
672 static u_char swapb[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
673 old_mouse_info_t *old_mouse = (old_mouse_info_t *)data;
676 mouse->operation = old_mouse->operation;
677 switch (mouse->operation) {
679 mouse->u.mode = old_mouse->u.mode;
687 mouse->u.data.x = old_mouse->u.data.x;
688 mouse->u.data.y = old_mouse->u.data.y;
690 mouse->u.data.buttons = swapb[old_mouse->u.data.buttons & 0x7];
693 old_mouse->u.data.x = scp->mouse_xpos;
694 old_mouse->u.data.y = scp->mouse_ypos;
695 old_mouse->u.data.buttons = swapb[scp->mouse_buttons & 0x7];
702 cur_scp = scp->sc->cur_scp;
704 switch (mouse->operation) {
706 if (ISSIGVALID(mouse->u.mode.signal)) {
707 scp->mouse_signal = mouse->u.mode.signal;
708 scp->mouse_proc = td->td_proc;
709 scp->mouse_pid = td->td_proc->p_pid;
712 scp->mouse_signal = 0;
713 scp->mouse_proc = NULL;
720 if (!(scp->sc->flags & SC_MOUSE_ENABLED)) {
721 scp->sc->flags |= SC_MOUSE_ENABLED;
722 cur_scp->status &= ~MOUSE_HIDDEN;
723 if (!ISGRAPHSC(cur_scp))
732 if (scp->sc->flags & SC_MOUSE_ENABLED) {
733 scp->sc->flags &= ~SC_MOUSE_ENABLED;
734 sc_remove_all_mouse(scp->sc);
742 scp->mouse_xpos = mouse->u.data.x;
743 scp->mouse_ypos = mouse->u.data.y;
750 scp->mouse_xpos += mouse->u.data.x;
751 scp->mouse_ypos += mouse->u.data.y;
757 mouse->u.data.x = scp->mouse_xpos;
758 mouse->u.data.y = scp->mouse_ypos;
760 mouse->u.data.buttons = scp->mouse_buttons;
764 case MOUSE_MOTION_EVENT:
765 /* send out mouse event on /dev/sysmouse */
767 /* this should maybe only be settable from /dev/consolectl SOS */
768 if (SC_VTY(tp->t_dev) != SC_CONSOLECTL)
772 if (mouse->u.data.x != 0 || mouse->u.data.y != 0) {
773 cur_scp->mouse_xpos += mouse->u.data.x;
774 cur_scp->mouse_ypos += mouse->u.data.y;
775 set_mouse_pos(cur_scp);
778 if (mouse->operation == MOUSE_ACTION) {
779 f = cur_scp->mouse_buttons ^ mouse->u.data.buttons;
780 cur_scp->mouse_buttons = mouse->u.data.buttons;
784 if (sysmouse_event(mouse) == 0)
788 * If any buttons are down or the mouse has moved a lot,
789 * stop the screen saver.
791 if (((mouse->operation == MOUSE_ACTION) && mouse->u.data.buttons)
792 || (mouse->u.data.x*mouse->u.data.x
793 + mouse->u.data.y*mouse->u.data.y
794 >= SC_WAKEUP_DELTA*SC_WAKEUP_DELTA)) {
795 sc_touch_scrn_saver();
798 cur_scp->status &= ~MOUSE_HIDDEN;
800 if (cur_scp->mouse_level > 0) {
801 sc_mouse_input(scp, mouse);
805 if (cur_scp->mouse_signal && cur_scp->mouse_proc) {
806 /* has controlling process died? */
807 if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))) {
808 cur_scp->mouse_signal = 0;
809 cur_scp->mouse_proc = NULL;
810 cur_scp->mouse_pid = 0;
814 kern_psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
815 PROC_UNLOCK(cur_scp->mouse_proc);
820 #ifndef SC_NO_CUTPASTE
821 if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
824 if ((mouse->operation == MOUSE_ACTION) && f) {
825 /* process button presses */
826 if (cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN)
827 mouse_cut_start(cur_scp);
829 mouse_cut_end(cur_scp);
830 if (cur_scp->mouse_buttons & MOUSE_BUTTON2DOWN ||
831 cur_scp->mouse_buttons & MOUSE_BUTTON3DOWN)
832 sc_mouse_paste(cur_scp);
834 #endif /* SC_NO_CUTPASTE */
837 case MOUSE_BUTTON_EVENT:
838 if ((mouse->u.event.id & MOUSE_BUTTONS) == 0)
840 if (mouse->u.event.value < 0)
843 /* this should maybe only be settable from /dev/consolectl SOS */
844 if (SC_VTY(tp->t_dev) != SC_CONSOLECTL)
847 if (mouse->u.event.value > 0)
848 cur_scp->mouse_buttons |= mouse->u.event.id;
850 cur_scp->mouse_buttons &= ~mouse->u.event.id;
852 if (sysmouse_event(mouse) == 0)
855 /* if a button is held down, stop the screen saver */
856 if (mouse->u.event.value > 0)
857 sc_touch_scrn_saver();
859 cur_scp->status &= ~MOUSE_HIDDEN;
861 if (cur_scp->mouse_level > 0) {
862 sc_mouse_input(scp, mouse);
866 if (cur_scp->mouse_signal && cur_scp->mouse_proc) {
867 if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))){
868 cur_scp->mouse_signal = 0;
869 cur_scp->mouse_proc = NULL;
870 cur_scp->mouse_pid = 0;
874 kern_psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
875 PROC_UNLOCK(cur_scp->mouse_proc);
880 #ifndef SC_NO_CUTPASTE
881 if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
884 switch (mouse->u.event.id) {
885 case MOUSE_BUTTON1DOWN:
886 switch (mouse->u.event.value % 4) {
888 mouse_cut_end(cur_scp);
890 case 1: /* single click: start cut operation */
891 mouse_cut_start(cur_scp);
893 case 2: /* double click: cut a word */
894 mouse_cut_word(cur_scp);
895 mouse_cut_end(cur_scp);
897 case 3: /* triple click: cut a line */
898 mouse_cut_line(cur_scp);
899 mouse_cut_end(cur_scp);
903 case SC_MOUSE_PASTEBUTTON:
904 switch (mouse->u.event.value) {
908 sc_mouse_paste(cur_scp);
912 case SC_MOUSE_EXTENDBUTTON:
913 switch (mouse->u.event.value) {
915 if (!(cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN))
916 mouse_cut_end(cur_scp);
919 mouse_cut_extend(cur_scp);
924 #endif /* SC_NO_CUTPASTE */
927 case MOUSE_MOUSECHAR:
928 if (mouse->u.mouse_char < 0) {
929 mouse->u.mouse_char = scp->sc->mouse_char;
931 if (mouse->u.mouse_char > UCHAR_MAX - 3)
934 sc_remove_all_mouse(scp->sc);
935 #ifndef SC_NO_FONT_LOADING
936 if (ISTEXTSC(cur_scp) && (cur_scp->font != NULL))
937 sc_load_font(cur_scp, 0, cur_scp->font_size,
939 cur_scp->font + cur_scp->font_size
940 * cur_scp->sc->mouse_char,
941 cur_scp->sc->mouse_char, 4);
943 scp->sc->mouse_char = mouse->u.mouse_char;
958 #endif /* SC_NO_SYSMOUSE */