Qt/Qml TextField receives keystroke twice when creating SDL window on macOS - macos

I created a Qt application with QML which contains a TextField. If I call SDL_CreateWindow() to create a new SDL2 window, typing in the TextField will duplicate every character. For example, if I type "hello" in the TextField, it will show "hheelllloo".
This only occurs after the creation of the SDL window. Also, this happens only on macOS. I compile the same application on Windows and Linux, and this problem is not visible.

I have also seen a similar bug in my Mac game using Cocoa windows with SDL2 2.0.14.
If the text fields are in a modal window, you could,,as a workaround call, SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE) before displaying the modal window and call SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE) when it closes.
With a non-modal window, you could try disabling the SDL text input when the window becomes active and enable when inactive.
Hope that helped.
Hopefully someone will fix this bug soon. I may look into it myself at some point soon. Note that I am not an SDL maintainer.

Related

SDL 2.0 on Mac - how to activate/respond to greyed-out Toggle Full Screen menu item?

Working on porting a Windows game to Mac using SDL2, and I noticed on the Mac that the menu bar for the game includes a View menu with an item Toggle Full Screen. I'm assuming SDL put it there automatically, as I didn't request it anywhere in my code. However, since the game can run in a window or full screen (and the window is resizable), I figure I should make this menu item actually work somehow.
I know practically nothing about Mac OSX coding (I just followed a tutorial to get my SDL app to build on the Mac side in XCode), and I can't find anything in the SDL documentation about how to respond to, activate, or remove this menu item (or other ones that are greyed out, like the Minimize option in the Window menu). Best I could find online is a reference to it being added in a commit to the SDL code base, but nothing in the commit message about how one is supposed to hook it up to their application code.
So, how do I activate and respond to this menu item (and any other menu items that only show up in OSX builds for that matter, like Minimize and About)? And is it something I can hook up in a cross-platform way via SDL itself, or did SDL add something that I have to deal with using platform-specific OSX code?

Mac OS X Carbon: What is the difference between SelectWindow vs. ActivateWindow and what are the Cocoa equivalents

The title basically sums up my question. I'd like to know what the difference between the Mac Carbon SelectWindow and ActivateWindow(..., TRUE) is. I've found these in old source and wonder if they are interchangeable (or what their Cocoa equivalents might be).
From memory...
SelectWindow was the response to clicking on a window. It brought the window to the front, activated it, and (usually) made it the first responder. (I'm using Cocoa terminology here.) It's sort of like OrderFront
The SelectWindow function removes highlighting from the previously
active window, brings the specified window to the front, highlights
it, and generates the activate events to deactivate the previously
active window and activate the specified window. If the specified
window is already active, SelectWindow has no effect. Call
SelectWindow when the user presses the mouse button while the cursor
is in the content region of an inactive window.
Activate Window updated the window frame to indicate that the window was the first responder.
You don't really need to know a Cocoa equivalent, you just need to identify what you want to do. Many things from Carbon that required you to implement them are done for you by AppKit. Other paradigms of Carbon APIs just do not happen in Cocoa. They look similar, and had many similar hooks to common OS things, but they're very very different.

How to prevent wxWidgets window from blinking in the taskbar when created?

If my wxWidgets application creates a new window while the application does not have focus, its taskbar icon blinks yellow until I switch to it, as shown here:
This is annoying. How can I prevent this from happening?
EDIT: The original version of this question suggested the blinking was happening during startup. After further investigation, this is not occurring right at application startup; rather, it occurs if I create an additional window while the application does not have focus.
To give a bit more background: my application is a sort of server, that opens windows in response to network events. If I boot up the application, then switch focus to something else and a network event comes in while the focus is elsewhere, my application will open a new window in the background (not grabbing focus) and this blinking will occur.
The windows are wxFrames; the application constructs them and their child widgets, then calls Show(true) on the frame.
Also, I've attempted to set a breakpoint on the FlashWindow Win32 API function, hoping to trap wherever in WX it's getting called, but haven't been able to make that work.
Maybe the following would work:
wxTopLevelWindow::ShowWithoutActivating ( )
http://docs.wxwidgets.org/trunk/classwx_top_level_window.html#a03e526f505716568318d601318527bd0
Yes. If you create a new top level window while the app does not have focus, then the task bar icon will flash. This is the intended behaviour of the windows operating system.

NSWindow, how not to be part of a screenshot?

My Cocoa app displays a transparent window on the screen, but when the user tries to take a screenshot using Mac OS X's built-in screen capture key with the option of selecting full windows (Command-Shift-4, then Space Bar), my window gets highlighted as part of the possible windows to capture.
How can I tell my Window or App not to allow this? My Window already refuses to be the Main Window or Key Window through -canBecomeKeyWindow and -canBecomeMainWindow both returning NO, but this still happens.
The Window is also at the NSModalPanelWindowLevel and NSScreenSaverWindowLevel does the same thing.
Notice that every window is eligible for screenshots, even the desktop, dock and menu bar, which are special windows. You can even take a screenshot of the Exposé overlay window itself. This leads me to believe that there is no way to do this.
I suppose you could hook the Command+Shift+4 key event and hide the window, but that key combo is user-definable, so it is subject to change.

bring the application from in focus, by clicking the icon of corresponding application

I was surprised this doesn't happen automatically, but I would like my applications window to be in focus as I click its dock icon, when in minimized mode.
Just to clarify, when I minimize the app, the window goes to dock, but when I click the its corresponding Dock Icon, the window don't come in focus.
Is there anything I am missing?
I am using Qt 4.5.3 on Mac OS X 10.5, 10.6
Thanks for help.
Rahul
First answer: That's the expected behavior of a Mac app. Try Safari for example. An app can be active without showing any window. In that case, only the menu bar at the top shows that the active app is changed. So, unless absolutely necessary, you shouldn't bring the minimized window back unless the user explicitly does so. That's the Mac way!
Second answer: I understand that there are cases where you want to bring the minimized window up. In Cocoa, the application delegate method -applicationDidBicomeActive is called when the application gets the focus, and there you can bring the window up yourself. I'm sure Qt also has a similar event/callback/signal or whatever, but I don't know any Qt ... :p Sorry I can't be of any help.

Resources