Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions
nsPointerService Class Reference

#include <nsPointerService.h>

List of all members.

Public Member Functions

WidgetUnderPointer (nsIWidget **_retval, PRUint32 *aXOffset, PRUint32 *aYOffset)

Detailed Description

Definition at line 39 of file nsPointerService.h.

Member Function Documentation

NS_IMETHODIMP nsPointerService::WidgetUnderPointer ( nsIWidget **  _retval,
PRUint32 aXOffset,
PRUint32 aYOffset 

Definition at line 49 of file nsPointerService.cpp.

  *_retval = nsnull;
  *aXOffset = 0;
  *aYOffset = 0;

  Bool retval;
  Window root_return;
  Window child_return = None;
  int root_x_return, root_y_return;
  int win_x_return, win_y_return;
  unsigned int mask_return;

  // Flush the queue to get any pending destroys out the door.  If we
  // don't then we can end up with a sitution where the XQueryPointer
  // flushes the queue and then the XTranslateCoordinates will cause
  // an X error since the window doesn't exist anymore.  God,
  // sometimes I just hate X.
  XSync(GDK_DISPLAY(), False);

  // Query the pointer
  retval = XQueryPointer(GDK_DISPLAY(),
                      &root_return, &child_return,
                      &root_x_return, &root_y_return,
                      &win_x_return, &win_y_return,

  // the pointer is on a different window
  if (!retval || child_return == None)
    return NS_OK;

  int done = 0;
  Window dest_w = child_return;
  int    xlate_x_return;
  int    xlate_y_return;

  // loop to find the inner most window
  while (!done) {
    Window xlate_return = None;
    retval = XTranslateCoordinates(GDK_DISPLAY(),
                               win_x_return, win_y_return,
                               &xlate_x_return, &xlate_y_return,
    // the pointer is on a different screen
    if (!retval)
      return NS_OK;

    // if xlate_return was None then we've reached the inner most window
    if (xlate_return == None)
      done = 1;
    // otherwise set our new destination window to the return from the
    // translation
      dest_w = xlate_return;

  GdkWindow *window;
  nsWindow  *widget;

  // get the gdk window under the pointer
  window = gdk_window_lookup(dest_w);
  // it's not a gdk window
  if (!window)
    return NS_OK;
  // is that an nsWindow window?
  gpointer data = NULL;
  gdk_window_get_user_data(window, &data);
  // nope
  if (!data)
    return NS_OK;

  // downcast
  widget = (nsWindow *)gtk_object_get_data(GTK_OBJECT(data), "nsWindow");
  if (!widget)
    return NS_OK;

  *_retval = NS_STATIC_CAST(nsIWidget *, widget);
  *aXOffset = xlate_x_return;
  *aYOffset = xlate_y_return;


  return NS_OK;

Here is the call graph for this function:

The documentation for this class was generated from the following files: