Skip to content

Commit

Permalink
Updated XCB-TRL (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerjenigeUberMensch authored Sep 15, 2024
1 parent 797ec2e commit f90172b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 24 deletions.
101 changes: 78 additions & 23 deletions tools/XCB-TRL/xcb_trl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3253,46 +3253,101 @@ XCBStoreName(
return ret;
}

int
XCBSetClassHintFast(
XCBDisplay *display,
XCBWindow window,
uint16_t instance_name_length,
uint16_t class_name_length,
XCBClassHint *class_hint
)
{
const uint8_t NULL_BYTE_COUNT = 2;

char mem[USHRT_MAX];
char *src;
char *dest;

uint16_t MAX_LEN = USHRT_MAX - NULL_BYTE_COUNT;
size_t size;

XCBCookie ret;

if(instance_name_length > MAX_LEN)
{ instance_name_length = MAX_LEN;
}

if(class_name_length > MAX_LEN)
{ class_name_length = MAX_LEN;
}

if(class_hint->instance_name && instance_name_length)
{
/* shrink next posible cpy size */
MAX_LEN -= instance_name_length;

src = class_hint->instance_name;
dest = mem;
size = instance_name_length;
memcpy(mem, src, size);
}
mem[instance_name_length] = '\0';

size = 0;
if(class_hint->instance_name && class_name_length)
{
src = class_hint->class_name;
dest = mem + instance_name_length + 1;
/* get smallest */
size = class_name_length > MAX_LEN ? MAX_LEN : class_name_length;
memcpy(dest, src, size);
}

mem[instance_name_length + size + 1] = '\0';

ret = xcb_icccm_set_wm_class(display, window, instance_name_length + class_name_length + NULL_BYTE_COUNT, mem);

#ifdef DBG
_xcb_push_func(ret, _fn);
#else
(void)ret;
#endif
return 0;
}

int
XCBSetClassHint(
XCBDisplay *display,
XCBWindow window,
XCBClassHint *class_hint
)
{
uint32_t ilen = 0;
uint32_t clen = 0;
const uint8_t NULL_BYTE_COUNT = 2;
uint32_t MAX_LEN = USHRT_MAX - NULL_BYTE_COUNT;
char *mem = NULL;
uint16_t ilen = 0;
uint16_t clen = 0;

XCBCookie ret;

if(class_hint->instance_name)
{ ilen = strnlen(class_hint->instance_name, MAX_LEN);
MAX_LEN -= ilen;
{ ilen = strnlen(class_hint->instance_name, USHRT_MAX);
}

if(class_hint->class_name)
{ clen = strnlen(class_hint->class_name, MAX_LEN);
}
mem = malloc(sizeof(char) * (ilen + clen + NULL_BYTE_COUNT));
if(mem)
{
if(ilen)
{ strncpy(mem, class_hint->instance_name, ilen);
}
mem[ilen] = '\0';
if(clen)
{ strncpy(mem + (sizeof(char) * (ilen + 1)), class_hint->class_name, clen);
}
mem[ilen + clen + 1] = '\0';
ret = xcb_icccm_set_wm_class(display, window, clen + ilen + 2, mem);
free(mem);
{ clen = strnlen(class_hint->class_name, USHRT_MAX);
}

#ifdef DBG
_xcb_push_func(ret, _fn);
#else
(void)ret;
#endif
return !mem;
return
XCBSetClassHintFast(
display,
window,
ilen,
clen,
class_hint
);
}


Expand Down
19 changes: 18 additions & 1 deletion tools/XCB-TRL/xcb_trl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3693,7 +3693,24 @@ XCBStoreName(

/*
*
* NOTE: This operation makes use of "malloc"
* NOTE: instance_name_length must be strlen(mystring);
* NOTE: class_name_length must be strlen(mystring);
*
* RETURN: 0 on Success.
* RETURN: 1 on Failure.
*/
int
XCBSetClassHintFast(
XCBDisplay *display,
XCBWindow window,
uint16_t instance_name_length,
uint16_t class_name_length,
XCBClassHint *hint
);

/*
*
* NOTE: This operation makes use of "strlen"
*
* RETURN: 0 on Success.
* RETURN: 1 on Failure.
Expand Down

0 comments on commit f90172b

Please sign in to comment.