Skip to content

Commit

Permalink
- added new config option to select mouse capture toggle method. In a…
Browse files Browse the repository at this point in the history
…ddition to

  the default Bochs method using the CTRL key and the middle mouse button there
  are now the choices CTRL+F10 (like DOSBox) and CTRL+ALT (like QEMU).
  * currently implemented in the X11 and SDL guis only
  * TODO: porting to wxWidgets and Win32, documentation updates
  • Loading branch information
vruppert committed May 16, 2010
1 parent 9c4a26d commit 4539157
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 114 deletions.
39 changes: 25 additions & 14 deletions .bochsrc
Expand Up @@ -641,23 +641,34 @@ keyboard_paste_delay: 100000

#=======================================================================
# MOUSE:
# The Bochs gui creates mouse "events" unless the 'enabled' option is
# set to 0. The hardware emulation itself is not disabled by this.
# Unless you have a particular reason for enabling the mouse by default,
# it is recommended that you leave it off. You can also toggle the mouse
# usage at runtime (control key + middle mouse button on X11, SDL,
# wxWidgets and Win32).
# With the mouse type option you can select the type of mouse to emulate.
# The default value is 'ps2'. The other choices are 'imps2' (wheel mouse
# on PS/2), 'serial', 'serial_wheel' and 'serial_msys' (one com port requires
# setting 'mode=mouse'). To connect a mouse to an USB port, see the 'usb_uhci'
# or 'usb_ohci' option (requires PCI and USB support).
# This defines parameters for the emulated mouse type, the initial status
# of the mouse capture and the runtime method to toggle it.
#
# TYPE:
# With the mouse type option you can select the type of mouse to emulate.
# The default value is 'ps2'. The other choices are 'imps2' (wheel mouse
# on PS/2), 'serial', 'serial_wheel' and 'serial_msys' (one com port requires
# setting 'mode=mouse'). To connect a mouse to an USB port, see the 'usb_uhci'
# or 'usb_ohci' option (requires PCI and USB support).
#
# ENABLED:
# The Bochs gui creates mouse "events" unless the 'enabled' option is
# set to 0. The hardware emulation itself is not disabled by this.
# Unless you have a particular reason for enabling the mouse by default,
# it is recommended that you leave it off. You can also toggle the mouse
# usage at runtime (X11, SDL, wxWidgets and Win32 - see below).
#
# TOGGLE:
# The default method to toggle the mouse capture at runtime is to press the
# CTRL key and the middle mouse button ('ctrl+mbutton'). This option allows
# to change the method to 'ctrl+f10' (like DOSBox) or 'ctrl+alt' (like QEMU).
# NOTE: currently implemented in the X11 and SDL guis only!
#
# Examples:
# mouse: enabled=1
# mouse: enabled=1, type=imps2
# mouse: enabled=1, type=serial
# mouse: enabled=0
# mouse: type=imps2, enabled=1
# mouse: type=serial, enabled=1
# mouse: enabled=0, toggle=ctrl+f10
#=======================================================================
mouse: enabled=0

Expand Down
26 changes: 22 additions & 4 deletions config.cc
@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: config.cc,v 1.203 2010/04/29 19:34:31 sshwarts Exp $
// $Id: config.cc,v 1.204 2010/05/16 09:01:36 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2009 The Bochs Project
Expand Down Expand Up @@ -229,7 +229,7 @@ void bx_init_options()
bx_list_c *deplist;
bx_param_num_c *ioaddr, *ioaddr2, *irq;
bx_param_bool_c *enabled, *status;
bx_param_enum_c *mode, *type, *ethmod;
bx_param_enum_c *mode, *type, *ethmod, *toggle;
bx_param_string_c *macaddr, *ethdev;
bx_param_filename_c *path;
char name[BX_PATHNAME_LEN], descr[512], group[16], label[512];
Expand Down Expand Up @@ -854,6 +854,20 @@ void bx_init_options()
enabled->set_handler(bx_param_handler);
enabled->set_runtime_param(1);

static const char *mouse_toggle_list[] = {
"ctrl+mbutton",
"ctrl+f10",
"ctrl+alt",
NULL
};
toggle = new bx_param_enum_c(mouse,
"toggle", "Mouse toggle method",
"The mouse toggle method can be one of these: 'ctrl+mbutton', 'ctrl+f10', 'ctrl+alt'",
mouse_toggle_list,
BX_MOUSE_TOGGLE_CTRL_MB,
BX_MOUSE_TOGGLE_CTRL_MB);
toggle->set_ask_format("Choose the mouse toggle method [%s] ");

kbd_mouse->set_options(kbd_mouse->SHOW_PARENT);
keyboard->set_options(keyboard->SHOW_PARENT);
mouse->set_options(mouse->SHOW_PARENT);
Expand Down Expand Up @@ -2821,6 +2835,9 @@ static int parse_line_formatted(const char *context, int num_params, char *param
} else if (!strncmp(params[i], "type=", 5)) {
if (!SIM->get_param_enum(BXPN_MOUSE_TYPE)->set_by_name(&params[i][5]))
PARSE_ERR(("%s: mouse type '%s' not available", context, &params[i][5]));
} else if (!strncmp(params[i], "toggle=", 7)) {
if (!SIM->get_param_enum(BXPN_MOUSE_TOGGLE)->set_by_name(&params[i][7]))
PARSE_ERR(("%s: mouse toggle method '%s' not available", context, &params[i][7]));
} else {
PARSE_ERR(("%s: mouse directive malformed.", context));
}
Expand Down Expand Up @@ -3859,9 +3876,10 @@ int bx_write_configuration(const char *rc, int overwrite)
bx_write_loader_options(fp);
bx_write_log_options(fp, (bx_list_c*) SIM->get_param("log"));
bx_write_keyboard_options(fp);
fprintf(fp, "mouse: enabled=%d, type=%s\n",
fprintf(fp, "mouse: enabled=%d, type=%s, toggle=%s\n",
SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get(),
SIM->get_param_enum(BXPN_MOUSE_TYPE)->get_selected());
SIM->get_param_enum(BXPN_MOUSE_TYPE)->get_selected(),
SIM->get_param_enum(BXPN_MOUSE_TOGGLE)->get_selected());
SIM->save_user_options(fp);
fclose(fp);
return 0;
Expand Down
48 changes: 47 additions & 1 deletion gui/gui.cc
@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: gui.cc,v 1.114 2010/02/26 14:18:18 sshwarts Exp $
// $Id: gui.cc,v 1.115 2010/05/16 09:01:36 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2009 The Bochs Project
Expand Down Expand Up @@ -117,6 +117,20 @@ void bx_gui_c::init(int argc, char **argv, unsigned tilewidth, unsigned tileheig
BX_GUI_THIS host_bpp = 8;
BX_GUI_THIS dialog_caps = BX_GUI_DLG_RUNTIME | BX_GUI_DLG_SAVE_RESTORE;

BX_GUI_THIS toggle_method = SIM->get_param_enum(BXPN_MOUSE_TOGGLE)->get();
BX_GUI_THIS toggle_keystate = 0;
switch (toggle_method) {
case BX_MOUSE_TOGGLE_CTRL_MB:
strcpy(mouse_toggle_text, "CTRL + 3rd button");
break;
case BX_MOUSE_TOGGLE_CTRL_F10:
strcpy(mouse_toggle_text, "CTRL + F10");
break;
case BX_MOUSE_TOGGLE_CTRL_ALT:
strcpy(mouse_toggle_text, "CTRL + ALT");
break;
}

specific_init(argc, argv, tilewidth, tileheight, BX_HEADER_BAR_Y);

// Define some bitmaps to use in the headerbar
Expand Down Expand Up @@ -512,6 +526,38 @@ void bx_gui_c::toggle_mouse_enable(void)
SIM->get_param_bool(BXPN_MOUSE_ENABLED)->set(!old);
}

bx_bool bx_gui_c::mouse_toggle_check(Bit32u key, bx_bool pressed)
{
Bit32u newstate;
bx_bool toggle = 0;

newstate = toggle_keystate;
if (pressed) {
newstate |= key;
if (newstate == toggle_keystate) return 0;
switch (toggle_method) {
case BX_MOUSE_TOGGLE_CTRL_MB:
toggle = (newstate & BX_GUI_MT_CTRL_MB) == BX_GUI_MT_CTRL_MB;
break;
case BX_MOUSE_TOGGLE_CTRL_F10:
toggle = (newstate & BX_GUI_MT_CTRL_F10) == BX_GUI_MT_CTRL_F10;
break;
case BX_MOUSE_TOGGLE_CTRL_ALT:
toggle = (newstate & BX_GUI_MT_CTRL_ALT) == BX_GUI_MT_CTRL_ALT;
break;
}
toggle_keystate = newstate;
} else {
toggle_keystate &= ~key;
}
return toggle;
}

const char* bx_gui_c::get_toggle_info(void)
{
return mouse_toggle_text;
}

Bit32u get_user_key(char *key)
{
int i = 0;
Expand Down
17 changes: 15 additions & 2 deletions gui/gui.h
@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: gui.h,v 1.62 2009/12/04 20:02:12 sshwarts Exp $
// $Id: gui.h,v 1.63 2010/05/16 09:01:36 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2009 The Bochs Project
Expand Down Expand Up @@ -32,6 +32,15 @@
#define BX_TEXT_BLINK_TOGGLE 0x02
#define BX_TEXT_BLINK_STATE 0x04

#define BX_MT_KEY_CTRL 0x01
#define BX_MT_KEY_ALT 0x02
#define BX_MT_KEY_F10 0x04
#define BX_MT_MBUTTON 0x08

#define BX_GUI_MT_CTRL_MB 0x09
#define BX_GUI_MT_CTRL_F10 0x05
#define BX_GUI_MT_CTRL_ALT 0x03

typedef struct {
Bit16u start_address;
Bit8u cs_start;
Expand Down Expand Up @@ -131,7 +140,8 @@ class BOCHSAPI bx_gui_c : public logfunctions {
int register_statusitem(const char *text);
static void init_signal_handlers();
static void toggle_mouse_enable(void);

bx_bool mouse_toggle_check(Bit32u key, bx_bool pressed);
const char* get_toggle_info(void);

protected:
// And these are defined and used privately in gui.cc
Expand Down Expand Up @@ -178,6 +188,9 @@ class BOCHSAPI bx_gui_c : public logfunctions {
Bit8u host_bpp;
Bit8u *framebuffer;
Bit32u dialog_caps;
Bit8u toggle_method;
Bit32u toggle_keystate;
char mouse_toggle_text[20];
};


Expand Down

0 comments on commit 4539157

Please sign in to comment.