Пример #1
0
bool x11_create_input_context(Display *dpy, Window win, XIM *xim, XIC *xic)
{
   x11_destroy_input_context(xim, xic);

   g_x11_has_focus = true;
   *xim            = XOpenIM(dpy, NULL, NULL, NULL);

   if (!*xim)
   {
      RARCH_ERR("[X11]: Failed to open input method.\n");
      return false;
   }

   *xic = XCreateIC(*xim, XNInputStyle,
         XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);

   if (!*xic)
   {
      RARCH_ERR("[X11]: Failed to create input context.\n");
      return false;
   }

   XSetICFocus(*xic);
   return true;
}
Пример #2
0
int HoLabel::create(){
  char *s = title->toString();
  created = 1;
#if hplatform==MW
  handle = CreateWindow(
    "STATIC",
    s,
    WS_CHILD | WS_VISIBLE,
    x,
    y,
    w,
    h,
    parent->handle,
    NULL,
    HoMainApp->hInstance,
    NULL
    );
#elif hplatform==XW
 int whiteColor = WhitePixel(HoMainApp->dpy, DefaultScreen(HoMainApp->dpy));
 handle = XCreateSimpleWindow(HoMainApp->dpy,parent->handle, x,y,w,h,0,whiteColor, whiteColor);
 XSetWMProtocols(HoMainApp->dpy, handle, & HoMainApp->xdel,1);
 XSelectInput(HoMainApp->dpy, handle, StructureNotifyMask);
 XMapWindow(HoMainApp->dpy, handle);
 xic = XCreateIC(HoMainApp->xim, XNInputStyle, HoMainApp->my_style, XNClientWindow,
    handle, NULL);

#endif

 HoMainApp->addWindow(this);
 free(s);
 return 1;
}
Пример #3
0
bool X11Window::internalSetupWindowInput()
{
    // try to set a latin1 locales, otherwise fallback to standard C locale
    static char locales[4][32] = { "en_US.iso88591", "iso88591", "en_US", "C" };
    for(int i=0;i<4;++i) {
        if(setlocale(LC_ALL, locales[i]))
            break;
    }

    //  create input context (to have better key input handling)
    if(!XSupportsLocale()) {
        g_logger.error("X11 doesn't support the current locale");
        return false;
    }

    XSetLocaleModifiers("");
    m_xim = XOpenIM(m_display, NULL, NULL, NULL);
    if(!m_xim) {
        g_logger.error("XOpenIM failed");
        return false;
    }

    m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_window, NULL);
    if(!m_xic) {
        g_logger.error("Unable to create the input context");
        return false;
    }

    return true;
}
Пример #4
0
bool StXDisplay::open() {
    hDisplay = XOpenDisplay(NULL); // get first display on server from DISPLAY in env
    //hDisplay = XOpenDisplay(":0.0");
    //hDisplay = XOpenDisplay("somehost:0.0");
    //hDisplay = XOpenDisplay("192.168.1.10:0.0");
    if(isOpened()) {
        initAtoms();

        hInputMethod = XOpenIM(hDisplay, NULL, NULL, NULL);
        if(hInputMethod == NULL) {
            return true;
        }

        XIMStyles* anIMStyles = NULL;
        char* anIMValues = XGetIMValues(hInputMethod, XNQueryInputStyle, &anIMStyles, NULL);
        if(anIMValues != NULL
        || anIMStyles == NULL
        || anIMStyles->count_styles <= 0) {
            // input method doesn't support any styles
            if(anIMStyles != NULL) {
                XFree(anIMStyles);
            }
            return true;
        }
        const XIMStyle anIMStyle = anIMStyles->supported_styles[0];
        XFree(anIMStyles);

        hInputCtx = XCreateIC(hInputMethod, XNInputStyle, anIMStyle, NULL);

        return true;
    }
    return false;
}
Пример #5
0
// Xft text box, optionally editable
textbox* textbox_create(Window parent, unsigned long flags, short x, short y, short w, short h, char *font, char *fg, char *bg, char *text, char *prompt)
{
	textbox *tb = calloc(1, sizeof(textbox));

	tb->flags = flags;
	tb->parent = parent;

	tb->x = x; tb->y = y; tb->w = MAX(1, w); tb->h = MAX(1, h);

	XColor color; Colormap map = DefaultColormap(display, DefaultScreen(display));
	unsigned int cp = XAllocNamedColor(display, map, bg, &color, &color) ? color.pixel: None;

	tb->window = XCreateSimpleWindow(display, tb->parent, tb->x, tb->y, tb->w, tb->h, 0, None, cp);

	// need to preload the font to calc line height
	textbox_font(tb, font, fg, bg);

	tb->prompt = strdup(prompt ? prompt: "");
	textbox_text(tb, text ? text: "");

	// auto height/width modes get handled here
	textbox_moveresize(tb, tb->x, tb->y, tb->w, tb->h);

	// edit mode controls
	if (tb->flags & TB_EDITABLE)
	{
		tb->xim = XOpenIM(display, NULL, NULL, NULL);
		tb->xic = XCreateIC(tb->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, tb->window, XNFocusWindow, tb->window, NULL);
	}

	return tb;
}
Пример #6
0
// Xft text box, optionally editable
textbox* textbox_create(Window parent, bitmap flags, short x, short y, short w, short h, char *font, char *fg, char *bg, char *text, char *prompt)
{
	textbox *tb = allocate_clear(sizeof(textbox));

	tb->flags = flags;
	tb->parent = parent;

	tb->x = x; tb->y = y; tb->w = MAX(1, w); tb->h = MAX(1, h);
	tb->window = XCreateSimpleWindow(display, tb->parent, tb->x, tb->y, tb->w, tb->h, 0, None, color_get(bg));

	// need to preload the font to calc line height
	textbox_font(tb, font, fg, bg);

	tb->prompt = strdup(prompt ? prompt: "");
	textbox_text(tb, text ? text: "");

	// auto height/width modes get handled here
	textbox_moveresize(tb, tb->x, tb->y, tb->w, tb->h);

	// edit mode controls
	if (tb->flags & TB_EDITABLE)
	{
		tb->xim = XOpenIM(display, NULL, NULL, NULL);
		tb->xic = XCreateIC(tb->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, tb->window, XNFocusWindow, tb->window, NULL);
	}

	return tb;
}
Пример #7
0
static void
InitI18N(Widget ctxw)
{
    LoginWidget ctx = (LoginWidget)ctxw;
    XIM         xim = (XIM) NULL;
    char *p;

    ctx->login.xic = (XIC) NULL;

    if ((p = XSetLocaleModifiers("@im=none")) != NULL && *p)
	xim = XOpenIM(XtDisplay(ctx), NULL, NULL, NULL);

    if (!xim) {
	LogError("Failed to open input method\n");
	return;
    }

    ctx->login.xic = XCreateIC(xim,
	XNInputStyle, (XIMPreeditNothing|XIMStatusNothing),
	XNClientWindow, ctx->core.window,
	XNFocusWindow,  ctx->core.window, NULL);

    if (!ctx->login.xic) {
	LogError("Failed to create input context\n");
	XCloseIM(xim);
    }
    return;
}
Пример #8
0
static void openwin(int x, int y, unsigned w, unsigned h, int b) {
        XSizeHints hints;
        XSetWindowAttributes swa; 
        unsigned long swamask;
        Atom datom;
        swa.event_mask = EVMASK;
        swamask = CWEventMask;
        hints.x = x;
        hints.y = y;
        hints.width = w;
        hints.height = h;
        assert(!g_win);
        g_win = XCreateWindow(g_dpy, XRootWindow(g_dpy, scr()),
                            hints.x, hints.y, hints.width, hints.height,
                            0, CopyFromParent,
                            InputOutput, 
                            CopyFromParent,
                            swamask, &swa);
        borders(b);
        hints.flags = USSize | USPosition;
        XSetWMNormalHints(g_dpy, g_win, &hints);
        datom = XInternAtom(g_dpy, "WM_DELETE_WINDOW", False);
        XSetWMProtocols(g_dpy, g_win, &datom, 1);
        XSelectInput(g_dpy, g_win, EVMASK);
        g_xic = XCreateIC(g_xim,
                        XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
                        XNClientWindow, g_win,
                        XNFocusWindow, g_win,
                        NULL);
        if (g_cursor)
                XDefineCursor(g_dpy, g_win, g_cursor);
        XStoreName(g_dpy, g_win, (const char*)cvInject(CVQ_NAME, 0, 0));
}
Пример #9
0
////////////////////////////////////////////////////////////
/// Do some common initializations after the window has been created
////////////////////////////////////////////////////////////
void WindowImplX11::Initialize()
{
    // Make sure the "last key release" is initialized with invalid values
    myLastKeyReleaseEvent.type = -1;

    // Get the atom defining the close event
    myAtomClose = XInternAtom(ourDisplay, "WM_DELETE_WINDOW", false);
    XSetWMProtocols(ourDisplay, myWindow, &myAtomClose, 1);

    // Create the input context
    if (ourInputMethod)
    {
        myInputContext = XCreateIC(ourInputMethod,
                                   XNClientWindow,  myWindow,
                                   XNFocusWindow,   myWindow,
                                   XNInputStyle,    XIMPreeditNothing  | XIMStatusNothing,
                                   NULL);
        
        if (!myInputContext)
            std::cerr << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl;
    }

    // Show the window
    XMapWindow(ourDisplay, myWindow);
    XFlush(ourDisplay);

    // Create the hiden cursor
    CreateHiddenCursor();

    // Set our context as the current OpenGL context for rendering
    SetActive();

    // Flush the commands queue
    XFlush(ourDisplay);
}
void
CXWindowsPrimaryScreen::onPostOpen()
{
	assert(m_window != None);

	// get cursor info
	m_screen->getCursorPos(m_x, m_y);
	m_screen->getCursorCenter(m_xCenter, m_yCenter);

	// get the input method
	CDisplayLock display(m_screen);
	m_im = XOpenIM(display, NULL, NULL, NULL);
	if (m_im == NULL) {
		return;
	}

	// find the appropriate style.  synergy supports XIMPreeditNothing
	// only at the moment.
	XIMStyles* styles;
	if (XGetIMValues(m_im, XNQueryInputStyle, &styles, NULL) != NULL ||
		styles == NULL) {
		LOG((CLOG_WARN "cannot get IM styles"));
		return;
	}
	XIMStyle style = 0;
	for (unsigned short i = 0; i < styles->count_styles; ++i) {
		style = styles->supported_styles[i];
		if ((style & XIMPreeditNothing) != 0) {
			if ((style & (XIMStatusNothing | XIMStatusNone)) != 0) {
				break;
			}
		}
	}
	XFree(styles);
	if (style == 0) {
		LOG((CLOG_WARN "no supported IM styles"));
		return;
	}

	// create an input context for the style and tell it about our window
	m_ic = XCreateIC(m_im, XNInputStyle, style, XNClientWindow, m_window, NULL);
	if (m_ic == NULL) {
		LOG((CLOG_WARN "cannot create IC"));
		return;
	}

	// find out the events we must select for and do so
	unsigned long mask;
	if (XGetICValues(m_ic, XNFilterEvents, &mask, NULL) != NULL) {
		LOG((CLOG_WARN "cannot get IC filter events"));
		return;
	}
	XWindowAttributes attr;
	XGetWindowAttributes(display, m_window, &attr);
	XSelectInput(display, m_window, attr.your_event_mask | mask);

	// no previous keycode
	m_lastKeycode = 0;
}
Пример #11
0
void t_keyboard_context_renew(struct t_ic *ic)
{
	if(xim) {
		ic->xic = XCreateIC(xim, XNInputStyle, xim_style, XNClientWindow, ic->client, XNFocusWindow, ic->focus, NULL);
		if(!ic->xic)
			g_message("Error creating Input Context for window 0x%x 0x%x\n", (guint)ic->client, (guint)ic->focus);
	}
}
Пример #12
0
void
x_init_input()
{
    X.xim = XOpenIM(X.dpy, NULL, NULL, NULL);
    X.xic = XCreateIC(X.xim, XNInputStyle, XIMPreeditNothing
                       | XIMStatusNothing, XNClientWindow, X.window,
                          XNFocusWindow, X.window, NULL);

}
Пример #13
0
__attribute__((constructor)) static void init()
{
	dpy = XOpenDisplay(0);
	screen = DefaultScreen(dpy);
	root = RootWindow(dpy, screen);
	im = XOpenIM(dpy, 0, 0, 0);
	ic = XCreateIC(im, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, 0);
	XSync(dpy, 0);
}
Пример #14
0
static Bool
scalefilterInitDisplay (CompPlugin  *p,
	    		CompDisplay *d)
{
    ScaleFilterDisplay *fd;
    CompPlugin         *scale = findActivePlugin ("scale");
    CompOption         *option;
    int                nOption;

    if (!scale || !scale->vTable->getDisplayOptions)
	return FALSE;

    option = (*scale->vTable->getDisplayOptions) (scale, d, &nOption);

    if (getIntOptionNamed (option, nOption, "abi", 0) != SCALE_ABIVERSION)
    {
	compLogMessage (d, "scalefilter", CompLogLevelError,
			"scale ABI version mismatch");
	return FALSE;
    }

    scaleDisplayPrivateIndex = getIntOptionNamed (option, nOption, "index", -1);
    if (scaleDisplayPrivateIndex < 0)
	return FALSE;

    fd = malloc (sizeof (ScaleFilterDisplay));
    if (!fd)
	return FALSE;

    fd->screenPrivateIndex = allocateScreenPrivateIndex (d);
    if (fd->screenPrivateIndex < 0)
    {
	free (fd);
	return FALSE;
    }

    fd->xim = XOpenIM (d->display, NULL, NULL, NULL);
    if (fd->xim)
	fd->xic = XCreateIC (fd->xim,
			     XNClientWindow, d->screens->root,
			     XNInputStyle,
			     XIMPreeditNothing  | XIMStatusNothing,
			     NULL);
    else
	fd->xic = NULL;

    if (fd->xic)
	setlocale (LC_CTYPE, "");

    WRAP (fd, d, handleEvent, scalefilterHandleEvent);
    WRAP (fd, d, handleEcompEvent, scalefilterHandleEcompEvent);

    d->privates[displayPrivateIndex].ptr = fd;

    return TRUE;
}
Пример #15
0
void BrowserControl::createInputMethodAndInputContext()
{
    m_im = XOpenIM(m_display, 0, 0, 0);
    if (!m_im)
        fprintf(stderr, "Could not open input method\n");

    m_ic = XCreateIC(m_im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_browserWindow->window(), 0);
    if (!m_ic)
        fprintf(stderr, "Could not open input context\n");
}
Пример #16
0
void setup() {
	XSetWindowAttributes attributes;
	XWindowAttributes window_attributes;
	Visual *vis;
	Colormap cmap;
	int ignore;
	
	display = XOpenDisplay(NULL);
	screen = DefaultScreen(display);
	vis = XDefaultVisual(display, screen);
	cmap = DefaultColormap(display, screen);

	if (XGetGeometry(display, RootWindow(display, screen), &root,
	        &ignore, &ignore,
	        &max_width, &max_height, &ignore, &ignore) == False)
	        die("Failed to get root Geometry!");

	if (!XftColorAllocName(display, vis, cmap, fg_name, &fg))
		die("Failed to allocate foreground color");
	if (!XftColorAllocName(display, vis, cmap, bg_name, &bg))
		die("Failed to allocate background color");

	/* Setup and map window */
	attributes.border_pixel = fg.pixel;
	attributes.background_pixel = bg.pixel;
	attributes.override_redirect = True;
	attributes.event_mask = 
	     ExposureMask|KeyPressMask|ButtonPressMask|ButtonReleaseMask;

	win = XCreateWindow(display, root,
	     0, 0, 1, 1, BORDER_WIDTH,
	     DefaultDepth(display, 0),
	     CopyFromParent, CopyFromParent,
	     CWBackPixel|CWOverrideRedirect|CWEventMask|CWBorderPixel,
	     &attributes);

	xim = XOpenIM(display, NULL, NULL, NULL);
	xic = XCreateIC(xim, XNInputStyle, 
	    XIMPreeditNothing | XIMStatusNothing,
	    XNClientWindow, win, XNFocusWindow, win, NULL);

	gc = XCreateGC(display, win, 0, 0);

	buf = XCreatePixmap(display, win, 1, 1, 
	                    DefaultDepth(display, screen));
	    
	draw = XftDrawCreate(display, buf, vis, cmap);

	load_font(font_str);
}
void WindowContextBase::enableOrResetIME() {
    Display *display = gdk_x11_display_get_xdisplay(glass_gdk_window_get_display(gdk_window));
    if (xim.im == NULL || xim.ic == NULL) {
        xim.im = XOpenIM(display, NULL, NULL, NULL);
        if (xim.im == NULL) {
            return;
        }

        XIMStyle styles = get_best_supported_style(xim.im);
        if (styles == 0) {
            return;
        }

        XIMCallback startCallback = {(XPointer) jview, (XIMProc) im_preedit_start};
        XIMCallback doneCallback = {(XPointer) jview, im_preedit_done};
        XIMCallback drawCallback = {(XPointer) jview, im_preedit_draw};
        XIMCallback caretCallback = {(XPointer) jview, im_preedit_caret};

        XVaNestedList list = XVaCreateNestedList(0,
                XNPreeditStartCallback, &startCallback,
                XNPreeditDoneCallback, &doneCallback,
                XNPreeditDrawCallback, &drawCallback,
                XNPreeditCaretCallback, &caretCallback,
                NULL);

        xim.ic = XCreateIC(xim.im,
                XNInputStyle, styles,
                XNClientWindow, GDK_WINDOW_XID(gdk_window),
                XNPreeditAttributes, list,
                NULL);

        XFree(list);

        if (xim.ic == NULL) {
            return;
        }
    }

    if (xim.enabled) { //called when changed focus to different input
        XmbResetIC(xim.ic);
    }


    XSetICFocus(xim.ic);

    xim.enabled = TRUE;
}
void CUnixEventEmitter::createIM()
{
	_im = XOpenIM(_dpy, NULL, NULL, NULL);
	if (_im)
	{
		_ic = XCreateIC(_im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, _win, XNFocusWindow, _win, NULL);
//		XSetICFocus(_ic);
	}
	else
	{
		_ic = 0;
		nlwarning("XCreateIM failed");
	}

	if (!_ic)
	{
		nlwarning("XCreateIC failed");
	}
}
Пример #19
0
bool X11Window::internalSetupWindowInput()
{
    //  create input context (to have better key input handling)
    if(!XSupportsLocale()) {
        g_logger.error("X11 doesn't support the current locale");
        return false;
    }

    XSetLocaleModifiers("");
    m_xim = XOpenIM(m_display, NULL, NULL, NULL);
    if(!m_xim) {
        g_logger.error("XOpenIM failed");
        return false;
    }

    m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_window, NULL);
    if(!m_xic) {
        g_logger.error("Unable to create the input context");
        return false;
    }

    return true;
}
Пример #20
0
void creategui()
{
	int x, y, w = width, h = height;
	XSetWindowAttributes wa;

	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
		fputs("no locale support\n", stderr);

	screen = DefaultScreen(dpy);
	root = RootWindow(dpy, screen);
	initfont(font);
	cursor = XCreateFontCursor(dpy, XC_left_ptr);

	dc.norm[ColBG] = getcolor(normbgcolor);
	dc.norm[ColFG] = getcolor(normfgcolor);
	dc.sel[ColBG] = getcolor(selbgcolor);
	dc.sel[ColFG] = getcolor(selfgcolor);
	dc.drawable = XCreatePixmap(dpy, root, w, 2 * h, DefaultDepth(dpy, screen));
	dc.gc = XCreateGC(dpy, root, 0, NULL);
	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
	if (!dc.font.set)
		XSetFont(dpy, dc.gc, dc.font.xfont->fid);

	wa.cursor = cursor;
	wa.background_pixel = dc.norm[ColBG];
	XChangeWindowAttributes(dpy, root, CWBackPixel|CWCursor, &wa);

	x = (DisplayWidth(dpy, screen) - w) / 2;
	y = DisplayHeight(dpy, screen) / 2;
	createinput(userprompt, x, y - h, w, h, innerpx, False);
	createinput(passprompt, x, y, w, h, innerpx, True);

	im = XOpenIM(dpy, NULL, NULL, NULL);
	ic = XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
			XNClientWindow, inputs->win, XNFocusWindow, inputs->win, NULL);
}
Пример #21
0
se_text_xviewer* se_text_xviewer_create( se_env* env )
{
    se_text_xviewer* viewer = g_malloc0( sizeof(se_text_xviewer) );
    if ( !viewer ) {
        se_error( "can not malloc a viewer obj" );
    }

    viewer->env = env;
    
    int width = 800;
    int height = 600;
    
    viewer->view = XCreateSimpleWindow(
        env->display, env->root, 0, 0, width, height, 0,
        BlackPixel(env->display, env->screen),
        WhitePixel(env->display, env->screen) );
    
    viewer->key_handler = se_text_xviewer_key_event;
    viewer->mouse_handler = se_text_xviewer_mouse_event;
    viewer->configure_change_handler = se_text_xviewer_configure_change_handler;

    viewer->show = se_text_xviewer_show;
    viewer->repaint = se_text_xviewer_repaint;
    viewer->redisplay = se_text_xviewer_redisplay;
    viewer->updateSize = se_text_xviewer_updateSize;
    
    se_text_xviewer_draw_create( viewer );

    viewer->content = g_malloc0( SE_MAX_COLUMNS * SE_MAX_ROWS );

    XIMStyles *im_supported_styles;
    XIMStyle app_supported_styles;
    XIMStyle style;
    XIMStyle best_style;

    XGetIMValues( env->xim, XNQueryInputStyle, &im_supported_styles, NULL );
    app_supported_styles = XIMPreeditNone | XIMPreeditNothing | XIMPreeditArea
        | XIMStatusNone | XIMStatusNothing | XIMStatusArea;
    best_style = 0;
    se_debug( "styles count: %d", im_supported_styles->count_styles );
    for(int i=0; i < im_supported_styles->count_styles; i++) {
        style = im_supported_styles->supported_styles[i];
        dump_style( style );
        if ((style & app_supported_styles) == style) /* if we can handle it */
            best_style = ChooseBetterStyle(style, best_style);
    }

    /* if we couldn't support any of them, print an error and exit */
    if (best_style == 0) {
        se_error("commonly supported interaction style.");
        exit(1);
    }
    XFree(im_supported_styles);
    dump_style( best_style );
    
    viewer->xic = XCreateIC(env->xim, XNInputStyle, best_style,
                            XNClientWindow, viewer->view,
                            NULL);
    if ( viewer->xic == NULL ) {
        se_debug(" create xic failed" );
        exit(1);        
    }
    se_debug( "XLocaleOfIM: %s", XLocaleOfIM( env->xim ) );
    
    return viewer;
}
Пример #22
0
void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {

	last_button_state=0;
	dpad_last[0]=0;
	dpad_last[1]=0;

	xmbstring=NULL;
	event_id=0;
	x11_window=0;
	last_click_ms=0;
	args=OS::get_singleton()->get_cmdline_args();
	current_videomode=p_desired;
	main_loop=NULL;
	last_timestamp=0;
	last_mouse_pos_valid=false;
	last_keyrelease_time=0;

	if (get_render_thread_mode()==RENDER_SEPARATE_THREAD) {
		XInitThreads();
	}
	
	/** XLIB INITIALIZATION **/
	x11_display = XOpenDisplay(NULL);
	
	char * modifiers = XSetLocaleModifiers ("@im=none");
	ERR_FAIL_COND( modifiers == NULL );
	
	xim = XOpenIM (x11_display, NULL, NULL, NULL);
	

	if (xim == NULL) {
		WARN_PRINT("XOpenIM failed");
		xim_style=NULL;
	} else {
		::XIMStyles *xim_styles=NULL;
		xim_style=0;
		char *imvalret=NULL;
		imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
		if (imvalret != NULL || xim_styles == NULL) {
			fprintf (stderr, "Input method doesn't support any styles\n");
		}
		
		if (xim_styles) {
			xim_style = 0;
			for (int i=0;i<xim_styles->count_styles;i++) {
				
				if (xim_styles->supported_styles[i] ==
				    (XIMPreeditNothing | XIMStatusNothing)) {
					    
					    xim_style = xim_styles->supported_styles[i];
					    break;
				    }
			}
			
			XFree (xim_styles);
		}
	}

	/*
	char* windowid = getenv("GODOT_WINDOWID");
	if (windowid) {

		//freopen("/home/punto/stdout", "w", stdout);
		//reopen("/home/punto/stderr", "w", stderr);
		x11_window = atol(windowid);

		XWindowAttributes xwa;
		XGetWindowAttributes(x11_display,x11_window,&xwa);

		current_videomode.width = xwa.width;
		current_videomode.height = xwa.height;
	};
	*/

	// maybe contextgl wants to be in charge of creating the window
	//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
	context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) );
	context_gl->initialize();

	if (true) {
		rasterizer = memnew( RasterizerGLES2 );
	} else {
		//rasterizer = memnew( RasterizerGLES1 );
	};

#endif
	visual_server = memnew( VisualServerRaster(rasterizer) );

	if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) {

		visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD));
	}

	// borderless fullscreen window mode
	if (current_videomode.fullscreen) {
		// needed for lxde/openbox, possibly others
		Hints hints;
		Atom property;
		hints.flags = 2;
		hints.decorations = 0;
		property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
		XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
		XMapRaised(x11_display, x11_window);
		XWindowAttributes xwa;
		XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa);
		XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height);

		// code for netwm-compliants
		XEvent xev;
		Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
		Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False);

		memset(&xev, 0, sizeof(xev));
		xev.type = ClientMessage;
		xev.xclient.window = x11_window;
		xev.xclient.message_type = wm_state;
		xev.xclient.format = 32;
		xev.xclient.data.l[0] = 1;
		xev.xclient.data.l[1] = fullscreen;
		xev.xclient.data.l[2] = 0;

		XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev);
	}

	// disable resizeable window
	if (!current_videomode.resizable) {
		XSizeHints *xsh;
		xsh = XAllocSizeHints();
		xsh->flags = PMinSize | PMaxSize;
		XWindowAttributes xwa;
		if (current_videomode.fullscreen) {
			XGetWindowAttributes(x11_display,DefaultRootWindow(x11_display),&xwa);
		} else {
			XGetWindowAttributes(x11_display,x11_window,&xwa);
		}
		xsh->min_width = xwa.width; 
		xsh->max_width = xwa.width;
		xsh->min_height = xwa.height;
		xsh->max_height = xwa.height;
		XSetWMNormalHints(x11_display, x11_window, xsh);
	}

	AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton();

	if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) {

		ERR_PRINT("Initializing audio failed.");
	}

	sample_manager = memnew( SampleManagerMallocSW );
	audio_server = memnew( AudioServerSW(sample_manager) );
	audio_server->init();
	spatial_sound_server = memnew( SpatialSoundServerSW );
	spatial_sound_server->init();
	spatial_sound_2d_server = memnew( SpatialSound2DServerSW );
	spatial_sound_2d_server->init();

	
	ERR_FAIL_COND(!visual_server);
	ERR_FAIL_COND(x11_window==0);

	XSetWindowAttributes new_attr;

	new_attr.event_mask=KeyPressMask | KeyReleaseMask | ButtonPressMask |
			   ButtonReleaseMask | EnterWindowMask |
			   LeaveWindowMask | PointerMotionMask |
			   Button1MotionMask |
			   Button2MotionMask | Button3MotionMask |
			   Button4MotionMask | Button5MotionMask |
			   ButtonMotionMask | KeymapStateMask |
			   ExposureMask | VisibilityChangeMask |
			   StructureNotifyMask |
			   SubstructureNotifyMask | SubstructureRedirectMask |
			   FocusChangeMask | PropertyChangeMask |
			   ColormapChangeMask | OwnerGrabButtonMask;

	XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr);
	
    XClassHint* classHint;

    /* set the titlebar name */
    XStoreName(x11_display, x11_window, "Godot");

    /* set the name and class hints for the window manager to use */
    classHint = XAllocClassHint();
    if (classHint) {
        classHint->res_name = "Godot";
        classHint->res_class = "Godot";
    }
    XSetClassHint(x11_display, x11_window, classHint);
    XFree(classHint);

	wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true);	
	XSetWMProtocols(x11_display, x11_window, &wm_delete, 1);
		

	if (xim && xim_style) {
		
		xic = XCreateIC (xim,XNInputStyle, xim_style,XNClientWindow,x11_window,XNFocusWindow, x11_window, (char*)NULL);
	} else {
		
		xic=NULL;
		WARN_PRINT("XCreateIC couldn't create xic");

	}	

	XcursorSetTheme(x11_display,"default");
	cursor_size = XcursorGetDefaultSize(x11_display);
	cursor_theme = XcursorGetTheme(x11_display);

	if (!cursor_theme) {
		print_line("not found theme");
		cursor_theme="default";
	}

	for(int i=0;i<CURSOR_MAX;i++) {

		cursors[i]=None;
	}

	current_cursor=CURSOR_ARROW;

	if (cursor_theme) {
		//print_line("cursor theme: "+String(cursor_theme));
		for(int i=0;i<CURSOR_MAX;i++) {

			static const char *cursor_file[]={
				"left_ptr",
				"xterm",
				"hand2",
				"cross",
				"watch",
				"left_ptr_watch",
				"fleur",
				"hand1",
				"X_cursor",
				"sb_v_double_arrow",
				"sb_h_double_arrow",
				"size_bdiag",
				"size_fdiag",
				"hand1",
				"sb_v_double_arrow",
				"sb_h_double_arrow",
				"question_arrow"
			};

			XcursorImage *img = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size);
			if (img) {
				cursors[i]=XcursorImageLoadCursor(x11_display,img);
				//print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i]));
			} else {
				if (OS::is_stdout_verbose())
					print_line("failed cursor: "+String(cursor_file[i]));
			}
		}

	}


	{
		Pixmap cursormask;
		 XGCValues xgc;
		 GC gc;
		 XColor col;
		 Cursor cursor;

		 cursormask = XCreatePixmap(x11_display, RootWindow(x11_display,DefaultScreen(x11_display)), 1, 1, 1);
		 xgc.function = GXclear;
		 gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc);
		XFillRectangle(x11_display, cursormask, gc, 0, 0, 1, 1);
		col.pixel = 0;
		col.red = 0;
		col.flags = 4;
		cursor = XCreatePixmapCursor(x11_display,
			      cursormask, cursormask,
			      &col, &col, 0, 0);
		 XFreePixmap(x11_display, cursormask);
		 XFreeGC(x11_display, gc);



		 if (cursor == None)
		 {
			 ERR_PRINT("FAILED CREATING CURSOR");
		 }

		 null_cursor=cursor;
	}
	set_cursor_shape(CURSOR_BUSY);


	visual_server->init();
	//
	physics_server = memnew( PhysicsServerSW );
	physics_server->init();
	physics_2d_server = memnew( Physics2DServerSW );
	physics_2d_server->init();

	input = memnew( InputDefault );

	probe_joystick();

	_ensure_data_dir();

	net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);


	//printf("got map notify\n");
		
}
Пример #23
0
void dpy_start(void)
{
	display = XOpenDisplay(NULL);
	if (!display)
	{
		fprintf(stderr, "Error: can't open display. Is DISPLAY set?\n");
		exit(1);
	}

	window = XCreateSimpleWindow(display, RootWindow(display, 0),
					  0, 0, 800, 600, 0, 0, BlackPixel(display, 0));
	XStoreName(display, window, "WordGrinder " VERSION);
	XSetClassHint(display, window,
		&((XClassHint) { "WordGrinder", "WordGrinder" }));
	XSelectInput(display, window,
		StructureNotifyMask | ExposureMask | KeyPressMask | KeymapStateMask);
	XMapWindow(display, window);

	glyphcache_init();

	colours[COLOUR_BLACK]  = load_colour("X11_BLACK_COLOUR",  "#000000");
	colours[COLOUR_DIM]    = load_colour("X11_DIM_COLOUR",    "#555555");
	colours[COLOUR_NORMAL] = load_colour("X11_NORMAL_COLOUR", "#888888");
	colours[COLOUR_BRIGHT] = load_colour("X11_BRIGHT_COLOUR", "#ffffff");

	draw = XftDrawCreate(display, window,
		DefaultVisual(display, DefaultScreen(display)),
		DefaultColormap(display, DefaultScreen(display)));

	xim = XOpenIM(display, NULL, NULL, NULL);
	if (xim)
		xic = XCreateIC(xim, XNInputStyle,
			XIMPreeditNothing | XIMStatusNothing, XNClientWindow, window, NULL);
	if (!xim || !xic)
	{
		fprintf(stderr, "Error: couldn't set up input methods\n");
		exit(1);
	}
	XSetICFocus(xic);

	{
		XGCValues gcv =
		{
			.graphics_exposures = false
		};

		gc = XCreateGC(display, window, GCGraphicsExposures, &gcv);
	}

	screenwidth = screenheight = 0;
	cursorx = cursory = 0;
}

void dpy_shutdown(void)
{
}

void dpy_clearscreen(void)
{
	dpy_cleararea(0, 0, screenwidth-1, screenheight-1);
}
Пример #24
0
void
setup(void) {
	int x, y, screen = DefaultScreen(dc->dpy);
	Window root = RootWindow(dc->dpy, screen);
	XSetWindowAttributes swa;
	XIM xim;
#ifdef XINERAMA
	int n;
	XineramaScreenInfo *info;
#endif

	clip = XInternAtom(dc->dpy, "CLIPBOARD",   False);
	utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);

	/* calculate menu geometry */
	bh = (line_height > dc->font.height + 2) ? line_height : dc->font.height + 2;
	lines = MAX(lines, 0);
	mh = (lines + 1) * bh;
#ifdef XINERAMA
	if((info = XineramaQueryScreens(dc->dpy, &n))) {
		int a, j, di, i = 0, area = 0;
		unsigned int du;
		Window w, pw, dw, *dws;
		XWindowAttributes wa;

		XGetInputFocus(dc->dpy, &w, &di);
		if(w != root && w != PointerRoot && w != None) {
			/* find top-level window containing current input focus */
			do {
				if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws)
					XFree(dws);
			} while(w != root && w != pw);
			/* find xinerama screen with which the window intersects most */
			if(XGetWindowAttributes(dc->dpy, pw, &wa))
				for(j = 0; j < n; j++)
					if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
						area = a;
						i = j;
					}
		}
		/* no focused window is on screen, so use pointer location instead */
		if(!area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
			for(i = 0; i < n; i++)
				if(INTERSECT(x, y, 1, 1, info[i]))
					break;

		x = info[i].x_org;
		y = info[i].y_org + (topbar ? yoffset : info[i].height - mh - yoffset);
		mw = info[i].width;
		XFree(info);
	}
	else
#endif
	{
		x = 0;
		y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh - yoffset;
		mw = DisplayWidth(dc->dpy, screen);
	}

	x += xoffset;
	mw = width ? width : mw;
	promptw = (prompt && *prompt) ? textw(dc, prompt) : 0;
	inputw = MIN(inputw, mw/3);
	match();

	/* create menu window */
	swa.override_redirect = True;
	swa.background_pixel = normcol->BG;
	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
	win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
	                    DefaultDepth(dc->dpy, screen), CopyFromParent,
	                    DefaultVisual(dc->dpy, screen),
	                    CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);

	/* open input methods */
	xim = XOpenIM(dc->dpy, NULL, NULL, NULL);
	xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
	                XNClientWindow, win, XNFocusWindow, win, NULL);

	XMapRaised(dc->dpy, win);
	resizedc(dc, mw, mh);
	drawmenu();
}
Пример #25
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;
			}
		}
	}
Пример #26
0
static void
setup(void)
{
	int x, y;
	XSetWindowAttributes swa;
	XIM xim;
#ifdef XINERAMA
	XineramaScreenInfo *info;
	Window w, pw, dw, *dws;
	XWindowAttributes wa;
	int a, j, di, n, i = 0, area = 0;
	unsigned int du;
#endif

	/* init appearance */
	scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
	scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
	scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
	scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
	scheme[SchemeOut].bg = drw_clr_create(drw, outbgcolor);
	scheme[SchemeOut].fg = drw_clr_create(drw, outfgcolor);

	clip = XInternAtom(dpy, "CLIPBOARD",   False);
	utf8 = XInternAtom(dpy, "UTF8_STRING", False);

	/* calculate menu geometry */
	bh = drw->fonts[0]->h + 2;
	lines = MAX(lines, 0);
	mh = (lines + 1) * bh;
#ifdef XINERAMA
	if ((info = XineramaQueryScreens(dpy, &n))) {
		XGetInputFocus(dpy, &w, &di);
		if (mon != -1 && mon < n)
			i = mon;
		if (!i && w != root && w != PointerRoot && w != None) {
			/* find top-level window containing current input focus */
			do {
				if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws)
					XFree(dws);
			} while (w != root && w != pw);
			/* find xinerama screen with which the window intersects most */
			if (XGetWindowAttributes(dpy, pw, &wa))
				for (j = 0; j < n; j++)
					if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
						area = a;
						i = j;
					}
		}
		/* no focused window is on screen, so use pointer location instead */
		if (mon == -1 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
			for (i = 0; i < n; i++)
				if (INTERSECT(x, y, 1, 1, info[i]))
					break;

		x = info[i].x_org;
		y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
		mw = info[i].width;
		XFree(info);
	} else
#endif
	{
		x = 0;
		y = topbar ? 0 : sh - mh;
		mw = sw;
	}
	promptw = (prompt && *prompt) ? TEXTW(prompt) : 0;
	inputw = MIN(inputw, mw/3);
	match();

	/* create menu window */
	swa.override_redirect = True;
	swa.background_pixel = scheme[SchemeNorm].bg->pix;
	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
	win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
	                    DefaultDepth(dpy, screen), CopyFromParent,
	                    DefaultVisual(dpy, screen),
	                    CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);

	/* open input methods */
	xim = XOpenIM(dpy, NULL, NULL, NULL);
	xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
	                XNClientWindow, win, XNFocusWindow, win, NULL);

	XMapRaised(dpy, win);
	drw_resize(drw, mw, mh);
	drawmenu();
}
Пример #27
0
void
x_window_rep::initialize () {
  SI min_w= Min_w, min_h= Min_h;
  SI def_w= Def_w, def_h= Def_h;
  SI max_w= Max_w, max_h= Max_h;

  dpy= gui->dpy;
  gc = gui->gc;
  full_screen_flag= false;

  // time_t start_1= texmacs_time ();
  ren->set_origin (0, 0);
  ren->decode (def_w, def_h); def_h= -def_h;
  ren->decode (min_w, min_h); min_h= -min_h;
  ren->decode (max_w, max_h); max_h= -max_h;
  // cout << "Size computation required " << (texmacs_time ()-start_1) << " ms\n";

  // time_t start_2= texmacs_time ();
  unsigned long valuemask= CWOverrideRedirect | CWSaveUnder;
  //unsigned long valuemask= CWOverrideRedirect | CWSaveUnder | CWBackingStore;
  XSetWindowAttributes setattr;
  setattr.override_redirect= (name==NULL);
  setattr.save_under       = True; // (name==NULL);
  // setattr.backing_store    = Always;
  // FIXME: backing store does not seem to work correctly
  if (win_w == 0) win_w= def_w;
  if (win_h == 0) win_h= def_h;
  if ((win_x+ win_w) > gui->screen_width) win_x= gui->screen_width- win_w;
  if (win_x < 0) win_x= 0;
  if ((win_y+ win_h) > gui->screen_height) win_y= gui->screen_height- win_h;
  if (win_y < 0) win_y=0;
  win= XCreateWindow (dpy, gui->root, win_x, win_y, win_w, win_h, 0,
		      gui->depth, InputOutput, CopyFromParent,
		      valuemask, &setattr);
  ren->win= (Drawable) win;
  // cout << "XWindow creation required " << (texmacs_time ()-start_2) << " ms\n";

  //cout << "Hints: "
  //     << min_w << ", " << min_h << " --- "
  //     << def_w << ", " << def_h << " --- "
  //     << max_w << ", " << max_h << "\n";
  if (name == NULL) name= const_cast<char*> ("popup");
  if (the_name == "") {
    the_name= name;
    mod_name= name;
  }
  set_hints (min_w, min_h, max_w, max_h);

  unsigned long ic_mask= 0;
  ic_ok= false;
  if (gui->im_ok) {
    ic= XCreateIC (gui->im,
		   XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
		   XNClientWindow, win,
		   NULL);
    if (ic == NULL)
      cout << "TeXmacs] Warning: couldn't create input context\n";
    else {
      ic_ok= true;
      XGetICValues (ic, XNFilterEvents, &ic_mask, NULL);
    }
  }

  XSelectInput (dpy, win,
		ExposureMask | StructureNotifyMask |
		SubstructureNotifyMask | FocusChangeMask |
		PointerMotionMask | EnterWindowMask | LeaveWindowMask |
		ButtonPressMask | ButtonReleaseMask |
		KeyPressMask | ic_mask);

  Atom wm_protocols     = XInternAtom(dpy, "WM_PROTOCOLS", 1);
  Atom wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", 1);
  XSetWMProtocols (dpy, win, &wm_protocols, 1);
  XSetWMProtocols (dpy, win, &wm_delete_window, 1);

  nr_windows++;
  Window_to_window (win)= (void*) this;
  set_identifier (w, (int) win);
  notify_position (w, 0, 0);
  notify_size (w, Def_w, Def_h);
}
Пример #28
0
XIC X11DRV_CreateIC(XIM xim, struct x11drv_win_data *data)
{
    XPoint spot = {0};
    XVaNestedList preedit = NULL;
    XVaNestedList status = NULL;
    XIC xic;
    XICCallback destroy = {(XPointer)data, (XICProc)X11DRV_DestroyIC};
    XICCallback P_StartCB, P_DoneCB, P_DrawCB, P_CaretCB;
    LANGID langid = PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale()));
    Window win = data->whole_window;

    TRACE("xim = %p\n", xim);

    wine_tsx11_lock();

    /* use complex and slow XIC initialization method only for CJK */
    if (langid != LANG_CHINESE &&
        langid != LANG_JAPANESE &&
        langid != LANG_KOREAN)
    {
        xic = XCreateIC(xim,
                        XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
                        XNClientWindow, win,
                        XNFocusWindow, win,
                        XNDestroyCallback, &destroy,
                        NULL);
        wine_tsx11_unlock();
        data->xic = xic;
        return xic;
    }

    /* create callbacks */
    P_StartCB.client_data = NULL;
    P_DoneCB.client_data = NULL;
    P_DrawCB.client_data = NULL;
    P_CaretCB.client_data = NULL;
    P_StartCB.callback = (XICProc)XIMPreEditStartCallback;
    P_DoneCB.callback = (XICProc)XIMPreEditDoneCallback;
    P_DrawCB.callback = (XICProc)XIMPreEditDrawCallback;
    P_CaretCB.callback = (XICProc)XIMPreEditCaretCallback;

    if ((ximStyle & (XIMPreeditNothing | XIMPreeditNone)) == 0)
    {
        preedit = XVaCreateNestedList(0,
                        XNSpotLocation, &spot,
                        XNPreeditStartCallback, &P_StartCB,
                        XNPreeditDoneCallback, &P_DoneCB,
                        XNPreeditDrawCallback, &P_DrawCB,
                        XNPreeditCaretCallback, &P_CaretCB,
                        NULL);
        TRACE("preedit = %p\n", preedit);
    }
    else
    {
        preedit = XVaCreateNestedList(0,
                        XNPreeditStartCallback, &P_StartCB,
                        XNPreeditDoneCallback, &P_DoneCB,
                        XNPreeditDrawCallback, &P_DrawCB,
                        XNPreeditCaretCallback, &P_CaretCB,
                        NULL);

        TRACE("preedit = %p\n", preedit);
    }

    if ((ximStyle & (XIMStatusNothing | XIMStatusNone)) == 0)
    {
        status = XVaCreateNestedList(0,
            NULL);
        TRACE("status = %p\n", status);
     }

    if (preedit != NULL && status != NULL)
    {
        xic = XCreateIC(xim,
              XNInputStyle, ximStyle,
              XNPreeditAttributes, preedit,
              XNStatusAttributes, status,
              XNClientWindow, win,
              XNFocusWindow, win,
              XNDestroyCallback, &destroy,
              NULL);
     }
    else if (preedit != NULL)
    {
        xic = XCreateIC(xim,
              XNInputStyle, ximStyle,
              XNPreeditAttributes, preedit,
              XNClientWindow, win,
              XNFocusWindow, win,
              XNDestroyCallback, &destroy,
              NULL);
    }
    else if (status != NULL)
    {
        xic = XCreateIC(xim,
              XNInputStyle, ximStyle,
              XNStatusAttributes, status,
              XNClientWindow, win,
              XNFocusWindow, win,
              XNDestroyCallback, &destroy,
              NULL);
    }
    else
    {
        xic = XCreateIC(xim,
              XNInputStyle, ximStyle,
              XNClientWindow, win,
              XNFocusWindow, win,
              XNDestroyCallback, &destroy,
              NULL);
    }

    TRACE("xic = %p\n", xic);
    data->xic = xic;

    if (preedit != NULL)
        XFree(preedit);
    if (status != NULL)
        XFree(status);

    wine_tsx11_unlock();

    return xic;
}
Пример #29
0
void DesktopWindowLinux::setup()
{
    char* loc = setlocale(LC_ALL, "");
    if (!loc)
        std::cerr << "Could not use the the default environment locale.\n";

    if (!XSupportsLocale())
        std::cerr << "Default locale \"" << (loc ? loc : "") << "\" is no supported.\n";

    // When changing the locale being used we must call XSetLocaleModifiers (refer to manpage).
    if (!XSetLocaleModifiers(""))
        std::cerr << "Could not set locale modifiers for locale \"" << (loc ? loc : "") << "\".\n";

    m_display = XOpenDisplay(0);
    if (!m_display)
        throw FatalError("Couldn't connect to X server");

    int attributes[] = {
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
                GLX_DOUBLEBUFFER,  True,
                GLX_RENDER_TYPE,
                GLX_RGBA_BIT,
                GLX_RED_SIZE,      1,
                GLX_GREEN_SIZE,    1,
                GLX_BLUE_SIZE,     1,
                GLX_ALPHA_SIZE,    1,
                GLX_TRANSPARENT_TYPE,
                GLX_NONE,
                None
    };

    int numReturned = 0;
    GLXFBConfig* fbConfigs(glXChooseFBConfig(m_display, DefaultScreen(m_display), attributes, &numReturned));
    if (!fbConfigs)
        throw FatalError("No double buffered config available");

    GLXFBConfig fbConfig = fbConfigs[0];
    ScopedXFree x(fbConfigs);

    m_visualInfo = glXGetVisualFromFBConfig(m_display, fbConfig);
    if (!m_visualInfo)
        throw FatalError("No appropriate visual found.");

    XSetWindowAttributes setAttributes;
    setAttributes.colormap = XCreateColormap(m_display, DefaultRootWindow(m_display), m_visualInfo->visual, AllocNone);
    setAttributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | PointerMotionMask;
    m_window = XCreateWindow(m_display, DefaultRootWindow(m_display),
                                0, 0, m_size.width, m_size.height, 0,
                                m_visualInfo->depth, InputOutput, m_visualInfo->visual,
                                CWColormap | CWEventMask, &setAttributes);

    m_im = XOpenIM(m_display, 0, 0, 0);
    if (!m_im)
        throw FatalError("Could not open input method.");

    m_ic = XCreateIC(m_im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_window, NULL);
    if (!m_ic)
        throw FatalError("Could not open input context.");

    wmDeleteMessageAtom = XInternAtom(m_display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(m_display, m_window, &wmDeleteMessageAtom, 1);

    XMapWindow(m_display, m_window);
    XStoreName(m_display, m_window, "Drowser");

    m_context = glXCreateNewContext(m_display, fbConfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
    if (!m_context)
        throw FatalError("glXCreateContext() failed.");
}
Пример #30
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;
}