focus events question

Steven J Abner pheonix.sja at att.net
Sun Feb 9 19:04:12 UTC 2025


 Was working on creating pop-ups when a pet-peeve of mine reared its 
head again. When changing focus from one window or object to another, a 
click in the window/object content to bring window forward or topmost 
can alter the content of the window you just focused. Always a pain to 
search for the title bar just to make a window topmost or focused so as 
not to change cursor or selection of the window you're changing to.
 Re-evaluation of my signal handing, I remembered that on one window 
manager the use of the combo leave/focus/enter for a focus in event. 
That window manager only passed on the leave of the combo the mode 
member of XCB_NOTIFY_MODE_GRAB. Reason I noticed was I was looking to 
place passed info via unused members.
 Well... looked into Xlib's documentation and in section 10.7 
(https://tronche.com/gui/x/xlib/events/input-focus/) it appears that 
mode member 'can' set this. No idea if does, as I am using xcb, but 
haven't seen it set but for the above exception. I found a workaround, 
but was wondering under what condition this is used. Two window 
managers don't set this for focus events, and only one uses that combo 
mentioned.
 Here is workaround, but is this set? blocked by both window managers? 
or does the fact xlib's is 32bit vs xcb's 8bit, not that it should 
matter other than maybe, a pack issue?

static bool
_event_focus(xcb_generic_event_t *nvt) {

  bool locus = ((nvt->response_type & (uint8_t)~0x80) == XCB_FOCUS_IN);
  xcb_focus_in_event_t *focus = (xcb_focus_in_event_t*)nvt;
  PhxInterface *iface = _interface_for(focus->event);
  xcb_screen_t *screen
    = xcb_setup_roots_iterator(xcb_get_setup(session->connection)).data;
  xcb_query_pointer_cookie_t c0
    = xcb_query_pointer(session->connection, screen->root);
  xcb_query_pointer_reply_t *r0
    = xcb_query_pointer_reply(session->connection, c0, NULL);

  DEBUG_ASSERT((iface == NULL), "failure: _event_focus().");
  if (focus->mode != XCB_NOTIFY_MODE_NORMAL)
    puts("bp mode");
  if ((r0->mask & XCB_KEY_BUT_MASK_BUTTON_1) != 0)
    puts("bp mask");
  free(r0);
  iface->state &= ~SBIT_CLICKS;
  if (!locus) iface = NULL;
  ui_active_focus_set((PhxObject*)iface);
  return true;
}

Steve





More information about the Xcb mailing list