Вот поизучал исходники xev и написал прогу только не пичатает зараза в окне русские буквы и всё тут !?!? может кто поможет ???
#include <stdio.h>
#include <stdlib.h>
//#include <locale.h>
#include <string.h>
#include <X11/Xlocale.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include <X11/Xatom.h>
#define OUTER_WINDOW_MIN_WIDTH 200
#define OUTER_WINDOW_MIN_HEIGHT 200
#define OUTER_WINDOW_DEF_WIDTH (OUTER_WINDOW_MIN_WIDTH + 100)
#define OUTER_WINDOW_DEF_HEIGHT (OUTER_WINDOW_MIN_HEIGHT + 100)
#define OUTER_WINDOW_DEF_X 100
#define OUTER_WINDOW_DEF_Y 100
#define BORDER_WIDTH 2
#define DEFAULT_FONT "-misc-*-*-*-*-*-*-200-*-*-*-*-koi8-r"
#define MAX_STRING 256
	XIM xim;
	XIC xic;
	Window root_win;
	Window win;
	Window sub_win;
	Font font;
	GC gc;
	XFontSet fs;
	Display* dpy;
	XIMStyles* xim_styles;
	XIMStyle xim_style;
	XSetWindowAttributes win_attr;
	XGCValues gcv;
	XSizeHints hints;
	XEvent event;
	
	
	char* mod;
	char* value_im;
	int scr;
	unsigned long mask;
	
	char string[ MAX_STRING+1 ];
	
	
	void set_sizehints(XSizeHints* hintp, int min_width, int min_height, 
	       int defwidth, int defheight, int defx, int defy, int scr );
	
	void	do_keypress( XEvent* event );
	void	do_expose( XEvent* event );
	void draw();
	int StrLenght( char* str );
//---------------------------------------------------------------------------
int main( int ac, char* av[] )
{
	xim_style = 0;
	if( setlocale( LC_ALL, "" ) == NULL )
		{
		printf( "%s: Error!! could not set default locale\n", av[0] );
    return -1;
    }
	else
	if( ( dpy = XOpenDisplay( NULL ) ) == NULL )
		{
		printf( "%s: Error!! open display \n", av[0] );
    return -1;
		}
	else
	if( ( mod = XSetLocaleModifiers ("@im=none") ) == NULL )
		{
		printf( "%s: Error!! XSetLocaleModifiers ", av[ 0 ] );
    return -1;
		}
	else
	if( ( xim = XOpenIM (dpy, NULL, NULL, NULL) ) == NULL )
		{
		printf( "%s: Error!! XSetLocaleModifiers ", av[ 0 ] );
    return -1;
		}
	else
	if( ( value_im = XGetIMValues( xim, XNQueryInputStyle, &xim_styles, NULL) ) != NULL ||
			xim_styles == NULL )
		{
		printf ( "%s: Error!! Input method doesn't support any styles\n", av[0] );
    return -1;
		}		
	else
	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;
			}
		}
	if( xim_style == 0 )
		{
		printf ( "%s: Error!! Input method doesn't support the style we support\n", av[0] );
    return -1;
		}
	XFree ( xim_styles );
	scr = DefaultScreen( dpy );
	root_win = RootWindow ( dpy, scr );
	( void )set_sizehints (&hints, OUTER_WINDOW_MIN_WIDTH, OUTER_WINDOW_MIN_HEIGHT,
		       OUTER_WINDOW_DEF_WIDTH, OUTER_WINDOW_DEF_HEIGHT, 
		       OUTER_WINDOW_DEF_X, OUTER_WINDOW_DEF_Y, scr );	
	win_attr.event_mask = KeyPressMask | StructureNotifyMask |
			SubstructureNotifyMask | ExposureMask;
	win_attr.background_pixel = BlackPixel( dpy, scr );
	win_attr.border_pixel = WhitePixel( dpy, scr );
	mask = 0L | ( CWBackPixel | CWBorderPixel | CWEventMask );
	win = XCreateWindow ( dpy, root_win, hints.x, hints.y,
			   hints.width, hints.height, BORDER_WIDTH, 0,
			   InputOutput, (Visual *)CopyFromParent,
			   mask, &win_attr);
	XSetStandardProperties( dpy, win, "Text locale",  NULL,
		(Pixmap)0, av, ac, &hints);
	font = XLoadFont( dpy, DEFAULT_FONT );
	gcv.background = BlackPixel( dpy, scr );
	gcv.foreground = WhitePixel( dpy, scr );
	//gcv.function = GXcopy;
	gcv.line_width = 3;
	gcv.line_style = LineSolid;	
	gcv.join_style = JoinMiter;
	gcv.font = font;
	gc = XCreateGC(dpy,	win, GCLineWidth |GCLineStyle | GCForeground |
				GCBackground | /*GCFont |*/ GCJoinStyle, &gcv );
	if( (xim && xim_style) && ( xic = XCreateIC( xim, XNInputStyle, xim_style, 
			XNClientWindow, win, XNFocusWindow, win, NULL) ) == NULL )
		{
		printf ( "%s: Error!! XCreateIC failed\n", av[0] );
    XDestroyWindow( dpy, win );
		XCloseDisplay( dpy );
    return -1;
		}	
	
/*XFontSet XCreateFontSet(display, base_font_name_list, missing_charset_list_return,
missing_charset_count_return, def_string_return)
Display *display;
char *base_font_name_list;
char ***missing_charset_list_return;
int *missing charset_count_return;
char **def_string_return;*/	
	char** charset_list_return;
	int charset_count_return;
	char* def_string_return;
	fs = XCreateFontSet( dpy, DEFAULT_FONT, &charset_list_return,
			&charset_count_return, &def_string_return );
	for( int i = 0; i < charset_count_return; i++ )
		{
		printf("charset list >%s<\n", charset_list_return[i] );
		}
	XMapWindow( dpy, win );
	while( 1 )
		{
		XNextEvent( dpy, &event );
		if( event.type == KeyPress )
			do_keypress( &event );
		else
		if( event.type == Expose )
			do_expose( &event );
		}
}
//---------------------------------------------------------------------------
void set_sizehints( XSizeHints *hintp, int min_width, int min_height, 
	       int defwidth, int defheight, int defx, int defy, int scr )
{
	int geom_result;
	hintp->width = hintp->min_width = min_width;
	hintp->height = hintp->min_height = min_height;
	hintp->flags = PMinSize;
	hintp->x = hintp->y = 0;
	geom_result = NoValue;
	if( !( hintp->flags & USSize) )
		{
		hintp->width = defwidth;
		hintp->height = defheight;
		hintp->flags |= PSize;
		}
	if (geom_result & XNegative)
		{
		hintp->x = DisplayWidth ( dpy, scr ) + hintp->x - hintp->width;
    }
  if (geom_result & YNegative)
  	{
  	hintp->y = DisplayHeight( dpy, scr ) + hintp->y - hintp->height;
    }
}
//---------------------------------------------------------------------------
void	do_expose( XEvent* event )
{
	if( event->xexpose.count > 0 )
		return;
	draw();
}
//---------------------------------------------------------------------------
void draw()
{
	XDrawString( dpy, win, gc, 20, 20, "test", StrLenght("test") );
}
//---------------------------------------------------------------------------
int StrLenght( char* str )
{
	int count = 0; while( str[ count ] != '\0' ) count++;
	return count;
}
//---------------------------------------------------------------------------
void	do_keypress( XEvent* event )
{
#define BUFSIZE 8
	printf("Press key\n");
	XKeyEvent* ke = ( XKeyEvent* ) event;
	KeySym ks;
	Status status;
	
	wchar_t symb[10];
	int nbytes;
	int nmbbytes;
	char* buf;
	int bufsize;
	bufsize = BUFSIZE;
	if( ( buf = ( char* )malloc( BUFSIZE ) ) == NULL )
		{
		return;
		}
	
	nbytes = XLookupString( ke, string, 256, &ks, NULL);
	do
		{
		nmbbytes = XmbLookupString( xic, ke, buf, bufsize-1, &ks, &status );
		buf[nmbbytes] = '\0';
		if( status == XBufferOverflow )
			{
			bufsize = nmbbytes + 1;
			buf = ( char* )realloc( buf, bufsize );
			}
    }
  while( status == XBufferOverflow );
	nmbbytes = XwcLookupString( xic, ke, symb, 9, &ks, &status );
	XwcDrawString( dpy, win, fs, gc, 40, 60, symb, 1 );
	//XDrawString( dpy, win, gc, 40, 40, "   ", StrLenght("   ") );
	char* strss = "����";
	XDrawString( dpy, win, gc, 40, 80, strss, 4 );
	
	XDrawString( dpy, win, gc, 40, 40, string, StrLenght(string) );
	printf(">%s<",string);
}

    
        Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.
      
Похожие темы
- Форум Я, X11 и select (2009)
- Форум помогите с select/pipe, плииииз... (2003)
- Форум помогите с select/pipe, плииииз... (2003)
- Форум pthread не работает (2006)
- Форум socket error (2009)
- Форум покритикуйте функцию (2009)
- Форум Вывести содержание бинарного файла (2013)
- Форум X11 (2010)
- Форум GLib проблема с потоками GMainLoop (2014)
- Форум Не могу разобраться с ошибкой сегментирования (2017)