0
|
1 #ifndef lint
|
|
2 static char rcs_id[] = "$Id: killxwnmo.c,v 1.2 2001/06/14 18:16:16 ura Exp $";
|
|
3 #endif /* lint */
|
|
4
|
|
5 /*
|
|
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
7 * This file is part of FreeWnn.
|
|
8 *
|
|
9 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
10 * Copyright 1992 by Massachusetts Institute of Technology
|
|
11 *
|
|
12 * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.jp>
|
|
13 *
|
|
14 * This program is free software; you can redistribute it and/or modify
|
|
15 * it under the terms of the GNU General Public License as published by
|
|
16 * the Free Software Foundation; either version 2, or (at your option)
|
|
17 * any later version.
|
|
18 *
|
|
19 * This program is distributed in the hope that it will be useful,
|
|
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 * GNU General Public License for more details.
|
|
23 *
|
|
24 * You should have received a copy of the GNU General Public License
|
|
25 * along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
27 *
|
|
28 * Commentary:
|
|
29 *
|
|
30 * Change log:
|
|
31 *
|
|
32 * Last modified date: 8,Feb.1999
|
|
33 *
|
|
34 * Code:
|
|
35 *
|
|
36 */
|
|
37 #include <signal.h>
|
|
38 #include <pwd.h>
|
|
39 #include "wnn_os.h"
|
|
40 #include <X11/Xlib.h>
|
|
41 #include <X11/Xatom.h>
|
|
42 #include "commonhd.h"
|
|
43 #include "sdefine.h"
|
|
44
|
|
45 void
|
|
46 signal_catch ()
|
|
47 {
|
|
48 printf ("Could not get any replay from the input manager \"%s\".\n", XIM_INPUTMETHOD);
|
|
49 exit (1);
|
|
50 }
|
|
51
|
|
52 void
|
|
53 main (argc, argv)
|
|
54 int argc;
|
|
55 char **argv;
|
|
56 {
|
|
57 Display *dpy;
|
|
58 Window window, im_id;
|
|
59 XEvent event;
|
|
60 Atom atom_im, prop_id = (Atom) 0;
|
|
61 char uname[128], *p;
|
|
62 int force = 0;
|
|
63 extern int getuid ();
|
|
64
|
|
65 if (argc > 1)
|
|
66 {
|
|
67 if (argv[1][0] == '-' && argv[1][1] == '9')
|
|
68 force = 1;
|
|
69 }
|
|
70 if (!(dpy = XOpenDisplay ("")))
|
|
71 {
|
|
72 printf ("Could not open Display\n");
|
|
73 exit (1);
|
|
74 }
|
|
75 if ((atom_im = XInternAtom (dpy, XIM_INPUTMETHOD, True)) == None || (im_id = XGetSelectionOwner (dpy, atom_im)) == (Window) 0)
|
|
76 {
|
|
77 printf ("Could not find the input manager \"%s\".\n", XIM_INPUTMETHOD);
|
|
78 exit (1);
|
|
79 }
|
|
80 window = XCreateSimpleWindow (dpy, RootWindow (dpy, DefaultScreen (dpy)), 10, 10, 10, 10, 1, 0, 0);
|
|
81 prop_id = XInternAtom (dpy, "XWNMO_KILL_PROP", False);
|
|
82 if (!(p = getpwuid (getuid ())->pw_name))
|
|
83 {
|
|
84 printf ("Could not get the user name.\n");
|
|
85 exit (1);
|
|
86 }
|
|
87 strcpy (uname, p);
|
|
88 XChangeProperty (dpy, RootWindow (dpy, DefaultScreen (dpy)), prop_id, XA_STRING, 8, PropModeReplace, (unsigned char *) uname, strlen (uname));
|
|
89 event.type = ClientMessage;
|
|
90 event.xclient.format = 32;
|
|
91 event.xclient.window = window;
|
|
92 event.xclient.data.l[0] = XWNMO_KILL;
|
|
93 event.xclient.data.l[1] = window;
|
|
94 event.xclient.data.l[2] = prop_id;
|
|
95 event.xclient.data.l[3] = force;
|
|
96 XSendEvent (dpy, im_id, False, NoEventMask, &event);
|
|
97 signal (SIGALRM, signal_catch);
|
|
98 alarm (10); /* If return doesn't occur while 10 minutes, go to exit. */
|
|
99 while (1)
|
|
100 {
|
|
101 XNextEvent (dpy, &event);
|
|
102 if (event.type != ClientMessage || event.xclient.data.l[0] != XWNMO_KILL)
|
|
103 continue;
|
|
104 if (event.xclient.data.l[1] == XWNMO_KILL_OK)
|
|
105 {
|
|
106 printf ("Completed termination of the input manager \"%s\".\n", XIM_INPUTMETHOD);
|
|
107 }
|
|
108 else
|
|
109 {
|
|
110 printf ("Failed termination of the input manager \"%s\".\n", XIM_INPUTMETHOD);
|
|
111 if (event.xclient.data.l[2] == -1)
|
|
112 {
|
|
113 printf ("Because permission denied.\n");
|
|
114 }
|
|
115 else
|
|
116 {
|
|
117 printf ("Because %d client(s) connect(s) to it.\n", event.xclient.data.l[2]);
|
|
118 }
|
|
119 }
|
|
120 exit (0);
|
|
121 }
|
|
122 }
|