Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions src/shared/shl_dlist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* shl - Double Linked List
*
* Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
* Copyright (c) 2011 University of Tuebingen
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/*
* A simple double linked list implementation
*/

#ifndef SHL_DLIST_H
#define SHL_DLIST_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

/* miscellaneous */

#define shl_offsetof(pointer, type, member) \
({ \
const typeof(((type *)0)->member) *__ptr = (pointer); \
(type *)(((char *)__ptr) - offsetof(type, member)); \
})

/* double linked list */

struct shl_dlist {
struct shl_dlist *next;
struct shl_dlist *prev;
};

#define SHL_DLIST_INIT(head) {&(head), &(head)}

static inline void shl_dlist_init(struct shl_dlist *list)
{
list->next = list;
list->prev = list;
}

static inline void shl_dlist__link(struct shl_dlist *prev, struct shl_dlist *next,
struct shl_dlist *n)
{
next->prev = n;
n->next = next;
n->prev = prev;
prev->next = n;
}

static inline void shl_dlist_link(struct shl_dlist *head, struct shl_dlist *n)
{
return shl_dlist__link(head, head->next, n);
}

static inline void shl_dlist_link_tail(struct shl_dlist *head, struct shl_dlist *n)
{
return shl_dlist__link(head->prev, head, n);
}

static inline void shl_dlist__unlink(struct shl_dlist *prev, struct shl_dlist *next)
{
next->prev = prev;
prev->next = next;
}

static inline void shl_dlist_unlink(struct shl_dlist *e)
{
shl_dlist__unlink(e->prev, e->next);
e->prev = NULL;
e->next = NULL;
}

static inline bool shl_dlist_empty(struct shl_dlist *head)
{
return head->next == head;
}

#define shl_dlist_entry(ptr, type, member) shl_offsetof((ptr), type, member)

#define shl_dlist_first(head, type, member) shl_dlist_entry((head)->next, type, member)

#define shl_dlist_last(head, type, member) shl_dlist_entry((head)->prev, type, member)

#define shl_dlist_next(iter, head, member) \
((iter)->member.next == (head) ? NULL : shl_dlist_entry((iter)->member.next, typeof(*iter), list))

#define shl_dlist_for_each(iter, head) for (iter = (head)->next; iter != (head); iter = iter->next)

#define shl_dlist_for_each_but_one(iter, start, head) \
for (iter = ((start)->next == (head)) ? (start)->next->next : (start)->next; \
iter != (start); \
iter = (iter->next == (head) && (start) != (head)) ? iter->next->next : iter->next)

#define shl_dlist_for_each_safe(iter, tmp, head) \
for (iter = (head)->next, tmp = iter->next; iter != (head); iter = tmp, tmp = iter->next)

#define shl_dlist_for_each_reverse(iter, head) \
for (iter = (head)->prev; iter != (head); iter = iter->prev)

#define shl_dlist_for_each_reverse_but_one(iter, start, head) \
for (iter = ((start)->prev == (head)) ? (start)->prev->prev : (start)->prev; \
iter != (start); \
iter = (iter->prev == (head) && (start) != (head)) ? iter->prev->prev : iter->prev)

#define shl_dlist_for_each_reverse_safe(iter, tmp, head) \
for (iter = (head)->prev, tmp = iter->prev; iter != (head); iter = tmp, tmp = iter->prev)

#endif /* SHL_DLIST_H */
36 changes: 20 additions & 16 deletions src/tsm/libtsm-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdlib.h>
#include <stdint.h>
#include "libtsm.h"
#include "shl_dlist.h"
#include "shl-llog.h"

#define SHL_EXPORT __attribute__((visibility("default")))
Expand Down Expand Up @@ -87,20 +88,26 @@ struct cell {
};

struct line {
struct line *next; /* next line (NULL if not sb) */
struct line *prev; /* prev line (NULL if not sb) */

struct shl_dlist list; /* list node, next/prev are NULL if not in sb */
unsigned int size; /* real width */
struct cell *cells; /* actuall cells */
uint64_t sb_id; /* sb ID */
uint64_t sb_id; /* sb ID, 0 if not in sb */
tsm_age_t age; /* age of the whole line */
};

#define SELECTION_TOP -1
struct selection_pos {
struct line *line;
unsigned int x;
int y;
unsigned int x; /* x offset from the start of the line */
struct line *line; /* line the selection is on */
};

struct tsm_scrollback {
/* scroll-back buffer */
unsigned int count; /* number of lines in sb */
struct shl_dlist list; /* list of lines in sb */
unsigned int max; /* max-limit of lines in sb */
struct line *pos; /* current position in sb or NULL */
unsigned int pos_num; /* current numeric position in sb */
uint64_t last_id; /* last id given to sb-line */
};

struct tsm_screen {
Expand Down Expand Up @@ -134,14 +141,7 @@ struct tsm_screen {
struct line **alt_lines; /* real alternative lines */
tsm_age_t age; /* whole screen age */

/* scroll-back buffer */
unsigned int sb_count; /* number of lines in sb */
struct line *sb_first; /* first line; was moved first */
struct line *sb_last; /* last line; was moved last*/
unsigned int sb_max; /* max-limit of lines in sb */
struct line *sb_pos; /* current position in sb or NULL */
unsigned int sb_pos_num; /* current numeric position in sb */
uint64_t sb_last_id; /* last id given to sb-line */
struct tsm_scrollback sb;

/* cursor: positions are always in-bound, but cursor_x might be
* bigger than size_x if new-line is pending */
Expand Down Expand Up @@ -172,6 +172,10 @@ static inline void screen_inc_age(struct tsm_screen *con)
}
}

static inline bool is_in_scrollback(struct selection_pos *sel) {
return (sel->line && sel->line->sb_id);
}

/* available character sets */

typedef tsm_symbol_t tsm_vte_charset[96];
Expand Down
33 changes: 14 additions & 19 deletions src/tsm/tsm-render.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "libtsm.h"
#include "libtsm-int.h"
#include "shl-llog.h"
#include "shl_dlist.h"

#define LLOG_SUBSYSTEM "tsm-render"

Expand All @@ -47,7 +48,7 @@ tsm_age_t tsm_screen_draw(struct tsm_screen *con, tsm_screen_draw_cb draw_cb,
{
unsigned int cur_x, cur_y;
unsigned int i, j, k;
struct line *iter, *line = NULL;
struct line *line, *next_line = NULL;
struct cell *cell, empty;
struct tsm_screen_attr attr;
int ret, warned = 0;
Expand All @@ -71,47 +72,41 @@ tsm_age_t tsm_screen_draw(struct tsm_screen *con, tsm_screen_draw_cb draw_cb,
cur_y = con->size_y - 1;

/* push each character into rendering pipeline */

iter = con->sb_pos;
k = 0;
next_line = con->sb.pos;

if (con->sel_active) {
if (!con->sel_start.line && con->sel_start.y == SELECTION_TOP)
if (!con->sel_start.line)
in_sel = !in_sel;
if (!con->sel_end.line && con->sel_end.y == SELECTION_TOP)
if (!con->sel_end.line)
in_sel = !in_sel;

if (con->sel_start.line &&
(!iter || con->sel_start.line->sb_id < iter->sb_id))
if (is_in_scrollback(&con->sel_start) &&
(!con->sb.pos || con->sel_start.line->sb_id < con->sb.pos->sb_id))
in_sel = !in_sel;
if (con->sel_end.line &&
(!iter || con->sel_end.line->sb_id < iter->sb_id))
if (is_in_scrollback(&con->sel_end) &&
(!con->sb.pos || con->sel_end.line->sb_id < con->sb.pos->sb_id))
in_sel = !in_sel;
}

for (i = 0; i < con->size_y; ++i) {
if (iter) {
line = iter;
iter = iter->next;
if (next_line) {
line = next_line;
next_line = shl_dlist_next(next_line, &con->sb.list, list);
} else {
line = con->lines[k];
k++;
}

if (con->sel_active) {
if (con->sel_start.line == line ||
(!con->sel_start.line &&
con->sel_start.y == k - 1))
if (con->sel_start.line == line)
sel_start = true;
else
sel_start = false;
if (con->sel_end.line == line ||
(!con->sel_end.line &&
con->sel_end.y == k - 1))
if (con->sel_end.line == line)
sel_end = true;
else
sel_end = false;

was_sel = false;
}

Expand Down
Loading
Loading