XtAddGrab(3)

πŸ’… XtAddGrab β€” redirect user input to a modal widget

okay bestie, so this is a page from the XT FUNCTIONS corner of the X world, and it's literally all about grabbing user input and being like "no babe, YOU'RE the main character right now" to exactly one widget. Two functions, one vibe: XtAddGrab and XtRemoveGrab. Let's get into it 🫢


✨ NAME ✨

XtAddGrab, XtRemoveGrab β€” redirect user input to a modal widget

🌸 SYNTAX 🌸

#include <X11/Intrinsic.h>

void XtAddGrab(Widget w, Boolean exclusive, Boolean spring_loaded);

void XtRemoveGrab(Widget w);

πŸŽ€ ARGUMENTS πŸŽ€

  • exclusive β€” tells you whether user events should be dispatched exclusively to this widget, or also to the previous widgets up in the cascade. it's giving "do I share the spotlight or is this a solo performance" ✨
  • spring_loaded β€” tells you whether this widget got popped up because the user pressed a pointer button. like, was this a spring-loaded pop-up moment? πŸ¦‹
  • w β€” the widget you're adding to (or removing from) the modal cascade. the actual star of the show πŸ‘‘

πŸ‘‘ DESCRIPTION πŸ‘‘

XtAddGrab β€” the adding era

So XtAddGrab appends the widget (and associated parameters) to the modal cascade, and it also checks that exclusive is True if spring_loaded is True. and if those aren't True?? it generates an error. no cap. 🚨

how the modal cascade actually gets used πŸ’«

The modal cascade is what XtDispatchEvent consults when it's trying to dispatch a user event. the way that it works: when there's at least one modal widget in the widget cascade, XtDispatchEvent first determines if the event should be delivered. it starts at the most recent cascade entry and follows the cascade up to and including the most recent cascade entry that was added with the exclusive parameter True. periodt.

the active subset 🌈

That subset of the modal cascade, plus all the descendants of those widgets, is what we call the active subset. user events that happen outside the widgets in this subset get ignored or remapped β€” sorry not sorry πŸ’€

some real-world tea for you:

  • Modal menus with submenus generally add a submenu widget to the cascade with exclusive set to False.
  • Modal dialog boxes that need to restrict user input to the most deeply nested dialog box add a subdialog widget to the cascade with exclusive set to True.

User events that occur within the active subset get delivered to the appropriate widget, which is usually a child or a further descendant of the modal widget. πŸ“

remap events, the special ones ✨

Regardless of where on the screen they occur, remap events are always delivered to the most recent widget in the active subset of the cascade that has spring_loaded True β€” if any such widget exists, that is. iykyk 😌

XtRemoveGrab β€” the removal arc 😭

XtRemoveGrab removes widgets from the modal cascade, starting at the most recent widget and going up to and including the specified widget. and it issues an error if the specified widget is not on the modal cascade. so like, don't try to remove something that was never there, bestie. πŸ™ˆ

⚠️ heads up: if exclusive isn't True while spring_loaded is True, XtAddGrab generates an error. and if you try to XtRemoveGrab a widget that isn't in the cascade, that's an error too. read the vibe check before you commit πŸ’…

πŸ’– SEE ALSO πŸ’–

  • X Toolkit Intrinsics - C Language Interface
  • Xlib - C Language X Interface

and that's the whole page, bestie!! this one came from X Version 11, libXt 1.3.1, and it's literally the XtAddGrab(3) page. slay, go forth and grab some input βœ¨πŸŽ€πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from