7c0defcd81155057afe4585d4edd634a4207cf19
[expresskeys.git] / src-expresskeys / exec_shell.c
1 /*
2  exec_shell.c -- Support ExpressKeys & Touch Strips on a Wacom Intuos3 tablet.
3
4  Copyright (C) 2005-2006 - Mats Johannesson
5
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21 #include "globals.h"
22
23 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24  Function uses the simple "system" command to execute another program in
25  a shell, waiting for it to return. Here it calls the "xsetwacom" from
26  the linuxwacom.sourceforge.net driver package. Observe that it doesn't
27  check whether the program gets executed or not, just that the shell gets
28  forked without an error.
29
30  This sample utilization of xsetwacom alters the pen sensitivity to pressure
31  just like setting the Feel -> Sensitivity in wacomcpl (the tcl utility
32  program) between Soft (lower) and Firm (higher) values (1 to 7, 4 is
33  default). Both STYLUS1_CURVE_DOWNWARD and STYLUS1_CURVE_UPWARD flip over in a
34  carousel fashion at the top and bottom values.
35  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
36
37 int call_xsetwacom(int num)
38 {
39
40         char buffer [MAXBUFFER];
41         char curve [12];
42
43         if ((num >= STYLUS1_CURVE_DOWNWARD) &&
44                 (num <= STYLUS1_CURVE_UPWARD)) {
45                 if (stylus1_info) {
46                         if (num == STYLUS1_CURVE_DOWNWARD) {
47                                 if (padstylus1_presscurve > 1) {
48                                         padstylus1_presscurve--;
49                                 } else {
50                                         padstylus1_presscurve = 7;
51                                 }
52                         }
53                         if (num == STYLUS1_CURVE_DEFAULT) {
54                                 padstylus1_presscurve = 4;
55                         }
56                         if (num == STYLUS1_CURVE_UPWARD) {
57                                 if (padstylus1_presscurve < 7) {
58                                         padstylus1_presscurve++;
59                                 } else {
60                                         padstylus1_presscurve = 1;
61                                 }
62                         }
63                         switch (padstylus1_presscurve) {
64
65                                 case 1:
66                                 sprintf(curve, "0 75 25 100");
67                                 break;
68
69                                 case 2:
70                                 sprintf(curve, "0 50 50 100");
71                                 break;
72
73                                 case 3:
74                                 sprintf(curve, "0 25 75 100");
75                                 break;
76
77                                 case 4:
78                                 sprintf(curve, "0 0 100 100");
79                                 break;
80
81                                 case 5:
82                                 sprintf(curve, "25 0 100 75");
83                                 break;
84
85                                 case 6:
86                                 sprintf(curve, "50 0 100 50");
87                                 break;
88
89                                 case 7:
90                                 sprintf(curve, "75 0 100 25");
91                                 break;
92
93                                 default:
94                                 sprintf(curve, "0 0 100 100");
95                                 break;
96
97                         }
98                         snprintf(buffer, MAXBUFFER, "xsetwacom set %s PressCurve %s", stylus1_name, curve);
99                         if ((system(buffer)) == NON_VALID) {
100                                 fprintf(stderr, "Failed to fork a shell for xsetwacom!\n");
101                         } else {
102                                 if (be_verbose) {
103                                         fprintf(stderr, "%s Sensitivity = %d PressCurve = %s\n", stylus1_name, padstylus1_presscurve, curve);
104                                 }
105                         }
106                 }
107         }
108         return 0;
109
110 }
111
112 /* End Code */
113