Attached is the source to xhole, the program that is shown on
         http://en.wikipedia.org/wiki/Shape_extension

Pat
---

On Tue, Feb 1, 2011 at 10:56 AM, Pat Kane <pekan...@gmail.com> wrote:
>  > Also, can anyone help me to understand
>  > what difference does it make if we call XSelectInput or XShapeSelectInput?
>
> This document:   http://www.x.org/docs/Xext/shape.pdf
> has this to say about it
>
>     ... only one event type can be selected
>     via the extension, XShapeSelectInput provides
>     a general mechanism similar to the standard
>     Xlib binding for window events. A mask value
>     has been defined, ShapeNotifyMask that is
>     the only valid bit in mask that may be specified.
>
> So I think you will need to use both.
>
> Pat
> ---
>
>
>
> On Tue, Feb 1, 2011 at 12:40 AM, Prasanta Sadhukhan
> <psadhuk...@gmail.com> wrote:
>> Thanks. I added the following lines as told. Now I am getting a window but
>> 1) it is not circular shaped although I am using X shape extension API
>> 2) it is not accepting any input. XNextEvent() still hangs
>>
>> attached is the modified program. Anything else I need to add
>>
>> Also, can anyone help me to understand
>> 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?
>>
>> Regards & thanks in advance
>>
>> On Tue, Feb 1, 2011 at 7:15 AM, Pat Kane <pekan...@gmail.com> wrote:
>>>
>>> You  should add a line like this too:
>>>  XSelectInput(dsp, win, ExposureMask|ButtonPressMask|ButtonReleaseMask );
>>>
>>>
>>> On Mon, Jan 31, 2011 at 9:39 AM, Pat Kane <pekan...@gmail.com> wrote:
>>> > Add this line just before the event loop:
>>> >  XMapWindow(dsp, win);
>>> > Pat
>>> > ---
>>> >
>>> >
>>> >
>>> > On Mon, Jan 31, 2011 at 2:05 AM, Prasanta Sadhukhan
>>> > <psadhuk...@gmail.com> wrote:
>>> >> 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
>>> >> <alan.coopersm...@oracle.com> 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-        alan.coopersm...@oracle.com
>>> >>>         Oracle Solaris Platform Engineering: X Window System
>>> >>>
>>> >>
>>> >>
>>> >> _______________________________________________
>>> >> xorg-devel@lists.x.org: X.Org development
>>> >> Archives: http://lists.x.org/archives/xorg-devel
>>> >> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>>> >>
>>> >
>>
>>
>
/*

  xhole.c

A sample application using the shape extension.
Creates a window with a hole in the middle. Works
with twm, fvwm, and mwm, but kde refuses to add
a title bar to it.
*/

#include<X11/Xlib.h>
#include<X11/extensions/shape.h>

int main() {
  Display *d;
  int s;
  Window w;
  Pixmap p;
  GC gw, gp;
  XEvent e;
  int x, y;

                        /* open connection with the server */
  d=XOpenDisplay(NULL);
  if(d==NULL) {
    printf("Cannot open display\n");
    exit(1);
  }
  s=DefaultScreen(d);
  gw=DefaultGC(d, s);

                        /* create window, select events, map  */
  w=XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 200, 1,
                        BlackPixel(d, s), WhitePixel(d, s));
  XSelectInput(d, w, ExposureMask | KeyPressMask | ButtonPressMask);
  XStoreName(d, w, "Hole");
  XMapWindow(d, w);

                        /* create the pixmap that specifies the shape */
  p=XCreatePixmap(d, w, 400, 300, 1);
  gp=XCreateGC(d, p, 0, NULL);
  XSetForeground(d, gp, WhitePixel(d, s));
  XFillRectangle(d, p, gp, 0, 0, 400, 300);
  XSetForeground(d, gp, BlackPixel(d, s));
  XFillArc(d, p, gp, 120, 100, 100, 100, 0, 360*64);

                        /* set the pixmap as the new window mask;
                        the pixmap is slightly larger than the window
                        to allow for the window border and title bar
                        (as added by the window manager) to be visible */
  XShapeCombineMask(d, w, ShapeBounding, -20, -50, p, ShapeSet);

                        /* event polling loop */
  while(1) {
    XNextEvent(d, &e);
                        /* draw or redraw the window */
    if(e.type==Expose) {
      /* not the correct way of drawing text... */
      for(y=10; y<=210; y+=11)
        for(x=0; x<300; x+=25)
          XDrawString(d, w, gw, x, y, "test", 4);
    }

                        /* exit on button press */
    if(e.type==ButtonPress)
      break;
  }

                        /* close connection to display */
  XCloseDisplay(d);

  return 0;
}
_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to