oxim_main.c#1.28
来自「linux 下的 oxim 输入法,简单易用.」· 28 代码 · 共 210 行
28
210 行
/* Copyright (C) 1999 by XCIN TEAM This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/ #ifdef HAVE_CONFIG_H# include "config.h"#endif#ifdef HPUX# define _INCLUDE_POSIX_SOURCE#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <unistd.h>#include <X11/Xlocale.h>#include <X11/Xlib.h>#include <X11/Xatom.h>#include <X11/Xft/Xft.h>#include <signal.h>#include "oximtool.h"#include "oxim.h"#include "fkey.h"int verbose, errstatus;static xccore_t oxim_core; /* OXIM kernel data. */void gui_init(xccore_t *xccore);void gui_loop(xccore_t *xccore);void xim_init(xccore_t *xccore);void gui_init_xft(void);/*---------------------------------------------------------------------------- Initial Input.----------------------------------------------------------------------------*/static voidoxim_setlocale(void){ char loc_return[128], enc_return[128]; oxim_set_perr("oxim"); oxim_set_lc_ctype("", loc_return, 128, enc_return, 128, OXIMMSG_ERROR); oxim_core.lc_ctype = (char *)strdup(loc_return); oxim_set_lc_messages("", loc_return, 128); if (XSupportsLocale() != True) oxim_perr(OXIMMSG_ERROR, N_("X locale \"%s\" is not supported by your system.\n"), oxim_core.lc_ctype);}static voidprint_usage(void){ oxim_perr(OXIMMSG_EMPTY, N_("OXIM (Open X Input Method) version %s.\n" "(module ver: %s).\n"), PACKAGE_VERSION, MODULE_VERSION); oxim_perr(OXIMMSG_EMPTY, _("\n" "Usage: oxim [-h] [-d DISPLAY] [-x XIM_name] [-v n] [-r]\n" "Options: -h: print this message.\n" " -d: set X Display.\n" " -x: register XIM server name to Xlib.\n" " -v: set debug level to n.\n" " -r: reload oxim.\n\n"));}static voidcommand_switch(int argc, char **argv)/* Command line arguements. */{ int rev;#ifdef HPUX extern char *optarg; extern int opterr, optopt;#endif/* * Command line arguement & preparing for oxim_rc_t. */ bzero(&oxim_core, sizeof(xccore_t)); oxim_setlocale(); opterr = 0; Display *dpy; Window win; while ((rev = getopt(argc, argv, "hd:x:v:r")) != EOF) { switch (rev) { case 'h': print_usage(); exit(0); case 'd': strncpy(oxim_core.display_name, optarg, sizeof(oxim_core.display_name)); break; case 'x': strncpy(oxim_core.xim_name, optarg, sizeof(oxim_core.xim_name)); break; case 'v': verbose = atoi(optarg); break; case 'r': if (! (dpy = XOpenDisplay(oxim_core.display_name))) { oxim_perr(OXIMMSG_ERROR, N_("cannot open display: %s\n"), oxim_core.display_name); } Atom oxim_atom = XInternAtom(dpy, OXIM_ATOM, True); win = XGetSelectionOwner(dpy, oxim_atom); if (oxim_atom != None && win != None ) { XClientMessageEvent event; event.type = ClientMessage; event.window = win; event.message_type = oxim_atom; event.format = 32; event.data.l[0] = OXIM_CMD_RELOAD; XSendEvent(dpy, win, False, 0, (XEvent *)&event); XSync(dpy, False); } exit(0); break; case '?': oxim_perr(OXIMMSG_ERROR, N_("unknown option -%c.\n"), optopt); break; } }/* * OXIM perface. */ oxim_perr(OXIMMSG_EMPTY, N_("OXIM (Open X Input Method) version %s.\n" "(use \"-h\" option for help)\n"), PACKAGE_VERSION); oxim_perr(OXIMMSG_NORMAL, N_("locale \"%s\"\n"), oxim_core.lc_ctype);}/*---------------------------------------------------------------------------- Main Program.----------------------------------------------------------------------------*/void xim_terminate(void);void sighandler(int sig){ if (sig == SIGQUIT) { DebugLog(1, ("catch signal: SIGQUIT\n")); } else if (sig == SIGTERM) { DebugLog(1, ("catch signal: SIGTERM\n")); } else { DebugLog(1, ("catch signal: SIGINT\n")); } if (sig == SIGQUIT) return; if (oxim_core.ic != NULL && (oxim_core.ic->ic_state & IC_FOCUS)) oxim_core.oxim_mode |= OXIM_RUN_KILL; else { xim_terminate(); exit(0); }}intmain(int argc, char **argv){ command_switch(argc, argv); signal(SIGQUIT, sighandler); signal(SIGTERM, sighandler); signal(SIGINT, sighandler); /* 初始化 OXIM */ oxim_init(); gui_init(&oxim_core); xim_init(&oxim_core); gui_loop(&oxim_core); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?