dmenu/patch/multiselect.c

54 lines
967 B
C
Raw Normal View History

static int
issel(size_t id)
{
for (int i = 0;i < selidsize;i++)
if (selid[i] == id)
return 1;
return 0;
}
static void
printsel(unsigned int state)
{
for (int i = 0;i < selidsize;i++)
if (selid[i] != -1 && (!sel || sel->id != selid[i])) {
2021-05-15 14:40:05 +02:00
#if PRINTINDEX_PATCH
if (print_index)
printf("%d\n", selid[i]);
else
2021-05-15 14:40:05 +02:00
#endif // PRINTINDEX_PATCH
puts(items[selid[i]].text);
}
if (sel && !(state & ShiftMask)) {
2021-05-15 14:40:05 +02:00
#if PRINTINDEX_PATCH
if (print_index)
printf("%d\n", sel->index);
else
2021-05-15 14:40:05 +02:00
#endif // PRINTINDEX_PATCH
puts(sel->text);
} else
puts(text);
}
static void
2024-07-16 21:42:32 +02:00
selsel(void)
{
if (!sel)
return;
if (issel(sel->id)) {
for (int i = 0; i < selidsize; i++)
if (selid[i] == sel->id)
selid[i] = -1;
} else {
for (int i = 0; i < selidsize; i++)
if (selid[i] == -1) {
selid[i] = sel->id;
return;
}
selidsize++;
selid = realloc(selid, (selidsize + 1) * sizeof(int));
selid[selidsize - 1] = sel->id;
}
2024-07-16 21:42:32 +02:00
}