Skip to content

Commit f2f048d

Browse files
joevtdingusdev
authored andcommitted
hostevents: Fix mouse grab for multiple displays.
Create a mouse grab toggle event to toggle the mouse grab using the current window. After the toggle event is transmitted, transmit a mouse grab changed event so that all windows can update their title.
1 parent a62a1dc commit f2f048d

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

core/hostevents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum : uint16_t {
3939
// Standard SDL window event types are uint8_t's.
4040
// We add our own custom events after that.
4141
DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
42+
DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE,
4243
DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED,
4344
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE,
4445
DPPC_WINDOWEVENT_WINDOW_BIGGER,

core/hostevents_sdl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ void EventManager::poll_events(uint32_t kbd_locale) {
5959
if (event.key.keysym.sym == SDLK_g && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
6060
if (event.type == SDL_KEYUP) {
6161
WindowEvent we;
62+
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE;
63+
we.window_id = event.window.windowID;
64+
this->_window_signal.emit(we);
6265
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED;
6366
we.window_id = event.window.windowID;
6467
this->_window_signal.emit(we);

devices/video/display_sdl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,12 @@ void Display::handle_events(const WindowEvent& wnd_event) {
289289
}
290290
break;
291291

292+
case DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE:
293+
if (wnd_event.window_id == impl->disp_wnd_id)
294+
this->toggle_mouse_grab();
295+
break;
296+
292297
case DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED:
293-
this->toggle_mouse_grab();
294298
this->update_window_title();
295299
break;
296300

0 commit comments

Comments
 (0)