summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author npwoods <npwoods@mess.org>2021-05-20 10:09:00 -0400
committer GitHub <noreply@github.com>2021-05-20 10:09:00 -0400
commitf4d7c0aa62795bea035c87824a16965b26490e5f (patch)
treea732dad5beca0e8141b5aee719071a8dcace6ab8
parent200d0b75cd25d20997a5654ea2dc242705df2180 (diff)
-attach_window support for SDLMAME (#8070)
-rw-r--r--src/osd/sdl/osdsdl.h4
-rw-r--r--src/osd/sdl/sdlmain.cpp3
-rw-r--r--src/osd/sdl/window.cpp62
3 files changed, 65 insertions, 4 deletions
diff --git a/src/osd/sdl/osdsdl.h b/src/osd/sdl/osdsdl.h
index 126b007d331..1c93428d876 100644
--- a/src/osd/sdl/osdsdl.h
+++ b/src/osd/sdl/osdsdl.h
@@ -16,6 +16,7 @@
#define SDLOPTION_INIPATH "inipath"
#define SDLOPTION_SDLVIDEOFPS "sdlvideofps"
#define SDLOPTION_USEALLHEADS "useallheads"
+#define SDLOPTION_ATTACH_WINDOW "attach_window"
#define SDLOPTION_CENTERH "centerh"
#define SDLOPTION_CENTERV "centerv"
@@ -89,7 +90,8 @@ public:
// full screen options
#ifdef SDLMAME_X11
bool use_all_heads() const { return bool_value(SDLOPTION_USEALLHEADS); }
-#endif
+ const char *attach_window() const { return value(SDLOPTION_ATTACH_WINDOW); }
+#endif // SDLMAME_X11
// keyboard mapping
bool keymap() const { return bool_value(SDLOPTION_KEYMAP); }
diff --git a/src/osd/sdl/sdlmain.cpp b/src/osd/sdl/sdlmain.cpp
index 0fdd9883955..1a65e48a846 100644
--- a/src/osd/sdl/sdlmain.cpp
+++ b/src/osd/sdl/sdlmain.cpp
@@ -93,7 +93,8 @@ const options_entry sdl_options::s_option_entries[] =
#ifdef SDLMAME_X11
{ nullptr, nullptr, OPTION_HEADER, "SDL FULL SCREEN OPTIONS" },
{ SDLOPTION_USEALLHEADS, "0", OPTION_BOOLEAN, "split full screen image across monitors" },
- #endif
+ { SDLOPTION_ATTACH_WINDOW, "", OPTION_STRING, "attach to arbitrary window" },
+ #endif // SDLMAME_X11
// keyboard mapping
{ nullptr, nullptr, OPTION_HEADER, "SDL KEYBOARD MAPPING" },
diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp
index d751472ebd7..0d15c4e4c0b 100644
--- a/src/osd/sdl/window.cpp
+++ b/src/osd/sdl/window.cpp
@@ -14,6 +14,7 @@
// standard SDL headers
#include <SDL2/SDL.h>
+#include <SDL2/SDL_syswm.h>
// standard C headers
#include <cmath>
@@ -681,11 +682,68 @@ int sdl_window_info::complete_create()
// get monitor work area for centering
osd_rect work = monitor()->usuable_position_size();
- // create the SDL window
- auto sdlwindow = SDL_CreateWindow(title().c_str(),
+ // create or attach to an existing window
+ SDL_Window *sdlwindow;
+#ifdef SDLMAME_X11
+ const char *attach_window = downcast<sdl_options &>(machine().options()).attach_window();
+#else
+ const char *attach_window = nullptr;
+#endif
+ if (attach_window && *attach_window)
+ {
+ // we're attaching to an existing window; parse the argument
+ unsigned long long attach_window_value;
+ try
+ {
+ attach_window_value = std::stoull(attach_window, nullptr, 0);
+ }
+ catch (std::invalid_argument &)
+ {
+ osd_printf_error("Invalid -attach_window value: %s\n", attach_window);
+ return 1;
+ }
+
+ // and attach to it
+ sdlwindow = SDL_CreateWindowFrom((void *)attach_window_value);
+ if (!sdlwindow)
+ {
+ osd_printf_error("Failed to attach to window \"%s\": %s\n", attach_window, SDL_GetError());
+ return 1;
+ }
+
+ // perform SDL subsystem-specific tasks
+ SDL_SysWMinfo swmi;
+ SDL_VERSION(&swmi.version);
+ if (SDL_GetWindowWMInfo(sdlwindow, &swmi))
+ {
+ switch (swmi.subsystem)
+ {
+#ifdef SDLMAME_X11
+ case SDL_SYSWM_X11:
+ // by default, SDL_CreateWindowFrom() doesn't ensure that we're getting the events that we
+ // expect
+ XSelectInput(swmi.info.x11.display, swmi.info.x11.window,
+ FocusChangeMask | EnterWindowMask | LeaveWindowMask |
+ PointerMotionMask | KeyPressMask | KeyReleaseMask |
+ PropertyChangeMask | StructureNotifyMask |
+ ExposureMask | KeymapStateMask);
+ break;
+#endif // SDLMAME_X11
+
+ default:
+ break;
+ }
+ }
+ }
+ else
+ {
+ // create the SDL window
+ sdlwindow = SDL_CreateWindow(title().c_str(),
work.left() + (work.width() - temp.width()) / 2,
work.top() + (work.height() - temp.height()) / 2,
temp.width(), temp.height(), m_extra_flags);
+ }
+
//window().sdl_window() = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
// width, height, m_extra_flags);