XDrawArc(3)
๐ NAME ๐
okay so bestie, welcome to the XDrawArc page โ home of XDrawArc, XDrawArcs, and the XArc struct ๐ (yes, that's the draw arcs and arc structure trifecta, this is an XLIB FUNCTIONS moment, main character energy fr fr).
โจ SYNTAX โจ
here's the summoning ritual, copy it exactly ๐
int XDrawArc(Display *display, Drawable d, GC gc, int x, int y, unsigned
int width, unsigned int height, int angle1, int angle2);
int XDrawArcs(Display *display, Drawable d, GC gc, XArc *arcs, int
narcs);
๐ ARGUMENTS ๐
angle1โ where the arc starts, measured from the three-o'clock position from the center. units are degrees * 64, no cap ๐ซถangle2โ the path and extent of the arc, relative to the start of the arc. also degrees * 64 โจarcsโ an array of arcs. it's giving plural ๐dโ the drawable. that's the thing you're drawing on, periodt.displayโ the connection to the X server. your lil phone line to the server bestie โ๏ธgcโ the GC. iconic, essential, we love her.narcsโ how many arcs are in that array. count 'em. ๐ขwidth,heightโ the width and height, which are literally the major and minor axes of the arc. big axis energy and little axis energy ๐ธx,yโ the x and y coordinates, relative to the origin of the drawable, specifying the upper-left corner of the bounding rectangle. yes, upper-LEFT, not the center, don't come for me ๐
๐ DESCRIPTION ๐
so XDrawArc draws one circular or elliptical arc, and XDrawArcs draws multiple circular or elliptical arcs โ the plural version truly ate ๐
. every arc is specified by a rectangle and two angles. the center of the circle or ellipse is the center of the rectangle, and the major and minor axes are specified by the width and height.
positive angles = counterclockwise motion ๐, negative angles = clockwise motion. and if the magnitude of angle2 is greater than 360 degrees? XDrawArc or XDrawArcs truncates it to 360 degrees. it said "that's enough outta you" ๐.
lowkey important: angle1 and angle2 are in units of degrees * 64, not plain degrees. don't forget the 64 or your arc will be somewhere unhinged.
okay, math time, but make it cute ๐งฎ โ for an arc specified as [x,y,width,height,angle1,angle2]:
- the origin of the major and minor axes is at
[x+_____,y+______] - the infinitely thin path describing the entire circle or ellipse intersects the horizontal axis at
[x,y+______]and[x+width,y+______] - and intersects the vertical axis at
[x+_____,y]and[x+_____,y+height]
these coordinates can be fractional and so are not truncated to discrete coordinates. the path should be defined by the ideal mathematical path โ we're being mathematically honest here โจ. for a wide line with line-width lw, the bounding outlines for filling are given by the two infinitely thin paths consisting of all points whose perpendicular distance from the path of the circle/ellipse is equal to lw/2 (which may be a fractional value โ slay, fractions). the cap-style and join-style are applied the same as for a line corresponding to the tangent of the circle/ellipse at the endpoint ๐.
now the spicy part ๐ถ๏ธ: for an arc specified as [x,y,width,height,angle1,angle2], the angles must be specified in the effectively skewed coordinate system of the ellipse (for a circle, the angles and coordinate systems are identical โ lucky them). the relationship between these angles and angles expressed in the normal coordinate system of the screen (as measured with a protractor) is as follows:
skewed-angle=atanโtan(normal-angle)*______โ +adjust
the skewed-angle and normal-angle are expressed in radians (rather than in degrees scaled by 64) in the range [0,2ฯ], and where atan returns a value in the range [โ_,_] and adjust is:
l l. 0 for normal-angle in the range [0,_] ฯ for normal-angle in the range [_,__] 2ฯ for normal-angle in the range [__,2ฯ]
ngl that whole block is a mood, but it's the real formula, don't @ me ๐ญ.
the pixel rules (important, pay attention bestie):
- for any given arc,
XDrawArcandXDrawArcsdo not draw a pixel more than once ๐ - if two arcs join correctly and the line-width is greater than zero and the arcs intersect,
XDrawArcandXDrawArcsdo not draw a pixel more than once either. team no double-drawing ๐ค - otherwise, the intersecting pixels of intersecting arcs are drawn multiple times. it's giving messy, but that's the spec ๐
- specifying an arc with one endpoint and a clockwise extent draws the same pixels as specifying the other endpoint and an equivalent counterclockwise extent โ except as it affects joins. symmetric queen โจ
joining arcs, the lore ๐ฆ:
- if the last point in one arc coincides with the first point in the following arc, the two arcs will join correctly.
- if the first point in the first arc coincides with the last point in the last arc, the two arcs will join correctly.
- by specifying one axis to be zero, a horizontal or vertical line can be drawn. line hack unlocked ๐
- angles are computed based solely on the coordinate system and ignore the aspect ratio. periodt.
the GC components era ๐
โ both functions use these GC components: function, plane-mask, line-width, line-style, cap-style, join-style, fill-style, subwindow-mode, clip-x-origin, clip-y-origin, and clip-mask. and they also use these GC mode-dependent components: foreground, background, tile, stipple, tile-stipple-x-origin, tile-stipple-y-origin, dash-offset, and dash-list. that's a lot of components and they're all equally important, we stan a thorough API ๐ซถ
and finally: XDrawArc and XDrawArcs can generate BadDrawable, BadGC, and BadMatch errors. the trio of chaos ๐ญ
๐ง STRUCTURES ๐ง
the XArc structure contains:
typedef struct {
short x, y;
unsigned short width, height;
short angle1, angle2; /* Degrees * 64 */
} XArc;
all x and y members are signed integers. the width and height members are 16-bit unsigned integers. you should be careful not to generate coordinates and sizes out of the 16-bit ranges, because the protocol only has 16-bit fields for these values ๐ฅ โ this is a real warning, not a vibe, so likeโฆ respect the 16 bits bestie ๐
๐ DIAGNOSTICS ๐
BadDrawableโ a value for aDrawableargument does not name a definedWindoworPixmap. it's giving "who dis" ๐BadGCโ a value for aGContextargument does not name a definedGContext. same energy, wrong context ๐ญBadMatchโ anInputOnlywindow is used as aDrawable. nope, not that kind of window ๐BadMatchโ some argument or pair of arguments has the correct type and range but fails to match in some other way required by the request. so close and yet so far ๐
๐ฆ SEE ALSO ๐ฆ
XDrawLine(3)XDrawPoint(3)XDrawRectangle(3)- Xlib - C Language X Interface
and that's the page babes ๐ซถ this whole thing comes to you straight from X Version 11, libX11 1.8.14 โ go draw some arcs, you're gonna absolutely slay ๐โจ๐
๐ฆ where this page comes from
- alpine 3.24: libx11-doc 1.8.14-r0 ยท X11
- arch rolling: libx11 1.8.14-1 ยท MIT AND X11
- nixos 26.05: libx11 1.8.14
- nixpkgs unstable: libx11 1.8.14
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms