XtConvert(3)

πŸ’– XtConvert(3) β€” XT COMPATIBILITY FUNCTIONS πŸ’–

okay bestie, we're doing XtConvert and XtDirectConvert today, and honestly? these two are the invoke-a-resource-converter girlies of the X Toolkit Intrinsics world. they're legacy, they're iconic, and they still work, so let's get into it. no cap. πŸŽ€


✨ NAME ✨

XtConvert, XtDirectConvert β€” invoke resource converters πŸ¦‹


✨ SYNTAX ✨

#include <X11/Intrinsic.h>

void XtConvert(Widget w, const char *from_type, XrmValuePtr from, const
       char *to_type, XrmValuePtr to_return);

void XtDirectConvert(XtConverter converter, XrmValuePtr args, Cardinal
       num_args, XrmValuePtr from, XrmValuePtr to_return);

like, literally copy that include line exactly, bestie, don't freestyle it πŸ’…


✨ ARGUMENTS ✨

here's the whole roster, alphabetically, no one left behind:

  • args β€” the argument list holding the extra arguments you need to actually pull off the conversion (often NULL, because sometimes you just don't need the extra ✨).
  • converter β€” the conversion procedure that's getting called. the main character, fr.
  • from β€” the value that's about to get converted. glow-up incoming.
  • from_type β€” the source type. where we're coming from, iykyk.
  • num_args β€” how many extra arguments there are (often zero, so don't stress).
  • to_type β€” the destination type. where we're going.
  • to_return β€” returns the converted value. the whole point. πŸ’–
  • w β€” the widget to use for additional arguments, if any are needed.

✨ DESCRIPTION ✨

so XtConvert is the one that does the legwork: it looks up the type converter that's registered to convert from_type to to_type, computes any additional arguments that are needed, and then calls XtDirectConvert. easy. BUT β€” and this is the part you have to remember β€” XtConvert has been replaced by XtConvertAndStore. it's giving legacy, bestie. 😭

meanwhile XtDirectConvert is a little more efficient about it: it looks in the converter cache to see if this conversion procedure has already been called with the specified arguments. if it has, it just returns a descriptor for the information already sitting in the cache β€” slay, no wasted work. otherwise it calls the converter and enters the result into the cache. 🫢

and here's the little detail that matters: before it calls the specified converter, XtDirectConvert sets the return value size to zero and the return value address to NULL. so to figure out whether the conversion actually succeeded, the client should check to_return.address for non-NULL. if it's not NULL, you ate. if it is, the conversion didn't happen. πŸ’€

⚠️ also heads up: XtDirectConvert has been replaced by XtCallConverter. so if you're writing something new, maybe don't pick these. still valid, still documented, just... vintage. like a thrifted jacket that actually fits. πŸ‘‘

✨ SEE ALSO ✨

go read these next, they're the friend group:


and that's the whole page, bestie!! 🌈 this one comes from X Version 11, libXt 1.3.1, so when you see XtConvert(3) out in the wild, you know exactly where it came from. stay converting, stay iconic, mwah πŸ’œπŸ§š

πŸ“¦ where this page comes from