XAllocSizeHints(3)

πŸ’– XAllocSizeHints(3) β€” the libX11 glow-up ✨

okay so bestie, this is the Xlib page for XAllocSizeHints(3) and its whole friend group β€” XSetWMNormalHints, XGetWMNormalHints, XSetWMSizeHints, XGetWMSizeHints, and the XSizeHints struct itself. it's all about allocating the size hints structure and setting or reading a window's WM_NORMAL_HINTS property. window-manager communication core, no cap 🫢


🌸 NAME

XAllocSizeHints, XSetWMNormalHints, XGetWMNormalHints, XSetWMSizeHints, XGetWMSizeHints, XSizeHints β€” allocate size hints structure and set or read a window's WM_NORMAL_HINTS property πŸ’…


πŸŽ€ SYNTAX

XSizeHints *XAllocSizeHints(void);

void XSetWMNormalHints(Display *display, Window w, XSizeHints *hints);

Status XGetWMNormalHints(Display *display, Window w, XSizeHints
       *hints_return, long *supplied_return);

void XSetWMSizeHints(Display *display, Window w, XSizeHints *hints, Atom
       property);

Status XGetWMSizeHints(Display *display, Window w, XSizeHints
       *hints_return, long *supplied_return, Atom property);

πŸ¦‹ ARGUMENTS

  • display β€” says which X server connection we're talking to ✨
  • hints β€” the size hints for the window in its normal state πŸ’–
  • hints β€” the XSizeHints structure being used πŸŽ€
  • hints_return β€” returns the size hints for the window in its normal state 🫢
  • property β€” the property name 🌸
  • supplied_return β€” returns the hints that were supplied by the user πŸ‘‘
  • w β€” the window πŸ’œ

(yes, hints really does show up twice, and yes, that's exactly what the page says β€” not me being messy, i promise 😭)


🌈 DESCRIPTION

Okay so the way this works is:

⭐ XAllocSizeHints

XAllocSizeHints allocates and hands you back a pointer to an XSizeHints structure. Important vibe check: all fields in the XSizeHints structure are initially set to zero. if there's not enough memory available, XAllocSizeHints returns NULL (πŸ’€). and when you're done with it, free that memory with XFree, bestie.

⭐ XSetWMNormalHints

XSetWMNormalHints replaces the size hints for the WM_NORMAL_HINTS property on the specified window. if the property doesn't already exist, XSetWMNormalHints sets the size hints for the WM_NORMAL_HINTS property on the specified window. the property is stored with a type of WM_SIZE_HINTS and a format of 32. periodt.

XSetWMNormalHints can generate BadAlloc and BadWindow errors. πŸ”₯

⭐ XGetWMNormalHints

XGetWMNormalHints returns the size hints stored in the WM_NORMAL_HINTS property on the specified window. so here's the deal: if the property is of type WM_SIZE_HINTS, is of format 32, and is long enough to contain either an old (pre-ICCCM) or new size hints structure, XGetWMNormalHints sets the various fields of the XSizeHints structure, sets the supplied_return argument to the list of fields that were supplied by the user (whether or not they contained defined values), and returns a nonzero status. otherwise, it returns a zero status. πŸ¦‹

if XGetWMNormalHints returns successfully and a pre-ICCCM size hints property is read, the supplied_return argument will contain the following bits:

(USPosition|USSize|PPosition|PSize|PMinSize|
 PMaxSize|PResizeInc|PAspect)

if the property is large enough to contain the base size and window gravity fields as well, the supplied_return argument will also contain the following bits:

PBaseSize|PWinGravity
XGetWMNormalHints can generate a PN BadWindow error. ngl, that PN is right there in the original text and i'm keeping it exactly as-is 😭

⭐ XSetWMSizeHints

XSetWMSizeHints replaces the size hints for the specified property on the named window. if the specified property doesn't already exist, XSetWMSizeHints sets the size hints for the specified property on the named window. property gets stored with a type of WM_SIZE_HINTS and a format of 32. and psst β€” to set a window's normal size hints, you can use the XSetWMNormalHints function instead πŸ’–

XSetWMSizeHints can generate BadAlloc, BadAtom, and BadWindow errors. πŸ”₯

⭐ XGetWMSizeHints

XGetWMSizeHints returns the size hints stored in the specified property on the named window. same conditions as its sibling: if the property is of type WM_SIZE_HINTS, is of format 32, and is long enough to contain either an old (pre-ICCCM) or new size hints structure, XGetWMSizeHints sets the various fields of the XSizeHints structure, sets the supplied_return argument to the list of fields that were supplied by the user (whether or not they contained defined values), and returns a nonzero status. otherwise, it returns a zero status. and hey β€” to get a window's normal size hints, you can use the XGetWMNormalHints function 🌸

if XGetWMSizeHints returns successfully and a pre-ICCCM size hints property is read, the supplied_return argument will contain the following bits:

(USPosition|USSize|PPosition|PSize|PMinSize|
 PMaxSize|PResizeInc|PAspect)

if the property is large enough to contain the base size and window gravity fields as well, the supplied_return argument will also contain the following bits:

PBaseSize|PWinGravity
XGetWMSizeHints can generate BadAtom and BadWindow errors. πŸ’…

🧚 PROPERTIES

  • WM_NORMAL_HINTS β€” size hints for a window in its normal state. the C type of this property is XSizeHints. πŸŽ€

πŸ‘‘ STRUCTURES

the XSizeHints structure contains:

/* Size hints mask bits */
#define   USPosition    (1L << 0)      /* user specified x, y */
#define   USSize        (1L << 1)      /* user specified width,
                                       height */
#define   PPosition     (1L << 2)      /* program specified
                                       position */
#define   PSize         (1L << 3)      /* program specified size */
#define   PMinSize      (1L << 4)      /* program specified minimum
                                       size */
#define   PMaxSize      (1L << 5)      /* program specified maximum
                                       size */
#define   PResizeInc    (1L << 6)      /* program specified resize
                                       increments */
#define   PAspect       (1L << 7)      /* program specified min and
                                       max aspect ratios */
#define   PBaseSize     (1L << 8)
#define   PWinGravity   (1L << 9)
#define   PAllHints     (PPosition|
                         PSize|
                         PMinSize|
                         PMaxSize|
                         PResizeInc|
                         PAspect)
/* Values */

typedef struct {
        long flags;     /* marks which fields in this structure are defined */
        int x, y;       /* Obsolete */
        int width, height;      /* Obsolete */
        int min_width, min_height;
        int max_width, max_height;
        int width_inc, height_inc;
        struct {
               int x;   /* numerator */
               int y;   /* denominator */
        } min_aspect, max_aspect;
        int base_width, base_height;
        int win_gravity;
        /* this structure may be extended in the future */
} XSizeHints;

πŸ’œ what all those fields actually mean

the x, y, width, and height members are now obsolete and are left solely for compatibility reasons β€” don't come for them, they're just vibing there for the old heads πŸ™ˆ

  • min_width and min_height β€” specify the minimum window size that still allows the application to be useful 🌸
  • max_width and max_height β€” specify the maximum window size πŸŽ€
  • width_inc and height_inc β€” define an arithmetic progression of sizes (minimum to maximum) into which the window prefers to be resized ✨
  • min_aspect and max_aspect β€” expressed as ratios of x and y, and they let an application specify the range of aspect ratios it prefers πŸ¦‹
  • base_width and base_height β€” define the desired size of the window πŸ’–
  • win_gravity β€” the window manager will interpret the position of the window and its border width to position the point of the outer rectangle of the overall window specified by the win_gravity member. the outer rectangle of the window includes any borders or decorations supplied by the window manager. in other words, if the window manager decides to place the window where the client asked, the position on the parent window's border named by the win_gravity will be placed where the client window would have been placed in the absence of a window manager. main character energy, honestly πŸ‘‘
note that use of the PAllHints macro is highly discouraged. like, fr fr, don't do it bestie πŸ’€

πŸ”₯ DIAGNOSTICS

  • BadAlloc β€” the server failed to allocate the requested resource or server memory 😭
  • BadAtom β€” a value for an Atom argument does not name a defined Atom
  • BadWindow β€” a value for a Window argument does not name a defined Window

🌈 SEE ALSO


and that's the whole page, bestie πŸ’…βœ¨ this one's from X Version 11, libX11 1.8.14, and the page itself is dated/versioned right there in that footer line β€” so go forth, set those hints, and slay πŸŽ€πŸ«ΆπŸ’–
πŸ“¦ where this page comes from