-
Notifications
You must be signed in to change notification settings - Fork 502
/
guiWrapper.cpp
332 lines (297 loc) · 7.49 KB
/
guiWrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#if BOOST_OS_LINUX
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkwindow.h>
#include <gdk/gdkx.h>
#ifdef HAS_WAYLAND
#include <gdk/gdkwayland.h>
#endif
#endif
#include "gui/wxgui.h"
#include "gui/guiWrapper.h"
#include "gui/CemuApp.h"
#include "gui/MainWindow.h"
#include "gui/debugger/DebuggerWindow2.h"
#include "Cafe/HW/Latte/Core/Latte.h"
#include "config/ActiveSettings.h"
#include "config/NetworkSettings.h"
#include "config/CemuConfig.h"
#include "Cafe/HW/Latte/Renderer/Renderer.h"
#include "Cafe/CafeSystem.h"
#include "wxHelper.h"
WindowInfo g_window_info {};
std::shared_mutex g_mutex;
MainWindow* g_mainFrame = nullptr;
#if BOOST_OS_WINDOWS
void _wxLaunch()
{
SetThreadName("MainThread_UI");
wxEntry();
}
#endif
void gui_create()
{
SetThreadName("MainThread");
#if BOOST_OS_WINDOWS
// on Windows wxWidgets there is a bug where wxDirDialog->ShowModal will deadlock in Windows internals somehow
// moving the UI thread off the main thread fixes this
std::thread t = std::thread(_wxLaunch);
t.join();
#else
int argc = 0;
char* argv[1]{};
wxEntry(argc, argv);
#endif
}
WindowInfo& gui_getWindowInfo()
{
return g_window_info;
}
void gui_updateWindowTitles(bool isIdle, bool isLoading, double fps)
{
std::string windowText;
windowText = BUILD_VERSION_WITH_NAME_STRING;
if (isIdle)
{
if (g_mainFrame)
g_mainFrame->AsyncSetTitle(windowText);
return;
}
if (isLoading)
{
windowText.append(" - loading...");
if (g_mainFrame)
g_mainFrame->AsyncSetTitle(windowText);
return;
}
const char* renderer = "";
if(g_renderer)
{
switch(g_renderer->GetType())
{
case RendererAPI::OpenGL:
renderer = "[OpenGL]";
break;
case RendererAPI::Vulkan:
renderer = "[Vulkan]";
break;
default: ;
}
}
// get GPU vendor/mode
const char* graphicMode = "[Generic]";
if (LatteGPUState.glVendor == GLVENDOR_AMD)
graphicMode = "[AMD GPU]";
else if (LatteGPUState.glVendor == GLVENDOR_INTEL)
graphicMode = "[Intel GPU]";
else if (LatteGPUState.glVendor == GLVENDOR_NVIDIA)
graphicMode = "[NVIDIA GPU]";
else if (LatteGPUState.glVendor == GLVENDOR_APPLE)
graphicMode = "[Apple GPU]";
const uint64 titleId = CafeSystem::GetForegroundTitleId();
windowText.append(fmt::format(" - FPS: {:.2f} {} {} [TitleId: {:08x}-{:08x}]", (double)fps, renderer, graphicMode, (uint32)(titleId >> 32), (uint32)(titleId & 0xFFFFFFFF)));
if (ActiveSettings::IsOnlineEnabled())
{
if (ActiveSettings::GetNetworkService() == NetworkService::Nintendo)
windowText.append(" [Online]");
else if (ActiveSettings::GetNetworkService() == NetworkService::Pretendo)
windowText.append(" [Online-Pretendo]");
else if (ActiveSettings::GetNetworkService() == NetworkService::Custom)
windowText.append(" [Online-" + GetNetworkConfig().networkname.GetValue() + "]");
}
windowText.append(" ");
windowText.append(CafeSystem::GetForegroundTitleName());
// append region
CafeConsoleRegion region = CafeSystem::GetForegroundTitleRegion();
uint16 titleVersion = CafeSystem::GetForegroundTitleVersion();
if (region == CafeConsoleRegion::JPN)
windowText.append(fmt::format(" [JP v{}]", titleVersion));
else if (region == CafeConsoleRegion::USA)
windowText.append(fmt::format(" [US v{}]", titleVersion));
else if (region == CafeConsoleRegion::EUR)
windowText.append(fmt::format(" [EU v{}]", titleVersion));
else
windowText.append(fmt::format(" [v{}]", titleVersion));
std::shared_lock lock(g_mutex);
if (g_mainFrame)
{
g_mainFrame->AsyncSetTitle(windowText);
auto* pad = g_mainFrame->GetPadView();
if (pad)
pad->AsyncSetTitle(fmt::format("{} - FPS: {:.02f}", _("GamePad View").utf8_string(), fps));
}
}
void gui_getWindowSize(int& w, int& h)
{
w = g_window_info.width;
h = g_window_info.height;
}
void gui_getPadWindowSize(int& w, int& h)
{
if (g_window_info.pad_open)
{
w = g_window_info.pad_width;
h = g_window_info.pad_height;
}
else
{
w = 0;
h = 0;
}
}
void gui_getWindowPhysSize(int& w, int& h)
{
w = g_window_info.phys_width;
h = g_window_info.phys_height;
}
void gui_getPadWindowPhysSize(int& w, int& h)
{
if (g_window_info.pad_open)
{
w = g_window_info.phys_pad_width;
h = g_window_info.phys_pad_height;
}
else
{
w = 0;
h = 0;
}
}
double gui_getWindowDPIScale()
{
return g_window_info.dpi_scale;
}
double gui_getPadDPIScale()
{
return g_window_info.pad_open ? g_window_info.pad_dpi_scale.load() : 1.0;
}
bool gui_isPadWindowOpen()
{
return g_window_info.pad_open;
}
#if BOOST_OS_LINUX
std::string gui_gtkRawKeyCodeToString(uint32 keyCode)
{
return gdk_keyval_name(keyCode);
}
#endif
void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, class wxWindow* wxw)
{
#if BOOST_OS_WINDOWS
handleInfoOut.hwnd = wxw->GetHWND();
#elif BOOST_OS_LINUX
GtkWidget* gtkWidget = (GtkWidget*)wxw->GetHandle(); // returns GtkWidget
gtk_widget_realize(gtkWidget);
GdkWindow* gdkWindow = gtk_widget_get_window(gtkWidget);
GdkDisplay* gdkDisplay = gdk_window_get_display(gdkWindow);
if(GDK_IS_X11_WINDOW(gdkWindow))
{
handleInfoOut.backend = WindowHandleInfo::Backend::X11;
handleInfoOut.xlib_window = gdk_x11_window_get_xid(gdkWindow);
handleInfoOut.xlib_display = gdk_x11_display_get_xdisplay(gdkDisplay);
if(!handleInfoOut.xlib_display)
{
cemuLog_log(LogType::Force, "Unable to get xlib display");
}
}
else
#ifdef HAS_WAYLAND
if(GDK_IS_WAYLAND_WINDOW(gdkWindow))
{
handleInfoOut.backend = WindowHandleInfo::Backend::WAYLAND;
handleInfoOut.surface = gdk_wayland_window_get_wl_surface(gdkWindow);
handleInfoOut.display = gdk_wayland_display_get_wl_display(gdkDisplay);
}
else
#endif
{
cemuLog_log(LogType::Force, "Unsuported GTK backend");
}
#else
handleInfoOut.handle = wxw->GetHandle();
#endif
}
bool gui_isKeyDown(uint32 key)
{
return g_window_info.get_keystate(key);
}
bool gui_isKeyDown(PlatformKeyCodes key)
{
return gui_isKeyDown((std::underlying_type_t<PlatformKeyCodes>)key);
}
void gui_notifyGameLoaded()
{
std::shared_lock lock(g_mutex);
if (g_mainFrame)
{
g_mainFrame->OnGameLoaded();
g_mainFrame->UpdateSettingsAfterGameLaunch();
}
}
void gui_notifyGameExited()
{
std::shared_lock lock(g_mutex);
if(g_mainFrame)
g_mainFrame->RestoreSettingsAfterGameExited();
}
bool gui_isFullScreen()
{
return g_window_info.is_fullscreen;
}
bool gui_hasScreenshotRequest()
{
const bool result = g_window_info.has_screenshot_request;
g_window_info.has_screenshot_request = false;
return result;
}
extern DebuggerWindow2* g_debugger_window;
void debuggerWindow_updateViewThreadsafe2()
{
if (g_debugger_window)
{
auto* evt = new wxCommandEvent(wxEVT_UPDATE_VIEW);
wxQueueEvent(g_debugger_window, evt);
}
}
void debuggerWindow_moveIP()
{
if (g_debugger_window)
{
auto* evt = new wxCommandEvent(wxEVT_MOVE_IP);
wxQueueEvent(g_debugger_window, evt);
}
}
void debuggerWindow_notifyDebugBreakpointHit2()
{
if (g_debugger_window)
{
auto* evt = new wxCommandEvent(wxEVT_BREAKPOINT_HIT);
wxQueueEvent(g_debugger_window, evt);
}
}
void debuggerWindow_notifyRun()
{
if (g_debugger_window)
{
auto* evt = new wxCommandEvent(wxEVT_RUN);
wxQueueEvent(g_debugger_window, evt);
}
}
void debuggerWindow_notifyModuleLoaded(void* module)
{
if (g_debugger_window)
{
auto* evt = new wxCommandEvent(wxEVT_NOTIFY_MODULE_LOADED);
evt->SetClientData(module);
wxQueueEvent(g_debugger_window, evt);
}
}
void debuggerWindow_notifyModuleUnloaded(void* module)
{
if (g_debugger_window)
{
auto* evt = new wxCommandEvent(wxEVT_NOTIFY_MODULE_UNLOADED);
evt->SetClientData(module);
wxQueueEvent(g_debugger_window, evt);
}
}