1 /*- 2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 14 * 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. 25 * 26 * $FreeBSD: src/sys/dev/syscons/scmouse.c,v 1.12.2.3 2001/07/28 12:51:47 yokota Exp $ 27 * $DragonFly: src/sys/dev/misc/syscons/scmouse.c,v 1.10 2005/06/11 00:29:10 dillon Exp $ 28 */ 29 30 #include "opt_syscons.h" 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/conf.h> 35 #include <sys/signalvar.h> 36 #include <sys/proc.h> 37 #include <sys/tty.h> 38 #include <sys/thread2.h> 39 40 #include <machine/console.h> 41 #include <machine/mouse.h> 42 43 #include "syscons.h" 44 45 #ifdef SC_TWOBUTTON_MOUSE 46 #define SC_MOUSE_PASTEBUTTON MOUSE_BUTTON3DOWN /* right button */ 47 #define SC_MOUSE_EXTENDBUTTON MOUSE_BUTTON2DOWN /* not really used */ 48 #else 49 #define SC_MOUSE_PASTEBUTTON MOUSE_BUTTON2DOWN /* middle button */ 50 #define SC_MOUSE_EXTENDBUTTON MOUSE_BUTTON3DOWN /* right button */ 51 #endif /* SC_TWOBUTTON_MOUSE */ 52 53 #define SC_WAKEUP_DELTA 20 54 55 #ifndef SC_NO_SYSMOUSE 56 57 /* local variables */ 58 static int cut_buffer_size; 59 static u_char *cut_buffer; 60 61 /* local functions */ 62 static void set_mouse_pos(scr_stat *scp); 63 #ifndef SC_NO_CUTPASTE 64 static int skip_spc_right(scr_stat *scp, int p); 65 static int skip_spc_left(scr_stat *scp, int p); 66 static void mouse_cut(scr_stat *scp); 67 static void mouse_cut_start(scr_stat *scp); 68 static void mouse_cut_end(scr_stat *scp); 69 static void mouse_cut_word(scr_stat *scp); 70 static void mouse_cut_line(scr_stat *scp); 71 static void mouse_cut_extend(scr_stat *scp); 72 static void mouse_paste(scr_stat *scp); 73 #endif /* SC_NO_CUTPASTE */ 74 75 #ifndef SC_NO_CUTPASTE 76 /* allocate a cut buffer */ 77 void 78 sc_alloc_cut_buffer(scr_stat *scp, int wait) 79 { 80 u_char *p; 81 82 if ((cut_buffer == NULL) 83 || (cut_buffer_size < scp->xsize * scp->ysize + 1)) { 84 p = cut_buffer; 85 cut_buffer = NULL; 86 if (p != NULL) 87 free(p, M_SYSCONS); 88 cut_buffer_size = scp->xsize * scp->ysize + 1; 89 p = malloc(cut_buffer_size, M_SYSCONS, (wait) ? M_WAITOK : M_NOWAIT); 90 if (p != NULL) 91 p[0] = '\0'; 92 cut_buffer = p; 93 } 94 } 95 #endif /* SC_NO_CUTPASTE */ 96 97 /* move mouse */ 98 void 99 sc_mouse_move(scr_stat *scp, int x, int y) 100 { 101 crit_enter(); 102 scp->mouse_xpos = scp->mouse_oldxpos = x; 103 scp->mouse_ypos = scp->mouse_oldypos = y; 104 if (scp->font_size <= 0) 105 scp->mouse_pos = scp->mouse_oldpos = 0; 106 else 107 scp->mouse_pos = scp->mouse_oldpos = 108 (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff; 109 scp->status |= MOUSE_MOVED; 110 crit_exit(); 111 } 112 113 /* adjust mouse position */ 114 static void 115 set_mouse_pos(scr_stat *scp) 116 { 117 if (scp->mouse_xpos < scp->xoff*8) 118 scp->mouse_xpos = scp->xoff*8; 119 if (scp->mouse_ypos < scp->yoff*scp->font_size) 120 scp->mouse_ypos = scp->yoff*scp->font_size; 121 if (ISGRAPHSC(scp)) { 122 if (scp->mouse_xpos > scp->xpixel-1) 123 scp->mouse_xpos = scp->xpixel-1; 124 if (scp->mouse_ypos > scp->ypixel-1) 125 scp->mouse_ypos = scp->ypixel-1; 126 return; 127 } else { 128 if (scp->mouse_xpos > (scp->xsize + scp->xoff)*8 - 1) 129 scp->mouse_xpos = (scp->xsize + scp->xoff)*8 - 1; 130 if (scp->mouse_ypos > (scp->ysize + scp->yoff)*scp->font_size - 1) 131 scp->mouse_ypos = (scp->ysize + scp->yoff)*scp->font_size - 1; 132 } 133 134 if (scp->mouse_xpos != scp->mouse_oldxpos || scp->mouse_ypos != scp->mouse_oldypos) { 135 scp->status |= MOUSE_MOVED; 136 scp->mouse_pos = 137 (scp->mouse_ypos/scp->font_size - scp->yoff)*scp->xsize 138 + scp->mouse_xpos/8 - scp->xoff; 139 #ifndef SC_NO_CUTPASTE 140 if ((scp->status & MOUSE_VISIBLE) && (scp->status & MOUSE_CUTTING)) 141 mouse_cut(scp); 142 #endif 143 } 144 } 145 146 #ifndef SC_NO_CUTPASTE 147 148 void 149 sc_draw_mouse_image(scr_stat *scp) 150 { 151 if (ISGRAPHSC(scp)) 152 return; 153 154 ++scp->sc->videoio_in_progress; 155 (*scp->rndr->draw_mouse)(scp, scp->mouse_xpos, scp->mouse_ypos, TRUE); 156 scp->mouse_oldpos = scp->mouse_pos; 157 scp->mouse_oldxpos = scp->mouse_xpos; 158 scp->mouse_oldypos = scp->mouse_ypos; 159 scp->status |= MOUSE_VISIBLE; 160 --scp->sc->videoio_in_progress; 161 } 162 163 void 164 sc_remove_mouse_image(scr_stat *scp) 165 { 166 int size; 167 int i; 168 169 if (ISGRAPHSC(scp)) 170 return; 171 172 ++scp->sc->videoio_in_progress; 173 (*scp->rndr->draw_mouse)(scp, 174 (scp->mouse_oldpos%scp->xsize + scp->xoff)*8, 175 (scp->mouse_oldpos/scp->xsize + scp->yoff) 176 * scp->font_size, 177 FALSE); 178 size = scp->xsize*scp->ysize; 179 i = scp->mouse_oldpos; 180 mark_for_update(scp, i); 181 mark_for_update(scp, i); 182 if (i + scp->xsize + 1 < size) { 183 mark_for_update(scp, i + scp->xsize + 1); 184 } else if (i + scp->xsize < size) { 185 mark_for_update(scp, i + scp->xsize); 186 } else if (i + 1 < size) { 187 mark_for_update(scp, i + 1); 188 } 189 scp->status &= ~MOUSE_VISIBLE; 190 --scp->sc->videoio_in_progress; 191 } 192 193 int 194 sc_inside_cutmark(scr_stat *scp, int pos) 195 { 196 int start; 197 int end; 198 199 if (scp->mouse_cut_end < 0) 200 return FALSE; 201 if (scp->mouse_cut_start <= scp->mouse_cut_end) { 202 start = scp->mouse_cut_start; 203 end = scp->mouse_cut_end; 204 } else { 205 start = scp->mouse_cut_end; 206 end = scp->mouse_cut_start - 1; 207 } 208 return ((start <= pos) && (pos <= end)); 209 } 210 211 void 212 sc_remove_cutmarking(scr_stat *scp) 213 { 214 crit_enter(); 215 if (scp->mouse_cut_end >= 0) { 216 mark_for_update(scp, scp->mouse_cut_start); 217 mark_for_update(scp, scp->mouse_cut_end); 218 } 219 scp->mouse_cut_start = scp->xsize*scp->ysize; 220 scp->mouse_cut_end = -1; 221 crit_exit(); 222 scp->status &= ~MOUSE_CUTTING; 223 } 224 225 void 226 sc_remove_all_cutmarkings(sc_softc_t *sc) 227 { 228 scr_stat *scp; 229 int i; 230 231 /* delete cut markings in all vtys */ 232 for (i = 0; i < sc->vtys; ++i) { 233 scp = SC_STAT(sc->dev[i]); 234 if (scp == NULL) 235 continue; 236 sc_remove_cutmarking(scp); 237 } 238 } 239 240 void 241 sc_remove_all_mouse(sc_softc_t *sc) 242 { 243 scr_stat *scp; 244 int i; 245 246 for (i = 0; i < sc->vtys; ++i) { 247 scp = SC_STAT(sc->dev[i]); 248 if (scp == NULL) 249 continue; 250 if (scp->status & MOUSE_VISIBLE) { 251 scp->status &= ~MOUSE_VISIBLE; 252 mark_all(scp); 253 } 254 } 255 } 256 257 #define IS_SPACE_CHAR(c) (((c) & 0xff) == ' ') 258 259 /* skip spaces to right */ 260 static int 261 skip_spc_right(scr_stat *scp, int p) 262 { 263 int c; 264 int i; 265 266 for (i = p % scp->xsize; i < scp->xsize; ++i) { 267 c = sc_vtb_getc(&scp->vtb, p); 268 if (!IS_SPACE_CHAR(c)) 269 break; 270 ++p; 271 } 272 return i; 273 } 274 275 /* skip spaces to left */ 276 static int 277 skip_spc_left(scr_stat *scp, int p) 278 { 279 int c; 280 int i; 281 282 for (i = p-- % scp->xsize - 1; i >= 0; --i) { 283 c = sc_vtb_getc(&scp->vtb, p); 284 if (!IS_SPACE_CHAR(c)) 285 break; 286 --p; 287 } 288 return i; 289 } 290 291 /* copy marked region to the cut buffer */ 292 static void 293 mouse_cut(scr_stat *scp) 294 { 295 int start; 296 int end; 297 int from; 298 int to; 299 int blank; 300 int c; 301 int p; 302 int i; 303 304 start = scp->mouse_cut_start; 305 end = scp->mouse_cut_end; 306 if (scp->mouse_pos >= start) { 307 from = start; 308 to = end = scp->mouse_pos; 309 } else { 310 from = end = scp->mouse_pos; 311 to = start - 1; 312 } 313 for (p = from, i = blank = 0; p <= to; ++p) { 314 cut_buffer[i] = sc_vtb_getc(&scp->vtb, p); 315 /* remember the position of the last non-space char */ 316 if (!IS_SPACE_CHAR(cut_buffer[i++])) 317 blank = i; /* the first space after the last non-space */ 318 /* trim trailing blank when crossing lines */ 319 if ((p % scp->xsize) == (scp->xsize - 1)) { 320 cut_buffer[blank] = '\r'; 321 i = blank + 1; 322 } 323 } 324 cut_buffer[i] = '\0'; 325 326 /* scan towards the end of the last line */ 327 --p; 328 for (i = p % scp->xsize; i < scp->xsize; ++i) { 329 c = sc_vtb_getc(&scp->vtb, p); 330 if (!IS_SPACE_CHAR(c)) 331 break; 332 ++p; 333 } 334 /* if there is nothing but blank chars, trim them, but mark towards eol */ 335 if (i >= scp->xsize) { 336 if (end >= start) 337 to = end = p - 1; 338 else 339 to = start = p; 340 cut_buffer[blank++] = '\r'; 341 cut_buffer[blank] = '\0'; 342 } 343 344 /* remove the current marking */ 345 crit_enter(); 346 if (scp->mouse_cut_start <= scp->mouse_cut_end) { 347 mark_for_update(scp, scp->mouse_cut_start); 348 mark_for_update(scp, scp->mouse_cut_end); 349 } else if (scp->mouse_cut_end >= 0) { 350 mark_for_update(scp, scp->mouse_cut_end); 351 mark_for_update(scp, scp->mouse_cut_start); 352 } 353 354 /* mark the new region */ 355 scp->mouse_cut_start = start; 356 scp->mouse_cut_end = end; 357 mark_for_update(scp, from); 358 mark_for_update(scp, to); 359 crit_exit(); 360 } 361 362 /* a mouse button is pressed, start cut operation */ 363 static void 364 mouse_cut_start(scr_stat *scp) 365 { 366 int i; 367 int j; 368 369 if (scp->status & MOUSE_VISIBLE) { 370 i = scp->mouse_cut_start; 371 j = scp->mouse_cut_end; 372 sc_remove_all_cutmarkings(scp->sc); 373 if (scp->mouse_pos == i && i == j) { 374 cut_buffer[0] = '\0'; 375 } else if (skip_spc_right(scp, scp->mouse_pos) >= scp->xsize) { 376 /* if the pointer is on trailing blank chars, mark towards eol */ 377 i = skip_spc_left(scp, scp->mouse_pos) + 1; 378 crit_enter(); 379 scp->mouse_cut_start = 380 (scp->mouse_pos / scp->xsize) * scp->xsize + i; 381 scp->mouse_cut_end = 382 (scp->mouse_pos / scp->xsize + 1) * scp->xsize - 1; 383 crit_exit(); 384 cut_buffer[0] = '\r'; 385 cut_buffer[1] = '\0'; 386 scp->status |= MOUSE_CUTTING; 387 } else { 388 crit_enter(); 389 scp->mouse_cut_start = scp->mouse_pos; 390 scp->mouse_cut_end = scp->mouse_cut_start; 391 crit_exit(); 392 cut_buffer[0] = sc_vtb_getc(&scp->vtb, scp->mouse_cut_start); 393 cut_buffer[1] = '\0'; 394 scp->status |= MOUSE_CUTTING; 395 } 396 mark_all(scp); /* this is probably overkill XXX */ 397 } 398 } 399 400 /* end of cut operation */ 401 static void 402 mouse_cut_end(scr_stat *scp) 403 { 404 if (scp->status & MOUSE_VISIBLE) 405 scp->status &= ~MOUSE_CUTTING; 406 } 407 408 /* copy a word under the mouse pointer */ 409 static void 410 mouse_cut_word(scr_stat *scp) 411 { 412 int start; 413 int end; 414 int sol; 415 int eol; 416 int c; 417 int i; 418 int j; 419 420 /* 421 * Because we don't have locale information in the kernel, 422 * we only distinguish space char and non-space chars. Punctuation 423 * chars, symbols and other regular chars are all treated alike. 424 */ 425 if (scp->status & MOUSE_VISIBLE) { 426 /* remove the current cut mark */ 427 crit_enter(); 428 if (scp->mouse_cut_start <= scp->mouse_cut_end) { 429 mark_for_update(scp, scp->mouse_cut_start); 430 mark_for_update(scp, scp->mouse_cut_end); 431 } else if (scp->mouse_cut_end >= 0) { 432 mark_for_update(scp, scp->mouse_cut_end); 433 mark_for_update(scp, scp->mouse_cut_start); 434 } 435 scp->mouse_cut_start = scp->xsize*scp->ysize; 436 scp->mouse_cut_end = -1; 437 crit_exit(); 438 439 sol = (scp->mouse_pos / scp->xsize) * scp->xsize; 440 eol = sol + scp->xsize; 441 c = sc_vtb_getc(&scp->vtb, scp->mouse_pos); 442 if (IS_SPACE_CHAR(c)) { 443 /* blank space */ 444 for (j = scp->mouse_pos; j >= sol; --j) { 445 c = sc_vtb_getc(&scp->vtb, j); 446 if (!IS_SPACE_CHAR(c)) 447 break; 448 } 449 start = ++j; 450 for (j = scp->mouse_pos; j < eol; ++j) { 451 c = sc_vtb_getc(&scp->vtb, j); 452 if (!IS_SPACE_CHAR(c)) 453 break; 454 } 455 end = j - 1; 456 } else { 457 /* non-space word */ 458 for (j = scp->mouse_pos; j >= sol; --j) { 459 c = sc_vtb_getc(&scp->vtb, j); 460 if (IS_SPACE_CHAR(c)) 461 break; 462 } 463 start = ++j; 464 for (j = scp->mouse_pos; j < eol; ++j) { 465 c = sc_vtb_getc(&scp->vtb, j); 466 if (IS_SPACE_CHAR(c)) 467 break; 468 } 469 end = j - 1; 470 } 471 472 /* copy the found word */ 473 for (i = 0, j = start; j <= end; ++j) 474 cut_buffer[i++] = sc_vtb_getc(&scp->vtb, j); 475 cut_buffer[i] = '\0'; 476 scp->status |= MOUSE_CUTTING; 477 478 /* mark the region */ 479 crit_enter(); 480 scp->mouse_cut_start = start; 481 scp->mouse_cut_end = end; 482 mark_for_update(scp, start); 483 mark_for_update(scp, end); 484 crit_exit(); 485 } 486 } 487 488 /* copy a line under the mouse pointer */ 489 static void 490 mouse_cut_line(scr_stat *scp) 491 { 492 int i; 493 int j; 494 495 if (scp->status & MOUSE_VISIBLE) { 496 /* remove the current cut mark */ 497 crit_enter(); 498 if (scp->mouse_cut_start <= scp->mouse_cut_end) { 499 mark_for_update(scp, scp->mouse_cut_start); 500 mark_for_update(scp, scp->mouse_cut_end); 501 } else if (scp->mouse_cut_end >= 0) { 502 mark_for_update(scp, scp->mouse_cut_end); 503 mark_for_update(scp, scp->mouse_cut_start); 504 } 505 506 /* mark the entire line */ 507 scp->mouse_cut_start = 508 (scp->mouse_pos / scp->xsize) * scp->xsize; 509 scp->mouse_cut_end = scp->mouse_cut_start + scp->xsize - 1; 510 mark_for_update(scp, scp->mouse_cut_start); 511 mark_for_update(scp, scp->mouse_cut_end); 512 crit_exit(); 513 514 /* copy the line into the cut buffer */ 515 for (i = 0, j = scp->mouse_cut_start; j <= scp->mouse_cut_end; ++j) 516 cut_buffer[i++] = sc_vtb_getc(&scp->vtb, j); 517 cut_buffer[i++] = '\r'; 518 cut_buffer[i] = '\0'; 519 scp->status |= MOUSE_CUTTING; 520 } 521 } 522 523 /* extend the marked region to the mouse pointer position */ 524 static void 525 mouse_cut_extend(scr_stat *scp) 526 { 527 int start; 528 int end; 529 530 if ((scp->status & MOUSE_VISIBLE) && !(scp->status & MOUSE_CUTTING) 531 && (scp->mouse_cut_end >= 0)) { 532 if (scp->mouse_cut_start <= scp->mouse_cut_end) { 533 start = scp->mouse_cut_start; 534 end = scp->mouse_cut_end; 535 } else { 536 start = scp->mouse_cut_end; 537 end = scp->mouse_cut_start - 1; 538 } 539 crit_enter(); 540 if (scp->mouse_pos > end) { 541 scp->mouse_cut_start = start; 542 scp->mouse_cut_end = end; 543 } else if (scp->mouse_pos < start) { 544 scp->mouse_cut_start = end + 1; 545 scp->mouse_cut_end = start; 546 } else { 547 if (scp->mouse_pos - start > end + 1 - scp->mouse_pos) { 548 scp->mouse_cut_start = start; 549 scp->mouse_cut_end = end; 550 } else { 551 scp->mouse_cut_start = end + 1; 552 scp->mouse_cut_end = start; 553 } 554 } 555 crit_exit(); 556 mouse_cut(scp); 557 scp->status |= MOUSE_CUTTING; 558 } 559 } 560 561 /* paste cut buffer contents into the current vty */ 562 static void 563 mouse_paste(scr_stat *scp) 564 { 565 if (scp->status & MOUSE_VISIBLE) 566 sc_paste(scp, cut_buffer, strlen(cut_buffer)); 567 } 568 569 #endif /* SC_NO_CUTPASTE */ 570 571 int 572 sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, 573 struct thread *td) 574 { 575 mouse_info_t *mouse; 576 scr_stat *cur_scp; 577 scr_stat *scp; 578 int f; 579 580 scp = SC_STAT(tp->t_dev); 581 582 switch (cmd) { 583 584 case CONS_MOUSECTL: /* control mouse arrow */ 585 mouse = (mouse_info_t*)data; 586 cur_scp = scp->sc->cur_scp; 587 588 switch (mouse->operation) { 589 case MOUSE_MODE: 590 if (ISSIGVALID(mouse->u.mode.signal)) { 591 scp->mouse_signal = mouse->u.mode.signal; 592 scp->mouse_proc = td->td_proc; 593 scp->mouse_pid = td->td_proc->p_pid; 594 } 595 else { 596 scp->mouse_signal = 0; 597 scp->mouse_proc = NULL; 598 scp->mouse_pid = 0; 599 } 600 return 0; 601 602 case MOUSE_SHOW: 603 crit_enter(); 604 if (!(scp->sc->flags & SC_MOUSE_ENABLED)) { 605 scp->sc->flags |= SC_MOUSE_ENABLED; 606 cur_scp->status &= ~MOUSE_HIDDEN; 607 if (!ISGRAPHSC(cur_scp)) 608 mark_all(cur_scp); 609 crit_exit(); 610 return 0; 611 } else { 612 crit_exit(); 613 return EINVAL; 614 } 615 break; 616 617 case MOUSE_HIDE: 618 crit_enter(); 619 if (scp->sc->flags & SC_MOUSE_ENABLED) { 620 scp->sc->flags &= ~SC_MOUSE_ENABLED; 621 sc_remove_all_mouse(scp->sc); 622 crit_exit(); 623 return 0; 624 } else { 625 crit_exit(); 626 return EINVAL; 627 } 628 break; 629 630 case MOUSE_MOVEABS: 631 crit_enter(); 632 scp->mouse_xpos = mouse->u.data.x; 633 scp->mouse_ypos = mouse->u.data.y; 634 set_mouse_pos(scp); 635 crit_exit(); 636 break; 637 638 case MOUSE_MOVEREL: 639 crit_enter(); 640 scp->mouse_xpos += mouse->u.data.x; 641 scp->mouse_ypos += mouse->u.data.y; 642 set_mouse_pos(scp); 643 crit_exit(); 644 break; 645 646 case MOUSE_GETINFO: 647 mouse->u.data.x = scp->mouse_xpos; 648 mouse->u.data.y = scp->mouse_ypos; 649 mouse->u.data.z = 0; 650 mouse->u.data.buttons = scp->mouse_buttons; 651 return 0; 652 653 case MOUSE_ACTION: 654 case MOUSE_MOTION_EVENT: 655 /* send out mouse event on /dev/sysmouse */ 656 #if 0 657 /* this should maybe only be settable from /dev/consolectl SOS */ 658 if (SC_VTY(tp->t_dev) != SC_CONSOLECTL) 659 return ENOTTY; 660 #endif 661 crit_enter(); 662 if (mouse->u.data.x != 0 || mouse->u.data.y != 0) { 663 cur_scp->mouse_xpos += mouse->u.data.x; 664 cur_scp->mouse_ypos += mouse->u.data.y; 665 set_mouse_pos(cur_scp); 666 } 667 f = 0; 668 if (mouse->operation == MOUSE_ACTION) { 669 f = cur_scp->mouse_buttons ^ mouse->u.data.buttons; 670 cur_scp->mouse_buttons = mouse->u.data.buttons; 671 } 672 crit_exit(); 673 674 if (sysmouse_event(mouse) == 0) 675 return 0; 676 677 /* 678 * If any buttons are down or the mouse has moved a lot, 679 * stop the screen saver. 680 */ 681 if (((mouse->operation == MOUSE_ACTION) && mouse->u.data.buttons) 682 || (mouse->u.data.x*mouse->u.data.x 683 + mouse->u.data.y*mouse->u.data.y 684 >= SC_WAKEUP_DELTA*SC_WAKEUP_DELTA)) { 685 sc_touch_scrn_saver(); 686 } 687 688 cur_scp->status &= ~MOUSE_HIDDEN; 689 690 if (cur_scp->mouse_signal) { 691 /* has controlling process died? */ 692 if (cur_scp->mouse_proc && 693 (cur_scp->mouse_proc != pfind(cur_scp->mouse_pid))){ 694 cur_scp->mouse_signal = 0; 695 cur_scp->mouse_proc = NULL; 696 cur_scp->mouse_pid = 0; 697 } else { 698 psignal(cur_scp->mouse_proc, cur_scp->mouse_signal); 699 break; 700 } 701 } 702 703 if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL)) 704 break; 705 706 #ifndef SC_NO_CUTPASTE 707 if ((mouse->operation == MOUSE_ACTION) && f) { 708 /* process button presses */ 709 if (cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN) 710 mouse_cut_start(cur_scp); 711 else 712 mouse_cut_end(cur_scp); 713 if (cur_scp->mouse_buttons & MOUSE_BUTTON2DOWN || 714 cur_scp->mouse_buttons & MOUSE_BUTTON3DOWN) 715 mouse_paste(cur_scp); 716 } 717 #endif /* SC_NO_CUTPASTE */ 718 break; 719 720 case MOUSE_BUTTON_EVENT: 721 if ((mouse->u.event.id & MOUSE_BUTTONS) == 0) 722 return EINVAL; 723 if (mouse->u.event.value < 0) 724 return EINVAL; 725 #if 0 726 /* this should maybe only be settable from /dev/consolectl SOS */ 727 if (SC_VTY(tp->t_dev) != SC_CONSOLECTL) 728 return ENOTTY; 729 #endif 730 if (mouse->u.event.value > 0) 731 cur_scp->mouse_buttons |= mouse->u.event.id; 732 else 733 cur_scp->mouse_buttons &= ~mouse->u.event.id; 734 735 if (sysmouse_event(mouse) == 0) 736 return 0; 737 738 /* if a button is held down, stop the screen saver */ 739 if (mouse->u.event.value > 0) 740 sc_touch_scrn_saver(); 741 742 cur_scp->status &= ~MOUSE_HIDDEN; 743 744 if (cur_scp->mouse_signal) { 745 if (cur_scp->mouse_proc && 746 (cur_scp->mouse_proc != pfind(cur_scp->mouse_pid))){ 747 cur_scp->mouse_signal = 0; 748 cur_scp->mouse_proc = NULL; 749 cur_scp->mouse_pid = 0; 750 } else { 751 psignal(cur_scp->mouse_proc, cur_scp->mouse_signal); 752 break; 753 } 754 } 755 756 if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL)) 757 break; 758 759 #ifndef SC_NO_CUTPASTE 760 switch (mouse->u.event.id) { 761 case MOUSE_BUTTON1DOWN: 762 switch (mouse->u.event.value % 4) { 763 case 0: /* up */ 764 mouse_cut_end(cur_scp); 765 break; 766 case 1: /* single click: start cut operation */ 767 mouse_cut_start(cur_scp); 768 break; 769 case 2: /* double click: cut a word */ 770 mouse_cut_word(cur_scp); 771 mouse_cut_end(cur_scp); 772 break; 773 case 3: /* triple click: cut a line */ 774 mouse_cut_line(cur_scp); 775 mouse_cut_end(cur_scp); 776 break; 777 } 778 break; 779 case SC_MOUSE_PASTEBUTTON: 780 switch (mouse->u.event.value) { 781 case 0: /* up */ 782 break; 783 default: 784 mouse_paste(cur_scp); 785 break; 786 } 787 break; 788 case SC_MOUSE_EXTENDBUTTON: 789 switch (mouse->u.event.value) { 790 case 0: /* up */ 791 if (!(cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN)) 792 mouse_cut_end(cur_scp); 793 break; 794 default: 795 mouse_cut_extend(cur_scp); 796 break; 797 } 798 break; 799 } 800 #endif /* SC_NO_CUTPASTE */ 801 break; 802 803 case MOUSE_MOUSECHAR: 804 if (mouse->u.mouse_char < 0) { 805 mouse->u.mouse_char = scp->sc->mouse_char; 806 } else { 807 if (mouse->u.mouse_char >= (unsigned char)-1 - 4) 808 return EINVAL; 809 crit_enter(); 810 sc_remove_all_mouse(scp->sc); 811 #ifndef SC_NO_FONT_LOADING 812 if (ISTEXTSC(cur_scp) && (cur_scp->font != NULL)) 813 sc_load_font(cur_scp, 0, cur_scp->font_size, cur_scp->font, 814 cur_scp->sc->mouse_char, 4); 815 #endif 816 scp->sc->mouse_char = mouse->u.mouse_char; 817 crit_exit(); 818 } 819 break; 820 821 default: 822 return EINVAL; 823 } 824 825 return 0; 826 } 827 828 return ENOIOCTL; 829 } 830 831 #endif /* SC_NO_SYSMOUSE */ 832