Thanks for the pointer. I saw that the example use widget API through
XCreateManagedWIdget APIs.
Are this required to use the shape extension API to work?
I wanted to use the shape API without this if possible. I tried a small
example of creating a circular window which will have 2 diagonal line in it
and the window should close when any button is pressed inside it. Attached
is the c program I tried but it is not creating any window and is hanging
inside XNextEvent() call
Can anyone please point to me as to what is wrong in this program. I am a
newbie to X-programming
Also, one more question regarding events is
what difference does it make if we call XSelectInput or XShapeSelectInput?
Do we always need to use XShapeSelectInput if we have set a shape on the
window? Or are there cases in which we would want to use XSelectInput with a
shaped window?
Thanks in advance
Prashant
On Mon, Jan 24, 2011 at 9:14 PM, Alan Coopersmith <
[email protected]> wrote:
> On 01/24/11 03:34 AM, Prasanta Sadhukhan wrote:
> > Thanks for the information. Is there any link which shows an example of
> how to
> > use this APIs for example, if I want to create a rounded-rect window.
>
> See the oclock sources, which use the shape extension to draw a circular
> clock
> window:
>
> http://cgit.freedesktop.org/xorg/app/oclock/tree/ or
> http://www.x.org/releases/individual/app/oclock-1.0.2.tar.bz2
>
> --
> -Alan Coopersmith- [email protected]
> Oracle Solaris Platform Engineering: X Window System
>
>
#include <Xlib.h> // preceede most other headers!
#include <extensions/shape.h>
#include <Xregion.h>
#include <Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
int main(){
int shape_event_base, shape_error_base, maj, min;
Pixmap shape_mask;
GC shape_GC;
XGCValues xgcv;
int win_width = 200, win_height = 200;
int origin_x = 50, origin_y = 50;
Display *dsp = XOpenDisplay( NULL );
if( !dsp ){ return 1; }
if (!XShapeQueryExtension(dsp, &shape_event_base, &shape_error_base))
{
printf("XShape Extension not supported\n");
exit(0);
}
/*
Status st = XShapeQueryVersion(dsp, &maj, &min);
if (st)
printf("XShapeQueryVersion returned major version %d, minor version %d\n", maj, min);
else
printf("XShapeQueryVersion failed, returned %d\n", st);
*/
int screenNumber = DefaultScreen(dsp);
unsigned long white = WhitePixel(dsp,screenNumber);
unsigned long black = BlackPixel(dsp,screenNumber);
Window win = XCreateSimpleWindow(dsp,
DefaultRootWindow(dsp),
origin_x, origin_y, // origin
300, 300, // size
0, black, // border
white ); // backgd
/* allocate a pixmap to draw shapes in */
shape_mask = XCreatePixmap(dsp, win, win_width, win_height, 1);
shape_GC = XCreateGC(dsp, shape_mask, 0, &xgcv);
fprintf(stdout, "allocate a pixmap to draw shapes in\n");
fflush(stdout);
/* erase the pixmap */
XSetForeground(dsp, shape_GC, 0);
XFillRectangle(dsp, shape_mask, shape_GC, origin_x,origin_y,win_width, win_height);
XSetForeground(dsp, shape_GC, 1);
fprintf(stdout, "erase the pixmap\n");
fflush(stdout);
/* draw the bounding shape */
XFillArc(dsp, shape_mask, shape_GC, win_width/2, win_height/2, win_width/2, win_height/2, 0, 360*64);
XShapeCombineMask(dsp, win, ShapeBounding, win_width, win_height, shape_mask, ShapeSet);
fprintf(stdout, "draw the bounding shape\n");
fflush(stdout);
/* draw the clip shape */
XFillArc(dsp, shape_mask, shape_GC, win_width/2, win_height/2, win_width/2, win_height/2, 0, 360*64);
XShapeCombineMask(dsp, win, ShapeClip, origin_x,origin_y, shape_mask, ShapeSet);
fprintf(stdout, "draw the clip shape\n");
fflush(stdout);
long eventMask = ShapeNotifyMask;
XShapeSelectInput(dsp, win, eventMask);
fprintf(stdout, "Event type selected. XNextEvent to be called\n");
fflush(stdout);
XEvent evt;
do{
XNextEvent( dsp, &evt ); // calls XFlush
fprintf(stdout, "XNextEvent called\n");
fflush(stdout);
}while( evt.type != MapNotify );
XSetForeground( dsp, shape_GC, black );
/* draw diagonal lines on the shaped window */
XDrawLine(dsp, shape_mask, shape_GC, 10, 10,190,190); //from-to
XDrawLine(dsp, shape_mask, shape_GC, 10,190,190, 10); //from-to
fprintf(stdout, "Draw Line drawn\n");
fflush(stdout);
eventMask = ButtonPressMask|ButtonReleaseMask;
XShapeSelectInput(dsp,win,eventMask); // override prev
printf("ButtonPressMask|ButtonReleaseMask selected\n");
do{
XNextEvent( dsp, &evt ); // calls XFlush()
printf("XFlush\n");
}while( evt.type != ButtonRelease );
XDestroyWindow( dsp, win );
XCloseDisplay( dsp );
printf("Window destroyed\n");
return 0;
}
_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel