Quantcast
Viewing latest article 2
Browse Latest Browse All 46

How GNUstep processes X events

10:03 -0400

As part of my GSoC project, I've been tracing through GNUstep's event handling to see how events from the X window system become OpenStep-style events. Here is a brief outline. (Non-technical readers will want to stop reading around here, if they haven't stopped already.)

First of all, the X window system communicates with applications using a socket (just like pretty much everything else in UNIX-land). GNUstep's X11 backend opens the socket, and transforms the socket into an NSFileHandle, and registers it with the GNUstep runloop. When new data is available on the socket, the runloop calls the backend's callback function, the -[XGServer processEvent:] (private) method in XGServerEvent.m. The -processEvent: method has a huge switch statement to determine what type of X event it received. It then (if necessary) creates a NSEvent, and sticks it on the GNUstep event queue.

GNUstep's runloop then picks up the event from the event queue, and then dispatches it to NSApplication through its -sendEvent: method, which basically forwards it to the window's -sendEvent: method. -[NSWindow sendEvent:] method also has big switch statement depending on what type of event it is. But this time, it uses NSEventTypes instead of XEvent types.

Aside from some simple filtering, -[NSApplication sendEvent:] doesn't modify the NSEvent at all. So, to figure out how an XEvent is handled by GNUstep, look for the appropriate branch in -[XGServer processEvent:], and then figure out what type of NSEvent (if any) is generated. Then look at -[NSWindow sendEvent:], to see how it gets handled (unless it's an NSKeyDown event, which may get sent to the main menu or the key window first).

0 Comments

Viewing latest article 2
Browse Latest Browse All 46

Trending Articles