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