Ejemplo n.º 1
0
void initFocusStatusAndXQueryTree() {
  if (g_library_inited == FALSE) {
    LOG("Library initialized.\n");
    g_library_inited = TRUE;
    init_cached_xquerytree();
    init_focus_keep_struct(&g_focus_status);
  }
}
Ejemplo n.º 2
0
int XNextEvent(Display *display, XEvent *outEvent) {
  // Code to pull the real function handle from X11 library.
  void *handle = NULL;

  //This will turn the function proto into a function pointer declaration
  int (*real_func)(Display *display, XEvent *outEvent) = NULL;
  handle = get_xlib_handle();

  if (handle == NULL) {
    return -1;
  }

  // The real event from XNextEvent
  XEvent realEvent;

  // Find the real function.
  real_func = dlsym(handle, "XNextEvent");
  // Invoke the real function.
  int rf_ret = real_func(display, &realEvent);

  OPEN_LOGGING_FILE;

  if (g_library_inited == FALSE) {
    LOG("Library initialized.\n");
    g_library_inited = TRUE;
    init_cached_xquerytree();
    init_focus_keep_struct(&g_focus_status);
  }


  // This display object will be used to inquire X server
  // about inferior and parent windows.
  Display* dpy = display;
  //assert(dpy != NULL);

  print_event_to_log(dpy, &realEvent);

  // Is the event on a window other than the active one?
  // If so, update gActiveWindow on two cases:
  // 1. It's the first window known to the module.
  // 2. It's the second window known to the module. The second
  // window is the actual browser window (the first one is just a
  // set-up one).
  //
  if ((get_active_window(&g_focus_status) == 0) && (is_focus_in(&realEvent))) {
    set_active_window(&g_focus_status, &realEvent);
  } else {
    identify_switch_situation(&g_focus_status);
  }

  if (is_reparent_notify(&realEvent)) {
    identify_new_window_situation(&g_focus_status, &realEvent);
  }

  if (is_destroy_notify(&realEvent)) {
    identify_active_destroyed(&g_focus_status, &realEvent);
  }

  if ((g_focus_status.during_switch == TRUE) ||
      (get_active_window(&g_focus_status) == 0)) {
      LOG("During switch: %d Active win: %#lx during close: %d\n",
          g_focus_status.during_switch, get_active_window(&g_focus_status),
          g_focus_status.during_close);
    *outEvent = realEvent;
  } else if (should_discard_focus_out_event(&g_focus_status, dpy, &realEvent)) {
    // Fake an event!
    fake_keymap_notify_event(outEvent, &realEvent);
    LOG("Fake event for focus out.\n");
  }  else if (should_discard_focus_in_event(&g_focus_status, dpy, &realEvent)) {
    fake_keymap_notify_event(outEvent, &realEvent);
    LOG("Fake event for focus in.\n");
  } else {
    *outEvent = realEvent;
  }

  steal_focus_back_if_needed(&g_focus_status, dpy);

  dlclose(handle);
  CLOSE_LOGGING_FILE;
  return rf_ret;
}