Introduction
Introduction Statistics Contact Development Disclaimer Help
Improve resizing the sidebar - sfeed_curses - sfeed curses UI (now part of sfee…
git clone git://git.codemadness.org/sfeed_curses
Log
Files
Refs
README
LICENSE
---
commit 7d9d4d493a90bbd56bbe5cf175970a32ecb915bd
parent a9deda50bcc3a23a8876237cd72b69c62ac21db0
Author: Hiltjo Posthuma <[email protected]>
Date: Tue, 16 Mar 2021 18:08:19 +0100
Improve resizing the sidebar
- Make sure the value of the actual set pane width / height using
getsidebarsize and checking it in updatesidebar() is the same and not out of
sync, which would unnecesarily call updategeom() and redraw unnecesary part.
This would be reproducable in a rare case when the window height is 1 row and
the feeds are toggled with 't'.
- Separate calculating the optimal default size of the feedbar in a
getsidebarsizedefault() function.
- Clamp the minimal and maximum value when adjusting the sidebar size depending
on the layout. This also fixes an issue in horizontal layout mode when the
sidebar is 1 column high. It would require 2 keypresses (instead of 1) to
increase the sidebar.
- Only call updategeom() when it actually changed.
Diffstat:
M sfeed_curses.c | 70 ++++++++++++++++++++++-------…
1 file changed, 51 insertions(+), 19 deletions(-)
---
diff --git a/sfeed_curses.c b/sfeed_curses.c
@@ -905,7 +905,7 @@ setlayout(int n)
void
updategeom(void)
{
- int barsize, h, w, x = 0, y = 0;
+ int h, w, x = 0, y = 0;
panes[PaneFeeds].hidden = layout == LayoutMonocle && (selpane != PaneF…
panes[PaneItems].hidden = layout == LayoutMonocle && (selpane != PaneI…
@@ -920,10 +920,7 @@ updategeom(void)
switch (layout) {
case LayoutVertical:
- /* NOTE: updatesidebar() must happen before this function for …
- remaining width */
- barsize = getsidebarsize();
- panes[PaneFeeds].width = MAX(barsize, 0);
+ panes[PaneFeeds].width = getsidebarsize();
x += panes[PaneFeeds].width;
w -= panes[PaneFeeds].width;
@@ -935,8 +932,7 @@ updategeom(void)
panes[PaneFeeds].height = MAX(h, 1);
break;
case LayoutHorizontal:
- barsize = getsidebarsize();
- panes[PaneFeeds].height = MAX(barsize, 1);
+ panes[PaneFeeds].height = getsidebarsize();
h -= panes[PaneFeeds].height;
y += panes[PaneFeeds].height;
@@ -1470,17 +1466,14 @@ feeds_reloadall(void)
updatetitle();
}
+/* calculate optimal (default) size */
int
-getsidebarsize(void)
+getsidebarsizedefault(void)
{
struct feed *feed;
size_t i;
int len, size;
- /* fixed sidebar size? else calculate an optimal size automatically */
- if (fixedsidebarsizes[layout] >= 0)
- return fixedsidebarsizes[layout];
-
switch (layout) {
case LayoutVertical:
for (i = 0, size = 0; i < nfeeds; i++) {
@@ -1507,6 +1500,51 @@ getsidebarsize(void)
return 0;
}
+int
+getsidebarsize(void)
+{
+ int size;
+
+ /* fixed sidebar size? else calculate an optimal size */
+ if ((size = fixedsidebarsizes[layout]) < 0)
+ size = getsidebarsizedefault();
+
+ switch (layout) {
+ case LayoutVertical:
+ return MAX(size, 0);
+ case LayoutHorizontal:
+ return MAX(size, 1);
+ }
+
+ return size;
+}
+
+void
+adjustsidebarsize(int n)
+{
+ int size;
+
+ /* fixed sidebar size? else calculate an optimal size */
+ if ((size = fixedsidebarsizes[layout]) < 0)
+ size = getsidebarsizedefault();
+ if (n > 0) {
+ if (layout == LayoutVertical && size + 1 < win.width)
+ size++;
+ else if (layout == LayoutHorizontal && size + 1 < win.height)
+ size++;
+ } else if (n < 0) {
+ if (layout == LayoutVertical && size > 0)
+ size--;
+ else if (layout == LayoutHorizontal && size > 1)
+ size--;
+ }
+
+ if (size != fixedsidebarsizes[layout]) {
+ fixedsidebarsizes[layout] = size;
+ updategeom();
+ }
+}
+
void
updatesidebar(void)
{
@@ -2174,13 +2212,7 @@ nextpage:
break;
case '<': /* decrease fixed sidebar width */
case '>': /* increase fixed sidebar width */
- if (fixedsidebarsizes[layout] < 0)
- fixedsidebarsizes[layout] = getsidebarsize();
- if (ch == '<' && fixedsidebarsizes[layout] > 0)
- fixedsidebarsizes[layout]--;
- else if (ch != '<')
- fixedsidebarsizes[layout]++;
- updategeom();
+ adjustsidebarsize(ch == '<' ? -1 : +1);
break;
case '=': /* reset fixed sidebar to automatic size */
fixedsidebarsizes[layout] = -1;
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.