Skip to content

GLFW Window Focus Fix - #8530

Open
danoli3 wants to merge 3 commits into
openframeworks:masterfrom
danoli3:glfw-window-focus
Open

GLFW Window Focus Fix#8530
danoli3 wants to merge 3 commits into
openframeworks:masterfrom
danoli3:glfw-window-focus

Conversation

@danoli3

@danoli3 danoli3 commented Aug 9, 2026

Copy link
Copy Markdown
Member

ofxGLFWWindow Focus

  • Add bWindowFocused member to ofAppGLFWWindow
  • Add focus_cb static callback (matches GLFWfocusfun), registered with
    glfwSetWindowFocusCallback alongside the other window callbacks in setup()
  • Seed initial state from glfwGetWindowAttrib(windowP, GLFW_FOCUSED) right
    after registration, since a window isn't guaranteed to start focused
  • Clear the callback in close() for symmetry with the other teardown calls
  • isWindowActive() now returns bWindowFocused instead of the stub

ofAppGLFWWindow::isWindowActive()was hardcoded toreturn true`, so window now can be detected if active or not active... useful for backgrounding apps running machines, so you can now actively pause or sleep draw or update

@danoli3 danoli3 added this to the 0.12.2 milestone Aug 9, 2026
@danoli3 danoli3 added the glfw label Aug 9, 2026
@danoli3

danoli3 commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Ideally this should be a windowResized event in coreEvents, &ofBaseApp::windowFocusChanged... however I think for complexity it's easier for the moment to just add it as a ofEvent windowFocusChanged where opt in is:

ofAddListener(ofEvents().windowFocusChanged, this, &MyApp::onFocusChanged)

easy

@danoli3

danoli3 commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Added ofEvent windowFocusChanged; to ofEvents

@danoli3
danoli3 force-pushed the glfw-window-focus branch from 2a5fdee to 9768350 Compare August 9, 2026 17:33
@danoli3

danoli3 commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

@ofTheo is ofEvent good idea for now vs change core events virtual function etc... I think this is good to merge

@danoli3 danoli3 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good changes

@danoli3
danoli3 requested a review from dimitre August 13, 2026 17:59
@dimitre

dimitre commented Aug 13, 2026

Copy link
Copy Markdown
Member

Thanks @danoli3 I'm not using this anymore in my day to day use.
but I've been using a simplified version of this for the last two years
if you want to take a look it is this code:
https://github.com/dimitre/openFrameworks/blob/ofworks/libs/openFrameworks/app/ofAppGLFWWindow.cpp

I removed some code that counted frames since state change and others simplifications. but there is api change there so near zero change of being pulled to OF main :/

Other two niceties there is ofWindowSettings is only one object for all kinds of windows (I think it is best) and also we can choose to span one same window to multiple monitors (poor's man Nvidia Mosaic) but I think it is very useful to span 4 outputs in one single window, as I do often.

@danoli3

danoli3 commented Aug 15, 2026

Copy link
Copy Markdown
Member Author

I'm going to put this in for now as Focus / pause event quite useful in general for apps for power usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants