Skip to content

Commit cbdf381

Browse files
Fix gamepad hotkey and game profile setting (#510)
1 parent c43fc81 commit cbdf381

File tree

11 files changed

+79
-64
lines changed

11 files changed

+79
-64
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ endif()
114114

115115
if (UNIX AND NOT APPLE)
116116
find_package(X11 REQUIRED)
117+
find_package(GTK3 REQUIRED)
117118
endif()
118119

119120
if (ENABLE_VULKAN)

cmake/FindGTK3.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: 2022 Andrea Pappacoda <[email protected]>
2+
# SPDX-License-Identifier: ISC
3+
4+
include(FindPackageHandleStandardArgs)
5+
6+
find_package(PkgConfig)
7+
if (PKG_CONFIG_FOUND)
8+
pkg_search_module(GTK3 IMPORTED_TARGET gtk+-3.0)
9+
if (GTK3_FOUND)
10+
add_library(GTK3::gtk ALIAS PkgConfig::GTK3)
11+
endif()
12+
find_package_handle_standard_args(GTK3
13+
REQUIRED_VARS GTK3_LINK_LIBRARIES
14+
VERSION_VAR GTK3_VERSION
15+
)
16+
endif()

src/Cafe/CafeSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ void cemu_initForGame()
394394
// replace any known function signatures with our HLE implementations and patch bugs in the games
395395
GamePatch_scan();
396396
}
397+
LatteGPUState.alwaysDisplayDRC = ActiveSettings::DisplayDRCEnabled();
397398
InfoLog_PrintActiveSettings();
398399
Latte_Start();
399400
// check for debugger entrypoint bp
@@ -864,4 +865,4 @@ namespace CafeSystem
864865
return currentUpdatedApplicationHash;
865866
}
866867

867-
}
868+
}

src/Cafe/HW/Latte/Core/Latte.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct LatteGPUState_t
5050
uint32 gx2InitCalled; // incremented every time GX2Init() is called
5151
// OpenGL control
5252
uint32 glVendor; // GLVENDOR_*
53+
bool alwaysDisplayDRC = false;
5354
// temporary (replace with proper solution later)
5455
bool tvBufferUsesSRGB;
5556
bool drcBufferUsesSRGB;
@@ -172,4 +173,4 @@ void LatteRenderTarget_updateViewport();
172173
// Latte emulation control
173174
void Latte_Start();
174175
void Latte_Stop();
175-
bool Latte_IsActive();
176+
bool Latte_IsActive();

src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,6 @@ void LatteRenderTarget_copyToBackbuffer(LatteTextureView* textureView, bool isPa
10041004
g_renderer->ImguiEnd();
10051005
}
10061006

1007-
bool alwaysDisplayDRC = false;
10081007
bool ctrlTabHotkeyPressed = false;
10091008

10101009
void LatteRenderTarget_itHLECopyColorBufferToScanBuffer(MPTR colorBufferPtr, uint32 colorBufferWidth, uint32 colorBufferHeight, uint32 colorBufferSliceIndex, uint32 colorBufferFormat, uint32 colorBufferPitch, Latte::E_HWTILEMODE colorBufferTilemode, uint32 colorBufferSwizzle, uint32 renderTarget)
@@ -1016,9 +1015,11 @@ void LatteRenderTarget_itHLECopyColorBufferToScanBuffer(MPTR colorBufferPtr, uin
10161015
return;
10171016
}
10181017

1019-
const bool tabPressed = gui_isKeyDown(WXK_TAB);
1020-
const bool ctrlPressed = gui_isKeyDown(0xA2); // VK_LCONTROL
1018+
const bool tabPressed = gui_isKeyDown(PlatformKeyCodes::TAB);
1019+
const bool ctrlPressed = gui_isKeyDown(PlatformKeyCodes::LCONTROL);
1020+
10211021
bool showDRC = swkbd_hasKeyboardInputHook() == false && tabPressed;
1022+
bool& alwaysDisplayDRC = LatteGPUState.alwaysDisplayDRC;
10221023

10231024
if (ctrlPressed && tabPressed)
10241025
{
@@ -1131,4 +1132,4 @@ void LatteRenderTarget_unloadAll()
11311132
LatteMRT::DeleteCachedFBO(g_emptyFBO);
11321133
g_emptyFBO = nullptr;
11331134
}
1134-
}
1135+
}

src/config/ActiveSettings.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.h"
1212
#include "Cafe/CafeSystem.h"
1313

14-
extern bool alwaysDisplayDRC;
15-
1614
std::set<fs::path>
1715
ActiveSettings::LoadOnce(const fs::path& user_data_path,
1816
const fs::path& config_path,
@@ -57,7 +55,6 @@ bool ActiveSettings::LoadSharedLibrariesEnabled()
5755

5856
bool ActiveSettings::DisplayDRCEnabled()
5957
{
60-
alwaysDisplayDRC = g_current_game_profile->StartWithGamepadView();
6158
return g_current_game_profile->StartWithGamepadView();
6259
}
6360

src/gui/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ target_link_libraries(CemuGui PRIVATE
147147
ZArchive::zarchive
148148
)
149149

150+
if(ENABLE_WXWIDGETS AND UNIX AND NOT APPLE)
151+
# PUBLIC because gdk/gdkkeysyms.h is included in guiWrapper.h
152+
target_link_libraries(CemuGui PUBLIC GTK3::gtk)
153+
endif()
154+
150155
if(ENABLE_CUBEB)
151156
target_link_libraries(CemuGui PRIVATE cubeb::cubeb)
152157
endif()

src/gui/CemuApp.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ int CemuApp::FilterEvent(wxEvent& event)
218218
const auto& key_event = (wxKeyEvent&)event;
219219
g_window_info.set_keystate(fix_raw_keycode(key_event.GetRawKeyCode(), key_event.GetRawKeyFlags()), false);
220220
}
221-
else if(event.GetEventType() == wxEVT_KILL_FOCUS)
221+
else if(event.GetEventType() == wxEVT_ACTIVATE_APP)
222222
{
223-
g_window_info.set_keystatesdown();
223+
const auto& activate_event = (wxActivateEvent&)event;
224+
if(!activate_event.GetActive())
225+
g_window_info.set_keystatesup();
224226
}
225227

226228
return wxApp::FilterEvent(event);

src/gui/guiWrapper.cpp

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#if BOOST_OS_LINUX
2+
#include <gtk/gtk.h>
3+
#include <gdk/gdk.h>
4+
#include <gdk/gdkwindow.h>
5+
#include <gdk/gdkx.h>
6+
#endif
7+
18
#include "gui/wxgui.h"
29
#include "gui/guiWrapper.h"
310
#include "gui/CemuApp.h"
@@ -156,63 +163,26 @@ bool gui_isPadWindowOpen()
156163
}
157164

158165
#if BOOST_OS_LINUX
159-
#include <wx/nativewin.h>
160-
#include <dlfcn.h>
161-
162-
typedef void GdkDisplay;
163-
namespace
164-
{
165-
const char* (*gdk_keyval_name)(unsigned int keyval);
166-
}
167166
std::string gui_gtkRawKeyCodeToString(uint32 keyCode)
168167
{
169168
return gdk_keyval_name(keyCode);
170169
}
171-
172170
#endif
173171

174172
void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, class wxWindow* wxw)
175173
{
176174
#if BOOST_OS_WINDOWS
177175
handleInfoOut.hwnd = wxw->GetHWND();
178176
#elif BOOST_OS_LINUX
179-
/* dynamically retrieve GTK imports so we dont have to include and link the whole lib */
180-
void (*dyn_gtk_widget_realize)(GtkWidget *widget);
181-
dyn_gtk_widget_realize = (void(*)(GtkWidget* widget))dlsym(RTLD_NEXT, "gtk_widget_realize");
182-
183-
GdkWindow* (*dyn_gtk_widget_get_window)(GtkWidget *widget);
184-
dyn_gtk_widget_get_window = (GdkWindow*(*)(GtkWidget* widget))dlsym(RTLD_NEXT, "gtk_widget_get_window");
185-
186-
GdkDisplay* (*dyn_gdk_window_get_display)(GdkWindow *widget);
187-
dyn_gdk_window_get_display = (GdkDisplay*(*)(GdkWindow* window))dlsym(RTLD_NEXT, "gdk_window_get_display");
188-
189-
Display* (*dyn_gdk_x11_display_get_xdisplay)(GdkDisplay *display);
190-
dyn_gdk_x11_display_get_xdisplay = (Display*(*)(GdkDisplay* display))dlsym(RTLD_NEXT, "gdk_x11_display_get_xdisplay");
191-
192-
Window (*dyn_gdk_x11_window_get_xid)(GdkWindow *window);
193-
dyn_gdk_x11_window_get_xid = (Window(*)(GdkWindow *window))dlsym(RTLD_NEXT, "gdk_x11_window_get_xid");
194-
195-
gdk_keyval_name = (const char* (*)(unsigned int))dlsym(RTLD_NEXT, "gdk_keyval_name");
196-
197-
if(!dyn_gtk_widget_realize || !dyn_gtk_widget_get_window ||
198-
!dyn_gdk_window_get_display || !dyn_gdk_x11_display_get_xdisplay ||
199-
!dyn_gdk_x11_window_get_xid || !gdk_keyval_name)
200-
{
201-
cemuLog_log(LogType::Force, "Unable to load GDK symbols");
202-
return;
203-
}
204-
205-
/* end of imports */
206-
207177
// get window
208178
GtkWidget* gtkWidget = (GtkWidget*)wxw->GetHandle(); // returns GtkWidget
209-
dyn_gtk_widget_realize(gtkWidget);
210-
GdkWindow* gdkWindow = dyn_gtk_widget_get_window(gtkWidget);
211-
handleInfoOut.xlib_window = dyn_gdk_x11_window_get_xid(gdkWindow);
179+
gtk_widget_realize(gtkWidget);
180+
GdkWindow* gdkWindow = gtk_widget_get_window(gtkWidget);
181+
handleInfoOut.xlib_window = gdk_x11_window_get_xid(gdkWindow);
212182

213183
// get display
214-
GdkDisplay* gdkDisplay = dyn_gdk_window_get_display(gdkWindow);
215-
handleInfoOut.xlib_display = dyn_gdk_x11_display_get_xdisplay(gdkDisplay);
184+
GdkDisplay* gdkDisplay = gdk_window_get_display(gdkWindow);
185+
handleInfoOut.xlib_display = gdk_x11_display_get_xdisplay(gdkDisplay);
216186
if(!handleInfoOut.xlib_display)
217187
{
218188
cemuLog_log(LogType::Force, "Unable to get xlib display");
@@ -222,11 +192,16 @@ void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, c
222192
#endif
223193
}
224194

225-
bool gui_isKeyDown(int key)
195+
bool gui_isKeyDown(uint32 key)
226196
{
227197
return g_window_info.get_keystate(key);
228198
}
229199

200+
bool gui_isKeyDown(PlatformKeyCodes key)
201+
{
202+
return gui_isKeyDown((std::underlying_type_t<PlatformKeyCodes>)key);
203+
}
204+
230205
void gui_notifyGameLoaded()
231206
{
232207
std::shared_lock lock(g_mutex);
@@ -311,4 +286,4 @@ void debuggerWindow_notifyModuleUnloaded(void* module)
311286
evt->SetClientData(module);
312287
wxQueueEvent(g_debugger_window, evt);
313288
}
314-
}
289+
}

src/gui/guiWrapper.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#if BOOST_OS_LINUX
66
#include "xcb/xproto.h"
7+
#include <gdk/gdkkeysyms.h>
78
#endif
89

910
struct WindowHandleInfo
@@ -25,6 +26,23 @@ struct WindowHandleInfo
2526
#endif
2627
};
2728

29+
enum struct PlatformKeyCodes : uint32
30+
{
31+
#if BOOST_OS_WINDOWS
32+
LCONTROL = VK_LCONTROL,
33+
RCONTROL = VK_RCONTROL,
34+
TAB = VK_TAB,
35+
#elif BOOST_OS_LINUX
36+
LCONTROL = GDK_KEY_Control_L,
37+
RCONTROL = GDK_KEY_Control_R,
38+
TAB = GDK_KEY_Tab,
39+
#else
40+
LCONTROL = 0,
41+
RCONTROL = 0,
42+
TAB = 0,
43+
#endif
44+
};
45+
2846
struct WindowInfo
2947
{
3048
std::atomic_bool app_active; // our app is active/has focus
@@ -56,7 +74,7 @@ struct WindowInfo
5674
return result->second;
5775
}
5876

59-
void set_keystatesdown()
77+
void set_keystatesup()
6078
{
6179
const std::lock_guard<std::mutex> lock(keycode_mutex);
6280
std::for_each(m_keydown.begin(), m_keydown.end(), [](std::pair<const uint32, bool>& el){ el.second = false; });
@@ -89,7 +107,8 @@ void gui_updateWindowTitles(bool isIdle, bool isLoading, double fps);
89107
void gui_getWindowSize(int* w, int* h);
90108
void gui_getPadWindowSize(int* w, int* h);
91109
bool gui_isPadWindowOpen();
92-
bool gui_isKeyDown(int key);
110+
bool gui_isKeyDown(uint32 key);
111+
bool gui_isKeyDown(PlatformKeyCodes key);
93112

94113
void gui_notifyGameLoaded();
95114
void gui_notifyGameExited();
@@ -114,4 +133,4 @@ void debuggerWindow_notifyDebugBreakpointHit2();
114133
void debuggerWindow_notifyRun();
115134
void debuggerWindow_moveIP();
116135
void debuggerWindow_notifyModuleLoaded(void* module);
117-
void debuggerWindow_notifyModuleUnloaded(void* module);
136+
void debuggerWindow_notifyModuleUnloaded(void* module);

0 commit comments

Comments
 (0)