commit d8b6431785a46807eca08c11b4c79ac540e0e718
parent af728a8b3107fc9c18562adc9ed7dbca46dbda4d
Author: lumidify <nobody@lumidify.org>
Date: Fri, 2 Sep 2022 14:50:24 +0200
Add format string for bottom bar
Diffstat:
9 files changed, 411 insertions(+), 236 deletions(-)
diff --git a/buffer.c b/buffer.c
@@ -269,18 +269,9 @@ buffer_unlock_all_views(ledit_buffer *buffer) {
}
}
-static void
-set_view_hard_line_text(ledit_buffer *buffer, ledit_view *view) {
- char *text = buffer->hard_line_based ? "|HL" : "|SL";
- window_set_mode_extra_text(view->window, text);
-}
-
void
buffer_set_hard_line_based(ledit_buffer *buffer, int hl) {
buffer->hard_line_based = hl;
- for (size_t i = 0; i < buffer->views_num; i++) {
- set_view_hard_line_text(buffer, buffer->views[i]);
- }
}
void
@@ -288,7 +279,6 @@ buffer_add_view(ledit_buffer *buffer, ledit_mode mode, size_t line, size_t pos,
size_t new_num = add_sz(buffer->views_num, 1);
buffer->views = ledit_reallocarray(buffer->views, new_num, sizeof(ledit_view *));
buffer->views[buffer->views_num] = view_create(buffer, mode, line, pos);
- set_view_hard_line_text(buffer, buffer->views[buffer->views_num]);
view_scroll(buffer->views[buffer->views_num], scroll_offset);
buffer->views_num = new_num;
}
diff --git a/configparser.c b/configparser.c
@@ -557,6 +557,7 @@ load_destroy_theme(ledit_common *common, ast_list *theme_list, ledit_theme *them
{"bar-fg", &theme->bar_fg, &parse_theme_color, &destroy_theme_color, BAR_FG, default_init},
{"bar-bg", &theme->bar_bg, &parse_theme_color, &destroy_theme_color, BAR_BG, default_init},
{"bar-cursor", &theme->bar_cursor, &parse_theme_color, &destroy_theme_color, BAR_CURSOR, default_init},
+ {"bar-fmt", &theme->bar_fmt, &parse_theme_string, &destroy_theme_string, BAR_FMT, default_init},
{"scrollbar-fg", &theme->scrollbar_fg, &parse_theme_color, &destroy_theme_color, SCROLLBAR_FG, default_init},
{"scrollbar-bg", &theme->scrollbar_bg, &parse_theme_color, &destroy_theme_color, SCROLLBAR_BG, default_init},
};
diff --git a/configparser.h b/configparser.h
@@ -22,6 +22,7 @@ typedef struct {
XftColor scrollbar_fg;
XftColor scrollbar_bg;
const char *text_font;
+ const char *bar_fmt;
} ledit_theme;
typedef struct {
diff --git a/leditrc.5 b/leditrc.5
@@ -1,4 +1,4 @@
-.Dd May 27, 2022
+.Dd September 2, 2022
.Dt LEDITRC 5
.Os
.Sh NAME
@@ -131,6 +131,30 @@ Default: #CCCCCC
.It Ar bar-cursor
Color of text cursor in line editor.
Default: #000000
+.It Ar bar-fmt
+Format string for the bottom bar.
+The following substitutions are performed:
+.Bl -tag -width Ds
+.It %%
+The character
+.Ql %
+itself.
+.It %l
+The current line position of the cursor.
+.It %b
+The current byte position of the cursor.
+Note that this is really only the raw byte position.
+There currently is no way to get the unicode character position in the format string.
+.It %m
+The current mode.
+.It %h
+The current hardline/softline mode.
+.It %s
+A separator.
+The remaining space is divided equally between all separators.
+.El
+.Pp
+Default: %l,%b%s%m|%h
.It Ar scrollbar-width
Width of scrollbar in pixels.
Default: 10
@@ -938,153 +962,145 @@ Let me know if there are any others I should add.
.Bl -tag -width Ds
.It Ar General keys
.Pp
-.Bl -tag -width Ds -compact
-.It Ar backspace
-.It Ar begin
-.It Ar break
-.It Ar cancel
-.It Ar clear
-.It Ar delete
-.It Ar down
-.It Ar end
-.It Ar escape
-.It Ar execute
-.It Ar find
-.It Ar help
-.It Ar home
-.It Ar insert
-.It Ar left
-.It Ar linefeed
-.It Ar menu
-.It Ar mode-switch
-.It Ar next
-.It Ar num-lock
-.It Ar page-down
-.It Ar page-up
-.It Ar pause
-.It Ar print
-.It Ar prior
-.It Ar redo
-.It Ar return
-.It Ar right
-.It Ar script-switch
-.It Ar scroll-lock
-.It Ar select
-.It Ar space
-.It Ar sysreq
-.It Ar tab
-.It Ar up
-.It Ar undo
-.El
+.Ar backspace
+.Ar begin
+.Ar break
+.Ar cancel
+.Ar clear
+.Ar delete
+.Ar down
+.Ar end
+.Ar escape
+.Ar execute
+.Ar find
+.Ar help
+.Ar home
+.Ar insert
+.Ar left
+.Ar linefeed
+.Ar menu
+.Ar mode-switch
+.Ar next
+.Ar num-lock
+.Ar page-down
+.Ar page-up
+.Ar pause
+.Ar print
+.Ar prior
+.Ar redo
+.Ar return
+.Ar right
+.Ar script-switch
+.Ar scroll-lock
+.Ar select
+.Ar space
+.Ar sysreq
+.Ar tab
+.Ar up
+.Ar undo
.It Ar Function keys
.Pp
-.Bl -tag -width Ds -compact
-.It Ar f1
-.It Ar f2
-.It Ar f3
-.It Ar f4
-.It Ar f5
-.It Ar f6
-.It Ar f7
-.It Ar f8
-.It Ar f9
-.It Ar f10
-.It Ar f11
-.It Ar f12
-.It Ar f13
-.It Ar f14
-.It Ar f15
-.It Ar f16
-.It Ar f17
-.It Ar f18
-.It Ar f19
-.It Ar f20
-.It Ar f21
-.It Ar f22
-.It Ar f23
-.It Ar f24
-.It Ar f25
-.It Ar f26
-.It Ar f27
-.It Ar f28
-.It Ar f29
-.It Ar f30
-.It Ar f31
-.It Ar f32
-.It Ar f33
-.It Ar f34
-.It Ar f35
-.El
+.Ar f1
+.Ar f2
+.Ar f3
+.Ar f4
+.Ar f5
+.Ar f6
+.Ar f7
+.Ar f8
+.Ar f9
+.Ar f10
+.Ar f11
+.Ar f12
+.Ar f13
+.Ar f14
+.Ar f15
+.Ar f16
+.Ar f17
+.Ar f18
+.Ar f19
+.Ar f20
+.Ar f21
+.Ar f22
+.Ar f23
+.Ar f24
+.Ar f25
+.Ar f26
+.Ar f27
+.Ar f28
+.Ar f29
+.Ar f30
+.Ar f31
+.Ar f32
+.Ar f33
+.Ar f34
+.Ar f35
.It Ar Keypad keys
.Pp
-.Bl -tag -width Ds -compact
-.It Ar kp-0
-.It Ar kp-1
-.It Ar kp-2
-.It Ar kp-3
-.It Ar kp-4
-.It Ar kp-5
-.It Ar kp-6
-.It Ar kp-7
-.It Ar kp-8
-.It Ar kp-9
-.It Ar kp-add
-.It Ar kp-begin
-.It Ar kp-decimal
-.It Ar kp-delete
-.It Ar kp-divide
-.It Ar kp-down
-.It Ar kp-end
-.It Ar kp-enter
-.It Ar kp-equal
-.It Ar kp-f1
-.It Ar kp-f2
-.It Ar kp-f3
-.It Ar kp-f4
-.It Ar kp-home
-.It Ar kp-insert
-.It Ar kp-left
-.It Ar kp-multiply
-.It Ar kp-next
-.It Ar kp-page-down
-.It Ar kp-page-up
-.It Ar kp-prior
-.It Ar kp-right
-.It Ar kp-separator
-.It Ar kp-space
-.It Ar kp-subtract
-.It Ar kp-tab
-.It Ar kp-up
-.El
+.Ar kp-0
+.Ar kp-1
+.Ar kp-2
+.Ar kp-3
+.Ar kp-4
+.Ar kp-5
+.Ar kp-6
+.Ar kp-7
+.Ar kp-8
+.Ar kp-9
+.Ar kp-add
+.Ar kp-begin
+.Ar kp-decimal
+.Ar kp-delete
+.Ar kp-divide
+.Ar kp-down
+.Ar kp-end
+.Ar kp-enter
+.Ar kp-equal
+.Ar kp-f1
+.Ar kp-f2
+.Ar kp-f3
+.Ar kp-f4
+.Ar kp-home
+.Ar kp-insert
+.Ar kp-left
+.Ar kp-multiply
+.Ar kp-next
+.Ar kp-page-down
+.Ar kp-page-up
+.Ar kp-prior
+.Ar kp-right
+.Ar kp-separator
+.Ar kp-space
+.Ar kp-subtract
+.Ar kp-tab
+.Ar kp-up
.It Ar Weird keys that I don't know
.Pp
-.Bl -tag -width Ds -compact
-.It Ar l1
-.It Ar l2
-.It Ar l3
-.It Ar l4
-.It Ar l5
-.It Ar l6
-.It Ar l7
-.It Ar l8
-.It Ar l9
-.It Ar l10
-.It Ar r1
-.It Ar r2
-.It Ar r3
-.It Ar r4
-.It Ar r5
-.It Ar r6
-.It Ar r7
-.It Ar r8
-.It Ar r9
-.It Ar r10
-.It Ar r11
-.It Ar r12
-.It Ar r13
-.It Ar r14
-.It Ar r15
-.El
+.Ar l1
+.Ar l2
+.Ar l3
+.Ar l4
+.Ar l5
+.Ar l6
+.Ar l7
+.Ar l8
+.Ar l9
+.Ar l10
+.Ar r1
+.Ar r2
+.Ar r3
+.Ar r4
+.Ar r5
+.Ar r6
+.Ar r7
+.Ar r8
+.Ar r9
+.Ar r10
+.Ar r11
+.Ar r12
+.Ar r13
+.Ar r14
+.Ar r15
.El
.Sh EXAMPLES
See the example configuration file
diff --git a/leditrc.example b/leditrc.example
@@ -13,6 +13,7 @@ theme = {
bar-fg = 000000
bar-bg = CCCCCC
bar-cursor = 000000
+ bar-fmt = "%l,%b%s%m|%h"
scrollbar-width = 10
scrollbar-step = 20
scrollbar-bg = CCCCCC
diff --git a/theme_config.h b/theme_config.h
@@ -33,6 +33,8 @@ static const char *BAR_FG = "#000000";
static const char *BAR_BG = "#CCCCCC";
/* color of text cursor in line editor */
static const char *BAR_CURSOR = "#000000";
+/* format of bottom bar */
+static const char *BAR_FMT = "%l,%b%s%m|%h";
/* FIXME: give in units other than pixels */
/* scrollbar width in pixels */
diff --git a/view.c b/view.c
@@ -92,7 +92,6 @@ void
view_set_mode(ledit_view *view, ledit_mode mode) {
view->mode = mode;
undo_change_mode_group(view->buffer->undo);
- window_set_mode(view->window, mode);
}
ledit_view *
@@ -108,7 +107,7 @@ view_create(ledit_buffer *buffer, ledit_mode mode, size_t line, size_t pos) {
ledit_view *view = ledit_malloc(sizeof(ledit_view));
view->mode = mode;
view->buffer = buffer;
- view->window = window_create(buffer->common, buffer->clipboard, mode);
+ view->window = window_create(buffer->common, buffer->clipboard);
view->cache = cache_create(buffer->common->dpy);
view->lock_text = NULL;
view->cur_action = (struct action){ACTION_NONE, NULL};
@@ -1992,6 +1991,10 @@ view_redraw_text(ledit_view *view) {
void
view_redraw(ledit_view *view) {
+ window_set_format_args(
+ view->window, view->mode, view->buffer->hard_line_based,
+ view->cur_line + 1, view->cur_index + 1
+ );
if (view->redraw || view->window->redraw) {
window_clear(view->window);
view_redraw_text(view);
diff --git a/window.c b/window.c
@@ -24,18 +24,32 @@
#include "draw_util.h"
#include "configparser.h"
+enum bb_itemtype {
+ BB_STR,
+ BB_MODE,
+ BB_HLMODE,
+ BB_LINE,
+ BB_BYTE,
+ BB_SEP
+};
+
+struct bb_item {
+ PangoLayout *layout;
+ ledit_draw *draw;
+ int w, h;
+ enum bb_itemtype type;
+ union {
+ int i;
+ ledit_mode m;
+ size_t sz;
+ } val;
+};
+
/* FIXME: Everything to do with the bottom bar is extremely hacky */
struct bottom_bar {
- /* FIXME: encapsulate layout, width, draw a bit */
- /* text display of mode and possible some further text */
- PangoLayout *mode;
- ledit_draw *mode_draw;
- int mode_w, mode_h;
-
- /* line and position display (not implemented yet - FIXME) */
- PangoLayout *ruler;
- ledit_draw *ruler_draw;
- int ruler_w, ruler_h;
+ struct bb_item *items;
+ size_t items_num, items_alloc;
+ int w_per_sep; /* pixels used per separator in bottom bar */
/* message or editable text display */
PangoLayout *line;
@@ -66,12 +80,104 @@ static void get_scroll_pos_height(ledit_window *windown, double *pos, double *he
*/
static void set_scroll_pos(ledit_window *window, double pos);
+/* FIXME: maybe just draw to one big draw instead of keeping all these small ones around */
+static void
+set_item_text(ledit_window *window, ledit_theme *theme, struct bb_item *item, char *text) {
+ pango_layout_set_text(item->layout, text, -1);
+ pango_layout_get_pixel_size(item->layout, &item->w, &item->h);
+ draw_grow(window, item->draw, item->w, item->h);
+ XftDrawRect(item->draw->xftdraw, &theme->bar_bg, 0, 0, item->w, item->h);
+ pango_xft_render_layout(item->draw->xftdraw, &theme->bar_fg, item->layout, 0, 0);
+}
+
+void
+window_set_format_args(ledit_window *window, ledit_mode mode, int hl_mode, size_t line, size_t byte) {
+ struct bb_item *items = window->bb->items;
+ char *text;
+ int changed = 0;
+ ledit_theme *theme = config_get_theme();
+ for (size_t i = 0; i < window->bb->items_num; i++) {
+ switch (items[i].type) {
+ case BB_MODE:
+ if (mode == items[i].val.m)
+ continue;
+ switch (mode) {
+ case NORMAL:
+ text = "Normal";
+ break;
+ case VISUAL:
+ text = "Visual";
+ break;
+ case INSERT:
+ text = "Insert";
+ break;
+ default:
+ text = "ledit is buggy";
+ break;
+ }
+ set_item_text(window, theme, &items[i], text);
+ changed = 1;
+ items[i].val.m = mode;
+ break;
+ case BB_HLMODE:
+ if (hl_mode == items[i].val.i)
+ continue;
+ if (hl_mode)
+ text = "HL";
+ else
+ text = "SL";
+ set_item_text(window, theme, &items[i], text);
+ changed = 1;
+ items[i].val.i = hl_mode;
+ break;
+ /* FIXME: avoid allocating new each time */
+ case BB_LINE:
+ if (line == items[i].val.sz)
+ continue;
+ text = print_fmt("%zu", line);
+ set_item_text(window, theme, &items[i], text);
+ free(text);
+ changed = 1;
+ items[i].val.sz = line;
+ break;
+ case BB_BYTE:
+ if (byte == items[i].val.sz)
+ continue;
+ text = print_fmt("%zu", byte);
+ set_item_text(window, theme, &items[i], text);
+ free(text);
+ changed = 1;
+ items[i].val.sz = byte;
+ break;
+ default:
+ break;
+ }
+ }
+ if (changed) {
+ recalc_text_size(window);
+ window->redraw = 1;
+ }
+}
+
/* FIXME: shouldn't window->bottom_text_shown also be true when message_shown? */
/* FIXME: guard against negative width/height */
static void
recalc_text_size(ledit_window *window) {
ledit_theme *theme = config_get_theme();
- int bar_h = window->bb->mode_h;
+ int bar_h = 0;
+ int total_static_w = 0;
+ int num_sep = 0;
+ struct bb_item *items = window->bb->items;
+ for (size_t i = 0; i < window->bb->items_num; i++) {
+ if (items[i].type == BB_SEP) {
+ num_sep++;
+ } else {
+ total_static_w += items[i].w;
+ if (items[i].h > bar_h)
+ bar_h = items[i].h;
+ }
+ }
+ window->bb->w_per_sep = (window->w - total_static_w) / num_sep;
if (window->bottom_text_shown || window->message_shown)
bar_h = window->bb->line_h;
window->text_w = window->w - theme->scrollbar_width;
@@ -308,44 +414,6 @@ window_hide_message(ledit_window *window) {
recalc_text_size(window);
}
-void
-window_set_mode(ledit_window *window, ledit_mode mode) {
- ledit_theme *theme = config_get_theme();
- window->mode = mode;
- char *text;
- switch (mode) {
- case NORMAL:
- text = "Normal";
- break;
- case VISUAL:
- text = "Visual";
- break;
- case INSERT:
- text = "Insert";
- break;
- default:
- text = "ledit is buggy";
- break;
- }
- char *final_text = ledit_strcat(text, window->mode_extra_text ? window->mode_extra_text : "");
- pango_layout_set_text(window->bb->mode, final_text, -1);
- free(final_text);
- pango_layout_get_pixel_size(window->bb->mode, &window->bb->mode_w, &window->bb->mode_h);
- draw_grow(window, window->bb->mode_draw, window->bb->mode_w, window->bb->mode_h);
- XftDrawRect(window->bb->mode_draw->xftdraw, &theme->bar_bg, 0, 0, window->bb->mode_w, window->bb->mode_h);
- pango_xft_render_layout(window->bb->mode_draw->xftdraw, &theme->bar_fg, window->bb->mode, 0, 0);
- recalc_text_size(window);
- window->redraw = 1;
-}
-
-void
-window_set_mode_extra_text(ledit_window *window, char *text) {
- free(window->mode_extra_text);
- window->mode_extra_text = ledit_strdup(text);
- window_set_mode(window, window->mode);
- window->redraw = 1;
-}
-
/* FIXME: give these functions more sensible names */
static void
get_scroll_pos_height(ledit_window *window, double *pos_ret, double *height_ret) {
@@ -483,8 +551,24 @@ xximspot(ledit_window *window, int x, int y) {
XSetICValues(window->xic, XNPreeditAttributes, window->spotlist, NULL);
}
+static struct bb_item *
+push_bb_item(ledit_window *window) {
+ if (window->bb->items_num == window->bb->items_alloc) {
+ size_t new_alloc = ideal_array_size(window->bb->items_alloc, add_sz(window->bb->items_num, 1));
+ window->bb->items = ledit_reallocarray(window->bb->items, new_alloc, sizeof(struct bb_item));
+ window->bb->items_alloc = new_alloc;
+ }
+ struct bb_item *item = &window->bb->items[window->bb->items_num];
+ item->layout = pango_layout_new(window->context);
+ pango_layout_set_font_description(item->layout, window->font);
+ item->draw = draw_create(window, 10, 10);
+ item->w = item->h = 0;
+ window->bb->items_num++;
+ return item;
+}
+
ledit_window *
-window_create(ledit_common *common, ledit_clipboard *clipboard, ledit_mode mode) {
+window_create(ledit_common *common, ledit_clipboard *clipboard) {
XGCValues gcv;
ledit_theme *theme = config_get_theme();
@@ -492,12 +576,10 @@ window_create(ledit_common *common, ledit_clipboard *clipboard, ledit_mode mode)
ledit_window *window = ledit_malloc(sizeof(ledit_window));
window->first_resize = 1;
- window->mode = mode;
window->scroll_dragging = 0;
window->scroll_grab_handle = 0;
window->w = 500;
window->h = 500;
- window->mode_extra_text = NULL;
window->scroll_callback = NULL;
window->button_callback = NULL;
window->resize_callback = NULL;
@@ -548,10 +630,9 @@ window_create(ledit_common *common, ledit_clipboard *clipboard, ledit_mode mode)
window->clipboard = clipboard;
window->bb = ledit_malloc(sizeof(bottom_bar));
- window->bb->mode = pango_layout_new(window->context);
- pango_layout_set_font_description(window->bb->mode, window->font);
- /* FIXME: only create "dummy draw" at first and create with proper size when needed */
- window->bb->mode_draw = draw_create(window, 10, 10);
+ window->bb->items = NULL;
+ window->bb->items_num = window->bb->items_alloc = 0;
+ window->bb->w_per_sep = 0;
window->bb->line = pango_layout_new(window->context);
pango_layout_set_font_description(window->bb->line, window->font);
pango_layout_set_wrap(window->bb->line, PANGO_WRAP_WORD_CHAR);
@@ -596,18 +677,102 @@ window_create(ledit_common *common, ledit_clipboard *clipboard, ledit_mode mode)
window->last_motion_valid = 0;
window->last_resize_valid = 0;
window->scroll_num = 0;
- recalc_text_size(window);
+
+ /* setup format for bottom bar */
+ /* FIXME: this seems ugly, there's probably a better way
+ also, it might still be buggy */
+ char *fmt = ledit_strdup(theme->bar_fmt);
+ int offset = 0;
+ int in_text = 0;
+ int start = 0;
+ size_t i = 0;
+ struct bb_item *item = NULL;
+ for (; fmt[i] != '\0'; i++) {
+ if (fmt[i] == '%') {
+ i++;
+ if (fmt[i] == '%') {
+ if (!in_text) {
+ start = i;
+ offset = 0;
+ in_text = 1;
+ } else {
+ offset++;
+ }
+ } else {
+ if (in_text) {
+ item = push_bb_item(window);
+ item->type = BB_STR;
+ fmt[i - 1 - offset] = '\0';
+ set_item_text(window, theme, item, fmt + start);
+ in_text = 0;
+ }
+ switch (fmt[i]) {
+ case 'l':
+ item = push_bb_item(window);
+ item->type = BB_LINE;
+ item->val.sz = 0;
+ break;
+ case 'b':
+ item = push_bb_item(window);
+ item->type = BB_BYTE;
+ item->val.sz = 0;
+ break;
+ case 'm':
+ item = push_bb_item(window);
+ item->type = BB_MODE;
+ item->val.m = VISUAL;
+ break;
+ case 'h':
+ item = push_bb_item(window);
+ item->type = BB_HLMODE;
+ item->val.i = -1;
+ break;
+ case 's':
+ /* FIXME: don't create layout and draw for this */
+ item = push_bb_item(window);
+ item->type = BB_SEP;
+ break;
+ default:
+ /* FIXME: better error reporting (also shown in window); sane behavior here */
+ fprintf(stderr, "WARNING: Invalid format string for bottom bar.\n");
+ window_show_message(window, "Invalid format string for bottom bar.", -1);
+ /* FIXME: it might make more sense to just add the character as a literal,
+ but this is the easiest */
+ goto end;
+ }
+ }
+ } else if (!in_text) {
+ start = i;
+ offset = 0;
+ in_text = 1;
+ }
+ fmt[i - offset] = fmt[i];
+ }
+ if (in_text) {
+ item = push_bb_item(window);
+ item->type = BB_STR;
+ fmt[i - offset] = '\0';
+ set_item_text(window, theme, item, fmt + start);
+ }
+end:
+ free(fmt);
+ window_set_format_args(window, NORMAL, 1, 1, 1);
return window;
}
void
window_destroy(ledit_window *window) {
+ struct bb_item *items = window->bb->items;
+ for (size_t i = 0; i < window->bb->items_num; i++) {
+ if (items[i].layout)
+ g_object_unref(items[i].layout);
+ if (items[i].draw)
+ draw_destroy(window, items[i].draw);
+ }
+ free(window->bb->items);
/* FIXME: check what's still missing */
- g_object_unref(window->bb->mode);
- /*g_object_unref(window->bb->ruler);*/ /* FIXME: implement ruler */
g_object_unref(window->bb->line);
- draw_destroy(window, window->bb->mode_draw);
draw_destroy(window, window->bb->line_draw);
pango_font_description_free(window->font);
@@ -621,8 +786,6 @@ window_destroy(ledit_window *window) {
XFree(window->spotlist);
XDestroyWindow(window->common->dpy, window->xwin);
- if (window->mode_extra_text)
- free(window->mode_extra_text);
free(window->bb->line_text);
free(window->bb);
free(window);
@@ -703,12 +866,21 @@ window_redraw(ledit_window *window) {
window->text_h + (strong.y + strong.height) / PANGO_SCALE
);
} else {
- XCopyArea(
- window->common->dpy, window->bb->mode_draw->pixmap,
- window->drawable, window->gc,
- 0, 0, window->bb->mode_w, window->bb->mode_h,
- window->w - window->bb->mode_w, window->text_h
- );
+ struct bb_item *items = window->bb->items;
+ int cur_x = 0;
+ for (size_t i = 0; i < window->bb->items_num; i++) {
+ if (items[i].type == BB_SEP) {
+ cur_x += window->bb->w_per_sep;
+ } else {
+ XCopyArea(
+ window->common->dpy, items[i].draw->pixmap,
+ window->drawable, window->gc,
+ 0, 0, items[i].w, items[i].h,
+ cur_x, window->text_h
+ );
+ cur_x += items[i].w;
+ }
+ }
}
XdbeSwapInfo swap_info;
diff --git a/window.h b/window.h
@@ -51,7 +51,6 @@ typedef struct {
int message_shown; /* whether a readonly message is shown at the bottom */
bottom_bar *bb; /* encapsulates the text at the bottom */
int redraw; /* whether something has changed and the window has to be redrawn */
- ledit_mode mode; /* mode of the view - a bit ugly to duplicate this here... */
Cursor cursor_text; /* text cursor shown when cursor is over text area */
/* stuff for filtering events so not too many have to be handled */
@@ -89,15 +88,12 @@ typedef struct {
void *scroll_cb_data;
void *button_cb_data;
void *resize_cb_data;
-
- /* extra text shown beside the mode display at the bottom */
- char *mode_extra_text;
} ledit_window;
/*
* Create a window with initial mode 'mode'.
*/
-ledit_window *window_create(ledit_common *common, ledit_clipboard *clipboard, ledit_mode mode);
+ledit_window *window_create(ledit_common *common, ledit_clipboard *clipboard);
/*
* Destroy a window.
@@ -211,15 +207,8 @@ void window_hide_message(ledit_window *window);
*/
int window_message_shown(ledit_window *window);
-/*
- * Set the displayed mode of the window.
- */
-void window_set_mode(ledit_window *window, ledit_mode mode);
-
-/*
- * Set extra text that is shown to the right of the mode.
- */
-void window_set_mode_extra_text(ledit_window *window, char *text);
+/* FIXME: document */
+void window_set_format_args(ledit_window *window, ledit_mode mode, int hl_mode, size_t line, size_t byte);
/*
* Set the total pixel height of the text.