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)
240 SC_VIDEO_LOCK(scp->sc);
241 (*scp->rndr->draw_mouse)(scp, scp->mouse_oldxpos, scp->mouse_oldypos,
244 * To simplify the renderer and ensure undrawing with correct
245 * attributes, mark for update a region containing the cursor
246 * (usually 2x2 character cells joined by almost a full line o
249 * The renderer should only undraw any pixels outside of the text
250 * window (e.g., ones in borders and hardware cursors).
252 i = scp->mouse_oldpos;
253 mark_for_update(scp, i);
254 mark_for_update(scp, i);
255 cols = 1 + howmany(10 - 1, scp->font_width); /* up to VGA cursor width 9 */
256 cols = imax(cols, 2); /* in case it is text mode 2x2 char cells */
257 cols = imin(cols, scp->xsize - i % scp->xsize);
258 rows = 1 + howmany(16 - 1, scp->font_size); /* up to VGA cursor height 16 */
259 rows = imax(rows, 2); /* don't bother reducing 3 to 2 if text */
260 rows = imin(rows, scp->ysize - i / scp->xsize);
261 mark_for_update(scp, i + (rows - 1) * scp->xsize + cols - 1);
262 scp->status &= ~MOUSE_VISIBLE;
263 SC_VIDEO_UNLOCK(scp->sc);
267 sc_inside_cutmark(scr_stat *scp, int pos)
272 if (scp->mouse_cut_end < 0)
274 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
275 start = scp->mouse_cut_start;
276 end = scp->mouse_cut_end;
278 start = scp->mouse_cut_end;
279 end = scp->mouse_cut_start - 1;
281 return ((start <= pos) && (pos <= end));
285 sc_remove_cutmarking(scr_stat *scp)
290 if (scp->mouse_cut_end >= 0) {
291 mark_for_update(scp, scp->mouse_cut_start);
292 mark_for_update(scp, scp->mouse_cut_end);
294 scp->mouse_cut_start = scp->xsize*scp->ysize;
295 scp->mouse_cut_end = -1;
297 scp->status &= ~MOUSE_CUTTING;
301 sc_remove_all_cutmarkings(sc_softc_t *sc)
306 /* delete cut markings in all vtys */
307 for (i = 0; i < sc->vtys; ++i) {
308 scp = SC_STAT(sc->dev[i]);
311 sc_remove_cutmarking(scp);
316 sc_remove_all_mouse(sc_softc_t *sc)
321 for (i = 0; i < sc->vtys; ++i) {
322 scp = SC_STAT(sc->dev[i]);
325 if (scp->status & MOUSE_VISIBLE) {
326 scp->status &= ~MOUSE_VISIBLE;
332 #define IS_SPACE_CHAR(c) (((c) & 0xff) == ' ')
334 #ifdef SC_CUT_SPACES2TABS
335 #define IS_BLANK_CHAR(c) (((c) & 0xff) == ' ' || ((c) & 0xff) == '\t')
337 #define IS_BLANK_CHAR(c) IS_SPACE_CHAR(c)
338 #endif /* SC_CUT_SPACES2TABS */
340 #ifdef SC_CUT_SEPCHARS
341 #define IS_SEP_CHAR(c) (index(SC_CUT_SEPCHARS, (c) & 0xff) != NULL)
343 #define IS_SEP_CHAR(c) IS_SPACE_CHAR(c)
344 #endif /* SC_CUT_SEPCHARS */
346 /* skip spaces to right */
348 skip_spc_right(scr_stat *scp, int p)
353 for (i = p % scp->xsize; i < scp->xsize; ++i) {
354 c = sc_vtb_getc(&scp->vtb, p);
355 if (!IS_SPACE_CHAR(c))
362 /* skip spaces to left */
364 skip_spc_left(scr_stat *scp, int p)
369 for (i = p-- % scp->xsize - 1; i >= 0; --i) {
370 c = sc_vtb_getc(&scp->vtb, p);
371 if (!IS_SPACE_CHAR(c))
379 mouse_do_cut(scr_stat *scp, int from, int to)
387 for (p = from, i = blank = leadspaces = 0; p <= to; ++p) {
388 cut_buffer[i] = sc_vtb_getc(&scp->vtb, p);
389 /* Be prepared that sc_vtb_getc() can return '\0' */
390 if (cut_buffer[i] == '\0')
392 #ifdef SC_CUT_SPACES2TABS
393 if (leadspaces != -1) {
394 if (IS_SPACE_CHAR(cut_buffer[i])) {
396 /* Check that we are at tabstop position */
397 if ((p % scp->xsize) % 8 == 7) {
399 cut_buffer[i] = '\t';
406 #endif /* SC_CUT_SPACES2TABS */
407 /* remember the position of the last non-space char */
408 if (!IS_BLANK_CHAR(cut_buffer[i]))
409 blank = i + 1; /* the first space after the last non-space */
411 /* trim trailing blank when crossing lines */
412 if ((p % scp->xsize) == (scp->xsize - 1)) {
413 cut_buffer[blank++] = '\r';
418 cut_buffer[i] = '\0';
420 /* remove the current marking */
422 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
423 mark_for_update(scp, scp->mouse_cut_start);
424 mark_for_update(scp, scp->mouse_cut_end);
425 } else if (scp->mouse_cut_end >= 0) {
426 mark_for_update(scp, scp->mouse_cut_end);
427 mark_for_update(scp, scp->mouse_cut_start);
430 /* mark the new region */
431 scp->mouse_cut_start = from;
432 scp->mouse_cut_end = to;
433 mark_for_update(scp, from);
434 mark_for_update(scp, to);
438 /* copy marked region to the cut buffer */
440 mouse_cut(scr_stat *scp)
451 start = scp->mouse_cut_start;
452 end = scp->mouse_cut_end;
453 if (scp->mouse_pos >= start) {
455 to = end = scp->mouse_pos;
457 from = end = scp->mouse_pos;
461 for (i = p % scp->xsize; i < scp->xsize; ++i) {
462 c = sc_vtb_getc(&scp->vtb, p);
463 if (!IS_SPACE_CHAR(c))
467 /* if there is nothing but blank chars, trim them, but mark towards eol */
468 if (i == scp->xsize) {
474 mouse_do_cut(scp, from, to);
476 scp->mouse_cut_start = start;
477 scp->mouse_cut_end = end;
481 /* a mouse button is pressed, start cut operation */
483 mouse_cut_start(scr_stat *scp)
488 if (scp->status & MOUSE_VISIBLE) {
489 sc_remove_all_cutmarkings(scp->sc);
490 if ((scp->mouse_pos == scp->mouse_cut_start) &&
491 (scp->mouse_pos == scp->mouse_cut_end)) {
492 cut_buffer[0] = '\0';
494 } else if (skip_spc_right(scp, scp->mouse_pos) >= scp->xsize) {
495 /* if the pointer is on trailing blank chars, mark towards eol */
496 i = skip_spc_left(scp, scp->mouse_pos) + 1;
498 scp->mouse_cut_start =
499 rounddown(scp->mouse_pos, scp->xsize) + i;
501 (scp->mouse_pos / scp->xsize + 1) * scp->xsize - 1;
503 cut_buffer[0] = '\r';
506 scp->mouse_cut_start = scp->mouse_pos;
507 scp->mouse_cut_end = scp->mouse_cut_start;
509 cut_buffer[0] = sc_vtb_getc(&scp->vtb, scp->mouse_cut_start);
511 cut_buffer[1] = '\0';
512 scp->status |= MOUSE_CUTTING;
513 mark_all(scp); /* this is probably overkill XXX */
517 /* end of cut operation */
519 mouse_cut_end(scr_stat *scp)
521 if (scp->status & MOUSE_VISIBLE)
522 scp->status &= ~MOUSE_CUTTING;
525 /* copy a word under the mouse pointer */
527 mouse_cut_word(scr_stat *scp)
538 * Because we don't have locale information in the kernel,
539 * we only distinguish space char and non-space chars. Punctuation
540 * chars, symbols and other regular chars are all treated alike
541 * unless user specified SC_CUT_SEPCHARS in his kernel config file.
543 if (scp->status & MOUSE_VISIBLE) {
544 sol = rounddown(scp->mouse_pos, scp->xsize);
545 eol = sol + scp->xsize;
546 c = sc_vtb_getc(&scp->vtb, scp->mouse_pos);
547 if (IS_SEP_CHAR(c)) {
549 for (j = scp->mouse_pos; j >= sol; --j) {
550 c = sc_vtb_getc(&scp->vtb, j);
555 for (j = scp->mouse_pos; j < eol; ++j) {
556 c = sc_vtb_getc(&scp->vtb, j);
563 for (j = scp->mouse_pos; j >= sol; --j) {
564 c = sc_vtb_getc(&scp->vtb, j);
569 for (j = scp->mouse_pos; j < eol; ++j) {
570 c = sc_vtb_getc(&scp->vtb, j);
577 /* copy the found word */
578 mouse_do_cut(scp, start, end);
579 len = strlen(cut_buffer);
580 if (cut_buffer[len - 1] == '\r')
581 cut_buffer[len - 1] = '\0';
585 /* copy a line under the mouse pointer */
587 mouse_cut_line(scr_stat *scp)
592 if (scp->status & MOUSE_VISIBLE) {
593 from = rounddown(scp->mouse_pos, scp->xsize);
594 mouse_do_cut(scp, from, from + scp->xsize - 1);
595 len = strlen(cut_buffer);
596 if (cut_buffer[len - 1] == '\r')
597 cut_buffer[len - 1] = '\0';
598 scp->status |= MOUSE_CUTTING;
602 /* extend the marked region to the mouse pointer position */
604 mouse_cut_extend(scr_stat *scp)
610 if ((scp->status & MOUSE_VISIBLE) && !(scp->status & MOUSE_CUTTING)
611 && (scp->mouse_cut_end >= 0)) {
612 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
613 start = scp->mouse_cut_start;
614 end = scp->mouse_cut_end;
616 start = scp->mouse_cut_end;
617 end = scp->mouse_cut_start - 1;
620 if (scp->mouse_pos > end) {
621 scp->mouse_cut_start = start;
622 scp->mouse_cut_end = end;
623 } else if (scp->mouse_pos < start) {
624 scp->mouse_cut_start = end + 1;
625 scp->mouse_cut_end = start;
627 if (scp->mouse_pos - start > end + 1 - scp->mouse_pos) {
628 scp->mouse_cut_start = start;
629 scp->mouse_cut_end = end;
631 scp->mouse_cut_start = end + 1;
632 scp->mouse_cut_end = start;
637 scp->status |= MOUSE_CUTTING;
641 /* paste cut buffer contents into the current vty */
643 sc_mouse_paste(scr_stat *scp)
645 sc_paste(scp, cut_buffer, strlen(cut_buffer));
648 #endif /* SC_NO_CUTPASTE */
651 sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
665 case CONS_MOUSECTL: /* control mouse arrow */
666 case OLD_CONS_MOUSECTL:
668 mouse = (mouse_info_t*)data;
670 random_harvest_queue(mouse, sizeof(mouse_info_t), 2, RANDOM_MOUSE);
672 if (cmd == OLD_CONS_MOUSECTL) {
673 static u_char swapb[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
674 old_mouse_info_t *old_mouse = (old_mouse_info_t *)data;
677 mouse->operation = old_mouse->operation;
678 switch (mouse->operation) {
680 mouse->u.mode = old_mouse->u.mode;
688 mouse->u.data.x = old_mouse->u.data.x;
689 mouse->u.data.y = old_mouse->u.data.y;
691 mouse->u.data.buttons = swapb[old_mouse->u.data.buttons & 0x7];
694 old_mouse->u.data.x = scp->mouse_xpos;
695 old_mouse->u.data.y = scp->mouse_ypos;
696 old_mouse->u.data.buttons = swapb[scp->mouse_buttons & 0x7];
703 cur_scp = scp->sc->cur_scp;
705 switch (mouse->operation) {
707 if (ISSIGVALID(mouse->u.mode.signal)) {
708 scp->mouse_signal = mouse->u.mode.signal;
709 scp->mouse_proc = td->td_proc;
710 scp->mouse_pid = td->td_proc->p_pid;
713 scp->mouse_signal = 0;
714 scp->mouse_proc = NULL;
721 if (!(scp->sc->flags & SC_MOUSE_ENABLED)) {
722 scp->sc->flags |= SC_MOUSE_ENABLED;
723 cur_scp->status &= ~MOUSE_HIDDEN;
724 if (!ISGRAPHSC(cur_scp))
733 if (scp->sc->flags & SC_MOUSE_ENABLED) {
734 scp->sc->flags &= ~SC_MOUSE_ENABLED;
735 sc_remove_all_mouse(scp->sc);
743 scp->mouse_xpos = mouse->u.data.x;
744 scp->mouse_ypos = mouse->u.data.y;
751 scp->mouse_xpos += mouse->u.data.x;
752 scp->mouse_ypos += mouse->u.data.y;
758 mouse->u.data.x = scp->mouse_xpos;
759 mouse->u.data.y = scp->mouse_ypos;
761 mouse->u.data.buttons = scp->mouse_buttons;
765 case MOUSE_MOTION_EVENT:
766 /* send out mouse event on /dev/sysmouse */
768 /* this should maybe only be settable from /dev/consolectl SOS */
769 if (SC_VTY(tp->t_dev) != SC_CONSOLECTL)
773 if (mouse->u.data.x != 0 || mouse->u.data.y != 0) {
774 cur_scp->mouse_xpos += mouse->u.data.x;
775 cur_scp->mouse_ypos += mouse->u.data.y;
776 set_mouse_pos(cur_scp);
779 if (mouse->operation == MOUSE_ACTION) {
780 f = cur_scp->mouse_buttons ^ mouse->u.data.buttons;
781 cur_scp->mouse_buttons = mouse->u.data.buttons;
785 if (sysmouse_event(mouse) == 0)
789 * If any buttons are down or the mouse has moved a lot,
790 * stop the screen saver.
792 if (((mouse->operation == MOUSE_ACTION) && mouse->u.data.buttons)
793 || (mouse->u.data.x*mouse->u.data.x
794 + mouse->u.data.y*mouse->u.data.y
795 >= SC_WAKEUP_DELTA*SC_WAKEUP_DELTA)) {
796 sc_touch_scrn_saver();
799 cur_scp->status &= ~MOUSE_HIDDEN;
801 if (cur_scp->mouse_level > 0) {
802 sc_mouse_input(scp, mouse);
806 if (cur_scp->mouse_signal && cur_scp->mouse_proc) {
807 /* has controlling process died? */
808 if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))) {
809 cur_scp->mouse_signal = 0;
810 cur_scp->mouse_proc = NULL;
811 cur_scp->mouse_pid = 0;
815 kern_psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
816 PROC_UNLOCK(cur_scp->mouse_proc);
821 #ifndef SC_NO_CUTPASTE
822 if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
825 if ((mouse->operation == MOUSE_ACTION) && f) {
826 /* process button presses */
827 if (cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN)
828 mouse_cut_start(cur_scp);
830 mouse_cut_end(cur_scp);
831 if (cur_scp->mouse_buttons & MOUSE_BUTTON2DOWN ||
832 cur_scp->mouse_buttons & MOUSE_BUTTON3DOWN)
833 sc_mouse_paste(cur_scp);
835 #endif /* SC_NO_CUTPASTE */
838 case MOUSE_BUTTON_EVENT:
839 if ((mouse->u.event.id & MOUSE_BUTTONS) == 0)
841 if (mouse->u.event.value < 0)
844 /* this should maybe only be settable from /dev/consolectl SOS */
845 if (SC_VTY(tp->t_dev) != SC_CONSOLECTL)
848 if (mouse->u.event.value > 0)
849 cur_scp->mouse_buttons |= mouse->u.event.id;
851 cur_scp->mouse_buttons &= ~mouse->u.event.id;
853 if (sysmouse_event(mouse) == 0)
856 /* if a button is held down, stop the screen saver */
857 if (mouse->u.event.value > 0)
858 sc_touch_scrn_saver();
860 cur_scp->status &= ~MOUSE_HIDDEN;
862 if (cur_scp->mouse_level > 0) {
863 sc_mouse_input(scp, mouse);
867 if (cur_scp->mouse_signal && cur_scp->mouse_proc) {
868 if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))){
869 cur_scp->mouse_signal = 0;
870 cur_scp->mouse_proc = NULL;
871 cur_scp->mouse_pid = 0;
875 kern_psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
876 PROC_UNLOCK(cur_scp->mouse_proc);
881 #ifndef SC_NO_CUTPASTE
882 if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
885 switch (mouse->u.event.id) {
886 case MOUSE_BUTTON1DOWN:
887 switch (mouse->u.event.value % 4) {
889 mouse_cut_end(cur_scp);
891 case 1: /* single click: start cut operation */
892 mouse_cut_start(cur_scp);
894 case 2: /* double click: cut a word */
895 mouse_cut_word(cur_scp);
896 mouse_cut_end(cur_scp);
898 case 3: /* triple click: cut a line */
899 mouse_cut_line(cur_scp);
900 mouse_cut_end(cur_scp);
904 case SC_MOUSE_PASTEBUTTON:
905 switch (mouse->u.event.value) {
909 sc_mouse_paste(cur_scp);
913 case SC_MOUSE_EXTENDBUTTON:
914 switch (mouse->u.event.value) {
916 if (!(cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN))
917 mouse_cut_end(cur_scp);
920 mouse_cut_extend(cur_scp);
925 #endif /* SC_NO_CUTPASTE */
928 case MOUSE_MOUSECHAR:
929 if (mouse->u.mouse_char < 0) {
930 mouse->u.mouse_char = scp->sc->mouse_char;
932 if (mouse->u.mouse_char > UCHAR_MAX - 3)
935 sc_remove_all_mouse(scp->sc);
936 #ifndef SC_NO_FONT_LOADING
937 if (ISTEXTSC(cur_scp) && (cur_scp->font != NULL))
938 sc_load_font(cur_scp, 0, cur_scp->font_size,
940 cur_scp->font + cur_scp->font_size
941 * cur_scp->sc->mouse_char,
942 cur_scp->sc->mouse_char, 4);
944 scp->sc->mouse_char = mouse->u.mouse_char;
959 #endif /* SC_NO_SYSMOUSE */