save item index

This commit is contained in:
speedie 2023-05-07 15:33:09 +02:00
parent 445351c09a
commit aad8baef66
5 changed files with 30 additions and 5 deletions

View file

@ -324,7 +324,6 @@ MD5() is deprecated as of OpenSSL 3.0, but this would also make it very
easy to have LibreSSL compatibility.</li> easy to have LibreSSL compatibility.</li>
<li>Image support: Ability to display icons, similar to rofi</li> <li>Image support: Ability to display icons, similar to rofi</li>
<li>Text drawing: Use cairo for text drawing over Xft.</li> <li>Text drawing: Use cairo for text drawing over Xft.</li>
<li>Item updating: Save item index before drawing the menu again</li>
<li>Typing: Disable insert mode completely when !type</li> <li>Typing: Disable insert mode completely when !type</li>
<li>Lines: Rofi-like newlines in the same entry <li>Lines: Rofi-like newlines in the same entry
<ul> <ul>

View file

@ -127,7 +127,6 @@ is deprecated as of OpenSSL 3.0, but this would also make it very easy to
have LibreSSL compatibility. have LibreSSL compatibility.
- Image support: Ability to display icons, similar to rofi - Image support: Ability to display icons, similar to rofi
- Text drawing: Use cairo for text drawing over Xft. - Text drawing: Use cairo for text drawing over Xft.
- Item updating: Save item index before drawing the menu again
- Typing: Disable insert mode completely when !type - Typing: Disable insert mode completely when !type
- Lines: Rofi-like newlines in the same entry - Lines: Rofi-like newlines in the same entry
- Just need to `XMoveResizeWindow()` as well as `mh += bh` and `y += bh` - Just need to `XMoveResizeWindow()` as well as `mh += bh` and `y += bh`

View file

@ -232,6 +232,8 @@ drawitem(int x, int y, int w)
rx = x; rx = x;
} }
int itemoverride = 1;
for (item = curr; item != next; item = item->right, i++) { for (item = curr; item != next; item = item->right, i++) {
x = drawitemtext( x = drawitemtext(
item, item,
@ -239,6 +241,11 @@ drawitem(int x, int y, int w)
y + (((i % lines) + 1) * bh), y + (((i % lines) + 1) * bh),
(mw - rx) / columns (mw - rx) / columns
); );
if (item == sel && itemoverride) {
itemnumber = i;
itemoverride = 0;
}
} }
// horizontal list // horizontal list
@ -248,7 +255,10 @@ drawitem(int x, int y, int w)
w = larrowWidth; w = larrowWidth;
x = drawlarrow(x, y, w); x = drawlarrow(x, y, w);
for (item = curr; item != next; item = item->right) // draw items itemnumber = 0;
int itemoverride = 1;
for (item = curr; item != next; item = item->right) { // draw items
x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text), x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text),
mw - x - mw - x -
rarrowWidth - rarrowWidth -
@ -260,6 +270,15 @@ drawitem(int x, int y, int w)
2 * borderwidth 2 * borderwidth
)); ));
if (itemoverride) {
itemnumber++;
}
if (item == sel) {
itemoverride = 0;
}
}
w = rarrowWidth + numberWidth + modeWidth + capsWidth + menumarginh + 2 * sp + 2 * borderwidth; w = rarrowWidth + numberWidth + modeWidth + capsWidth + menumarginh + 2 * sp + 2 * borderwidth;
x = drawrarrow(mw - w, y, w); x = drawrarrow(mw - w, y, w);
} }

View file

@ -58,6 +58,13 @@ void eventloop(void) {
if (listchanged) { if (listchanged) {
match(); match();
for (int i = 0; i < itemnumber; i++) {
if (sel && sel->right && (sel = sel->right) == next) {
curr = next;
}
}
drawmenu(); drawmenu();
} }
} }

View file

@ -148,6 +148,7 @@ static int lrpad; // sum of left and right padding
static int vp; // vertical padding for bar static int vp; // vertical padding for bar
static int sp; // side padding for bar static int sp; // side padding for bar
static int cursorstate = 1; // cursor state static int cursorstate = 1; // cursor state
static int itemnumber = 0; // item number
static size_t cursor; static size_t cursor;
static struct item *items = NULL, *backup_items, *list_items; static struct item *items = NULL, *backup_items, *list_items;
static struct item *matches, *matchend; static struct item *matches, *matchend;