From 7f6078a591a2d689194de15e9b4e49a7af353ef4 Mon Sep 17 00:00:00 2001 From: gbeauche <> Date: Sat, 27 Dec 2003 10:37:30 +0000 Subject: [PATCH] Merge in Mouse Wheel support from Basilisk II. --- SheepShaver/src/Unix/prefs_editor_gtk.cpp | 35 ++++++++++++++++++++++ SheepShaver/src/Unix/prefs_unix.cpp | 4 +++ SheepShaver/src/Unix/user_strings_unix.cpp | 6 +++- SheepShaver/src/Unix/user_strings_unix.h | 7 ++++- SheepShaver/src/Unix/video_x.cpp | 29 ++++++++++++++---- 5 files changed, 74 insertions(+), 7 deletions(-) diff --git a/SheepShaver/src/Unix/prefs_editor_gtk.cpp b/SheepShaver/src/Unix/prefs_editor_gtk.cpp index e9f044e0..deda01d3 100644 --- a/SheepShaver/src/Unix/prefs_editor_gtk.cpp +++ b/SheepShaver/src/Unix/prefs_editor_gtk.cpp @@ -702,11 +702,13 @@ static void create_graphics_pane(GtkWidget *top) */ static GtkWidget *w_keycode_file; +static GtkWidget *w_mouse_wheel_lines; // Set sensitivity of widgets static void set_input_sensitive(void) { gtk_widget_set_sensitive(w_keycode_file, PrefsFindBool("keycodes")); + gtk_widget_set_sensitive(w_mouse_wheel_lines, PrefsFindInt32("mousewheelmode") == 1); } // "Use Raw Keycodes" button toggled @@ -716,6 +718,10 @@ static void tb_keycodes(GtkWidget *widget) set_input_sensitive(); } +// "Mouse Wheel Mode" selected +static void mn_wheel_page(...) {PrefsReplaceInt32("mousewheelmode", 0); set_input_sensitive();} +static void mn_wheel_cursor(...) {PrefsReplaceInt32("mousewheelmode", 1); set_input_sensitive();} + // Read settings from widgets and set preferences static void read_input_settings(void) { @@ -724,6 +730,8 @@ static void read_input_settings(void) PrefsReplaceString("keycodefile", str); else PrefsRemoveItem("keycodefile"); + + PrefsReplaceInt32("mousewheellines", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w_mouse_wheel_lines))); } // Create "Input" pane @@ -737,6 +745,33 @@ static void create_input_pane(GtkWidget *top) make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes)); w_keycode_file = make_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile"); + make_separator(box); + + static const opt_desc options[] = { + {STR_MOUSEWHEELMODE_PAGE_LAB, GTK_SIGNAL_FUNC(mn_wheel_page)}, + {STR_MOUSEWHEELMODE_CURSOR_LAB, GTK_SIGNAL_FUNC(mn_wheel_cursor)}, + {0, NULL} + }; + int wheelmode = PrefsFindInt32("mousewheelmode"), active = 0; + switch (wheelmode) { + case 0: active = 0; break; + case 1: active = 1; break; + } + menu = make_option_menu(box, STR_MOUSEWHEELMODE_CTRL, options, active); + + hbox = gtk_hbox_new(FALSE, 4); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); + + label = gtk_label_new(GetString(STR_MOUSEWHEELLINES_CTRL)); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + adj = gtk_adjustment_new(PrefsFindInt32("mousewheellines"), 1, 1000, 1, 5, 0); + w_mouse_wheel_lines = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 0.0, 0); + gtk_widget_show(w_mouse_wheel_lines); + gtk_box_pack_start(GTK_BOX(hbox), w_mouse_wheel_lines, FALSE, FALSE, 0); + set_input_sensitive(); } diff --git a/SheepShaver/src/Unix/prefs_unix.cpp b/SheepShaver/src/Unix/prefs_unix.cpp index be802718..bb0e29d6 100644 --- a/SheepShaver/src/Unix/prefs_unix.cpp +++ b/SheepShaver/src/Unix/prefs_unix.cpp @@ -32,6 +32,8 @@ prefs_desc platform_prefs_items[] = { {"ether", TYPE_STRING, false, "device name of Mac ethernet adapter"}, {"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"}, {"keycodefile", TYPE_STRING, false, "path of keycode translation file"}, + {"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"}, + {"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"}, {"dsp", TYPE_STRING, false, "audio output (dsp) device name"}, {"mixer", TYPE_STRING, false, "audio mixer device name"}, #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION @@ -100,6 +102,8 @@ void AddPlatformPrefsDefaults(void) { PrefsAddBool("keycodes", false); PrefsReplaceString("extfs", "/"); + PrefsReplaceInt32("mousewheelmode", 1); + PrefsReplaceInt32("mousewheellines", 3); PrefsAddInt32("windowmodes", 3); PrefsAddInt32("screenmodes", 0x3f); #ifdef __linux__ diff --git a/SheepShaver/src/Unix/user_strings_unix.cpp b/SheepShaver/src/Unix/user_strings_unix.cpp index 05beedd5..b4ecfeee 100644 --- a/SheepShaver/src/Unix/user_strings_unix.cpp +++ b/SheepShaver/src/Unix/user_strings_unix.cpp @@ -66,9 +66,13 @@ user_string_def platform_strings[] = { {STR_HELP_ITEM_ABOUT_GTK, "/Help/_About SheepShaver"}, {STR_DSPDEVICE_FILE_CTRL, "Audio Output Device"}, {STR_MIXERDEVICE_FILE_CTRL, "Audio Mixer Device"}, - {STR_INPUT_PANE_TITLE, "Keyboard"}, + {STR_INPUT_PANE_TITLE, "Mouse/Keyboard"}, {STR_KEYCODES_CTRL, "Use Raw Keycodes"}, {STR_KEYCODE_FILE_CTRL, "Keycode Translation File"}, + {STR_MOUSEWHEELMODE_CTRL, "Mouse Wheel Function"}, + {STR_MOUSEWHEELMODE_PAGE_LAB, "Page Up/Down"}, + {STR_MOUSEWHEELMODE_CURSOR_LAB, "Cursor Up/Down"}, + {STR_MOUSEWHEELLINES_CTRL, "Lines To Scroll"}, {STR_SUSPEND_WINDOW_TITLE, "SheepShaver suspended. Press Space to reactivate."}, {STR_VOSF_INIT_ERR, "Cannot initialize Video on SEGV signals."}, diff --git a/SheepShaver/src/Unix/user_strings_unix.h b/SheepShaver/src/Unix/user_strings_unix.h index ba0e1c88..5a0a8bcc 100644 --- a/SheepShaver/src/Unix/user_strings_unix.h +++ b/SheepShaver/src/Unix/user_strings_unix.h @@ -61,9 +61,14 @@ enum { STR_SUSPEND_WINDOW_TITLE, STR_DSPDEVICE_FILE_CTRL, STR_MIXERDEVICE_FILE_CTRL, + STR_INPUT_PANE_TITLE, STR_KEYCODES_CTRL, - STR_KEYCODE_FILE_CTRL + STR_KEYCODE_FILE_CTRL, + STR_MOUSEWHEELMODE_CTRL, + STR_MOUSEWHEELMODE_PAGE_LAB, + STR_MOUSEWHEELMODE_CURSOR_LAB, + STR_MOUSEWHEELLINES_CTRL, }; #endif diff --git a/SheepShaver/src/Unix/video_x.cpp b/SheepShaver/src/Unix/video_x.cpp index ba1f0b64..510fa751 100644 --- a/SheepShaver/src/Unix/video_x.cpp +++ b/SheepShaver/src/Unix/video_x.cpp @@ -54,6 +54,8 @@ const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; // Global variables static int32 frame_skip; +static int16 mouse_wheel_mode; +static int16 mouse_wheel_lines; static bool redraw_thread_active = false; // Flag: Redraw thread installed static pthread_t redraw_thread; // Redraw thread @@ -166,11 +168,6 @@ static bool open_window(int width, int height) // Set absolute mouse mode ADBSetRelMouseMode(false); - // Read frame skip prefs - frame_skip = PrefsFindInt32("frameskip"); - if (frame_skip == 0) - frame_skip = 1; - // Create window XSetWindowAttributes wattr; wattr.event_mask = eventmask = win_eventmask; @@ -682,6 +679,15 @@ bool VideoInit(void) // Init keycode translation keycode_init(); + // Read frame skip prefs + frame_skip = PrefsFindInt32("frameskip"); + if (frame_skip == 0) + frame_skip = 1; + + // Read mouse wheel prefs + mouse_wheel_mode = PrefsFindInt32("mousewheelmode"); + mouse_wheel_lines = PrefsFindInt32("mousewheellines"); + // Init variables private_data = NULL; cur_mode = 0; // Window 640x480 @@ -1184,6 +1190,19 @@ static void handle_events(void) unsigned int button = ((XButtonEvent *)&event)->button; if (button < 4) ADBMouseDown(button - 1); + else if (button < 6) { // Wheel mouse + if (mouse_wheel_mode == 0) { + int key = (button == 5) ? 0x79 : 0x74; // Page up/down + ADBKeyDown(key); + ADBKeyUp(key); + } else { + int key = (button == 5) ? 0x3d : 0x3e; // Cursor up/down + for(int i=0; i