4 * Copyright (c) Tuomo Valkonen 1999-2001.
5 * See the included file LICENSE for details.
21 static void waitrelease(WScreen
*screen
);
25 void adhoc_insstr(WEdln
*wedln
, XKeyEvent
*ev
)
27 static XComposeStatus cs
={NULL
, 0};
33 if(wedln
->input
.win
.xic
!=NULL
){
34 if(XFilterEvent((XEvent
*)ev
, ev
->window
))
36 n
=XmbLookupString(wedln
->input
.win
.xic
, ev
, buf
, 16, &ksym
, &stat
);
38 n
=XLookupString(ev
, buf
, 16, &ksym
, &cs
);
41 if(n
<=0 || *(uchar
*)buf
<32)
44 edln_insstr(&(wedln
->edln
), buf
);
47 static WBinding
*lookup_binding_from_event(WWindow
*thing
, XKeyEvent
*ev
)
52 bindptr
=&thing
->bindmap
;
53 assert(*bindptr
!=NULL
);
55 binding
=lookup_binding(*bindptr
, ACT_KEYPRESS
, ev
->state
, ev
->keycode
);
60 * the return values are those expected by GrabHandler's, i.e.
61 * you can just pass through the retval obtained from this function
63 static bool dispatch_binding(WThing
*thing
, WBinding
*binding
, XKeyEvent
*ev
)
68 /* Get the screen now for waitrel grab - the thing might
69 * have been destroyed when call_binding returns.
72 call_binding(binding
, thing
);
73 if(ev
->state
!=0 && binding
->waitrel
){
75 /* return FALSE here to prevent uninstalling the waitrelease handler
76 immediately after establishing it */
83 static void send_key(XEvent
*ev
, WClientWin
*cwin
)
87 ev
->xkey
.subwindow
=None
;
88 XSendEvent(wglobal
.dpy
, win
, False
, KeyPressMask
, ev
);
92 static bool quote_next_handler(WThing
*thing
, XEvent
*xev
)
94 XKeyEvent
*ev
=&xev
->xkey
;
95 if(ev
->type
==KeyRelease
)
97 if(ismod(ev
->keycode
))
99 assert(WTHING_IS(thing
, WClientWin
));
100 send_key(xev
, (WClientWin
*)thing
);
101 return TRUE
; /* remove the grab */
104 void quote_next(WClient
*client
)
106 WClientWin
*cwin
=LAST_THING(client
, WClientWin
);
111 grab_establish((WThing
*)cwin
, quote_next_handler
, FocusChangeMask
);
114 static bool waitrelease_handler(WThing
*thing
, XEvent
*ev
)
116 if(!unmod(ev
->xkey
.state
, ev
->xkey
.keycode
))
121 static void waitrelease(WScreen
*screen
)
123 grab_establish((WThing
*)screen
, waitrelease_handler
, FocusChangeMask
);
126 static bool submapgrab_handler(WThing
*thing
, XEvent
*ev
)
130 /*if(ev->type==KeyRelease)
133 binding
=lookup_binding_from_event((WWindow
*)thing
, &ev
->xkey
);
136 if(ismod(ev
->xkey
.keycode
)){
140 return dispatch_binding(thing
, binding
, &ev
->xkey
);
143 static void submapgrab(WThing
*thing
)
145 grab_establish(thing
, submapgrab_handler
, FocusChangeMask
|KeyReleaseMask
);
148 void handle_keypress(XKeyEvent
*ev
)
152 WBinding
*binding
=NULL
;
157 /* this function gets called with grab_holder==NULL */
159 thing
=FIND_WINDOW(ev
->window
);
160 if(thing
==NULL
|| !WTHING_IS(thing
, WWindow
))
163 toplvl
=WTHING_IS(thing
, WFrame
);
164 bindptr
=&(((WWindow
*)thing
)->bindmap
);
166 while((*bindptr
)->parent
!=NULL
){
168 *bindptr
=(*bindptr
)->parent
;
171 binding
=lookup_binding_from_event((WWindow
*)thing
, ev
);
174 if(binding
!=NULL
&& binding
->submap
!=NULL
){
175 *bindptr
=binding
->submap
;
183 dispatch_binding(thing
, binding
, ev
);
185 if(topmap
&& WTHING_IS(thing
, WEdln
))
186 adhoc_insstr((WEdln
*)thing
, ev
);