Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSIX cli joystick/keyboard fixes (replaces #822) #852

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion desmume/src/frontend/interface/draw_sdl_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ EXPORTED int desmume_draw_window_init(BOOL auto_pause, BOOL use_opengl_if_possib
// TODO: Make configurable instead.
load_default_config(cli_kb_cfg);

ctrls_cfg.boost = 0;
ctrls_cfg.sdl_quit = 0;
ctrls_cfg.auto_pause = auto_pause;
ctrls_cfg.focused = 1;
Expand Down
7 changes: 2 additions & 5 deletions desmume/src/frontend/posix/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,8 @@ int main(int argc, char ** argv) {
/* Initialize joysticks */
if(!init_joy()) return 1;
/* Load keyboard and joystick configuration */
keyfile = desmume_config_read_file(cli_kb_cfg);
keyfile = desmume_config_read_file(cli_kb_cfg, "SDLKEYS");
desmume_config_dispose(keyfile);
/* Since gtk has a different mapping the keys stop to work with the saved configuration :| */
load_default_config(cli_kb_cfg);

if(my_config.load_slot != -1){
loadstate_slot(my_config.load_slot);
Expand All @@ -548,7 +546,6 @@ int main(int argc, char ** argv) {
osd = new OSDCLASS(-1);
#endif

ctrls_cfg.boost = 0;
ctrls_cfg.sdl_quit = 0;
ctrls_cfg.auto_pause = my_config.auto_pause;
ctrls_cfg.focused = 1;
Expand Down Expand Up @@ -579,7 +576,7 @@ int main(int argc, char ** argv) {
#ifdef DISPLAY_FPS
now = SDL_GetTicks();
#endif
if ( !my_config.disable_limiter && !ctrls_cfg.boost) {
if ( !my_config.disable_limiter && !(ctrls_cfg.keypad & KEYMASK_(KEY_BOOST - 1))) {
#ifndef DISPLAY_FPS
now = SDL_GetTicks();
#endif
Expand Down
19 changes: 17 additions & 2 deletions desmume/src/frontend/posix/gtk2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2194,13 +2194,19 @@ static void Modify_Key(GtkWidget* widget, gpointer data)

}

#include "../shared/gdksdl.cpp"

static void Edit_Controls()
{
GtkWidget *ecDialog;
GtkWidget *ecKey;
gchar *Key_Label;
u32 keyboard_cfg_sdl[NB_KEYS];
int i;

g_assert(sizeof(Keypad_Temp) == sizeof(keyboard_cfg) &&
sizeof(keyboard_cfg) == sizeof(keyboard_cfg_sdl));

memcpy(&Keypad_Temp, &keyboard_cfg, sizeof(keyboard_cfg));

ecDialog = gtk_dialog_new_with_buttons("Edit controls",
Expand All @@ -2222,8 +2228,17 @@ static void Edit_Controls()

switch (gtk_dialog_run(GTK_DIALOG(ecDialog))) {
case GTK_RESPONSE_OK:
memcpy(&keyboard_cfg, &Keypad_Temp, sizeof(keyboard_cfg));
desmume_config_update_keys(keyfile);
/* convert keycodes to SDL for the cli frontend, since it has no config menu */
for (i = 0; i < NB_KEYS; ++i) {
int sk = gdk_to_sdl_keycode(Keypad_Temp[i]);
/* if we don't know the keycode, chances are that SDL knows it anyways */
if (sk == -1) sk = (u32) Keypad_Temp[i];
keyboard_cfg_sdl[i] = sk;
}
memcpy(keyboard_cfg, keyboard_cfg_sdl, sizeof(keyboard_cfg));
desmume_config_update_keys(keyfile, "SDLKEYS");
memcpy(keyboard_cfg, Keypad_Temp, sizeof(keyboard_cfg));
desmume_config_update_keys(keyfile, "KEYS");
break;
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_NONE:
Expand Down
10 changes: 0 additions & 10 deletions desmume/src/frontend/posix/shared/ctrlssdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ do_process_joystick_events( u16 *keypad, SDL_Event *event) {
break;

/* Joystick button pressed */
/* FIXME: Add support for BOOST */
case SDL_JOYBUTTONDOWN:
key_code = ((event->jbutton.which & 15) << 12) | JOY_BUTTON << 8 | (event->jbutton.button & 255);
key = lookup_joy_key( key_code );
Expand Down Expand Up @@ -536,15 +535,6 @@ process_ctrls_event( SDL_Event& event,
driver->AddLine("Fake mic disabled");
break;
#endif

case SDLK_o:
cfg->boost = !cfg->boost;
if (cfg->boost)
driver->AddLine("Boost mode enabled");
else
driver->AddLine("Boost mode disabled");
break;

case SDLK_LSHIFT:
shift_pressed &= ~1;
break;
Expand Down
1 change: 0 additions & 1 deletion desmume/src/frontend/posix/shared/ctrlssdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ struct ctrls_event_config {
int auto_pause;
int focused;
int sdl_quit;
int boost;
int fake_mic;
void *screen_texture;
void (*resize_cb)(u16 width, u16 height, void *screen_texture);
Expand Down
14 changes: 7 additions & 7 deletions desmume/src/frontend/posix/shared/desmume_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const gchar *desmume_old_config_file = ".desmume.ini";
static const gchar *desmume_config_dir = "desmume";
static const gchar *desmume_config_file = "config";

GKeyFile *desmume_config_read_file(const u32 *kb_cfg)
GKeyFile *desmume_config_read_file(const u32 *kb_cfg, const char* keysection)
{
gchar *config_file, *config_dir, *old_config_file;
GKeyFile *keyfile;
Expand Down Expand Up @@ -56,7 +56,7 @@ GKeyFile *desmume_config_read_file(const u32 *kb_cfg)
g_free(old_config_file);

load_default_config(kb_cfg);
desmume_config_read_keys(keyfile);
desmume_config_read_keys(keyfile, keysection);
desmume_config_read_joykeys(keyfile);

return keyfile;
Expand Down Expand Up @@ -92,10 +92,10 @@ static gboolean desmume_config_write_file(GKeyFile *keyfile)
return ret;
}

gboolean desmume_config_update_keys(GKeyFile *keyfile)
gboolean desmume_config_update_keys(GKeyFile *keyfile, const char *section)
{
for(int i = 0; i < NB_KEYS; i++) {
g_key_file_set_integer(keyfile, "KEYS", key_names[i], keyboard_cfg[i]);
g_key_file_set_integer(keyfile, section, key_names[i], keyboard_cfg[i]);
}

return desmume_config_write_file(keyfile);
Expand All @@ -110,15 +110,15 @@ gboolean desmume_config_update_joykeys(GKeyFile *keyfile)
return desmume_config_write_file(keyfile);
}

gboolean desmume_config_read_keys(GKeyFile *keyfile)
gboolean desmume_config_read_keys(GKeyFile *keyfile, const char *section)
{
GError *error = NULL;

if (!g_key_file_has_group(keyfile, "KEYS"))
if (!g_key_file_has_group(keyfile, section))
return TRUE;

for (int i = 0; i < NB_KEYS; i++) {
keyboard_cfg[i] = g_key_file_get_integer(keyfile, "KEYS", key_names[i], &error);
keyboard_cfg[i] = g_key_file_get_integer(keyfile, section, key_names[i], &error);
if (error != NULL) {
g_error_free(error);
return FALSE;
Expand Down
12 changes: 9 additions & 3 deletions desmume/src/frontend/posix/shared/desmume_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
#ifndef _DESMUME_GTK_CONFIG
#define _DESMUME_GTK_CONFIG

GKeyFile *desmume_config_read_file(const u32 *);
GKeyFile *desmume_config_read_file(const u32 *, const char *keysection = "KEYS");
void desmume_config_dispose(GKeyFile *);

gboolean desmume_config_update_keys(GKeyFile*);
/* since GTK uses GDK keysymbols, not SDL2 ones, we need
different sections for cli/gtk frontends.
KEYS = gtk keys,
SDLKEYS = sdl2 keys
*/
gboolean desmume_config_update_keys(GKeyFile*, const char *section = "KEYS");
gboolean desmume_config_read_keys(GKeyFile*, const char *section = "KEYS");

gboolean desmume_config_update_joykeys(GKeyFile*);
gboolean desmume_config_read_keys(GKeyFile*);
gboolean desmume_config_read_joykeys(GKeyFile*);

#endif
Loading