openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.97k stars 2.55k forks source link

ofxPanel stops receiving mouse after switch from full screen to window mode (dual monitor setup) #6448

Open moebiussurfing opened 4 years ago

moebiussurfing commented 4 years ago

Hi @moebiussurfing I think this has to do with a change in the coordinate system rather than an mouse events problem. As for what you say, those 20 pixels on the y axis seem to be there to compensate the window's top bar. I am not sure if there is a specific window event for when it changes to/from fullscreen. Although I guess that the window size event will work. So, register to this event so when it triggers then you just flag for a re-render. I'll try out this and let you know.

Originally posted by @roymacdonald in https://github.com/openframeworks/openFrameworks/pull/6429#issuecomment-552587497

moebiussurfing commented 4 years ago

@roymacdonald that's a snippet of the code I am using. macOS (Xcode 10, AppCode, High Sierra) with main branch:


//ofApp

//--------------------------------------------------------------
void ofApp::keyPressed(int key)
{
    //switch window mode
    if (key == 'f')
    {
        if (ofGetWindowMode() == OF_WINDOW)//go full screen
        {
            ofSetFullscreen(true);
        }
        else if (ofGetWindowMode() == OF_FULLSCREEN)//go window mode
        {
            ofSetFullscreen(false);

            ////TODO: bug: 
            // gui stops receiving mouse fine (goes -20 y px)
            // when fullScreen to window mode switched

            // 1. this do not solves nothing:
            // it's only repaired when clicking the window bar to maximize window on top

            //ofSetWindowPosition(0, -20);
            //fontAnimator.windowResized(ofGetWindowWidth(), ofGetWindowHeight());
        }
    }
}

//---

//myClass: ofxFontAnimator

EDIT:
//--------------------------------------------------------------
ofxFontAnimator::ofxFontAnimator()
{
     addMouseListeners();
}

//--------------------------------------------------------------
void ofxFontAnimator::setup()
{
    ...
    //ofxGui theme
    ofxGuiSetFont("fonts/PragmataProR_0822.ttf", 8);
    ofxGuiSetDefaultHeight(18);
    ofxGuiSetFillColor(ofColor(48));
    ...
    gui.setup();
    ...
}

//--------------------------------------------------------------
void ofxFontAnimator::addMouseListeners()
{
    ofAddListener(ofEvents().mouseDragged, this, &ofxFontAnimator::mouseDragged);
    ofAddListener(ofEvents().mousePressed, this, &ofxFontAnimator::mousePressed);
    ofAddListener(ofEvents().mouseReleased, this, &ofxFontAnimator::mouseReleased);
}

//--------------------------------------------------------------
void ofxFontAnimator::removeMouseListeners()
{
    ofRemoveListener(ofEvents().mouseDragged, this, &ofxFontAnimator::mouseDragged);
    ofRemoveListener(ofEvents().mousePressed, this, &ofxFontAnimator::mousePressed);
    ofRemoveListener(ofEvents().mouseReleased, this, &ofxFontAnimator::mouseReleased);
}

//--------------------------------------------------------------
void ofxFontAnimator::mousePressed(ofMouseEventArgs &eventArgs)
{
    const int &x = eventArgs.x;
    const int &y = eventArgs.y;
    const int &button = eventArgs.button;

    //ofLogNotice("ofxFontAnimator") << "mousePressed " << x << ", " << y << ", " << button;
}

//--------------------------------------------------------------
void ofxFontAnimator::windowResized(int w, int h)
{
    // move the ofxPanel to fit inside window screen
    gui.setPosition(w-300, h-100);

    // 2. this do not repair the mouse neither:
    //removeMouseListeners();
    //addMouseListeners();
}
moebiussurfing commented 4 years ago

I noticed that when changing window mode WINDOW/FULL SCREEN with ofSetFullscreen(MODE), ofxGui does not receive the mouse coordinates fine when switching from full-screen to window mode. (Window goes like 20 pixels above the top border in the vertical y axis. The mouse pointer is like displaced vertically 20 pixels below. In full-screen mode, it works.)

I need to click the window top title bar to resize again and then the mouse interacts fine with ofxGui again.

I am using a dual monitor setup if this could mean something... also, the ofxPanels are into some classes, not in ofApp. And the screen mode switching is called into ofApp.

Not sure what you mean about 'change in the coordinate system', but drawing/ofTranslate push/pop looks fine...

moebiussurfing commented 4 years ago

This is how I have aligned my 2 monitors: Screen Shot 2019-11-12 at 20 11 15

When mirroring both monitors the problem is solved! Mouse cliks goes fine to the gui: Screen Shot 2019-11-13 at 22 23 31

So I tried to move up the 1st monitor but do not help. I put both monitors to horizontal and aligned at the same height but it fails to. Screen Shot 2019-11-13 at 22 25 04

roymacdonald commented 4 years ago

Hi. so, does that code fix this issue? when the ofxFontAnimator::windowResized gets called does it fix this issue?

moebiussurfing commented 4 years ago

nope, I commented that on keyPressed method... the only way that it's solved is when clicking window top bar and maximize window 'by macOS', or when using both monitor screens in mirror mode. (not tested with only one monitor plugged...)

moebiussurfing commented 4 years ago

hey @roymacdonald , thanks your your attention, but nevermind, it's not important.

just two more cents just in case help:

when switching from full-screen: Screen Shot 2019-11-13 at 23 50 29

to window mode: Screen Shot 2019-11-13 at 23 50 50

the window is moved down 20px (?). Then when clicking the bar goes up to top border again, and gui starts working again Screen Shot 2019-11-13 at 23 50 58

(sometimes window goes locked and must resize from the borders, bar drag do not move) (the top header of panels are at -20px up just to hide the header, because the method to hide do not looked nice)

roymacdonald commented 4 years ago

Hi, I understand. I am not seeing this issue though.

roymacdonald commented 4 years ago

do you see this issue with other stuff besides the gui? if you have something where you add points to a polyline or mesh at the mouse position and then switch modes.

moebiussurfing commented 4 years ago

yes, it happens to some custom buttons I have in the same class. I tried with one monitor plugged and It happens too.

moebiussurfing commented 4 years ago

to window mode: Screen Shot 2019-11-13 at 23 50 50

the problems happen when window is displaced like this screenshot. And sometimes drawings are displaced 20px too. When window is auto placed to top border mouse seems to work fine.

I have another thing to test: I am using a system windows manager system (Moom), I'll try to disable this too... EDIT: I disabled Moom but do not help.

roymacdonald commented 4 years ago

I see. It is odd though. I'll try to replicate it.