Search
lxdream.org :: lxdream/src/hotkeys.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/hotkeys.c
changeset 1298:d0eb2307b847
prev1072:d82e04e6d497
author nkeynes
date Wed Feb 04 08:38:23 2015 +1000 (5 years ago)
permissions -rw-r--r--
last change Fix assorted compile warnings reported by Clang
file annotate diff log raw
nkeynes@1015
     1
/**
nkeynes@1072
     2
 * $Id$
nkeynes@1015
     3
 *
nkeynes@1015
     4
 * Handles hotkeys for pause/continue, save states, quit, etc
nkeynes@1015
     5
 *
nkeynes@1015
     6
 * Copyright (c) 2009 wahrhaft
nkeynes@1015
     7
 *
nkeynes@1015
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@1015
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@1015
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@1015
    11
 * (at your option) any later version.
nkeynes@1015
    12
 *
nkeynes@1015
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@1015
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1015
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@1015
    16
 * GNU General Public License for more details.
nkeynes@1015
    17
 */
nkeynes@1015
    18
#include <assert.h>
nkeynes@1015
    19
#include <glib.h>
nkeynes@1015
    20
#include <sys/stat.h>
nkeynes@1015
    21
#include <stdint.h>
nkeynes@1015
    22
#include <stdlib.h>
nkeynes@1015
    23
#include "lxdream.h"
nkeynes@1015
    24
#include "dreamcast.h"
nkeynes@1015
    25
#include "display.h"
nkeynes@1015
    26
#include "hotkeys.h"
nkeynes@1015
    27
#include "gui.h"
nkeynes@1015
    28
#include "config.h"
nkeynes@1015
    29
nkeynes@1072
    30
static void hotkey_key_callback( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown );
nkeynes@1015
    31
nkeynes@1072
    32
#define TAG_RESUME 0
nkeynes@1072
    33
#define TAG_STOP 1
nkeynes@1072
    34
#define TAG_RESET 2
nkeynes@1072
    35
#define TAG_EXIT 3
nkeynes@1072
    36
#define TAG_SAVE 4
nkeynes@1072
    37
#define TAG_LOAD 5
nkeynes@1072
    38
#define TAG_SELECT(i) (6+(i))
nkeynes@1015
    39
nkeynes@1072
    40
struct lxdream_config_group hotkeys_group = {
nkeynes@1072
    41
    "hotkeys", input_keygroup_changed, hotkey_key_callback, NULL, {
nkeynes@1072
    42
        {"resume", N_("Resume emulation"), CONFIG_TYPE_KEY, NULL, TAG_RESUME },
nkeynes@1072
    43
        {"stop", N_("Stop emulation"), CONFIG_TYPE_KEY, NULL, TAG_STOP },
nkeynes@1072
    44
        {"reset", N_("Reset emulator"), CONFIG_TYPE_KEY, NULL, TAG_RESET },
nkeynes@1072
    45
        {"exit", N_("Exit emulator"), CONFIG_TYPE_KEY, NULL, TAG_EXIT },
nkeynes@1072
    46
        {"save", N_("Save current quick save"), CONFIG_TYPE_KEY, NULL, TAG_SAVE },
nkeynes@1072
    47
        {"load", N_("Load current quick save"), CONFIG_TYPE_KEY, NULL, TAG_LOAD },
nkeynes@1072
    48
        {"state0", N_("Select quick save state 0"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(0) },
nkeynes@1072
    49
        {"state1", N_("Select quick save state 1"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(1) },
nkeynes@1072
    50
        {"state2", N_("Select quick save state 2"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(2) },
nkeynes@1072
    51
        {"state3", N_("Select quick save state 3"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(3) },
nkeynes@1072
    52
        {"state4", N_("Select quick save state 4"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(4) },
nkeynes@1072
    53
        {"state5", N_("Select quick save state 5"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(5) },
nkeynes@1072
    54
        {"state6", N_("Select quick save state 6"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(6) },
nkeynes@1072
    55
        {"state7", N_("Select quick save state 7"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(7) },
nkeynes@1072
    56
        {"state8", N_("Select quick save state 8"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(8) },
nkeynes@1072
    57
        {"state9", N_("Select quick save state 9"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(9) },
nkeynes@1072
    58
        {NULL, CONFIG_TYPE_NONE}} };
nkeynes@1015
    59
nkeynes@1038
    60
void hotkeys_init() 
nkeynes@1038
    61
{
nkeynes@1015
    62
    hotkeys_register_keys();
nkeynes@1015
    63
}
nkeynes@1015
    64
nkeynes@1015
    65
void hotkeys_register_keys()
nkeynes@1015
    66
{
nkeynes@1072
    67
    input_register_keygroup( &hotkeys_group );
nkeynes@1015
    68
}
nkeynes@1015
    69
nkeynes@1015
    70
void hotkeys_unregister_keys()
nkeynes@1015
    71
{
nkeynes@1072
    72
    input_unregister_keygroup( &hotkeys_group );
nkeynes@1072
    73
}
nkeynes@1072
    74
nkeynes@1072
    75
lxdream_config_group_t hotkeys_get_config()
nkeynes@1072
    76
{
nkeynes@1072
    77
    return &hotkeys_group;
nkeynes@1072
    78
}
nkeynes@1072
    79
nkeynes@1072
    80
static void hotkey_key_callback( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown )
nkeynes@1072
    81
{
nkeynes@1072
    82
    if( isKeyDown ) {
nkeynes@1072
    83
        switch(value) {
nkeynes@1072
    84
        case TAG_RESUME:
nkeynes@1072
    85
            if( !dreamcast_is_running() )
nkeynes@1072
    86
                gui_do_later(dreamcast_run);
nkeynes@1072
    87
            break;
nkeynes@1072
    88
        case TAG_STOP:
nkeynes@1072
    89
            if( dreamcast_is_running() )
nkeynes@1072
    90
                gui_do_later(dreamcast_stop);
nkeynes@1072
    91
            break;
nkeynes@1072
    92
        case TAG_RESET:
nkeynes@1072
    93
            dreamcast_reset();
nkeynes@1072
    94
            break;
nkeynes@1072
    95
        case TAG_EXIT:
nkeynes@1072
    96
            dreamcast_shutdown();
nkeynes@1072
    97
            exit(0);
nkeynes@1072
    98
            break;
nkeynes@1072
    99
        case TAG_SAVE:
nkeynes@1072
   100
            dreamcast_quick_save();
nkeynes@1072
   101
            break;
nkeynes@1072
   102
        case TAG_LOAD:
nkeynes@1072
   103
            dreamcast_quick_load();
nkeynes@1072
   104
            break;
nkeynes@1072
   105
        default:
nkeynes@1072
   106
            dreamcast_set_quick_state(value- TAG_SELECT(0) );
nkeynes@1072
   107
            break;
nkeynes@1072
   108
        }
nkeynes@1015
   109
    }
nkeynes@1015
   110
}
.