discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

a question using NSFileHandle


From: ]d
Subject: a question using NSFileHandle
Date: Mon, 18 Feb 2002 06:59:48 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20020112

Hello,
I have a question. How can I handle X window event?

I tried...
       display = XOpenDisplay("");

... and then I created an X window on the display receiving some events

id fh = [[NSFileHandle alloc] initWithFileDescriptor:ConnectionNumber(display)];

here, I want to be noticed if an XEvent arrive on the ConnectionNumber(display) file descriptor, which is 3 as I am testing. But I strace the process after some instructions below which aimed to select() the file descriptor. But I didn't get any notification nor
see if the process really do select() on the file description which is 3.

       id myObject = [MyObject new];

[[NSNotificationCenter defaultCenter] addObserver:myObject selector:@selector(printHello) name:NSFileHandleDataAvailableNotification object:nil];
       [fh waitForDataInBackgroundAndNotify];

       [NSApplication sharedApplication];
       [NSApp setDelegate: [MyObject new]];

       return NSApplicationMain (argc, argv);

What am I missing here? Is that the right thing to do to handle XEvent on
a different Display? Please help me.


this is the full source.


#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>

@interface MyObject : NSObject
- (void) printHello;
@end

@implementation MyObject
- (void) printHello {printf("hello event\n");}
@end


int main (int argc, const char **argv)
{
       Display* display;
       int screen_number;
       Window window;
       XSetWindowAttributes attributes;
       unsigned long attributemask;
       Visual *visual;
       XEvent event;


       display = XOpenDisplay("");
       screen_number = DefaultScreen(display);
       visual= CopyFromParent;
       attributes.background_pixel= WhitePixel(display, screen_number);
       attributes.border_pixel = WhitePixel(display, screen_number);
attributes.event_mask = KeyPressMask|ExposureMask|ButtonPressMask|StructureNotifyMask;
       attributemask = CWBackPixel|CWBorderPixel|CWEventMask;

       window = XCreateWindow(display, RootWindow(display, screen_number),
                       200,200,200,200,0,
CopyFromParent,InputOutput,visual,attributemask,&attributes);
       XMapRaised(display, window);
       XFlush(display);
       printf ("%d <<\n", ConnectionNumber(display));


id fh = [[NSFileHandle alloc] initWithFileDescriptor:ConnectionNumber(display)];
       id myObject = [MyObject new];

[[NSNotificationCenter defaultCenter] addObserver:myObject selector:@selector(printHello) name:NSFileHandleDataAvailableNotification object:nil];
       [fh waitForDataInBackgroundAndNotify];

       [NSApplication sharedApplication];
       [NSApp setDelegate: [MyObject new]];

       return NSApplicationMain (argc, argv);
}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]