winex11.drv: Connect to XIM server dynamically. [take 2]
Kusanagi Kouichi
slash at ma.neweb.ne.jp
Sat Mar 29 07:52:20 CDT 2008
If I want to use XIM, I must start XIM server before wine.
Furthermore, if XIM server stops, wine can't use XIM again
even if XIM server restarts.
---
dlls/winex11.drv/window.c | 15 ++++++++----
dlls/winex11.drv/x11drv.h | 5 ++-
dlls/winex11.drv/x11drv_main.c | 7 ++++-
dlls/winex11.drv/xim.c | 47 ++++++++++++++++++++++++++++++++++++---
4 files changed, 61 insertions(+), 13 deletions(-)
diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c
index ffeed8e..8f3d488 100644
--- a/dlls/winex11.drv/window.c
+++ b/dlls/winex11.drv/window.c
@@ -1126,7 +1126,6 @@ static Window create_whole_window( Display *display, struct x11drv_win_data *dat
{
int cx, cy, mask;
XSetWindowAttributes attr;
- XIM xim;
WCHAR text[1024];
HRGN hrgn;
@@ -1166,9 +1165,6 @@ static Window create_whole_window( Display *display, struct x11drv_win_data *dat
return 0;
}
- xim = x11drv_thread_data()->xim;
- if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
-
set_initial_wm_hints( display, data );
X11DRV_set_wm_hints( display, data );
@@ -1487,9 +1483,18 @@ Window X11DRV_get_client_window( HWND hwnd )
XIC X11DRV_get_ic( HWND hwnd )
{
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
+ XIM xim;
if (!data) return 0;
- return data->xic;
+
+ if (data->xic)
+ return data->xic;
+
+ xim = x11drv_thread_data()->xim;
+ if (!xim)
+ return NULL;
+
+ return X11DRV_CreateIC(xim, data->whole_window, &data->xic);
}
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index 52670e8..1ff2bd6 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -274,8 +274,9 @@ extern Drawable get_glxdrawable(X11DRV_PDEVICE *physDev);
extern BOOL destroy_glxpixmap(Display *display, XID glxpixmap);
/* XIM support */
-extern XIC X11DRV_CreateIC(XIM xim, Display *display, Window win);
-extern XIM X11DRV_SetupXIM(Display *display, const char *input_style);
+extern char input_style[];
+extern XIC X11DRV_CreateIC(XIM xim, Window win, XIC *xic);
+extern void X11DRV_SetupXIM(Display *display, XPointer xim, XPointer data);
extern void X11DRV_XIMLookupChars( const char *str, DWORD count );
extern void X11DRV_XDND_EnterEvent( HWND hWnd, XClientMessageEvent *event );
diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c
index d445e64..ed2f740 100644
--- a/dlls/winex11.drv/x11drv_main.c
+++ b/dlls/winex11.drv/x11drv_main.c
@@ -100,7 +100,7 @@ static int err_callback_result; /* error callback result */
static unsigned long err_serial; /* serial number of first request */
static int (*old_error_handler)( Display *, XErrorEvent * );
static int use_xim = 1;
-static char input_style[20];
+char input_style[20];
#define IS_OPTION_TRUE(ch) \
((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1')
@@ -651,7 +651,10 @@ struct x11drv_thread_data *x11drv_init_thread_data(void)
if (TRACE_ON(synchronous)) XSynchronize( data->display, True );
wine_tsx11_unlock();
- if (use_xim && !(data->xim = X11DRV_SetupXIM( data->display, input_style )))
+ data->xim = NULL;
+ if (use_xim &&
+ !XRegisterIMInstantiateCallback(data->display, NULL, NULL, NULL,
+ X11DRV_SetupXIM, (XPointer)&data->xim))
WARN("Input Method is not available\n");
set_queue_display_fd( data->display );
diff --git a/dlls/winex11.drv/xim.c b/dlls/winex11.drv/xim.c
index ad28bc5..8222ccf 100644
--- a/dlls/winex11.drv/xim.c
+++ b/dlls/winex11.drv/xim.c
@@ -394,15 +394,27 @@ void X11DRV_ForceXIMReset(HWND hwnd)
}
}
+static void X11DRV_DestroyIM(XIM xim, XPointer p, XPointer data)
+{
+ TRACE("xim = %p, p = %p\n", xim, p);
+ *(XIM *)p = NULL;
+ ximStyle = 0;
+ wine_tsx11_lock();
+ XRegisterIMInstantiateCallback(XDisplayOfIM(xim), NULL, NULL, NULL,
+ X11DRV_SetupXIM, p);
+ wine_tsx11_unlock();
+}
+
/***********************************************************************
* X11DRV Ime creation
*/
-XIM X11DRV_SetupXIM(Display *display, const char *input_style)
+void X11DRV_SetupXIM(Display *display, XPointer p, XPointer data)
{
XIMStyle ximStyleRequest, ximStyleCallback, ximStyleNone;
XIMStyles *ximStyles = NULL;
INT i;
XIM xim;
+ XIMCallback destroy;
ximStyleRequest = STYLE_CALLBACK;
@@ -433,6 +445,14 @@ XIM X11DRV_SetupXIM(Display *display, const char *input_style)
goto err;
}
+ destroy.client_data = p;
+ destroy.callback = X11DRV_DestroyIM;
+ if (XSetIMValues(xim, XNDestroyCallback, &destroy, NULL))
+ {
+ WARN("Could not set destroy callback.\n");
+ }
+
+ TRACE("xim = %p\n", xim);
TRACE("X display of IM = %p\n", XDisplayOfIM(xim));
TRACE("Using %s locale of Input Method\n", XLocaleOfIM(xim));
@@ -440,6 +460,8 @@ XIM X11DRV_SetupXIM(Display *display, const char *input_style)
if (ximStyles == 0)
{
WARN("Could not find supported input style.\n");
+ XCloseIM(xim);
+ goto err;
}
else
{
@@ -499,6 +521,8 @@ XIM X11DRV_SetupXIM(Display *display, const char *input_style)
}
+ *(XIM *)p = xim;
+ XUnregisterIMInstantiateCallback(display, NULL, NULL, NULL, X11DRV_SetupXIM, p);
wine_tsx11_unlock();
if(!hImmDll)
@@ -513,26 +537,34 @@ XIM X11DRV_SetupXIM(Display *display, const char *input_style)
}
}
- return xim;
+ return;
err:
wine_tsx11_unlock();
- return NULL;
+ return;
}
+static BOOL X11DRV_DestroyIC(XIC xic, XPointer p, XPointer data)
+{
+ TRACE("xic = %p, p = %p\n", xic, p);
+ *(XIC *)p = NULL;
+ return TRUE;
+}
-XIC X11DRV_CreateIC(XIM xim, Display *display, Window win)
+XIC X11DRV_CreateIC(XIM xim, Window win, XIC *p)
{
XPoint spot = {0};
XVaNestedList preedit = NULL;
XVaNestedList status = NULL;
XIC xic;
+ XICCallback destroy = {(XPointer)p, X11DRV_DestroyIC};
XIMCallback P_StartCB;
XIMCallback P_DoneCB;
XIMCallback P_DrawCB;
XIMCallback P_CaretCB;
LANGID langid = PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale()));
+ TRACE("xim = %p\n", xim);
wine_tsx11_lock();
/* use complex and slow XIC initialization method only for CJK */
@@ -544,8 +576,10 @@ XIC X11DRV_CreateIC(XIM xim, Display *display, Window win)
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, win,
XNFocusWindow, win,
+ XNDestroyCallback, &destroy,
NULL);
wine_tsx11_unlock();
+ *p = xic;
return xic;
}
@@ -597,6 +631,7 @@ XIC X11DRV_CreateIC(XIM xim, Display *display, Window win)
XNStatusAttributes, status,
XNClientWindow, win,
XNFocusWindow, win,
+ XNDestroyCallback, &destroy,
NULL);
}
else if (preedit != NULL)
@@ -606,6 +641,7 @@ XIC X11DRV_CreateIC(XIM xim, Display *display, Window win)
XNPreeditAttributes, preedit,
XNClientWindow, win,
XNFocusWindow, win,
+ XNDestroyCallback, &destroy,
NULL);
}
else if (status != NULL)
@@ -615,6 +651,7 @@ XIC X11DRV_CreateIC(XIM xim, Display *display, Window win)
XNStatusAttributes, status,
XNClientWindow, win,
XNFocusWindow, win,
+ XNDestroyCallback, &destroy,
NULL);
}
else
@@ -623,10 +660,12 @@ XIC X11DRV_CreateIC(XIM xim, Display *display, Window win)
XNInputStyle, ximStyle,
XNClientWindow, win,
XNFocusWindow, win,
+ XNDestroyCallback, &destroy,
NULL);
}
TRACE("xic = %p\n", xic);
+ *p = xic;
if (preedit != NULL)
XFree(preedit);
--
1.5.4.5
More information about the wine-patches
mailing list