1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*
Copyright (C) 1994 Edward Der-Hua Liu, Hsin-Chu, Taiwan
*/
#include "protocol.h"
#ifndef __FreeBSD__
#include <sys/stat.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include "state.h"
Window cli_win;
extern Display *display;
extern Window main_win;
extern Atom xcin_atom;
extern void p_err(char *fmt,...);
extern void switch_active_client(InmdState *state, Window cli_win);
extern void close_xcin(Window cli_win);
extern void getch(KeySym ch, int state);
extern int puts(char *s);
/*
extern void load_phrase(Window cli_win, u_long bytes_after);
*/
#define ENDIAN_TEST() (*(int *)"\x11\x22\x33\x44"==0x11223344)
char my_endian;
void init_msg_channel()
{
Window twin;
xcin_atom=XInternAtom(display,XCIN_ATOM,False);
my_endian=ENDIAN_TEST();
if ((twin=XGetSelectionOwner(display,xcin_atom))!=None) {
p_err("Xcin is already active. Win Id %x\n",twin);
}
XSetSelectionOwner(display, xcin_atom, main_win, CurrentTime);
}
int ignore_first_time=1;
#define TSIZE (256)
void message_dispatch(XClientMessageEvent *ev)
{
u_char *buf=(u_char *) &ev->data.l[0];
cli_win=ev->window;
if (ev->format==8 && buf[0]==0xff && buf[1]==0xff && buf[2]==0xff) {
if (buf[3]==CLI_FOCUS_IN)
switch_active_client((InmdState *)&buf[4],cli_win);
else
close_xcin(cli_win);
}
else
if (ev->format==32) {
#if 0
printf("key rec %x %x\n", *(int *)buf, *(int *)&buf[4]);
#endif 0
getch(* (int *)buf, *((int *)&buf[4]));
}
else
puts("error");
}
void property_dispatch(XPropertyEvent *ev)
{
Atom actual_type;
int actual_format;
u_long nitems,bytes_after;
int *cmd,cm;
Window cli_win=ev->window;
if (ev->state==PropertyDelete || cli_win==main_win) return;
if (XGetWindowProperty(display,cli_win,xcin_atom, 0, 1,
True, AnyPropertyType, &actual_type,&actual_format,
&nitems,&bytes_after,(unsigned char **)&cmd) != Success)
puts("err prop");
if (nitems==0) return;
cm=*cmd;
XFree(cmd);
/*
if (cm==LOAD_KEYWORD) {
load_phrase(cli_win, bytes_after);
} else {
puts("Unknown property");
}
*/
}
void big_little(char *i)
{
char t;
t=*i; *i=*(i+3); *(i+3)=t;
t=*(i+1); *(i+1)=*(i+2); *(i+2)=t;
}
void write_reply(char *str, int len, int status)
{
extern InmdState inmdstate;
int slen;
XCIN_RES res;
res.len=len;
res.status=status;
res.inmdstate=inmdstate;
if (my_endian) { /* the format is convert to little-endian */
big_little((char *)&res.len);
big_little((char *)&res.status);
}
memcpy(res.tkey, str, len);
slen=sizeof(res)-sizeof(res.tkey)+len;
XChangeProperty(display, main_win , xcin_atom, XA_STRING, 8,
PropModeReplace, (u_char *)&res, slen);
XSync(display,False);
}
|