Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update XCB-TRL #451

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 113 additions & 39 deletions tools/XCB-TRL/xcb_trl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1984,15 +1984,16 @@ XCBSetErrorHandler(
)
)
{

XCBCookie ret = { .sequence = 0 };
_xcb_push_func(ret);

if(error_handler)
{ _handler = error_handler;
return 1;
}
return 0;
else
{ _handler = _xcb_handler;
}
return 1;
}

void
Expand Down Expand Up @@ -3679,51 +3680,50 @@ XCBGetWMHintsReply(
XCBGenericError *err = NULL;

XCBWindowProperty *reply = XCBGetPropertyReply(display, cookie);
XCBWMHints *data = NULL;

/* error handling */
if(err)
{
_xcb_err_handler(display, err);
goto FAILURE;
}
/* make sure data matches */
if(!reply || reply->type != XCB_ATOM_WM_HINTS || reply->format != 32)
{ goto FAILURE;
}
if(reply)
{
const uint32_t VALID_FORMAT = 32;
const uint32_t DATA_FIELD_SIZE = 4;

data = xcb_get_property_value(reply);
if(!data)
{ goto FAILURE;
}
XCBWMHints *data = xcb_get_property_value(reply);
int length = xcb_get_property_value_length(reply);
unsigned int num_elem = abs(length) / DATA_FIELD_SIZE;

/* doesnt use our(s) cause we check for format != 32 */
u32 length = xcb_get_property_value_length(reply);
u32 num_elem = length / (reply->format / 8);

if(num_elem < XCB_ICCCM_NUM_WM_HINTS_ELEMENTS - 1)
{ goto FAILURE;
}
u8 bad_format = reply->format != VALID_FORMAT;
u8 bad_atom = reply->type != XCB_ATOM_WM_HINTS;
u8 no_data = !data;

if(num_elem < XCB_ICCCM_NUM_WM_HINTS_ELEMENTS)
{ data->window_group = XCB_NONE;
}
if(bad_format || bad_atom || no_data || num_elem < XCB_ICCCM_NUM_WM_HINTS_ELEMENTS - 1)
{
__XCBThrowError(display, cookie, XCBBadImplementation, X_GetProperty, XCB_NONE);
goto USER_ERROR;
}

/* yes this this is xcb_size_hints_t no its not a mistake */
if(length > sizeof(xcb_size_hints_t))
{ length = sizeof(xcb_size_hints_t);
}
if(length > sizeof(xcb_size_hints_t))
{ length = sizeof(xcb_size_hints_t);
}
memmove(reply, data, length);

/* yes this this is xcb_size_hints_t no its not a mistake */
xcb_size_hints_t safedata;
if(num_elem == XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS - 1)
{
/* dont ask me what this does but its a suppose to be here */
((xcb_icccm_wm_hints_t *)reply)->window_group = 0;
}
}

memcpy(&safedata, (xcb_size_hints_t *)data, length);
memcpy(reply, (xcb_size_hints_t *)&safedata, length);
/* error handling */
if(err)
{
_xcb_err_handler(display, err);
USER_ERROR:
if(reply)
{ free(reply);
}
reply = NULL;
}

return (XCBWMHints *)reply;
FAILURE:
free(reply);
return NULL;
}

XCBCookie
Expand Down Expand Up @@ -3825,6 +3825,80 @@ XCBGetWMNormalHintsReply(
return status;
}

XCBSizeHints *
XCBGetWMNormalHintsReplyNoFill(
XCBDisplay *display,
XCBCookie cookie
)
{
XCBGenericError *err = NULL;
XCBCookie ret = { .sequence = 0 };
_xcb_push_func(ret);

XCBWindowProperty *reply = XCBGetPropertyReply(display, cookie);

if(reply)
{
const uint32_t VALID_FORMAT = 32;

void *data = xcb_get_property_value(reply);
u8 bad_format = reply->format != VALID_FORMAT;
u8 bad_atom = reply->type != XCB_ATOM_WM_SIZE_HINTS;
u8 no_data = !data;

if(bad_format || bad_atom || no_data)
{
__XCBThrowError(display, cookie, XCBBadImplementation, X_GetProperty, XCB_NONE);
goto USER_ERROR;
}

int length;

/* format is never 0 as we check for bad_format, so no DIV by 0 errs */
length = xcb_get_property_value_length(reply) / (reply->format / 8);

if(length > XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS)
{ length = XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS;
}

/* sizeof(uint32_t) is not could theoretically not be '4' */
const uint8_t DATA_FIELD_SIZE = 4;
const unsigned int bytes_copy = abs(length) * DATA_FIELD_SIZE;

memmove(reply, data, bytes_copy);

uint32_t VALID_FLAGS = (XCB_ICCCM_SIZE_HINT_US_POSITION|XCB_ICCCM_SIZE_HINT_US_SIZE|
XCB_ICCCM_SIZE_HINT_P_POSITION|XCB_ICCCM_SIZE_HINT_P_SIZE|
XCB_ICCCM_SIZE_HINT_P_MIN_SIZE|XCB_ICCCM_SIZE_HINT_P_MAX_SIZE|
XCB_ICCCM_SIZE_HINT_P_RESIZE_INC|XCB_ICCCM_SIZE_HINT_P_ASPECT
);

xcb_size_hints_t *hint = (xcb_size_hints_t *)reply;
/* NumPropSizeElements =- 18 (ICCCM ver. 1) */
if(length == XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS)
{ VALID_FLAGS |= (XCB_ICCCM_SIZE_HINT_BASE_SIZE | XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY);
}
else
{
hint->base_width = 0;
hint->base_height = 0;
hint->win_gravity = 0;
}
hint->flags &= VALID_FLAGS;
}

if(err)
{
_xcb_err_handler(display, err);
USER_ERROR:
if(reply)
{ free(reply);
}
reply = NULL;
}
return (XCBSizeHints *)reply;
}

XCBCookie
XCBGetWMClassCookie(
XCBDisplay *display,
Expand Down
31 changes: 18 additions & 13 deletions tools/XCB-TRL/xcb_trl.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,8 @@ union XCBARGB


/* macros */
enum XCBWMWindowState
enum
XCBWMWindowState
{
XCB_WINDOW_NORMAL_STATE = XCB_ICCCM_WM_STATE_NORMAL,
XCB_WINDOW_ICONIC_STATE = XCB_ICCCM_WM_STATE_ICONIC,
Expand Down Expand Up @@ -3861,17 +3862,12 @@ XCBKillClient(
typedef xcb_icccm_get_wm_protocols_reply_t XCBWMProtocols;
typedef xcb_icccm_wm_hints_t XCBWMHints;
typedef xcb_icccm_get_wm_class_reply_t XCBWMClass;
/*
* min_aspect_num: The minimum aspect ratios for the width.
* min_aspect_den: The minimum aspect ratios for the height.
* max_aspect_num: The maximum aspect ratios for the width.
* max_aspect_den: The maximum aspect ratios for the height.
*/
typedef xcb_size_hints_t XCBSizeHints;



enum
XCBWMHintsFlags
{
XCB_WM_HINT_INPUT = XCB_ICCCM_WM_HINT_INPUT ,
XCB_WM_HINT_STATE = XCB_ICCCM_WM_HINT_STATE ,
Expand All @@ -3881,19 +3877,28 @@ enum
XCB_WM_HINT_ICON_MASK = XCB_ICCCM_WM_HINT_ICON_MASK ,
XCB_WM_HINT_WINDOW_GROUP = XCB_ICCCM_WM_HINT_WINDOW_GROUP ,
XCB_WM_HINT_URGENCY = XCB_ICCCM_WM_HINT_X_URGENCY,
XCB_WM_HINT_ALL_HINTS = (XCB_ICCCM_WM_HINT_INPUT|
XCB_ICCCM_WM_HINT_STATE|
XCB_ICCCM_WM_HINT_ICON_PIXMAP|
XCB_ICCCM_WM_HINT_ICON_WINDOW|
XCB_ICCCM_WM_HINT_ICON_POSITION|
XCB_ICCCM_WM_HINT_ICON_MASK
|XCB_ICCCM_WM_HINT_WINDOW_GROUP
)
};

enum
XCBSizeHintsFlags
{
XCB_SIZE_HINT_P_SIZE = XCB_ICCCM_SIZE_HINT_P_SIZE,
XCB_SIZE_HINT_US_POSITION = XCB_ICCCM_SIZE_HINT_US_POSITION,
XCB_SIZE_HINT_US_SIZE = XCB_ICCCM_SIZE_HINT_US_SIZE,
XCB_SIZE_HINT_P_ASPECT = XCB_ICCCM_SIZE_HINT_P_ASPECT,
XCB_SIZE_HINT_P_BASE_SIZE = XCB_ICCCM_SIZE_HINT_BASE_SIZE,
XCB_SIZE_HINT_P_MAX_SIZE = XCB_ICCCM_SIZE_HINT_P_MAX_SIZE,
XCB_SIZE_HINT_P_MIN_SIZE = XCB_ICCCM_SIZE_HINT_P_MIN_SIZE,
XCB_SIZE_HINT_P_POSITION = XCB_ICCCM_SIZE_HINT_P_POSITION,
XCB_SIZE_HINT_US_POSITION = XCB_ICCCM_SIZE_HINT_US_POSITION,
XCB_SIZE_HINT_P_SIZE = XCB_ICCCM_SIZE_HINT_P_SIZE,
XCB_SIZE_HINT_P_MIN_SIZE = XCB_ICCCM_SIZE_HINT_P_MIN_SIZE,
XCB_SIZE_HINT_P_MAX_SIZE = XCB_ICCCM_SIZE_HINT_P_MAX_SIZE,
XCB_SIZE_HINT_P_RESIZE_INC = XCB_ICCCM_SIZE_HINT_P_RESIZE_INC,
XCB_SIZE_HINT_P_ASPECT = XCB_ICCCM_SIZE_HINT_P_ASPECT,
XCB_SIZE_HINT_P_BASE_SIZE = XCB_ICCCM_SIZE_HINT_BASE_SIZE,
XCB_SIZE_HINT_P_WIN_GRAVITY = XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY,
};

Expand Down