Using manually installed SDL2 version

Hello fellows. I faced some problems with the version of SDL2 (2.0.20) that I installed through apt on Ubuntu 22.04.
So following the installation instructions I installed version 2.31.0 through github. But I did so without removing the previous version.

Now, sdl2-config --version on the terminal shows that it is 2.31.0 but I think my programs are still using version 2.0.20.

Is it not advisable to install newer versions of software without first uninstalling the previous ones? Do I simply uninstall both versions and redo?
Can anyone help me out here? Thank you.

update: I uninstalled both the versions, then installed just 2.31.0. But programs still face the same problem they faced with version 2.0.20, namely: some inputs (mouse button up and down, some keys on keyboard) are being followed by the SDL_keymapchanged code. Any clues?

I don’t know what will happen if you have two versions installed. They will probably be installed at different locations, apt-get in /usr/lib, /usr/include, etc. and your manual install in /usr/local/lib, /usr/local/include, etc. so my guess is that you can uninstall the 2.0.20 version using apt-get without interfering with the 2.31.0 version.

1 Like

Did you uninstall both the “dev” package (libsdl2-dev) and the normal “runtime” package (libsdl2-2.0-0)?

You can use SDL_GetVersion to verify that you’re using the right version.

SDL_version version;
printf("I'm using SDL version %d.%d.%d\n", version.major, version.minor, version.patch);
1 Like

Thank you for your response.

I used SDL_GetVersion and the program still says version 2.0.20 eventhough I have uninstalled it. Even sdl2-config --version return 2.31.0.

Also I am using #include </usr/local/include/SDL2/SDL.h> (eventhough just <SDL2/SDL.h> was working jut fine)
Further, I checked usr/include and there is no SDL2 folder there.

what do you think?

I DID NOT uninstall the normal runtime package. Is that it?

Removing the runtime package fixed it. Now, the program runs on 2.31.0!
Thank you!

I just have one doubt. If you have the time…

In 2.0.20, since my program wasn’t working right, I made a simple program which just returns the event.type after SDL_PollEvent, to check exactly the problem.
with each mousebutton down, I would get 512, 1025, 772
with each mousebutton up, I would get 772, 1026, 772
some keys on the keyboard also would be wrapped in 772 (the code for SDL_KEYMAPCHANGED).

Now, that is largely fixed. Just that the mousebutton down input is still preceded by 512 (code for SDL_WINDOWEVENT).
Is this normal behaviour?

Thank you very much!

Which window event is it? Does it happen each time or only the first time (e.g. when the window gains focus?)

1 Like

I get the code 512. So I checked the SDL_Events.h file and in that is listed:

SDL_WINDOWEVENT = 0x200, /**< Window state change */

The hex translates to 512 decimal.

This happens with each mousebuttondown event. This does not happen with SDL2 v2.0.10 in my other computer.

There are multiple different “window events”. Look at the example on the SDL_WindowEvent wiki page.

1 Like

the event.window.event shows 15.

This happens each time I click.

I tested this on my computers (Debian/X11, SDL 2.0.5 and SDL 2.29.2) and I don’t seem to get any SDL_WINDOWEVENT_TAKE_FOCUS events unless I click on the window borders. If I click on the title bar I get two such events each time.

I don’t fully understand how this event is meant to be used so I don’t know which behaviour is correct. You’re being “offered focus” but you already have focus so what’s the harm? It seems to be a Linux-only thing. You can probably just ignore it. I think most programs probably don’t handle this event. If you want to react to receiving focus you would use SDL_WINDOWEVENT_FOCUS_GAINED instead.

If you really are interested to know more about this event...

…here are some information that I found:

What the wiki says:
SDL_WINDOWEVENT_TAKE_FOCUS, /**< Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) */

What the SDL 2.0.5 release notes said:
Added a window event SDL_WINDOWEVENT_TAKE_FOCUS when a window manager asks the SDL window whether it wants to take focus.

You might want to read about X11’s WM_TAKE_FOCUS:
It seems like this is where SDL gets the underlying event from which it just forwards to the application as SDL_WINDOWEVENT_TAKE_FOCUS.

1 Like

I swtiched from wayland to X11… and it works fine. I am crying.
Thank you for helping me :slight_smile:

some rambling, I want to vent TT -

I spent the entire day trying to get everything working after installing from source. SDL2_ttf was giving me problems. When it did work finally, I realized that the window event (which was preceding SDL_MOUSEBUTTONDOWN), was about 1 in 20 times following the SDL_MOUSEBUTTONDOWN event, REPLACING what was coming after it (sometimes even one after the other for 10 times straight).
So, a simple mouse click often did not work because it wouldn’t detect a SDL_MOUSEBUTTONUP. And I needed to check for either a mouse button up or mouse motion event after a mouse button down, so I couldn’t just assume what would come after the button down. Although I see it could have been fixed by recording the x and y coordinates on mousebuttondown, and then comparing with the coordinates of the mouse cursor after the faulty window event to figure out whether it was supposed to be a mouse click, or drag.

All this when I could have made this small change. But I did end up learning a few things. That is something.

I don’t think it should matter in which order you receive the SDL_MOUSEBUTTONDOWN and SDL_WINDOWEVENT_TAKE_FOCUS events.

You might get many different events for many different reasons so you cannot rely on what the previous event was.

This sounds like a much better idea.