1
/***************************************************************************
2
* Copyright (C) 2008~2010 by wind (xihe) *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#ifdef FCITX_HAVE_CONFIG_H
29
#include <sys/socket.h>
30
#include <sys/types.h>
37
#include "fcitx/frontend.h"
38
#include "fcitx-utils/utils.h"
40
int create_socket(const char *name)
45
struct sockaddr_un uds_addr;
47
fd = socket(AF_UNIX, SOCK_STREAM, 0);
53
/* setup address struct */
54
memset(&uds_addr, 0, sizeof(uds_addr));
56
uds_addr.sun_family = AF_UNIX;
58
strcpy(uds_addr.sun_path, name);
60
r = connect(fd, (struct sockaddr *) & uds_addr, sizeof(uds_addr));
71
printf("Usage: fcitx-remote [OPTION]\n"
72
"\t-c\t\tinactivate input method\n"
73
"\t-o\t\tactivate input method\n"
74
"\t-r\t\treload fcitx config\n"
75
"\t-t,-T\t\tswitch Active/Inactive\n"
76
"\t[no option]\tdisplay fcitx state, %d for close, %d for inactive, %d for acitve\n"
77
"\t-h\t\tdisplay this help and exit\n",
78
IS_CLOSED, IS_INACTIVE, IS_ACTIVE);
81
int main(int argc, char *argv[])
83
char *socketfile = NULL;
89
while ((c = getopt(argc, argv, "chortT")) != -1) {
118
asprintf(&socketfile, "/tmp/fcitx-socket-:%d", fcitx_utils_get_display_number());
120
socket_fd = create_socket(socketfile);
123
fprintf(stderr, "Can't open socket %s: %s\n", socketfile, strerror(errno));
130
write(socket_fd, &o, sizeof(o));
132
read(socket_fd, &buf, sizeof(buf));
136
write(socket_fd, &o, sizeof(o));
141
} /* ---------- end of function main ---------- */
144
// kate: indent-mode cstyle; space-indent on; indent-width 4;