Skip to content

Commit

Permalink
create an input context for a window when selecting KeyPress evennts and
Browse files Browse the repository at this point in the history
add all supporting for it
This allows composed characters, at least in west europ keyboards
  • Loading branch information
NotFound committed Dec 3, 2011
1 parent 267583a commit 44eced5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
63 changes: 58 additions & 5 deletions src/Guitor.winxed
Expand Up @@ -66,6 +66,7 @@ class Display
var xdisplay; var xdisplay;
var default_screen; var default_screen;
var default_font; var default_font;
var xim;


function Display(string displayname[optional]) function Display(string displayname[optional])
{ {
Expand Down Expand Up @@ -153,13 +154,33 @@ class Display
var fn = getfun("XKeysymToString"); var fn = getfun("XKeysymToString");
return string_from_nci(fn(keysym)); return string_from_nci(fn(keysym));
} }
function LookupString(event) function getIM()
{
var xim = self.xim;
if (self.xim == null) {
xim = getfun("XOpenIM")(self.xdisplay, null, null, null);
if (! xim)
xim = false;
self.xim = xim;
}
return xim;
}
function _LookupString(window, event)
{ {
const int BUFSIZE = 32; const int BUFSIZE = 32;
var fun = getfun("XLookupString");
var buffer = new ["ByteBuffer"]; var buffer = new ["ByteBuffer"];
buffer =: BUFSIZE; buffer =: BUFSIZE;
int len = fun(event.eventdata, buffer, BUFSIZE, null, null); int len;
var fun;
var xic = window.getIC();
if (xic == null || ! xic) {
fun = getfun("XLookupString");
len = fun(event.eventdata, buffer, BUFSIZE, null, null);
}
else {
fun = getfun("XmbLookupString");
len = fun(xic, event.eventdata, buffer, BUFSIZE, null, null);
}
string str; string str;
if (len > 0) { if (len > 0) {
buffer =: len; buffer =: len;
Expand Down Expand Up @@ -914,16 +935,43 @@ class Drawable


class Window : Drawable class Window : Drawable
{ {
var xic;
function Destroy() function Destroy()
{ {
__DEBUG__ && cry(__FUNCTION__); __DEBUG__ && cry(__FUNCTION__);
getfun("XDestroyWindow")(self.display.xdisplay, self.xdrawable); getfun("XDestroyWindow")(self.display.xdisplay, self.xdrawable);
self.xdrawable = None; self.xdrawable = None;
} }
function CreateIC()
{
var xic = self.xic;
if (xic == null) {
var xim = self.display.getIM();
if (xim) {
int xwin = self.xdrawable;
xic = getfun("XCreateIC")(xim,
str_to_cstring("inputStyle"), 0x408,
str_to_cstring("clientWindow"), xwin,
str_to_cstring("focusWindow"), xwin,
null);
if (! xic)
xic = false;
}
else
xic = false;
self.xic = xic;
}
}
function getIC()
{
return self.xic;
}
function SelectInput(int eventmask) function SelectInput(int eventmask)
{ {
__DEBUG__ && cry(__FUNCTION__); __DEBUG__ && cry(__FUNCTION__);
getfun("XSelectInput")(self.display.xdisplay, self.xdrawable, eventmask); getfun("XSelectInput")(self.display.xdisplay, self.xdrawable, eventmask);
if (eventmask & KeyPressMask)
self.CreateIC();
} }
function StoreName(string name) function StoreName(string name)
{ {
Expand Down Expand Up @@ -985,6 +1033,10 @@ class Window : Drawable
Free(props); Free(props);
return result; return result;
} }
function LookupString(event)
{
return self.display._LookupString(self, event);
}
} }


//************************************************************** //**************************************************************
Expand Down Expand Up @@ -1048,7 +1100,8 @@ class Controller
var event = new Event(); var event = new Event();
do { do {
display.NextEvent(event); display.NextEvent(event);
self.handleEvent(event); if (! getfun("XFilterEvent")(event.eventdata, None))
self.handleEvent(event);
} while (self.running); } while (self.running);
} }
function Quit() function Quit()
Expand Down Expand Up @@ -1441,7 +1494,7 @@ class EditBox : ChildWindow
key = " "; key = " ";
break; break;
} }
key = display.LookupString(event); key = self.LookupString(event);
if (length(key) < 1) if (length(key) < 1)
return; return;
self.cursor(); self.cursor();
Expand Down
15 changes: 14 additions & 1 deletion src/GuitorNci.winxed
Expand Up @@ -540,7 +540,10 @@ function create_function(string funcname)
sig = "vpii"; sig = "vpii";
break; break;
case "XNextEvent": case "XNextEvent":
sig = "ipp"; sig = "vpp";
break;
case "XFilterEvent":
sig = "ipi";
break; break;
case "XKeycodeToKeysym": case "XKeycodeToKeysym":
sig = "ipii"; sig = "ipii";
Expand All @@ -551,6 +554,16 @@ function create_function(string funcname)
case "XLookupString": case "XLookupString":
sig = "ippipp"; sig = "ippipp";
break; break;
case "XmbLookupString":
case "Xutf8LookupString":
sig = "ipppipp";
break;
case "XOpenIM":
sig = "ppppp";
break;
case "XCreateIC":
sig = "ppplplplp";
break;
case "XSelectInput": case "XSelectInput":
sig = "ipii"; sig = "ipii";
break; break;
Expand Down

0 comments on commit 44eced5

Please sign in to comment.