Beispiel #1
0
static Bool
ResizeVendorShell_Core(VendorShellWidget vw, XawVendorShellExtPart *ve,
		       XawIcTableList p)
{
    XVaNestedList		pe_attr, st_attr;
    XRectangle			pe_area, st_area;
    XRectangle			*get_pe_area = NULL, *get_st_area = NULL;

    st_area.width = 0;
    if (p->input_style & XIMStatusArea) {
	st_attr = XVaCreateNestedList(0, XNArea, &get_st_area, NULL);
	XGetICValues(p->xic, XNStatusAttributes, st_attr, NULL);
	XFree(st_attr);
	if (p->xic == NULL) {
	    return(FALSE);
	}
	st_area.x = 0;
	st_area.y = vw->core.height - ve->im.area_height;
	st_area.width = get_st_area->width;
	st_area.height = get_st_area->height;
	XFree(get_st_area);
	st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL);
	XSetICValues(p->xic, XNStatusAttributes, st_attr, NULL);
	XFree(st_attr);
	if (p->xic == NULL) {
	    return(FALSE);
	}
    }
    if (p->input_style & XIMPreeditArea) {
	pe_attr = XVaCreateNestedList(0, XNArea, &get_pe_area, NULL);
	XGetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
	XFree(pe_attr);
	if (p->xic == NULL) {
	    return(FALSE);
	}
	pe_area.x = st_area.width;
	pe_area.y = vw->core.height - ve->im.area_height;
	pe_area.width = vw->core.width;
	pe_area.height = get_pe_area->height;
	if (p->input_style & XIMStatusArea) {
	    pe_area.width -= st_area.width;
	}
	XFree(get_pe_area);
	pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
	XSetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
	XFree(pe_attr);
    }
    return(TRUE);
}
Beispiel #2
0
static void
_ecore_imf_context_xim_cursor_location_set(Ecore_IMF_Context *ctx,
                                           int x, int y, int w, int h)
{
   Ecore_IMF_Context_Data *imf_context_data = ecore_imf_context_data_get(ctx);
   XIC ic;
   XVaNestedList preedit_attr;
   XPoint spot;

   DBG("ctx=%p, imf_context_data=%p, location=(%d, %d, %d, %d)",
       ctx, imf_context_data, x, y, w, h);

   EINA_SAFETY_ON_NULL_RETURN(imf_context_data);
   ic = imf_context_data->ic;
   if (!ic)
     return;

   spot.x = x;
   spot.y = y + h;

   preedit_attr = XVaCreateNestedList(0,
                                      XNSpotLocation, &spot,
                                      NULL);
   XSetICValues(ic,
                XNPreeditAttributes, preedit_attr,
                NULL);

   XFree(preedit_attr);
}
Beispiel #3
0
/*ARGSUSED*/
static void
ConfigureCB(Widget w, XtPointer closure, XEvent *event, Boolean *unused)
{
    XawIcTableList		p;
    XawVendorShellExtPart	*ve;
    VendorShellWidget		vw;
    XVaNestedList		pe_attr;
    XRectangle			pe_area;
    XawTextMargin		*margin;

    if (event->type != ConfigureNotify) return;

    if ((vw = SearchVendorShell(w)) == NULL) return;

    if ((ve = GetExtPart(vw)) != NULL) {
        if (IsSharedIC(ve)) return;
	if ((ve->im.xim == NULL) ||
	    ((p = GetIcTableShared(w, ve)) == NULL) ||
	    (p->xic == NULL) || !(p->input_style & XIMPreeditPosition)) return;
	pe_area.x = 0;
        pe_area.y = 0;
        pe_area.width = w->core.width;
        pe_area.height = w->core.height;
	margin = &(((TextWidget)w)->text.margin);
	pe_area.x += margin->left;
	pe_area.y += margin->top;
	pe_area.width -= (margin->left + margin->right - 1);
	pe_area.height -= (margin->top + margin->bottom - 1);

	pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
	XSetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
	XtFree(pe_attr);
    }
}
Beispiel #4
0
/*
 * Sets the focus window to the given XIC.
 */
static void
setXICWindowFocus(XIC ic, Window w)
{
    if (ic == NULL) {
        (void)fprintf(stderr, "Couldn't find X Input Context\n");
        return;
    }
    (void) XSetICValues(ic, XNFocusWindow, w, NULL);
}
Beispiel #5
0
void TInputContext::SetSpotLocation(const TPoint& point)
{
	XPoint xpoint;
	xpoint.x = point.h;
	xpoint.y = point.v;
	
	ICArg args[2] = { {XNSpotLocation, &xpoint}, {NULL, NULL} };
	XSetICValues(fXIC, XNPreeditAttributes, args, NULL);
}
Beispiel #6
0
void
rxvt_term::IMSetPosition ()
{
  XRectangle preedit_rect, status_rect, *needed_rect;
  XVaNestedList preedit_attr, status_attr;

  if (!Input_Context
      || !focus
      || !(input_style & (XIMPreeditArea | XIMPreeditPosition))
      || !IMisRunning ())
    return;

  if (input_style & XIMPreeditPosition)
    {
      im_set_size (preedit_rect);
      preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);

      XSetICValues (Input_Context,
                    XNPreeditAttributes, preedit_attr, NULL);
    }
  else
    {
      /* Getting the necessary width of preedit area */
      status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
      XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
      XFree (status_attr);

      im_set_preedit_area (preedit_rect, status_rect, *needed_rect);
      XFree (needed_rect);

      preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
      status_attr  = XVaCreateNestedList (0, XNArea, &status_rect,  NULL);

      XSetICValues (Input_Context,
                    XNPreeditAttributes, preedit_attr,
                    XNStatusAttributes,  status_attr,
                    NULL);

      XFree (status_attr);
    }

   XFree (preedit_attr);
}
Beispiel #7
0
/* _al_xwin_keyboard_switch_handler:
 *  Handle a focus switch event.
 */
void _al_xwin_keyboard_switch_handler(ALLEGRO_DISPLAY *display, bool focus_in)
{
    _al_event_source_lock(&the_keyboard.parent.es);

    if (focus_in) {
        the_keyboard.state.display = display;
#ifdef ALLEGRO_XWINDOWS_WITH_XIM
        if (xic) {
            ALLEGRO_DISPLAY_XGLX *display_glx = (void *)display;
            XSetICValues(xic, XNClientWindow, display_glx->window, NULL);
        }
#endif
    }
    else {
        the_keyboard.state.display = NULL;
    }

    _al_event_source_unlock(&the_keyboard.parent.es);
}
Beispiel #8
0
void
Tk_SetCaretPos(
    Tk_Window tkwin,
    int x,
    int y,
    int height)
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;

    if ((dispPtr->caret.winPtr == winPtr)
	    && (dispPtr->caret.x == x)
	    && (dispPtr->caret.y == y)
	    && (dispPtr->caret.height == height)) {
	return;
    }

    dispPtr->caret.winPtr = winPtr;
    dispPtr->caret.x = x;
    dispPtr->caret.y = y;
    dispPtr->caret.height = height;

    /*
     * Adjust the XIM caret position.
     */

#ifdef TK_USE_INPUT_METHODS
    if ((dispPtr->flags & TK_DISPLAY_USE_IM)
	    && (dispPtr->inputStyle & XIMPreeditPosition)
	    && (winPtr->inputContext != NULL)) {
	XVaNestedList preedit_attr;
	XPoint spot;

	spot.x = dispPtr->caret.x;
	spot.y = dispPtr->caret.y + dispPtr->caret.height;
	preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
	XSetICValues(winPtr->inputContext, XNPreeditAttributes, preedit_attr,
		NULL);
	XFree(preedit_attr);
    }
#endif
}
Beispiel #9
0
void
rxvt_term::IMSendSpot ()
{
  XPoint nspot;
  XVaNestedList preedit_attr;

  if (!Input_Context
      || !focus
      || !(input_style & (XIMPreeditPosition | XIMPreeditCallbacks)))
    return;

  im_set_position (nspot);

  if (nspot.x == spot.x && nspot.y == spot.y)
    return;

  spot = nspot;

  preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
  XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
  XFree (preedit_attr);
}
Beispiel #10
0
void X11DRV_SetPreeditState(HWND hwnd, BOOL fOpen)
{
    XIC ic;
    XIMPreeditState state;
    XVaNestedList attr;

    ic = X11DRV_get_ic(hwnd);
    if (!ic)
        return;

    if (fOpen)
        state = XIMPreeditEnable;
    else
        state = XIMPreeditDisable;

    attr = XVaCreateNestedList(0, XNPreeditState, state, NULL);
    if (attr != NULL)
    {
        XSetICValues(ic, XNPreeditAttributes, attr, NULL);
        XFree(attr);
    }
}
Beispiel #11
0
static void
_ecore_imf_context_xim_cursor_location_set(Ecore_IMF_Context *ctx,
                                           int x, int y, int w, int h)
{
   EINA_LOG_DBG("%s in", __FUNCTION__);

#ifdef ENABLE_XIM
   Ecore_IMF_Context_Data *imf_context_data;
   XIC ic;
   XVaNestedList preedit_attr;
   XPoint spot;

   imf_context_data = ecore_imf_context_data_get(ctx);
   EINA_SAFETY_ON_NULL_RETURN(imf_context_data);
   ic = imf_context_data->ic;
   if (!ic)
     return;

   spot.x = x;
   spot.y = y + h;

   preedit_attr = XVaCreateNestedList(0,
                                      XNSpotLocation, &spot,
                                      NULL);
   XSetICValues(ic,
                XNPreeditAttributes, preedit_attr,
                NULL);

   XFree(preedit_attr);
#else
   (void)ctx;
   (void)x;
   (void)y;
   (void)h;
#endif
   (void)(w); // yes w is unused, but only a bi-product of the algorithm
}
Beispiel #12
0
static void
_ecore_imf_context_xim_reset(Ecore_IMF_Context *ctx)
{
   EINA_LOG_DBG("%s in", __FUNCTION__);
#ifdef ENABLE_XIM
   XIC ic;
   Ecore_IMF_Context_Data *imf_context_data;
   char *result;

   /* restore conversion state after resetting ic later */
   XIMPreeditState preedit_state = XIMPreeditUnKnown;
   XVaNestedList preedit_attr;
   Eina_Bool have_preedit_state = EINA_FALSE;

   imf_context_data = ecore_imf_context_data_get(ctx);
   EINA_SAFETY_ON_NULL_RETURN(imf_context_data);

   ic = imf_context_data->ic;
   if (!ic)
     return;

   if (imf_context_data->preedit_length == 0)
     return;

   preedit_attr = XVaCreateNestedList(0,
                                      XNPreeditState, &preedit_state,
                                      NULL);
   if (!XGetICValues(ic,
                     XNPreeditAttributes, preedit_attr,
                     NULL))
     have_preedit_state = EINA_TRUE;

   XFree(preedit_attr);

   result = XmbResetIC(ic);

   preedit_attr = XVaCreateNestedList(0,
                                      XNPreeditState, preedit_state,
                                      NULL);
   if (have_preedit_state)
     XSetICValues(ic,
                  XNPreeditAttributes, preedit_attr,
                  NULL);

   XFree(preedit_attr);

   if (imf_context_data->feedbacks)
     {
        free(imf_context_data->feedbacks);
        imf_context_data->feedbacks = NULL;
     }

   if (imf_context_data->preedit_length)
     {
        imf_context_data->preedit_length = 0;
        free(imf_context_data->preedit_chars);
        imf_context_data->preedit_chars = NULL;

        ecore_imf_context_preedit_changed_event_add(ctx);
        ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL);
     }

   if (result)
     {
        char *result_utf8 = strdup(result);
        if (result_utf8)
          {
             ecore_imf_context_commit_event_add(ctx, result_utf8);
             ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_COMMIT, result_utf8);
             free(result_utf8);
          }
     }

   XFree(result);
#else
   (void)ctx;
#endif
}
Beispiel #13
0
static void
SetICValues(Widget w, XawVendorShellExtPart *ve, Bool focus)
{
    XawIcTableList	p;
    XPoint		position;
    XRectangle		pe_area;
    XVaNestedList	pe_attr = NULL, st_attr = NULL;
    XPointer		ic_a[20], pe_a[20], st_a[20];
    int			ic_cnt = 0, pe_cnt = 0, st_cnt = 0;
    XawTextMargin	*margin;
    int			height = 0;

    if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
	(p->xic == NULL)) return;

    if (IsSharedIC(ve)) SetICValuesShared(w, ve, p, TRUE);
    XFlush(XtDisplay(w));
    if (focus == FALSE &&
	!(p->flg & (CIFontSet | CIFg | CIBg |
		    CIBgPixmap | CICursorP | CILineS))) return;
#ifdef SPOT
    if ((p->input_style & XIMPreeditPosition)
	&& ((!IsSharedIC(ve) && ((p->flg & ~CIICFocus) == CICursorP))
	    || (IsSharedIC(ve) && p->flg == CICursorP))) {
	_XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
	_XipChangeSpot(p->xic, position.x, position.y);
	p->flg &= ~CICursorP;
	return;
    }
#endif

    if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) {
	if (p->flg & CIFontSet) {
	    pe_a[pe_cnt] = (XPointer) XNFontSet; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) p->font_set; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNFontSet; st_cnt++;
	    st_a[st_cnt] = (XPointer) p->font_set; st_cnt++;
	    if (p->font_set) {
		height = maxAscentOfFontSet(p->font_set)
		    + maxDescentOfFontSet(p->font_set);
	    }
	    height = SetVendorShellHeight(ve, height);
	}
	if (p->flg & CIFg) {
	    pe_a[pe_cnt] = (XPointer) XNForeground; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->foreground; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNForeground; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->foreground; st_cnt++;
	}
	if (p->flg & CIBg) {
	    pe_a[pe_cnt] = (XPointer) XNBackground; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->background; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNBackground; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->background; st_cnt++;
	}
	if (p->flg & CIBgPixmap) {
	    pe_a[pe_cnt] = (XPointer) XNBackgroundPixmap; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->bg_pixmap; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNBackgroundPixmap; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->bg_pixmap; st_cnt++;
	}
	if (p->flg & CILineS) {
	    pe_a[pe_cnt] = (XPointer) XNLineSpace; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->line_spacing; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNLineSpace; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->line_spacing; st_cnt++;
	}
    }
    if (p->input_style & XIMPreeditPosition) {
	if (p->flg & CICursorP) {
	    _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
	    pe_a[pe_cnt] = (XPointer) XNSpotLocation; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) &position; pe_cnt++;
	}
    }
    if (IsSharedIC(ve)) {
	if (p->input_style & XIMPreeditPosition) {
	    pe_area.x = 0;
	    pe_area.y = 0;
	    pe_area.width = w->core.width;
	    pe_area.height = w->core.height;
	    margin = &(((TextWidget)w)->text.margin);
	    pe_area.x += margin->left;
	    pe_area.y += margin->top;
	    pe_area.width -= (margin->left + margin->right - 1);
	    pe_area.height -= (margin->top + margin->bottom - 1);
	    pe_a[pe_cnt] = (XPointer) XNArea; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) &pe_area; pe_cnt++;
	}
    }

    if (pe_cnt > 0) {
	pe_a[pe_cnt] = (XPointer) NULL;
	pe_attr = XVaCreateNestedList(0, pe_a[0], pe_a[1], pe_a[2], pe_a[3],
				      pe_a[4], pe_a[5], pe_a[6], pe_a[7],
				      pe_a[8], pe_a[9], pe_a[10], pe_a[11],
				      pe_a[12], pe_a[13], pe_a[14], pe_a[15],
				      pe_a[16], pe_a[17], pe_a[18],  NULL);
	ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++;
    }
    if (st_cnt > 0) {
	st_a[st_cnt] = (XPointer) NULL;
	st_attr = XVaCreateNestedList(0, st_a[0], st_a[1], st_a[2], st_a[3],
				      st_a[4], st_a[5], st_a[6], st_a[7],
				      st_a[8], st_a[9], st_a[10], st_a[11],
				      st_a[12], st_a[13], st_a[14], st_a[15],
				      st_a[16], st_a[17], st_a[18],  NULL);
	ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++;
    }
    if (focus == TRUE) {
	ic_a[ic_cnt] = (XPointer) XNFocusWindow; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) (uintptr_t)XtWindow(w); ic_cnt++;
    }
    if (ic_cnt > 0) {
	ic_a[ic_cnt] = (XPointer) NULL;
	XSetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4],
		     ic_a[5], ic_a[6], ic_a[7], ic_a[8], ic_a[9], ic_a[10],
		     ic_a[11], ic_a[12], ic_a[13], ic_a[14], ic_a[15],
		     ic_a[16], ic_a[17], ic_a[18], NULL);
	if (pe_attr) XtFree(pe_attr);
	if (st_attr) XtFree(st_attr);
    }

    if (IsSharedIC(ve) && p->flg & CIFontSet)
	SizeNegotiation(p, ve->parent->core.width, ve->parent->core.height);

    p->flg &= ~(CIFontSet | CIFg | CIBg | CIBgPixmap | CICursorP | CILineS);
}
Beispiel #14
0
	int main(int argc, char **argv)
	{
		Display *display;
		int screen_num;
		Window win;			//窗口ID
		unsigned int width, height;	//窗口尺寸
		unsigned int border_width = 4;	//边界空白
		unsigned int display_width, display_height;//屏幕尺寸
		XEvent report;
		GC gc;
		unsigned long valuemask = 0;
		XGCValues values;
		char *display_name = NULL;
		Atom          protocols;

		//edit
		int           len = 127;
		unsigned char string[128], s_tab[ROW][127];
		KeySym        keysym;
		int           row = 0, col = 0;
		int           i, count = 0;
		Status        status;
		//字体集
		XFontSet fontset;
		char **missing_charsets;
		int num_missing_charsets;
		char *default_string;
		XFontSetExtents *fs_ext;
		int dec;    

		//XIM
		XIM im;
		XIC ic;
		//overspot
		XRectangle    spot, s_rect;
		XVaNestedList preedit_attr, status_attr;

		//设置locale	
		if((setlocale(LC_ALL, "")) == NULL){
			printf("cannot set locale\n");
			exit(1);
		}

		//判断X是否支持locale
		if(!XSupportsLocale()){
			printf("X does not support current locale\n");
			exit(1);
		}

		//设置locale修饰
		if(XSetLocaleModifiers(NULL)){
			printf("Cannot set locale modifiers\n");
			exit(1);
		}
	
		// 和X 服务器连接
		if ( (display=XOpenDisplay(display_name)) == NULL )
		{
			printf("Cannot connect to X server %s\n", 
					XDisplayName(display_name));
			exit(-1);
		}

		//获得缺省的 screen_num
		screen_num = DefaultScreen(display);

		//获得屏幕的宽度和高度
		display_width = DisplayWidth(display, screen_num);
		display_height = DisplayHeight(display, screen_num);
	
		//建立字体集
		fontset = XCreateFontSet(display, 
			"8x16,-*-song-medium-r-normal--16-*-*-*-*-*-gb2312.1980-0",
			&missing_charsets, &num_missing_charsets,
			&default_string);

		if(num_missing_charsets > 0){
			int i;
			printf("Following charsets are missing:\n");
			for(i=0; i<num_missing_charsets; i++){
				printf("Missing %d: %s\n", 
					i, missing_charsets[i]);
			}
			printf("\nDefault string:%s\n", default_string);
			XFreeStringList(missing_charsets);
		}
		//字体的Extents
		fs_ext = XExtentsOfFontSet(fontset);
		dec = fs_ext->max_logical_extent.height 
			+ fs_ext->max_logical_extent.y;

		width  = W_WIDTH;
		height = W_HEIGHT + dec;

	
		//建立窗口
		win = XCreateSimpleWindow(display, 	//display
			RootWindow(display,screen_num), //父窗口
			0, 0, width, height, 		//位置和大小
			border_width, 			//边界宽度
			BlackPixel(display,screen_num), //前景色
			WhitePixel(display,screen_num));//背景色
	
		//选择窗口感兴趣的事件掩码
		XSelectInput(display, win, 
			ExposureMask | KeyPressMask | 
			ButtonPressMask | StructureNotifyMask);

		//建立GC
		gc = XCreateGC(display, win, valuemask, &values);

		protocols = XInternAtom(display, "WM_DELETE_WINDOW", True);
		XSetWMProtocols(display, win, &protocols, 1);

		//显示窗口
		XMapWindow(display, win);

		//联接输入服务器
		if((im = XOpenIM(display, NULL, NULL, NULL)) == NULL){
			printf("Error : XOpenIM !\n");
			exit(1);
		}

		//设置输入服务器的位置
		spot.x = F_SIZE / 2 * col;
		spot.y = F_SIZE * (row + 1) - dec; 
		preedit_attr = XVaCreateNestedList(0,
			XNSpotLocation, &spot,
			XNFontSet, fontset, 
			NULL);
		s_rect.x = 0;
		s_rect.y = F_SIZE * ROW + dec + 2;
		s_rect.width = W_WIDTH;
		s_rect.height = F_SIZE;
		status_attr = XVaCreateNestedList(0,
			XNArea, &s_rect,
			XNFontSet, fontset,
			NULL);
		//建立IC
		if((ic = XCreateIC(im, 
			XNInputStyle, XIMPreeditPosition | XIMStatusNothing,
			XNClientWindow, win, 
			XNPreeditAttributes, preedit_attr,
			XNStatusAttributes, status_attr, NULL)) == NULL){
			printf("Error : XCreateIC() ! \n");
			XCloseIM(im);
			exit(0);
		}
		//释放内存
		XFree(preedit_attr);
		XFree(status_attr);


		//写屏缓冲区初始化
		for(i = 0; i < ROW; i++)s_tab[i][0] = 0;

		//进入事件循环
		while (1)  {

			//取得队列中的事件
			XNextEvent(display, &report);

			//过滤事件
			if(XFilterEvent(&report, None) == True) continue;
			switch  (report.type) {

			//聚焦发声变化
			case FocusIn:
				XSetICFocus(ic); 
				break;
			case FocusOut:
				XUnsetICFocus(ic);
				break;

			//曝光事件, 窗口应重绘
			case Expose:
				//取得最后一个曝光事件
				if (report.xexpose.count != 0) break;
				for ( i=0; i < ROW; i++)
					XmbDrawString(display, win, fontset,gc, 
					0, F_SIZE * (i +1), 
					s_tab[i], strlen(s_tab[i]));
				break;

			//窗口尺寸改变, 重新取得窗口的宽度和高度
			case ConfigureNotify:
				width = report.xconfigure.width;
				height = report.xconfigure.height;
				break;

			//鼠标点击或有按键, 释放资源则退出
			case KeyPress:
				count = XmbLookupString(ic, 
					(XKeyPressedEvent *) &report,
					string, len, &keysym, &status);
				string[count] = 0;
				if (status == XLookupBoth&&keysym == XK_Return){
					row = (++row) % ROW;
					col = 0;
					s_tab[row][0] = 0;
					XClearArea(display, win, 
						0, F_SIZE * row + dec,
						W_WIDTH, F_SIZE, False);
				} else if (status = XLookupChars 
					|| status == XLookupBoth){
					XmbDrawString(display, win, fontset, gc,
					F_SIZE / 2 * col, F_SIZE * (row + 1),
					string, count);
					for (i = 0; i < count && col < len && 
						string[i]; i++, col++)
						s_tab[row][col] = string[i];
						s_tab[row][col] = 0;
				}
				//更新输入服务器位置
				spot.x = F_SIZE / 2 * col;
				spot.y = F_SIZE * (row + 1);
				preedit_attr = XVaCreateNestedList(0,
					XNSpotLocation, &spot,
					NULL);
				XSetICValues(ic, 
					XNPreeditAttributes, preedit_attr, 
					NULL);
				XFree(preedit_attr);
				break;
			case ClientMessage:
				if (report.xclient.data.l[0] == protocols) {
					XDestroyIC(ic);
					XCloseIM(im);
					XDestroyWindow(display, win);
					XCloseDisplay(display);
					exit(0);
				}
				break;
			default:
				break;
			}
		}
	}
int32_t
awt_motif_getIMStatusHeight(Widget vw, jobject tc)
{
    XmICStruct *icp;
    XmVendorShellExtObject ve;
    XmWidgetExtData extData;
    XmImInfo *im_info;
    int32_t width = 0;
    int32_t height = 0;
    XRectangle rect;
    XRectangle *rp;
    int32_t old_height;
    Arg args[1];
    int32_t base_height;
    XFontSet fs;
    XFontSet fss = NULL;
    XFontSet fsp = NULL;

    extData = (XmWidgetExtData)_XmGetWidgetExtData((Widget) vw, XmSHELL_EXTENSION);
    ve = (XmVendorShellExtObject) extData->widget;

    if ((icp = get_iclist(vw)) == NULL) {
	ve->vendor.im_height = 0;
	return 0;
    }
    im_info = (XmImInfo *) ve->vendor.im_info;
    if (im_info->xic == NULL) {
	ve->vendor.im_height = 0;
	return 0;
    }
    status_vlist[0].name = XNFontSet;
    status_vlist[1].name = NULL;
    preedit_vlist[0].name = XNFontSet;
    preedit_vlist[1].name = NULL;

    xic_vlist[0].name = XNAreaNeeded;
    xic_vlist[1].name = NULL;

    im_info->status_width = 0;
    im_info->status_height = 0;
    im_info->preedit_width = 0;
    im_info->preedit_height = 0;
    for (; icp != NULL; icp = icp->next) {
	if (im_info->input_style & XIMStatusArea) {
	    if (icp->status_height == 0) {
		char *ret;

		if (icp->font_list == NO_ARG_VAL ||
		    (fss = extract_fontset((XmFontList) icp->font_list)) == NULL)
		    continue;

		status_vlist[0].value = (XtArgVal) fss;
		XSetICValues(im_info->xic,
			     XNStatusAttributes, &status_vlist[0],
			     NULL);

		xic_vlist[0].value = (XtArgVal) & rp;
		ret = XGetICValues(im_info->xic,
				   XNStatusAttributes, &xic_vlist[0],
				   NULL);

		if (ret) {
		    /* Cannot obtain XIC value. IM server may be gone. */
		    ve->vendor.im_height = 0;
		    return 0;
		} else {
		    icp->status_width = rp->width;
		    icp->status_height = rp->height;
		    XFree(rp);
		}
	    }
	    if (icp->status_width > im_info->status_width)
		im_info->status_width = icp->status_width;
	    if (icp->status_height > im_info->status_height)
		im_info->status_height = icp->status_height;
	}
	if (im_info->input_style & XIMPreeditArea) {
	    if (icp->preedit_height == 0) {
		if (icp->font_list == NO_ARG_VAL ||
		    (fsp = extract_fontset((XmFontList) icp->font_list)) == NULL)
		    continue;

		preedit_vlist[0].value = (XtArgVal) fsp;
		XSetICValues(im_info->xic,
			     XNPreeditAttributes, &preedit_vlist[0],
			     NULL);

		xic_vlist[0].value = (XtArgVal) & rp;
		XGetICValues(im_info->xic,
			     XNPreeditAttributes, &xic_vlist[0],
			     NULL);

		icp->preedit_width = rp->width;
		icp->preedit_height = rp->height;
		XFree(rp);
	    }
	    if (icp->preedit_width > im_info->preedit_width)
		im_info->preedit_width = icp->preedit_width;
	    if (icp->preedit_height > im_info->preedit_height)
		im_info->preedit_height = icp->preedit_height;
	}
    }

    if (im_info->current != NULL && (fss != NULL || fsp != NULL)) {
	if (im_info->current->font_list != NO_ARG_VAL &&
	    (fs = extract_fontset((XmFontList) im_info->current->font_list))
	    != NULL) {
	    if (fss != NULL)
		status_vlist[0].value = (XtArgVal) fs;
	    else
		status_vlist[0].name = NULL;
	    if (fsp != NULL)
		preedit_vlist[0].value = (XtArgVal) fs;
	    else
		preedit_vlist[0].name = NULL;
	    XSetICValues(im_info->xic,
			 XNStatusAttributes, &status_vlist[0],
			 XNPreeditAttributes, &preedit_vlist[0],
			 NULL);
	}
    }
    if (im_info->status_height > im_info->preedit_height)
	height = im_info->status_height;
    else
	height = im_info->preedit_height;
    old_height = ve->vendor.im_height;
    if (height)
	height += SEPARATOR_HEIGHT;

    ve->vendor.im_height = height;

    XtSetArg(args[0], XtNbaseHeight, &base_height);
    XtGetValues(vw, args, 1);
    if (base_height < 0)
	base_height = 0;
    XtSetArg(args[0], XtNbaseHeight, base_height);
    XtSetValues(vw, args, 1);
    return height;
}
void QXIMInputContext::setHolderWidget( QWidget *widget )
{
    if ( ! widget )
	return;

    QInputContext::setHolderWidget( widget );

#if !defined(QT_NO_XIM)
    if (! qt_xim) {
	qWarning("QInputContext: no input method context available");
	return;
    }

    if (! widget->isTopLevel()) {
	qWarning("QInputContext: cannot create input context for non-toplevel widgets");
	return;
    }

    XVaNestedList preedit_attr = 0;
    XIMCallback startcallback, drawcallback, donecallback;

    startcallback.client_data = (XPointer) this;
    startcallback.callback = (XIMProc) xic_start_callback;
    drawcallback.client_data = (XPointer) this;
    drawcallback.callback = (XIMProc)xic_draw_callback;
    donecallback.client_data = (XPointer) this;
    donecallback.callback = (XIMProc) xic_done_callback;

    preedit_attr = XVaCreateNestedList(0,
		   XNPreeditStartCallback, &startcallback,
		   XNPreeditDrawCallback, &drawcallback,
		   XNPreeditDoneCallback, &donecallback,
			   (char *) 0);

    if (preedit_attr)
    {
	ic = XCreateIC(qt_xim,
		       XNInputStyle, XIMPreeditCallbacks|XIMStatusCallbacks,
		       XNClientWindow, widget->winId(),
		       XNPreeditAttributes, preedit_attr,
		       (char *) 0);
	XFree(preedit_attr);
    }
    else
    {
	ic = XCreateIC(qt_xim,
		       XNInputStyle, XIMPreeditCallbacks|XIMStatusCallbacks,
		       XNClientWindow, widget->winId(),
		       (char *) 0);
    }

    if (! ic)
	qFatal("Failed to create XIM input context!");

    setComposePosition(1,1);

    // when resetting the input context, preserve the input state
    (void) XSetICValues((XIC) ic, XNResetState, XIMPreserveState, (char *) 0);

    if( ! ximContextList )
	ximContextList = new QPtrList<QXIMInputContext>;
    ximContextList->append( this );
#endif // !QT_NO_XIM
}
Beispiel #17
0
/* x_keyboard_init
 *  Initialise the X11 keyboard driver.
 */
static int x_keyboard_init(void)
{
#ifdef ALLEGRO_XWINDOWS_WITH_XIM
    char *old_locale;
    XIMStyles *xim_styles;
    XIMStyle xim_style = 0;
    char *imvalret;
    int i;
#endif
    ALLEGRO_SYSTEM_XGLX *s = (void *)al_get_system_driver();

    if (xkeyboard_installed)
        return 0;

    if (s->x11display == NULL)
        return 0;

    main_pid = getpid();

    memcpy(key_names, _al_keyboard_common_names, sizeof key_names);

    _al_mutex_lock(&s->lock);

    /* HACK: XkbSetDetectableAutoRepeat is broken in some versions of X.Org */
    Bool supported;
    XkbSetDetectableAutoRepeat(s->x11display, True, &supported);
    if (!supported) {
        ALLEGRO_WARN("XkbSetDetectableAutoRepeat failed.\n");
    }

#ifdef ALLEGRO_XWINDOWS_WITH_XIM
    ALLEGRO_INFO("Using X Input Method.\n");

    old_locale = setlocale(LC_CTYPE, NULL);
    ALLEGRO_DEBUG("Old locale: %s\n", old_locale ? old_locale : "(null)");
    if (old_locale) {
        /* The return value of setlocale() may be clobbered by the next call
         * to setlocale() so we must copy it.
         */
        old_locale = strdup(old_locale);
    }

    /* Otherwise we are restricted to ISO-8859-1 characters. */
    if (setlocale(LC_CTYPE, "") == NULL) {
        ALLEGRO_WARN("Could not set default locale.\n");
    }

    /* TODO: is this needed?
       modifiers = XSetLocaleModifiers("@im=none");
       if (modifiers == NULL) {
          ALLEGRO_WARN("XSetLocaleModifiers failed.\n");
       }
    */

    xim = XOpenIM(s->x11display, NULL, NULL, NULL);
    if (xim == NULL) {
        ALLEGRO_WARN("XOpenIM failed.\n");
    }

    if (old_locale) {
        ALLEGRO_DEBUG("Restoring old locale: %s\n", old_locale);
        setlocale(LC_CTYPE, old_locale);
        free(old_locale);
    }

    if (xim) {
        imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
        if (imvalret != NULL || xim_styles == NULL) {
            ALLEGRO_WARN("Input method doesn't support any styles.\n");
        }

        if (xim_styles) {
            xim_style = 0;
            for (i = 0;  i < xim_styles->count_styles;  i++) {
                if (xim_styles->supported_styles[i] ==
                        (XIMPreeditNothing | XIMStatusNothing)) {
                    xim_style = xim_styles->supported_styles[i];
                    break;
                }
            }

            if (xim_style == 0) {
                ALLEGRO_WARN("Input method doesn't support the style we support.\n");
            }
            else {
                ALLEGRO_INFO("Input method style = %ld\n", xim_style);
            }
            XFree(xim_styles);
        }
    }

    if (xim && xim_style) {
        xic = XCreateIC(xim,
                        XNInputStyle, xim_style,
                        NULL);
        if (xic == NULL) {
            ALLEGRO_WARN("XCreateIC failed.\n");
        }
        else {
            ALLEGRO_INFO("XCreateIC succeeded.\n");
        }

        /* In case al_install_keyboard() is called when there already is
         * a display, we set it as client window.
         */
        ALLEGRO_DISPLAY *display = al_get_current_display();
        ALLEGRO_DISPLAY_XGLX *display_glx = (void *)display;
        if (display_glx && xic)
            XSetICValues(xic, XNClientWindow, display_glx->window, NULL);
    }
#endif

    if (!_al_xwin_get_keyboard_mapping()) {
        return 1;
    }

    _al_mutex_unlock(&s->lock);

    xkeyboard_installed = 1;

    return 0;
}
Beispiel #18
0
static void
SizeNegotiation(XawIcTableList p, unsigned int width, unsigned int height)
{
    XRectangle		pe_area, st_area;
    XVaNestedList	pe_attr = NULL, st_attr = NULL;
    int			ic_cnt = 0;
    XRectangle		*pe_area_needed = NULL, *st_area_needed = NULL;
    XPointer		ic_a[5];

    if (p->input_style & XIMPreeditArea) {
	pe_attr = XVaCreateNestedList(0, XNAreaNeeded, &pe_area_needed, NULL);
	ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++;
    }
    if (p->input_style & XIMStatusArea) {
	st_attr = XVaCreateNestedList(0, XNAreaNeeded, &st_area_needed, NULL);
	ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++;
    }
    ic_a[ic_cnt] = (XPointer) NULL;

    if (ic_cnt > 0) {
	XGetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], NULL);
	if (pe_attr) XFree(pe_attr);
	if (st_attr) XFree(st_attr);
	if (p->xic == NULL) {
	    p->openic_error = True;
	    return;
	}
	pe_attr = st_attr = NULL;
	ic_cnt = 0;
	if (p->input_style & XIMStatusArea) {
	    st_area.height = st_area_needed->height;
	    st_area.x = 0;
	    st_area.y = height - st_area.height;
	    if (p->input_style & XIMPreeditArea) {
		st_area.width = st_area_needed->width;
	    } else {
		st_area.width = width;
	    }

	    XFree(st_area_needed);
	    st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL);
	    ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++;
	    ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++;
	}
	if (p->input_style & XIMPreeditArea) {
	    if (p->input_style & XIMStatusArea) {
		pe_area.x = st_area.width;
		pe_area.width = width - st_area.width;
	    } else {
		pe_area.x = 0;
		pe_area.width = width;
	    }
	    pe_area.height = pe_area_needed->height;
	    XFree(pe_area_needed);
	    pe_area.y = height - pe_area.height;
	    pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
	    ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++;
	    ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++;
	}
	ic_a[ic_cnt] = (XPointer) NULL;
	XSetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], NULL);
	if (pe_attr) XFree(pe_attr);
	if (st_attr) XFree(st_attr);
	if (p->xic == NULL) {
	    p->openic_error = True;
	    return;
	}
    }
}