Rewrite of the userbutton shortcut handling: now parsing shortcut string in
gui init and string paramter handler. The shortcut keys are now stored in an array of BX_KEY* values in the gui object. siminterface.h: Fixed some default return values.
This commit is contained in:
parent
3d08187563
commit
894e66574a
@ -119,9 +119,13 @@ const char *bx_param_string_handler(bx_param_string_c *param, int set,
|
|||||||
|
|
||||||
param->get_param_path(pname, BX_PATHNAME_LEN);
|
param->get_param_path(pname, BX_PATHNAME_LEN);
|
||||||
if (!strcmp(pname, BXPN_SCREENMODE)) {
|
if (!strcmp(pname, BXPN_SCREENMODE)) {
|
||||||
if (set==1) {
|
if (set == 1) {
|
||||||
BX_INFO(("Screen mode changed to %s", val));
|
BX_INFO(("Screen mode changed to %s", val));
|
||||||
}
|
}
|
||||||
|
} else if (!strcmp(pname, BXPN_USER_SHORTCUT)) {
|
||||||
|
if ((set == 1) && (SIM->get_init_done())) {
|
||||||
|
bx_gui->parse_user_shortcut(val);
|
||||||
|
}
|
||||||
#if BX_PLUGINS
|
#if BX_PLUGINS
|
||||||
} else if (!strncmp(pname, "misc.user_plugin", 16)) {
|
} else if (!strncmp(pname, "misc.user_plugin", 16)) {
|
||||||
if ((strlen(oldval) > 0) && (strcmp(oldval, "none"))) {
|
if ((strlen(oldval) > 0) && (strcmp(oldval, "none"))) {
|
||||||
@ -1002,11 +1006,12 @@ void bx_init_options()
|
|||||||
deplist->add(keymap);
|
deplist->add(keymap);
|
||||||
use_kbd_mapping->set_dependent_list(deplist);
|
use_kbd_mapping->set_dependent_list(deplist);
|
||||||
|
|
||||||
new bx_param_string_c(keyboard,
|
bx_param_string_c *user_shortcut = new bx_param_string_c(keyboard,
|
||||||
"user_shortcut",
|
"user_shortcut",
|
||||||
"Userbutton shortcut",
|
"Userbutton shortcut",
|
||||||
"Defines the keyboard shortcut to be sent when you press the 'user' button in the headerbar.",
|
"Defines the keyboard shortcut to be sent when you press the 'user' button in the headerbar.",
|
||||||
"none", 20);
|
"none", 20);
|
||||||
|
user_shortcut->set_handler(bx_param_string_handler);
|
||||||
|
|
||||||
static const char *mouse_type_list[] = {
|
static const char *mouse_type_list[] = {
|
||||||
"none",
|
"none",
|
||||||
|
@ -241,6 +241,10 @@ void bx_gui_c::init(int argc, char **argv, unsigned max_xres, unsigned max_yres,
|
|||||||
BX_GRAVITY_RIGHT, userbutton_handler);
|
BX_GRAVITY_RIGHT, userbutton_handler);
|
||||||
BX_GUI_THIS set_tooltip(BX_GUI_THIS user_hbar_id, "Send keyboard shortcut");
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS user_hbar_id, "Send keyboard shortcut");
|
||||||
|
|
||||||
|
if (!parse_user_shortcut(SIM->get_param_string(BXPN_USER_SHORTCUT)->getptr())) {
|
||||||
|
SIM->get_param_string(BXPN_USER_SHORTCUT)->set("none");
|
||||||
|
}
|
||||||
|
|
||||||
BX_GUI_THIS charmap_updated = 0;
|
BX_GUI_THIS charmap_updated = 0;
|
||||||
|
|
||||||
if (!BX_GUI_THIS new_gfx_api && (BX_GUI_THIS framebuffer == NULL)) {
|
if (!BX_GUI_THIS new_gfx_api && (BX_GUI_THIS framebuffer == NULL)) {
|
||||||
@ -657,49 +661,50 @@ Bit32u get_user_key(char *key)
|
|||||||
return BX_KEY_UNKNOWN;
|
return BX_KEY_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bx_bool bx_gui_c::parse_user_shortcut(const char *val)
|
||||||
|
{
|
||||||
|
char *ptr, shortcut_tmp[512];
|
||||||
|
Bit32u symbol;
|
||||||
|
|
||||||
|
user_shortcut_len = 0;
|
||||||
|
if ((strlen(val) == 0) || !strcmp(val, "none")) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
strcpy(shortcut_tmp, val);
|
||||||
|
ptr = strtok(shortcut_tmp, "-");
|
||||||
|
while (ptr) {
|
||||||
|
symbol = get_user_key(ptr);
|
||||||
|
if (symbol == BX_KEY_UNKNOWN) {
|
||||||
|
BX_ERROR(("Unknown key symbol '%s' ignored", ptr));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (user_shortcut_len < 3) {
|
||||||
|
user_shortcut[user_shortcut_len++] = symbol;
|
||||||
|
ptr = strtok(NULL, "-");
|
||||||
|
} else {
|
||||||
|
BX_ERROR(("Ignoring extra key symbol '%s'", ptr));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void bx_gui_c::userbutton_handler(void)
|
void bx_gui_c::userbutton_handler(void)
|
||||||
{
|
{
|
||||||
Bit32u shortcut[4];
|
int i, ret = 1;
|
||||||
Bit32u symbol;
|
|
||||||
bx_param_string_c *sparam;
|
|
||||||
char user_shortcut[512];
|
|
||||||
char *ptr;
|
|
||||||
int i, len = 0, ret = 1;
|
|
||||||
|
|
||||||
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_USER) {
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_USER) {
|
||||||
ret = SIM->ask_param(BXPN_USER_SHORTCUT);
|
ret = SIM->ask_param(BXPN_USER_SHORTCUT);
|
||||||
}
|
}
|
||||||
sparam = SIM->get_param_string(BXPN_USER_SHORTCUT);
|
if ((ret > 0) && (BX_GUI_THIS user_shortcut_len > 0)) {
|
||||||
if ((ret > 0) && !sparam->isempty()) {
|
|
||||||
strcpy(user_shortcut, sparam->getptr());
|
|
||||||
ptr = strtok(user_shortcut, "-");
|
|
||||||
if ((strcmp(ptr, sparam->getptr())) ||
|
|
||||||
(strlen(sparam->getptr()) < 7)) {
|
|
||||||
while (ptr) {
|
|
||||||
symbol = get_user_key(ptr);
|
|
||||||
if (symbol == BX_KEY_UNKNOWN) {
|
|
||||||
BX_ERROR(("Unknown shortcut '%s' ignored", ptr));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (len < 3) {
|
|
||||||
shortcut[len++] = symbol;
|
|
||||||
ptr = strtok(NULL, "-");
|
|
||||||
} else {
|
|
||||||
BX_ERROR(("Ignoring extra key symbol '%s'", ptr));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
BX_ERROR(("Unknown shortcut '%s' ignored", user_shortcut));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < len) {
|
while (i < BX_GUI_THIS user_shortcut_len) {
|
||||||
DEV_kbd_gen_scancode(shortcut[i++]);
|
DEV_kbd_gen_scancode(BX_GUI_THIS user_shortcut[i++]);
|
||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
while (i >= 0) {
|
while (i >= 0) {
|
||||||
DEV_kbd_gen_scancode(shortcut[i--] | BX_KEY_RELEASED);
|
DEV_kbd_gen_scancode(BX_GUI_THIS user_shortcut[i--] | BX_KEY_RELEASED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,7 @@ public:
|
|||||||
static void toggle_mouse_enable(void);
|
static void toggle_mouse_enable(void);
|
||||||
bx_bool mouse_toggle_check(Bit32u key, bx_bool pressed);
|
bx_bool mouse_toggle_check(Bit32u key, bx_bool pressed);
|
||||||
const char* get_toggle_info(void);
|
const char* get_toggle_info(void);
|
||||||
|
bx_bool parse_user_shortcut(const char *val);
|
||||||
#if BX_DEBUGGER && BX_DEBUGGER_GUI
|
#if BX_DEBUGGER && BX_DEBUGGER_GUI
|
||||||
void init_debug_dialog(void);
|
void init_debug_dialog(void);
|
||||||
void close_debug_dialog(void);
|
void close_debug_dialog(void);
|
||||||
@ -244,6 +245,9 @@ protected:
|
|||||||
Bit8u toggle_method;
|
Bit8u toggle_method;
|
||||||
Bit32u toggle_keystate;
|
Bit32u toggle_keystate;
|
||||||
char mouse_toggle_text[20];
|
char mouse_toggle_text[20];
|
||||||
|
// userbutton shortcut
|
||||||
|
Bit32u user_shortcut[4];
|
||||||
|
int user_shortcut_len;
|
||||||
// gui dialog capabilities
|
// gui dialog capabilities
|
||||||
Bit32u dialog_caps;
|
Bit32u dialog_caps;
|
||||||
};
|
};
|
||||||
|
@ -633,8 +633,8 @@ public:
|
|||||||
bx_simulator_interface_c() {}
|
bx_simulator_interface_c() {}
|
||||||
virtual ~bx_simulator_interface_c() {}
|
virtual ~bx_simulator_interface_c() {}
|
||||||
virtual void set_quit_context(jmp_buf *context) {}
|
virtual void set_quit_context(jmp_buf *context) {}
|
||||||
virtual int get_init_done() { return -1; }
|
virtual int get_init_done() { return 0; }
|
||||||
virtual int set_init_done(int n) {return -1;}
|
virtual int set_init_done(int n) {return 0;}
|
||||||
virtual void reset_all_param() {}
|
virtual void reset_all_param() {}
|
||||||
// new param methods
|
// new param methods
|
||||||
virtual bx_param_c *get_param(const char *pname, bx_param_c *base=NULL) {return NULL;}
|
virtual bx_param_c *get_param(const char *pname, bx_param_c *base=NULL) {return NULL;}
|
||||||
@ -644,15 +644,15 @@ public:
|
|||||||
virtual bx_param_enum_c *get_param_enum(const char *pname, bx_param_c *base=NULL) {return NULL;}
|
virtual bx_param_enum_c *get_param_enum(const char *pname, bx_param_c *base=NULL) {return NULL;}
|
||||||
virtual unsigned gen_param_id() {return 0;}
|
virtual unsigned gen_param_id() {return 0;}
|
||||||
virtual int get_n_log_modules() {return -1;}
|
virtual int get_n_log_modules() {return -1;}
|
||||||
virtual const char *get_logfn_name(int mod) {return 0;}
|
virtual const char *get_logfn_name(int mod) {return NULL;}
|
||||||
virtual int get_logfn_id(const char *name) {return -1;}
|
virtual int get_logfn_id(const char *name) {return -1;}
|
||||||
virtual const char *get_prefix(int mod) {return 0;}
|
virtual const char *get_prefix(int mod) {return NULL;}
|
||||||
virtual int get_log_action(int mod, int level) {return -1;}
|
virtual int get_log_action(int mod, int level) {return -1;}
|
||||||
virtual void set_log_action(int mod, int level, int action) {}
|
virtual void set_log_action(int mod, int level, int action) {}
|
||||||
virtual int get_default_log_action(int level) {return -1;}
|
virtual int get_default_log_action(int level) {return -1;}
|
||||||
virtual void set_default_log_action(int level, int action) {}
|
virtual void set_default_log_action(int level, int action) {}
|
||||||
virtual const char *get_action_name(int action) {return 0;}
|
virtual const char *get_action_name(int action) {return NULL;}
|
||||||
virtual const char *get_log_level_name(int level) {return 0;}
|
virtual const char *get_log_level_name(int level) {return NULL;}
|
||||||
virtual int get_max_log_level() {return -1;}
|
virtual int get_max_log_level() {return -1;}
|
||||||
|
|
||||||
// exiting is somewhat complicated! The preferred way to exit bochs is
|
// exiting is somewhat complicated! The preferred way to exit bochs is
|
||||||
|
Loading…
Reference in New Issue
Block a user