[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Hide grafisk cursor i et xterm vindue.



Kim Schmock skrev:

Kim Schmock skrev:

Er i gang med en windows manager (tinywm uden mouse support).
jeg fork'er en xterm, men jeg har den grafiske cursor lige midt i skærmen.
Hvordan fjerner jeg den.
Har prøvet forskellig kode fundet på nettet, men det virker ikke.
Det virker i selve windows manager, altså root vinduet, men ikke i et subvindue (som xterm burde være).

Løst - gemmer cursor for windows manager vindue, gemmer cursor for xterm vindue. Sætter cursor attribute for xterm vindue til "None". Flytter cursor med XWarpPointer(), og vupti så forsvinder cursor.
Det forekommer mig dog lidt mystisk, at effekten først kommer når man programatisk flytter cursor, og ikke hvis man bevæger musen, men ok - det virker.

Var lidt for hurtig. Det virker ikke hver gang. Der må være et timing problem. Har forsøgt at find info om event sekvens ved start af windows manager og undervinduer, uden held.
Jeg poster koden her for at se om deer er nogen der kan forklare hvorfor det kun virker nogen gange:


/*************************************************************************
* windows manager.
*
*************************************************************************/
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
#include <X11/X.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define logfile_name "log.txt"

using namespace std ;

Pixmap bm_no ;
Cursor no_cursor ;
Colormap colormap ;

static unsigned char bm_no_data[] = { 0,0,0,0, 0,0,0,0 } ;

void log_masks( Display *dpy, Window root, ofstream &of ) {
XWindowAttributes attr;


	XGetWindowAttributes( dpy, root, &attr ) ;
	long allevents = attr.all_event_masks ;
	long yourevents = attr.your_event_mask ;
	long donotpropagate = attr.do_not_propagate_mask ;

	of << " Alleventsmask: " << allevents << "\n" ;
	of << " Yourevents: " << yourevents << "\n" ;
	of << " Donotpropagate: " << donotpropagate << "\n" ;	

}
void log_root( Display *dpy, Window root, ofstream &of ) {
XWindowAttributes attr;
XGetWindowAttributes( dpy, root, &attr ) ;
of << " Win root: " << root ;
of << " -width: " << attr.width ;
of << " -height: " << attr.height ;
of << " -x: " << attr.x ;
of << " -y: " << attr.y << "\n" ;


}
Window get_win( Display *dpy, Window root, unsigned int target_w, ofstream &of )
{
unsigned int nwins ;
Window dw1, dw2, *wins ;


if( XQueryTree( dpy, root, &dw1, &dw2, &wins, &nwins ) == 0 )
{
of << " XQuerryTree failed!" << "\n" ;
return None ;
}
if( target_w < nwins )
return wins[target_w] ;
else
of << " get_win() target_w out of boundary!" << "\n" ;
return None ;
}
void init(Display *dpy)
{
int scr_no ;


	scr_no = DefaultScreen( dpy) ;
	colormap = DefaultColormap( dpy, scr_no ) ;
}

void hide_cursor( Display *dpy, Window root, Window target_w, ofstream &of )
{
XColor black, dummy ;

if( (bm_no = XCreateBitmapFromData( dpy, target_w, (const char*) bm_no_data, 8, 8 )) == None)
of << " hide_cursor() - XCreateBitmapFromData() returned None" << "\n" ;
if( XAllocNamedColor( dpy, colormap, "black", &black, &dummy ) == 0 )
of << " XAllocNamedColor failed!" ;
no_cursor = XCreatePixmapCursor( dpy, bm_no, bm_no, &black, &black, 0, 0) ;


	XDefineCursor( dpy, target_w, no_cursor ) ;

	XFreeCursor( dpy, no_cursor ) ;
	if( bm_no != None)
	    XFreePixmap( dpy, bm_no ) ;
	XFreeColors( dpy, colormap, &black.pixel, 1, 0 ) ;
}

void log_attrib( Display *dpy, Window root,ofstream &of ) {
XWindowAttributes attr;
unsigned int i, nwins ;
Window dw1, dw2, *wins ;
/* query for windows.*/
if( XQueryTree( dpy, root, &dw1, &dw2, &wins, &nwins ) == 0 )
of << " XQuerryTree failed!" << "\n" ;


	of << " Number of wins: " << nwins << "\n" ;
	for( i = 0; i < nwins; i++ )
	{
		XGetWindowAttributes( dpy, wins[i], &attr ) ;
		of << " Win: " << i << " root: " << attr.root << " id: " << wins[i] ;
		of << " -width: " << attr.width ;
		of << " -height: " << attr.height ;
		of << " -x: " << attr.x ;
		of << " -y: " << attr.y << "\n" ;
	}
}

void wait_for_event(Display *dpy, ofstream &of)
{
	XEvent ev;

for(;;)
{
XNextEvent(dpy, &ev);
if( ev.type == CreateNotify )
{
of << " wait_for_event() - Received CreateNotify event for: " << ev.xcreatewindow.window << "\n" ;
break ;
}
else if( ev.type == KeyPress )
{
of << " wait_for_event() - Received key event: " << ev.type << "\n" ;
break ;
}
else
of << " wait_for_event() - Received event: " << ev.type << "\n" ;
}


}
void launch_app( char *str ) {
if( fork() == 0 )
{
execlp("/bin/sh", "/bin/sh", "-c", str, 0) ;
exit( 1 ) ;
}
}


int main()
{
	Display * dpy;
	Window root, target_w;
	XSetWindowAttributes cwattr ;
	XButtonEvent start;
	XEvent ev;
	int scr_width = 0 ;
	int scr_height = 0 ;

	ofstream of( logfile_name, ios::out) ;
	of << "---- init log for session ----" << "\n" ;

	if(!(dpy = XOpenDisplay(0x0))) return 1;

	root = DefaultRootWindow(dpy);
	of << " Root window are: " << root << "\n" ;
	init( dpy ) ;

hide_cursor( dpy, root, root, of ) ;

// calc size of terminal window
XWindowAttributes attr;
XGetWindowAttributes( dpy, root, &attr ) ;
scr_width = attr.width ;
scr_height = attr.height ;
of << " The root window size are: " << scr_width << "x" << scr_height << "\n" ;
of << " Create a xterm child." << "\n" ;

char buf[256] ;
sprintf( buf, "xterm -geometry %dx%d+0+0 -e /root/spm_server/server",scr_width/6, scr_height/13) ;
launch_app(buf) ;

of << " Create a xawtv child." << "\n" ;


	sprintf( buf, "xawtv -geometry %dx%d-0+0",scr_width/3, scr_width/3) ;
	launch_app(buf) ;

XSelectInput(dpy, root,StructureNotifyMask | SubstructureNotifyMask | KeyPressMask);

wait_for_event( dpy, of ); // wait for creation of xterm window.

of << " 'Resetting event mask." << "\n" ;
cwattr.event_mask = NoEventMask ;
XChangeWindowAttributes( dpy, root, CWEventMask, &cwattr ) ;

of << " Set Grab key <Alt>+<F1> " << "\n" ;
XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("F1")), Mod1Mask, root,
True, GrabModeAsync, GrabModeAsync);
XGrabButton(dpy, 1, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None) ;
XGrabButton(dpy, 3, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None) ;
of << " -- Starting event handling -- " << "\n" ;
for(;;)
{
XNextEvent(dpy, &ev);
if( ev.type == CreateNotify )
{
of << " Received CreateNotify event for: " << ev.xcreatewindow.window << "\n" ;
of << " Hide cursor in xterm window. " << "\n" ;
target_w = get_win( dpy, root, 0, of ) ;
hide_cursor( dpy, root, target_w, of ) ;
cwattr.cursor = None ;
XChangeWindowAttributes( dpy, target_w, CWCursor, &cwattr ) ;
of << " Move cursor" << "\n" ;
XWarpPointer( dpy, None, target_w, 0,0,0,0,0,0) ;
}
else if(ev.type == KeyPress)
{
if( ev.xkey.subwindow != None)
{
of << " Received terminate event." << "\n" ;
break ;
}
else
{
// we want to exit on <Alt>+<F1> from wm window.
of << " Received keycode: " << ev.xkey.keycode << "\n" ;
break ;
}
}


else if(ev.type == ButtonPress && ev.xbutton.subwindow != None)
{
of << " ButtenPress event received" << "\n" ;
XDefineCursor( dpy, root, None) ; XGrabPointer(dpy, ev.xbutton.subwindow, True,
PointerMotionMask|ButtonReleaseMask, GrabModeAsync,
GrabModeAsync, None, None, CurrentTime);
// XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr);
//start = ev.xbutton;
}
else if(ev.type == MotionNotify)
{
int xdiff, ydiff;
while(XCheckTypedEvent(dpy, MotionNotify, &ev));
xdiff = ev.xbutton.x_root - start.x_root;
ydiff = ev.xbutton.y_root - start.y_root;
/*XMoveResizeWindow(dpy, ev.xmotion.window,
attr.x + (start.button==1 ? xdiff : 0),
attr.y + (start.button==1 ? ydiff : 0),
MAX(1, attr.width + (start.button==3 ? xdiff : 0)),
MAX(1, attr.height + (start.button==3 ? ydiff : 0)));
*/
}
else if(ev.type == ButtonRelease)
{
of << " ButtonRelease event received." << "\n" ;
XUngrabPointer(dpy, CurrentTime);
}
//else if ( ev.type != 17 )
else
of << " Other event received." << ev.type << "\n" ;
}

log_attrib( dpy, root, of ) ;


	of << "---- ending session ---- " ;
	of.close() ;
	XCloseDisplay( dpy ) ;
	exit( 0 );
}




 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-07-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *