555 Component target = getEventSource(); 556 ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); 557 558 if (!compAccessor.getIgnoreRepaint(target) 559 && compAccessor.getWidth(target) != 0 560 && compAccessor.getHeight(target) != 0) 561 { 562 postPaintEvent(target, x, y, w, h); 563 } 564 } 565 566 public void postPaintEvent(Component target, int x, int y, int w, int h) { 567 PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher(). 568 createPaintEvent(target, x, y, w, h); 569 if (event != null) { 570 postEventToEventQueue(event); 571 } 572 } 573 574 static int getModifiers(int state, int button, int keyCode) { 575 return getModifiers(state, button, keyCode, 0, false); 576 } 577 578 static int getModifiers(int state, int button, int keyCode, int type, boolean wheel_mouse) { 579 int modifiers = 0; 580 581 if (((state & XConstants.ShiftMask) != 0) ^ (keyCode == KeyEvent.VK_SHIFT)) { 582 modifiers |= InputEvent.SHIFT_DOWN_MASK; 583 } 584 if (((state & XConstants.ControlMask) != 0) ^ (keyCode == KeyEvent.VK_CONTROL)) { 585 modifiers |= InputEvent.CTRL_DOWN_MASK; 586 } 587 if (((state & XToolkit.metaMask) != 0) ^ (keyCode == KeyEvent.VK_META)) { 588 modifiers |= InputEvent.META_DOWN_MASK; 589 } 590 if (((state & XToolkit.altMask) != 0) ^ (keyCode == KeyEvent.VK_ALT)) { 591 modifiers |= InputEvent.ALT_DOWN_MASK; 592 } 593 if (((state & XToolkit.modeSwitchMask) != 0) ^ (keyCode == KeyEvent.VK_ALT_GRAPH)) { 594 modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK; 595 } 596 //InputEvent.BUTTON_DOWN_MASK array is starting from BUTTON1_DOWN_MASK on index == 0. 597 // button currently reflects a real button number and starts from 1. (except NOBUTTON which is zero ) 598 599 /* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/ 600 601 //reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc. 602 for (int i = 0; i < XConstants.buttons.length; i ++){ 603 //modifier should be added if : 604 // 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or 605 // 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons. 606 // ONLY one of these conditions should be TRUE to add that modifier. 607 if (((state & XlibUtil.getButtonMask(i + 1)) != 0) != (button == XConstants.buttons[i])){ 608 //exclude wheel buttons from adding their numbers as modifiers 609 if (!wheel_mouse) { 610 modifiers |= InputEvent.getMaskForButton(i+1); 611 } 612 } 613 } 614 return modifiers; 615 } 616 617 static int getXModifiers(AWTKeyStroke stroke) { 618 int mods = stroke.getModifiers(); 619 int res = 0; 620 if ((mods & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) { 621 res |= XConstants.ShiftMask; 622 } 623 if ((mods & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) { 624 res |= XConstants.ControlMask; 625 } 626 if ((mods & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) { 627 res |= XToolkit.altMask; 628 } 629 if ((mods & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) { 630 res |= XToolkit.metaMask; 631 } 632 if ((mods & (InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.ALT_GRAPH_MASK)) != 0) { 633 res |= XToolkit.modeSwitchMask; 634 } 635 return res; 636 } 637 638 static int getMouseMovementSmudge() { 639 //TODO: It's possible to read corresponding settings 640 return AWT_MULTICLICK_SMUDGE; 641 } 642 643 public void handleButtonPressRelease(XEvent xev) { 644 super.handleButtonPressRelease(xev); 645 XButtonEvent xbe = xev.get_xbutton(); 646 if (isEventDisabled(xev)) { 647 return; 648 } 649 if (eventLog.isLoggable(PlatformLogger.Level.FINE)) { 650 eventLog.fine(xbe.toString()); 651 } 652 long when; 653 int modifiers; 654 boolean popupTrigger = false; 655 int button=0; 656 boolean wheel_mouse = false; 657 int lbutton = xbe.get_button(); 658 /* 659 * Ignore the buttons above 20 due to the bit limit for 660 * InputEvent.BUTTON_DOWN_MASK. 661 * One more bit is reserved for FIRST_HIGH_BIT. 662 */ 663 if (lbutton > SunToolkit.MAX_BUTTONS_SUPPORTED) { 664 return; 665 } 666 int type = xev.get_type(); 667 when = xbe.get_time(); 668 long jWhen = XToolkit.nowMillisUTC_offset(when); 669 670 int x = xbe.get_x(); 671 int y = xbe.get_y(); 672 if (xev.get_xany().get_window() != window) { 673 Point localXY = toLocal(xbe.get_x_root(), xbe.get_y_root()); 674 x = localXY.x; 675 y = localXY.y; 676 } 689 } 690 if (lastWindow == this && lastButton == lbutton && (when - lastTime) < XToolkit.getMultiClickTime()) { 691 clickCount++; 692 } else { 693 clickCount = 1; 694 lastWindowRef = new WeakReference<>(this); 695 lastButton = lbutton; 696 lastX = x; 697 lastY = y; 698 } 699 lastTime = when; 700 701 702 /* 703 Check for popup trigger !! 704 */ 705 popupTrigger = (lbutton == 3); 706 } 707 708 button = XConstants.buttons[lbutton - 1]; 709 // 4 and 5 buttons are usually considered assigned to a first wheel 710 if (lbutton == XConstants.buttons[3] || 711 lbutton == XConstants.buttons[4]) { 712 wheel_mouse = true; 713 } 714 715 // mapping extra buttons to numbers starting from 4. 716 if ((button > XConstants.buttons[4]) && (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled())){ 717 return; 718 } 719 720 if (button > XConstants.buttons[4]){ 721 button -= 2; 722 } 723 modifiers = getModifiers(xbe.get_state(),button,0, type, wheel_mouse); 724 725 if (!wheel_mouse) { 726 MouseEvent me = new MouseEvent(getEventSource(), 727 type == XConstants.ButtonPress ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED, 728 jWhen,modifiers, x, y, 729 xbe.get_x_root(), 730 xbe.get_y_root(), 731 clickCount,popupTrigger,button); 732 733 postEventToEventQueue(me); 734 735 if ((type == XConstants.ButtonRelease) && 736 ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state 737 { 738 postEventToEventQueue(me = new MouseEvent(getEventSource(), 739 MouseEvent.MOUSE_CLICKED, 740 jWhen, 741 modifiers, 742 x, y, 743 xbe.get_x_root(), 744 xbe.get_y_root(), 745 clickCount, | 555 Component target = getEventSource(); 556 ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); 557 558 if (!compAccessor.getIgnoreRepaint(target) 559 && compAccessor.getWidth(target) != 0 560 && compAccessor.getHeight(target) != 0) 561 { 562 postPaintEvent(target, x, y, w, h); 563 } 564 } 565 566 public void postPaintEvent(Component target, int x, int y, int w, int h) { 567 PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher(). 568 createPaintEvent(target, x, y, w, h); 569 if (event != null) { 570 postEventToEventQueue(event); 571 } 572 } 573 574 static int getModifiers(int state, int button, int keyCode) { 575 int modifiers = 0; 576 577 if (((state & XConstants.ShiftMask) != 0) ^ (keyCode == KeyEvent.VK_SHIFT)) { 578 modifiers |= InputEvent.SHIFT_DOWN_MASK; 579 } 580 if (((state & XConstants.ControlMask) != 0) ^ (keyCode == KeyEvent.VK_CONTROL)) { 581 modifiers |= InputEvent.CTRL_DOWN_MASK; 582 } 583 if (((state & XToolkit.metaMask) != 0) ^ (keyCode == KeyEvent.VK_META)) { 584 modifiers |= InputEvent.META_DOWN_MASK; 585 } 586 if (((state & XToolkit.altMask) != 0) ^ (keyCode == KeyEvent.VK_ALT)) { 587 modifiers |= InputEvent.ALT_DOWN_MASK; 588 } 589 if (((state & XToolkit.modeSwitchMask) != 0) ^ (keyCode == KeyEvent.VK_ALT_GRAPH)) { 590 modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK; 591 } 592 //InputEvent.BUTTON_DOWN_MASK array is starting from BUTTON1_DOWN_MASK on index == 0. 593 // button currently reflects a real button number and starts from 1. (except NOBUTTON which is zero ) 594 595 /* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/ 596 597 //reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc. 598 for (int i = 0; i < XConstants.buttons.length; i ++){ 599 //modifier should be added if : 600 // 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or 601 // 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons. 602 // ONLY one of these conditions should be TRUE to add that modifier. 603 if (((state & XlibUtil.getButtonMask(i + 1)) != 0) != (button == XConstants.buttons[i])){ 604 //exclude wheel buttons from adding their numbers as modifiers 605 if (!isWheel(XConstants.buttons[i])) { 606 modifiers |= InputEvent.getMaskForButton(i+1); 607 } 608 } 609 } 610 return modifiers; 611 } 612 613 static boolean isWheel(int button) { 614 // 4 and 5 buttons are usually considered assigned to a first wheel 615 return button == XConstants.buttons[3] || button == XConstants.buttons[4]; 616 } 617 618 static int getXModifiers(AWTKeyStroke stroke) { 619 int mods = stroke.getModifiers(); 620 int res = 0; 621 if ((mods & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) { 622 res |= XConstants.ShiftMask; 623 } 624 if ((mods & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) { 625 res |= XConstants.ControlMask; 626 } 627 if ((mods & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) { 628 res |= XToolkit.altMask; 629 } 630 if ((mods & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) { 631 res |= XToolkit.metaMask; 632 } 633 if ((mods & (InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.ALT_GRAPH_MASK)) != 0) { 634 res |= XToolkit.modeSwitchMask; 635 } 636 return res; 637 } 638 639 static int getMouseMovementSmudge() { 640 //TODO: It's possible to read corresponding settings 641 return AWT_MULTICLICK_SMUDGE; 642 } 643 644 public void handleButtonPressRelease(XEvent xev) { 645 super.handleButtonPressRelease(xev); 646 XButtonEvent xbe = xev.get_xbutton(); 647 if (isEventDisabled(xev)) { 648 return; 649 } 650 if (eventLog.isLoggable(PlatformLogger.Level.FINE)) { 651 eventLog.fine(xbe.toString()); 652 } 653 long when; 654 int modifiers; 655 boolean popupTrigger = false; 656 int button=0; 657 int lbutton = xbe.get_button(); 658 /* 659 * Ignore the buttons above 20 due to the bit limit for 660 * InputEvent.BUTTON_DOWN_MASK. 661 * One more bit is reserved for FIRST_HIGH_BIT. 662 */ 663 if (lbutton > SunToolkit.MAX_BUTTONS_SUPPORTED) { 664 return; 665 } 666 int type = xev.get_type(); 667 when = xbe.get_time(); 668 long jWhen = XToolkit.nowMillisUTC_offset(when); 669 670 int x = xbe.get_x(); 671 int y = xbe.get_y(); 672 if (xev.get_xany().get_window() != window) { 673 Point localXY = toLocal(xbe.get_x_root(), xbe.get_y_root()); 674 x = localXY.x; 675 y = localXY.y; 676 } 689 } 690 if (lastWindow == this && lastButton == lbutton && (when - lastTime) < XToolkit.getMultiClickTime()) { 691 clickCount++; 692 } else { 693 clickCount = 1; 694 lastWindowRef = new WeakReference<>(this); 695 lastButton = lbutton; 696 lastX = x; 697 lastY = y; 698 } 699 lastTime = when; 700 701 702 /* 703 Check for popup trigger !! 704 */ 705 popupTrigger = (lbutton == 3); 706 } 707 708 button = XConstants.buttons[lbutton - 1]; 709 710 // mapping extra buttons to numbers starting from 4. 711 if ((button > XConstants.buttons[4]) && (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled())){ 712 return; 713 } 714 715 if (button > XConstants.buttons[4]){ 716 button -= 2; 717 } 718 modifiers = getModifiers(xbe.get_state(),button,0); 719 720 if (!isWheel(lbutton)) { 721 MouseEvent me = new MouseEvent(getEventSource(), 722 type == XConstants.ButtonPress ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED, 723 jWhen,modifiers, x, y, 724 xbe.get_x_root(), 725 xbe.get_y_root(), 726 clickCount,popupTrigger,button); 727 728 postEventToEventQueue(me); 729 730 if ((type == XConstants.ButtonRelease) && 731 ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state 732 { 733 postEventToEventQueue(me = new MouseEvent(getEventSource(), 734 MouseEvent.MOUSE_CLICKED, 735 jWhen, 736 modifiers, 737 x, y, 738 xbe.get_x_root(), 739 xbe.get_y_root(), 740 clickCount, |