From e6365974f6ff7dae6ce21143b25740c2c2e6a64c Mon Sep 17 00:00:00 2001
From: William Kendrick
Date: Mon, 31 Mar 2014 05:54:32 +0000
Subject: [PATCH] * --joystick-buttons-ignore option can be used to ignore
joystick buttons (rather than all non-command-assigned buttons being used
asi left-mouse-click) * Updated docs re: joysticks a bit.
---
docs/CHANGES.txt | 15 +++++++++------
docs/OPTIONS.txt | 10 +++++++++-
docs/html/OPTIONS.html | 11 ++++++++++-
src/manpage/tuxpaint.1 | 2 ++
src/parse.gperf | 1 +
src/parse.h | 1 +
src/tuxpaint-completion.bash | 1 +
src/tuxpaint.c | 31 +++++++++++++++++++++++++++++--
8 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt
index 226bf1654..2b2617ab9 100644
--- a/docs/CHANGES.txt
+++ b/docs/CHANGES.txt
@@ -151,18 +151,19 @@ $Id$
* ASDW is QWERTY-centric; drop it, or add ways to support other
keyboard layouts.
- * Joystick can be used to drive Tuxpaint
+ * Joystick can be used to drive Tux Paint
by Ankit Choudary (GSOC 2010)
with integration and fixes by Pere Pujal i Carabantes
- * Uses the first joystick found on the system, so should work out
- of the box.
+ * Use --joystick-dev to choose joystick (otherwise
+ uses the first joystick found on the system).
* Uses any of the buttons found in the joystick, no need for
- configuration.
- * The hat of the joystick moves one pixel at a time, usefull to
+ configuration. (--joystick-buttons-ignore can be used to
+ ignore buttons.)
+ * The hat of the joystick moves one pixel at a time, useful to
carefully place the pointer.
* The ball of the joystick should also trigger pointer
- motion. FIXME: This should work but is not tested.
+ motion.
* The responsivity of the joystick can be configured via command
line or config files:
* --joystick-slownes sets a delay at each axis motion event.
@@ -173,6 +174,8 @@ $Id$
* --joystick_maxsteps sets the maximum number of pixels that
the pointer will move at a time.
Allowed values from 1 to 7, defaults to 7.
+ * Joystick buttons can be assigned used to activate certain commands.
+ (--joystick-btn-COMMAND options)
* Magic Tool Improvememnts:
-------------------------
diff --git a/docs/OPTIONS.txt b/docs/OPTIONS.txt
index feb0f4c74..c9b33d53a 100644
--- a/docs/OPTIONS.txt
+++ b/docs/OPTIONS.txt
@@ -9,7 +9,7 @@ Options Documentation
bill@newbreedsoftware.com
http://www.tuxpaint.org/
- March 28, 2013
+ March 30, 2013
----------------------------------------------------------------------
@@ -485,6 +485,12 @@ Windows Users
Selects the joystick button number, as seen by SDL, that will
be a shortcurt to print.
+ joystick-buttons-ignore=BUTTON1,BUTTON2,...
+ A set of joystick button numbers, as seen by SDL, that should
+ be ignored. Otherwise, unless they are used by one of the
+ "joystick-btn-" options above, buttons will be seen as a mouse
+ left-click.
+
stampsize=SIZE
Use this option to force Tux Paint to set the starting size of
@@ -909,6 +915,7 @@ Windows Users
--onscreen-keyboard
--onscreen-keyboard-layout
--onscreen-keyboard-disable-change
+ --joystick-dev
--joystick-slowness
--joystick-threshold
--joystick-maxsteps
@@ -930,6 +937,7 @@ Windows Users
--joystick-btn-save
--joystick-btn-pgsetup
--joystick-btn-print
+ --joystick-buttons-ignore
--sysfonts
--alllocalefonts
--mirrorstamps
diff --git a/docs/html/OPTIONS.html b/docs/html/OPTIONS.html
index e96460c84..1289e83a2 100644
--- a/docs/html/OPTIONS.html
+++ b/docs/html/OPTIONS.html
@@ -23,7 +23,7 @@ New Breed Software
http://www.tuxpaint.org/
-March 28, 2013
+March 30, 2013
@@ -604,6 +604,13 @@ New Breed Software
Selects the joystick button number, as seen by SDL, that will be a shortcurt to print.
+ joystick-buttons-ignore=BUTTON1,BUTTON2,...
+
+ A set of joystick button numbers, as seen by SDL, that should be ignored.
+ Otherwise, unless they are used by one of the "joystick-btn-" options
+ above, buttons will be seen as a mouse left-click.
+
+
@@ -1388,6 +1395,7 @@ New Breed Software
--onscreen-keyboard
--onscreen-keyboard-layout
--onscreen-keyboard-disable-change
+ --joystick-dev
--joystick-slowness
--joystick-threshold
--joystick-maxsteps
@@ -1409,6 +1417,7 @@ New Breed Software
--joystick-btn-save
--joystick-btn-pgsetup
--joystick-btn-print
+ --joystick-buttons-ignore
--sysfonts
--alllocalefonts
--mirrorstamps
diff --git a/src/manpage/tuxpaint.1 b/src/manpage/tuxpaint.1
index 90dd29f38..767f48a01 100644
--- a/src/manpage/tuxpaint.1
+++ b/src/manpage/tuxpaint.1
@@ -113,6 +113,8 @@ tuxpaint -- "Tux Paint", a drawing program for young children.
.br
[\-\-joystick-btn-print=\fIBUTTON\fP]
.br
+[\-\-joystick-buttons-ignore=\fIBUTTON1,BUTTON2,...\fP]
+.br
[\-\-stampsize=\fISIZE\fP]
.br
[\-\-keyboard]
diff --git a/src/parse.gperf b/src/parse.gperf
index f8bc26e37..1a8ad92ec 100644
--- a/src/parse.gperf
+++ b/src/parse.gperf
@@ -180,6 +180,7 @@ joystick-btn-open, MULTI(joystick_button_open)
joystick-btn-save, MULTI(joystick_button_save)
joystick-btn-pgsetup, MULTI(joystick_button_pagesetup)
joystick-btn-print, MULTI(joystick_button_print)
+joystick-buttons-ignore, MULTI(joystick_buttons_ignore)
%%
void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const char *opt, const char *restrict src)
diff --git a/src/parse.h b/src/parse.h
index 6ff400746..3eb7dcd1d 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -80,6 +80,7 @@ struct cfginfo
const char *joystick_button_save;
const char *joystick_button_pagesetup;
const char *joystick_button_print;
+ const char *joystick_buttons_ignore;
};
diff --git a/src/tuxpaint-completion.bash b/src/tuxpaint-completion.bash
index 9a96ae549..14405aabe 100644
--- a/src/tuxpaint-completion.bash
+++ b/src/tuxpaint-completion.bash
@@ -86,6 +86,7 @@ _tuxpaint()
--joystick-btn-save \
--joystick-btn-pgsetup \
--joystick-btn-print \
+ --joystick-buttons-ignore \
--colorfile' -- $cur ) )
# We don't accept filenames on the command-line yet -bjk 2009.09.09
# else
diff --git a/src/tuxpaint.c b/src/tuxpaint.c
index c287197e4..6d6605b64 100644
--- a/src/tuxpaint.c
+++ b/src/tuxpaint.c
@@ -1080,6 +1080,8 @@ static int joystick_button_open = 255;
static int joystick_button_save = 255;
static int joystick_button_pagesetup = 255;
static int joystick_button_print = 255;
+static int joystick_buttons_ignore_len = 0;
+static int joystick_buttons_ignore[256];
static Uint32 old_hat_ticks = 0;
static int oldpos_x;
static int oldpos_y;
@@ -22082,6 +22084,22 @@ static void setup_config(char *argv[])
}
joystick_button_print = strtof(tmpcfg.joystick_button_print, NULL);
}
+ if(tmpcfg.joystick_buttons_ignore)
+ {
+ int i;
+ char * token;
+
+ token = strtok(tmpcfg.joystick_buttons_ignore, ",");
+ while (token != NULL) {
+ if (strtof(token, NULL) < 0 || strtof(token, NULL) > 254) {
+ /* FIXME: Find better exit code */
+ printf("Joystick buttons must be between 0 and 254", tmpcfg.joystick_button_print);
+ exit(1);
+ }
+ joystick_buttons_ignore[joystick_buttons_ignore_len++] = strtof(token, NULL);
+ token = strtok(NULL, ",");
+ }
+ }
/* having any of theese implies having onscreen keyboard setted */
@@ -23899,6 +23917,7 @@ static void handle_joybuttonupdown(SDL_Event event, int oldpos_x, int oldpos_y)
}
static void handle_joybuttonupdownscl(SDL_Event event, int oldpos_x, int oldpos_y, SDL_Rect real_r_tools) {
+ int i, ignore = 0;
int eby, ts;
SDL_Event ev;
@@ -24060,6 +24079,14 @@ static void handle_joybuttonupdownscl(SDL_Event event, int oldpos_x, int oldpos_
printf("result %d %d\n", ev.button.x, ev.button.y);
#endif
- SDL_PushEvent(&ev);
-}
+ /* See if it's a button we ignore */
+ for (i = 0; i < joystick_buttons_ignore_len && !ignore; i++) {
+ if (event.button.button == joystick_buttons_ignore[i]) {
+ ignore = 1;
+ }
+ }
+
+ if (!ignore)
+ SDL_PushEvent(&ev);
+}