1 /* $NetBSD: action.c,v 1.1 2003/08/06 22:11:49 jmmv Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name authors may not be used to endorse or promote products
16 * derived from this software without specific prior written
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: action.c,v 1.1 2003/08/06 22:11:49 jmmv Exp $");
38 #include <sys/ioctl.h>
40 #include <sys/types.h>
42 #include <dev/wscons/wsconsio.h>
48 #include "pathnames.h"
51 /* ---------------------------------------------------------------------- */
54 * Public interface exported by the `action' mode.
57 int action_startup(struct mouse
*m
);
58 int action_cleanup(void);
59 void action_wsmouse_event(struct wscons_event
);
61 struct mode_bootstrap Action_Mode
= {
70 /* ---------------------------------------------------------------------- */
76 static int Initialized
= 0;
78 /* ---------------------------------------------------------------------- */
81 * Prototypes for functions private to this module.
84 static void run_action(int, const char *);
86 /* ---------------------------------------------------------------------- */
88 /* Initializes the action mode. Does nothing, aside from checking it is
89 * not initialized twice. */
92 action_startup(struct mouse
*m
)
96 log_warnx("action mode already initialized");
105 /* ---------------------------------------------------------------------- */
115 /* ---------------------------------------------------------------------- */
117 /* Parses wsmouse events. Only button events are picked. */
119 action_wsmouse_event(struct wscons_event evt
)
122 if (IS_BUTTON_EVENT(evt
.type
)) {
124 case WSCONS_EVENT_MOUSE_UP
:
125 run_action(evt
.value
, "up");
128 case WSCONS_EVENT_MOUSE_DOWN
:
129 run_action(evt
.value
, "down");
133 log_warnx("unknown button event");
138 /* ---------------------------------------------------------------------- */
140 /* Executes a command. `button' specifies the number of the button that
141 * was pressed or released. `ud' contains the word `up' or `down', which
142 * specify the type of event received. */
144 run_action(int button
, const char *ud
)
150 (void)snprintf(buf
, sizeof(buf
), "button_%d_%s", button
, ud
);
152 conf
= config_get_mode("action");
153 cmd
= block_get_propval(conf
, buf
, NULL
);
155 log_info("running command `%s'", cmd
);