]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.sbin/sysinstall/mouse.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / usr.sbin / sysinstall / mouse.c
1 /*-
2  * Copyright (c) 1998 Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote 
14  *    products derived from this software without specific prior written 
15  *    permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHRO AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHRO OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #include "sysinstall.h"
33 #include <string.h>
34
35 int
36 mousedTest(dialogMenuItem *self)
37 {
38         char *type;
39         char *port;
40         char *flags;
41         int ret;
42
43         type = variable_get(VAR_MOUSED_TYPE);
44         port = variable_get(VAR_MOUSED_PORT);
45         flags = variable_get(VAR_MOUSED_FLAGS);
46         if ((type == NULL) || (port == NULL) 
47                 || (strlen(type) <= 0) || (strlen(port) <= 0)
48                 || (strcmp(type, "NO") == 0)) {
49                 msgConfirm("Please select a mouse protocol and a port first.");
50                 return DITEM_FAILURE;
51         }
52
53         msgNotify("Trying to start the mouse daemon...");
54         if (file_readable("/var/run/moused.pid"))
55             vsystem("kill `cat /var/run/moused.pid`");
56         systemExecute("vidcontrol -m on");
57         if (flags != NULL)
58             vsystem("moused -t %s -p %s %s", type, port, flags);
59         else
60             vsystem("moused -t %s -p %s", type, port);
61
62         ret = msgYesNo("Now move the mouse and see if it works.\n"
63               "(Note that buttons don't have any effect for now.)\n\n"
64               "         Is the mouse cursor moving?\n");
65         systemExecute("vidcontrol -m off");
66         if (ret) {
67                 if (file_readable("/var/run/moused.pid"))
68                     vsystem("kill `cat /var/run/moused.pid`");
69                 variable_set2(VAR_MOUSED, "NO", 1);
70         } else {
71                 variable_set2(VAR_MOUSED, "YES", 1);
72                 vsystem("ln -fs /dev/sysmouse /dev/mouse"); /* backwards compat */
73         }
74
75         return DITEM_SUCCESS | DITEM_RESTORE;
76 }
77
78 int
79 mousedDisable(dialogMenuItem *self)
80 {
81         if (file_readable("/var/run/moused.pid"))
82             vsystem("kill `cat /var/run/moused.pid`");
83         variable_set2(VAR_MOUSED, "NO", 1);
84         variable_set2(VAR_MOUSED_TYPE, "NO", 1);
85         variable_unset(VAR_MOUSED_PORT);
86         variable_unset(VAR_MOUSED_FLAGS);
87         msgConfirm("The mouse daemon is disabled.");
88         return DITEM_SUCCESS;
89 }
90
91 int 
92 setMouseFlags(dialogMenuItem *self)
93 {
94     int ret;
95     ret = variable_get_value(VAR_MOUSED_FLAGS,
96                              "Please Specify the mouse daemon flags.  If you would like to\n"
97                              "emulate 3 buttons, use -3 here.\n", 1)
98         ? DITEM_SUCCESS : DITEM_FAILURE;
99     if (ret != DITEM_SUCCESS)
100         variable_unset(VAR_MOUSED_FLAGS);
101     return ret;
102 }
103