moved input_methods to QEmacsState

qe_register_binding takes ModeDef* and returns status
cosmetic changes in QEDisplay API
added int dpy_init(QEditScreen *s, QEDisplay *dpy, int w, int h);
  copies *dpy (or dummy_dpy if NULL) to QEditScreen and calls method
simplified dpy_init methods and calls
inlined 5 more methods
moved dummy_dpy to display.c and simplified
simplified to_hex
simplified qe_colors array handling
This commit is contained in:
Charlie Gordon 2008-01-11 11:29:28 +00:00
commit 28397f424f
14 changed files with 256 additions and 304 deletions

147
display.c
View file

@ -22,6 +22,101 @@
static QEDisplay *first_dpy; static QEDisplay *first_dpy;
/* dummy display driver for initialization time */
static int dummy_dpy_init(QEditScreen *s, __unused__ int w, __unused__ int h)
{
s->charset = &charset_8859_1;
return 0;
}
static void dummy_dpy_close(__unused__ QEditScreen *s)
{
}
static void dummy_dpy_flush(__unused__ QEditScreen *s)
{
}
static int dummy_dpy_is_user_input_pending(__unused__ QEditScreen *s)
{
return 0;
}
static void dummy_dpy_fill_rectangle(__unused__ QEditScreen *s,
__unused__ int x1, __unused__ int y1,
__unused__ int w, __unused__ int h,
__unused__ QEColor color)
{
}
static QEFont *dummy_dpy_open_font(__unused__ QEditScreen *s,
__unused__ int style, __unused__ int size)
{
return NULL;
}
static void dummy_dpy_close_font(__unused__ QEditScreen *s,
__unused__ QEFont *font)
{
}
static void dummy_dpy_text_metrics(__unused__ QEditScreen *s,
__unused__ QEFont *font,
QECharMetrics *metrics,
__unused__ const unsigned int *str,
__unused__ int len)
{
metrics->font_ascent = 1;
metrics->font_descent = 0;
metrics->width = len;
}
static void dummy_dpy_draw_text(__unused__ QEditScreen *s,
__unused__ QEFont *font,
__unused__ int x, __unused__ int y,
__unused__ const unsigned int *str,
__unused__ int len,
__unused__ QEColor color)
{
}
static void dummy_dpy_set_clip(__unused__ QEditScreen *s,
__unused__ int x, __unused__ int y,
__unused__ int w, __unused__ int h)
{
}
static QEDisplay const dummy_dpy = {
"dummy",
NULL,
dummy_dpy_init,
dummy_dpy_close,
dummy_dpy_flush,
dummy_dpy_is_user_input_pending,
dummy_dpy_fill_rectangle,
dummy_dpy_open_font,
dummy_dpy_close_font,
dummy_dpy_text_metrics,
dummy_dpy_draw_text,
dummy_dpy_set_clip,
NULL, /* dpy_selection_activate */
NULL, /* dpy_selection_request */
NULL, /* dpy_invalidate */
NULL, /* dpy_cursor_at */
NULL, /* dpy_bmp_alloc */
NULL, /* dpy_bmp_free */
NULL, /* dpy_bmp_draw */
NULL, /* dpy_bmp_lock */
NULL, /* dpy_bmp_unlock */
NULL, /* dpy_full_screen */
NULL, /* next */
};
/*----------------*/
void fill_rectangle(QEditScreen *s, void fill_rectangle(QEditScreen *s,
int x1, int y1, int w, int h, QEColor color) int x1, int y1, int w, int h, QEColor color)
{ {
@ -113,12 +208,12 @@ void push_clip_rectangle(QEditScreen *s, CSSRect *or, CSSRect *r)
int qe_register_display(QEDisplay *dpy) int qe_register_display(QEDisplay *dpy)
{ {
QEDisplay **p; QEDisplay **pp;
p = &first_dpy; pp = &first_dpy;
while (*p != NULL) while (*pp != NULL)
p = &(*p)->next; pp = &(*pp)->next;
*p = dpy; *pp = dpy;
dpy->next = NULL; dpy->next = NULL;
return 0; return 0;
} }
@ -132,8 +227,7 @@ QEDisplay *probe_display(void)
dpy = NULL; dpy = NULL;
probe_max = 0; probe_max = 0;
while (p != NULL) { while (p != NULL) {
// CG: probe = p->dpy_probe ? p->dpy_probe() : 0; probe = p->dpy_probe ? p->dpy_probe() : 0;
probe = p->dpy_probe();
if (probe >= probe_max) { if (probe >= probe_max) {
probe_max = probe; probe_max = probe;
dpy = p; dpy = p;
@ -143,6 +237,12 @@ QEDisplay *probe_display(void)
return dpy; return dpy;
} }
int dpy_init(QEditScreen *s, QEDisplay *dpy, int w, int h)
{
s->dpy = dpy ? *dpy : dummy_dpy;
return s->dpy.dpy_init(s, w, h);
}
/* simple font cache */ /* simple font cache */
#define FONT_CACHE_SIZE 32 #define FONT_CACHE_SIZE 32
@ -205,18 +305,6 @@ QEFont *select_font(QEditScreen *s, int style, int size)
return fc; return fc;
} }
void selection_activate(QEditScreen *s)
{
if (s->dpy.dpy_selection_activate)
s->dpy.dpy_selection_activate(s);
}
void selection_request(QEditScreen *s)
{
if (s->dpy.dpy_selection_request)
s->dpy.dpy_selection_request(s);
}
QEBitmap *bmp_alloc(QEditScreen *s, int width, int height, int flags) QEBitmap *bmp_alloc(QEditScreen *s, int width, int height, int flags)
{ {
QEBitmap *b; QEBitmap *b;
@ -244,27 +332,6 @@ void bmp_free(QEditScreen *s, QEBitmap **bp)
} }
} }
void bmp_draw(QEditScreen *s, QEBitmap *b,
int dst_x, int dst_y, int dst_w, int dst_h,
int offset_x, int offset_y, int flags)
{
s->dpy.dpy_bmp_draw(s, b, dst_x, dst_y, dst_w, dst_h,
offset_x, offset_y, flags);
}
/* used to access the bitmap data. Return the necessary pointers to
modify the image in 'pict'. */
void bmp_lock(QEditScreen *s, QEBitmap *bitmap, QEPicture *pict,
int x1, int y1, int w1, int h1)
{
s->dpy.dpy_bmp_lock(s, bitmap, pict, x1, y1, w1, h1);
}
void bmp_unlock(QEditScreen *s, QEBitmap *bitmap)
{
s->dpy.dpy_bmp_unlock(s, bitmap);
}
#if 0 #if 0
/* bitmap cache */ /* bitmap cache */
typedef struct QECachedBitmap { typedef struct QECachedBitmap {

View file

@ -106,7 +106,6 @@ struct QEDisplay {
int (*dpy_probe)(void); int (*dpy_probe)(void);
int (*dpy_init)(QEditScreen *s, int w, int h); int (*dpy_init)(QEditScreen *s, int w, int h);
void (*dpy_close)(QEditScreen *s); void (*dpy_close)(QEditScreen *s);
void (*dpy_cursor_at)(QEditScreen *s, int x1, int y1, int w, int h);
void (*dpy_flush)(QEditScreen *s); void (*dpy_flush)(QEditScreen *s);
int (*dpy_is_user_input_pending)(QEditScreen *s); int (*dpy_is_user_input_pending)(QEditScreen *s);
void (*dpy_fill_rectangle)(QEditScreen *s, void (*dpy_fill_rectangle)(QEditScreen *s,
@ -121,9 +120,13 @@ struct QEDisplay {
QEColor color); QEColor color);
void (*dpy_set_clip)(QEditScreen *s, void (*dpy_set_clip)(QEditScreen *s,
int x, int y, int w, int h); int x, int y, int w, int h);
/* These are optional, may be NULL */
void (*dpy_selection_activate)(QEditScreen *s); void (*dpy_selection_activate)(QEditScreen *s);
void (*dpy_selection_request)(QEditScreen *s); void (*dpy_selection_request)(QEditScreen *s);
void (*dpy_invalidate)(void); void (*dpy_invalidate)(QEditScreen *s);
void (*dpy_cursor_at)(QEditScreen *s, int x1, int y1, int w, int h);
/* bitmap support */ /* bitmap support */
int (*dpy_bmp_alloc)(QEditScreen *s, QEBitmap *b); int (*dpy_bmp_alloc)(QEditScreen *s, QEBitmap *b);
void (*dpy_bmp_free)(QEditScreen *s, QEBitmap *b); void (*dpy_bmp_free)(QEditScreen *s, QEBitmap *b);
@ -139,7 +142,7 @@ struct QEDisplay {
}; };
struct QEditScreen { struct QEditScreen {
struct QEDisplay dpy; QEDisplay dpy;
FILE *STDIN, *STDOUT; FILE *STDIN, *STDOUT;
int width, height; int width, height;
QECharset *charset; /* the charset of the TTY, XXX: suppress that, QECharset *charset; /* the charset of the TTY, XXX: suppress that,
@ -153,11 +156,19 @@ struct QEditScreen {
void *private; void *private;
}; };
static inline void draw_text(QEditScreen *s, QEFont *font, int qe_register_display(QEDisplay *dpy);
int x, int y, const unsigned int *str, int len, QEDisplay *probe_display(void);
QEColor color)
int dpy_init(QEditScreen *s, QEDisplay *dpy, int w, int h);
static inline void dpy_close(QEditScreen *s)
{ {
s->dpy.dpy_draw_text(s, font, x, y, str, len, color); s->dpy.dpy_close(s);
}
static inline void dpy_flush(QEditScreen *s)
{
s->dpy.dpy_flush(s);
} }
static inline QEFont *open_font(QEditScreen *s, static inline QEFont *open_font(QEditScreen *s,
@ -179,6 +190,55 @@ static inline void text_metrics(QEditScreen *s, QEFont *font,
s->dpy.dpy_text_metrics(s, font, metrics, str, len); s->dpy.dpy_text_metrics(s, font, metrics, str, len);
} }
static inline void draw_text(QEditScreen *s, QEFont *font,
int x, int y, const unsigned int *str, int len,
QEColor color)
{
s->dpy.dpy_draw_text(s, font, x, y, str, len, color);
}
static inline void selection_activate(QEditScreen *s)
{
if (s->dpy.dpy_selection_activate)
s->dpy.dpy_selection_activate(s);
}
static inline void selection_request(QEditScreen *s)
{
if (s->dpy.dpy_selection_request)
s->dpy.dpy_selection_request(s);
}
static inline void dpy_invalidate(QEditScreen *s)
{
if (s->dpy.dpy_invalidate)
s->dpy.dpy_invalidate(s);
}
QEBitmap *bmp_alloc(QEditScreen *s, int width, int height, int flags);
void bmp_free(QEditScreen *s, QEBitmap **bp);
static inline void bmp_draw(QEditScreen *s, QEBitmap *b,
int dst_x, int dst_y, int dst_w, int dst_h,
int offset_x, int offset_y, int flags)
{
s->dpy.dpy_bmp_draw(s, b, dst_x, dst_y, dst_w, dst_h,
offset_x, offset_y, flags);
}
/* used to access the bitmap data. Return the necessary pointers to
modify the image in 'pict'. */
static inline void bmp_lock(QEditScreen *s, QEBitmap *bitmap, QEPicture *pict,
int x1, int y1, int w1, int h1)
{
s->dpy.dpy_bmp_lock(s, bitmap, pict, x1, y1, w1, h1);
}
static inline void bmp_unlock(QEditScreen *s, QEBitmap *bitmap)
{
s->dpy.dpy_bmp_unlock(s, bitmap);
}
/* XXX: only needed for backward compatibility */ /* XXX: only needed for backward compatibility */
static inline int glyph_width(QEditScreen *s, QEFont *font, int ch) static inline int glyph_width(QEditScreen *s, QEFont *font, int ch)
{ {
@ -189,23 +249,11 @@ static inline int glyph_width(QEditScreen *s, QEFont *font, int ch)
return metrics.width; return metrics.width;
} }
static inline void dpy_flush(QEditScreen *s)
{
s->dpy.dpy_flush(s);
}
static inline void dpy_close(QEditScreen *s)
{
s->dpy.dpy_close(s);
}
void fill_rectangle(QEditScreen *s, void fill_rectangle(QEditScreen *s,
int x1, int y1, int w, int h, QEColor color); int x1, int y1, int w, int h, QEColor color);
void set_clip_rectangle(QEditScreen *s, CSSRect *r); void set_clip_rectangle(QEditScreen *s, CSSRect *r);
void push_clip_rectangle(QEditScreen *s, CSSRect *or, CSSRect *r); void push_clip_rectangle(QEditScreen *s, CSSRect *or, CSSRect *r);
int qe_register_display(QEDisplay *dpy);
QEDisplay *probe_display(void);
QEFont *select_font(QEditScreen *s, int style, int size); QEFont *select_font(QEditScreen *s, int style, int size);
static inline QEFont *lock_font(__unused__ QEditScreen *s, QEFont *font) { static inline QEFont *lock_font(__unused__ QEditScreen *s, QEFont *font) {
@ -218,16 +266,4 @@ static inline void release_font(__unused__ QEditScreen *s, QEFont *font) {
font->refcount--; font->refcount--;
} }
void selection_activate(QEditScreen *s);
void selection_request(QEditScreen *s);
QEBitmap *bmp_alloc(QEditScreen *s, int width, int height, int flags);
void bmp_free(QEditScreen *s, QEBitmap **bp);
void bmp_draw(QEditScreen *s, QEBitmap *b,
int dst_x, int dst_y, int dst_w, int dst_h,
int offset_x, int offset_y, int flags);
void bmp_lock(QEditScreen *s, QEBitmap *bitmap, QEPicture *pict,
int x1, int y1, int w1, int h1);
void bmp_unlock(QEditScreen *s, QEBitmap *bitmap);
#endif #endif

4
hex.c
View file

@ -367,8 +367,8 @@ static int hex_init(void)
qe_register_cmd_table(hex_commands, &ascii_mode); qe_register_cmd_table(hex_commands, &ascii_mode);
/* additional mode specific keys */ /* additional mode specific keys */
qe_register_binding(KEY_TAB, "toggle-hex", "hex"); qe_register_binding(KEY_TAB, "toggle-hex", &hex_mode);
qe_register_binding(KEY_SHIFT_TAB, "toggle-hex", "hex"); qe_register_binding(KEY_SHIFT_TAB, "toggle-hex", &hex_mode);
return 0; return 0;
} }

View file

@ -111,7 +111,6 @@ static QEDisplay ppm_dpy = {
NULL, NULL,
ppm_init, ppm_init,
ppm_close, ppm_close,
NULL, /* dpy_cursor_at */
NULL, /* dpy_flush */ NULL, /* dpy_flush */
NULL, /* dpy_is_user_input_pending */ NULL, /* dpy_is_user_input_pending */
NULL, /* dpy_fill_rectangle */ NULL, /* dpy_fill_rectangle */
@ -123,6 +122,7 @@ static QEDisplay ppm_dpy = {
NULL, /* dpy_selection_activate */ NULL, /* dpy_selection_activate */
NULL, /* dpy_selection_request */ NULL, /* dpy_selection_request */
NULL, /* dpy_invalidate */ NULL, /* dpy_invalidate */
NULL, /* dpy_cursor_at */
NULL, /* dpy_bmp_alloc */ NULL, /* dpy_bmp_alloc */
NULL, /* dpy_bmp_free */ NULL, /* dpy_bmp_free */
NULL, /* dpy_bmp_draw */ NULL, /* dpy_bmp_draw */
@ -156,8 +156,6 @@ static int ppm_init(QEditScreen *s, int w, int h)
{ {
CFBContext *cfb; CFBContext *cfb;
memcpy(&s->dpy, &ppm_dpy, sizeof(QEDisplay));
cfb = qe_malloc(CFBContext); cfb = qe_malloc(CFBContext);
if (!cfb) if (!cfb)
return -1; return -1;
@ -430,7 +428,6 @@ static void help(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
QEDisplay *dpy;
QEditScreen screen1, *screen = &screen1; QEditScreen screen1, *screen = &screen1;
int page_width, c, strict_xml, flags; int page_width, c, strict_xml, flags;
const char *outfilename, *infilename; const char *outfilename, *infilename;
@ -485,8 +482,7 @@ int main(int argc, char **argv)
infilename = argv[optind]; infilename = argv[optind];
/* init display driver with dummy height */ /* init display driver with dummy height */
dpy = &ppm_dpy; if (dpy_init(screen, &ppm_dpy, page_width, 1) < 0) {
if (dpy->dpy_init(screen, page_width, 1) < 0) {
fprintf(stderr, "Could not init display driver\n"); fprintf(stderr, "Could not init display driver\n");
exit(1); exit(1);
} }
@ -508,6 +504,6 @@ int main(int argc, char **argv)
#endif #endif
/* close screen */ /* close screen */
screen->dpy.dpy_close(screen); dpy_close(screen);
return 0; return 0;
} }

View file

@ -855,7 +855,7 @@ static int image_init(void)
qe_register_cmd_table(image_commands, &image_mode); qe_register_cmd_table(image_commands, &image_mode);
register_completion("pixel_format", pixel_format_completion); register_completion("pixel_format", pixel_format_completion);
/* additional mode specific keys */ /* additional mode specific keys */
qe_register_binding('f', "toggle-full-screen", "image"); qe_register_binding('f', "toggle-full-screen", &image_mode);
return 0; return 0;
} }

17
input.c
View file

@ -24,8 +24,6 @@
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
static InputMethod *input_methods;
static int default_input(__unused__ int *match_buf, static int default_input(__unused__ int *match_buf,
__unused__ int match_buf_size, __unused__ int match_buf_size,
__unused__ int *match_len_ptr, __unused__ int *match_len_ptr,
@ -74,9 +72,10 @@ static InputMethod unicode_input_method = {
void register_input_method(InputMethod *m) void register_input_method(InputMethod *m)
{ {
QEmacsState *qs = &qe_state;
InputMethod **p; InputMethod **p;
p = &input_methods; p = &qs->input_methods;
while (*p != NULL) { while (*p != NULL) {
p = &(*p)->next; p = &(*p)->next;
} }
@ -86,18 +85,20 @@ void register_input_method(InputMethod *m)
static void input_completion(CompleteState *cp) static void input_completion(CompleteState *cp)
{ {
QEmacsState *qs = cp->s->qe_state;
InputMethod *m; InputMethod *m;
for (m = input_methods; m != NULL; m = m->next) { for (m = qs->input_methods; m != NULL; m = m->next) {
complete_test(cp, m->name); complete_test(cp, m->name);
} }
} }
static InputMethod *find_input_method(const char *name) static InputMethod *find_input_method(const char *name)
{ {
QEmacsState *qs = &qe_state;
InputMethod *m; InputMethod *m;
for (m = input_methods; m != NULL; m = m->next) { for (m = qs->input_methods; m != NULL; m = m->next) {
if (strequal(m->name, name)) if (strequal(m->name, name))
return m; return m;
} }
@ -118,10 +119,10 @@ void do_set_input_method(EditState *s, const char *name)
void do_switch_input_method(EditState *s) void do_switch_input_method(EditState *s)
{ {
if (!s->input_method) if (s->input_method)
s->input_method = s->selected_input_method;
else
s->input_method = NULL; s->input_method = NULL;
else
s->input_method = s->selected_input_method;
} }
void init_input_methods(void) void init_input_methods(void)

187
qe.c
View file

@ -61,7 +61,6 @@ static void display1(DisplayState *s);
static void save_selection(void); static void save_selection(void);
#endif #endif
static CompletionFunc find_completion(const char *name); static CompletionFunc find_completion(const char *name);
static int dummy_dpy_init(QEditScreen *s, int w, int h);
QEmacsState qe_state; QEmacsState qe_state;
/* should handle multiple screens, and multiple sessions */ /* should handle multiple screens, and multiple sessions */
@ -166,6 +165,9 @@ static int qe_register_binding1(unsigned int *keys, int nb_keys,
KeyDef **lp, *p; KeyDef **lp, *p;
int i; int i;
if (!d)
return -1;
/* add key */ /* add key */
p = qe_malloc_hack(KeyDef, (nb_keys - 1) * sizeof(p->keys[0])); p = qe_malloc_hack(KeyDef, (nb_keys - 1) * sizeof(p->keys[0]));
if (!p) if (!p)
@ -190,7 +192,7 @@ static int qe_register_binding1(unsigned int *keys, int nb_keys,
} }
/* convert compressed mappings to real ones */ /* convert compressed mappings to real ones */
static void qe_register_binding2(int key, CmdDef *d, ModeDef *m) static int qe_register_binding2(int key, CmdDef *d, ModeDef *m)
{ {
int nb_keys; int nb_keys;
unsigned int keys[3]; unsigned int keys[3];
@ -209,7 +211,7 @@ static void qe_register_binding2(int key, CmdDef *d, ModeDef *m)
} else { } else {
keys[nb_keys++] = key; keys[nb_keys++] = key;
} }
qe_register_binding1(keys, nb_keys, d, m); return qe_register_binding1(keys, nb_keys, d, m);
} }
#if 0 #if 0
@ -278,36 +280,9 @@ void qe_register_cmd_table(CmdDef *cmds, ModeDef *m)
/* key binding handling */ /* key binding handling */
void qe_register_binding(int key, const char *cmd_name, const char *mode_names) int qe_register_binding(int key, const char *cmd_name, ModeDef *m)
{ {
CmdDef *d; return qe_register_binding2(key, qe_find_cmd(cmd_name), m);
ModeDef *m;
const char *p, *r;
char mode_name[64];
d = qe_find_cmd(cmd_name);
if (!d)
return;
if (!mode_names || mode_names[0] == '\0') {
qe_register_binding2(key, d, NULL);
} else {
p = mode_names;
for (;;) {
r = strchr(p, '|');
if (r) {
pstrncpy(mode_name, sizeof(mode_name), p, r - p);
} else {
pstrcpy(mode_name, sizeof(mode_name), p);
}
m = find_mode(mode_name);
if (m) {
qe_register_binding2(key, d, m);
}
if (!r)
break;
p = r + 1;
}
}
} }
void command_completion(CompleteState *cp) void command_completion(CompleteState *cp)
@ -2123,6 +2098,9 @@ void display_window_borders(EditState *e)
} }
} }
#if 1
/* Should move all this to display.c */
/* compute style */ /* compute style */
static void apply_style(QEStyleDef *style, int style_index) static void apply_style(QEStyleDef *style, int style_index)
{ {
@ -2173,8 +2151,8 @@ void style_completion(CompleteState *cp)
int i; int i;
QEStyleDef *style; QEStyleDef *style;
for (i = 0; i < QE_STYLE_NB; i++) { style = qe_styles;
style = &qe_styles[i]; for (i = 0; i < QE_STYLE_NB; i++, style++) {
complete_test(cp, style->name); complete_test(cp, style->name);
} }
} }
@ -2184,20 +2162,14 @@ QEStyleDef *find_style(const char *name)
int i; int i;
QEStyleDef *style; QEStyleDef *style;
for (i = 0; i < QE_STYLE_NB; i++) { style = qe_styles;
style = &qe_styles[i]; for (i = 0; i < QE_STYLE_NB; i++, style++) {
if (strequal(style->name, name)) if (strequal(style->name, name))
return style; return style;
} }
return NULL; return NULL;
} }
void do_define_color(EditState *e, const char *name, const char *value)
{
if (css_define_color(name, value))
put_status(e, "Invalid color '%s'", value);
}
/* Note: we use the same syntax as CSS styles to ease merging */ /* Note: we use the same syntax as CSS styles to ease merging */
void do_set_style(EditState *e, const char *stylestr, void do_set_style(EditState *e, const char *stylestr,
const char *propstr, const char *value) const char *propstr, const char *value)
@ -2212,7 +2184,9 @@ void do_set_style(EditState *e, const char *stylestr,
} }
prop_index = css_get_enum(propstr, prop_index = css_get_enum(propstr,
"color,background-color,font-family,font-style,font-weight,font-size,text-decoration"); "color,background-color,font-family,"
"font-style,font-weight,font-size,"
"text-decoration");
if (prop_index < 0) { if (prop_index < 0) {
put_status(e, "Unknown property '%s'", propstr); put_status(e, "Unknown property '%s'", propstr);
return; return;
@ -2274,6 +2248,13 @@ void do_set_style(EditState *e, const char *stylestr,
} }
} }
void do_define_color(EditState *e, const char *name, const char *value)
{
if (css_define_color(name, value))
put_status(e, "Invalid color '%s'", value);
}
#endif
void do_set_display_size(__unused__ EditState *s, int w, int h) void do_set_display_size(__unused__ EditState *s, int w, int h)
{ {
if (w != NO_ARG && h != NO_ARG) { if (w != NO_ARG && h != NO_ARG) {
@ -4279,7 +4260,7 @@ void put_status(__unused__ EditState *s, const char *fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, ap); vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap); va_end(ap);
if (qs->screen->dpy.dpy_init == dummy_dpy_init) { if (!qs->screen->dpy.dpy_probe) {
eb_format_message(qs, "*errors*", buf); eb_format_message(qs, "*errors*", buf);
} else { } else {
if (!strequal(buf, qs->status_shadow)) { if (!strequal(buf, qs->status_shadow)) {
@ -6119,8 +6100,7 @@ void do_refresh(__unused__ EditState *s1)
int width, height, resized; int width, height, resized;
if (qs->complete_refresh) { if (qs->complete_refresh) {
if (qs->screen->dpy.dpy_invalidate) dpy_invalidate(qs->screen);
qs->screen->dpy.dpy_invalidate();
} }
/* recompute various dimensions */ /* recompute various dimensions */
@ -7388,115 +7368,6 @@ static CmdOptionDef cmd_options[] = {
#include "qeconfig.h" #include "qeconfig.h"
/* dummy display driver for initialization time */
static int dummy_dpy_probe(void)
{
return 1;
}
extern QEDisplay dummy_dpy;
static int dummy_dpy_init(QEditScreen *s, __unused__ int w, __unused__ int h)
{
memcpy(&s->dpy, &dummy_dpy, sizeof(QEDisplay));
s->charset = &charset_8859_1;
return 0;
}
static void dummy_dpy_close(__unused__ QEditScreen *s)
{
}
static void dummy_dpy_cursor_at(__unused__ QEditScreen *s,
__unused__ int x1, __unused__ int y1,
__unused__ int w, __unused__ int h)
{
}
static int dummy_dpy_is_user_input_pending(__unused__ QEditScreen *s)
{
return 0;
}
static void dummy_dpy_fill_rectangle(__unused__ QEditScreen *s,
__unused__ int x1, __unused__ int y1,
__unused__ int w, __unused__ int h,
__unused__ QEColor color)
{
}
static QEFont *dummy_dpy_open_font(__unused__ QEditScreen *s,
__unused__ int style, __unused__ int size)
{
return NULL;
}
static void dummy_dpy_close_font(__unused__ QEditScreen *s,
__unused__ QEFont *font)
{
}
static void dummy_dpy_text_metrics(__unused__ QEditScreen *s,
__unused__ QEFont *font,
QECharMetrics *metrics,
__unused__ const unsigned int *str,
__unused__ int len)
{
metrics->font_ascent = 1;
metrics->font_descent = 0;
metrics->width = len;
}
static void dummy_dpy_draw_text(__unused__ QEditScreen *s,
__unused__ QEFont *font,
__unused__ int x, __unused__ int y,
__unused__ const unsigned int *str,
__unused__ int len,
__unused__ QEColor color)
{
}
static void dummy_dpy_set_clip(__unused__ QEditScreen *s,
__unused__ int x, __unused__ int y,
__unused__ int w, __unused__ int h)
{
}
static void dummy_dpy_flush(__unused__ QEditScreen *s)
{
}
QEDisplay dummy_dpy = {
"dummy",
dummy_dpy_probe,
dummy_dpy_init,
dummy_dpy_close,
dummy_dpy_cursor_at,
dummy_dpy_flush,
dummy_dpy_is_user_input_pending,
dummy_dpy_fill_rectangle,
dummy_dpy_open_font,
dummy_dpy_close_font,
dummy_dpy_text_metrics,
dummy_dpy_draw_text,
dummy_dpy_set_clip,
NULL, /* dpy_selection_activate */
NULL, /* dpy_selection_request */
NULL, /* dpy_invalidate */
NULL, /* dpy_bmp_alloc */
NULL, /* dpy_bmp_free */
NULL, /* dpy_bmp_draw */
NULL, /* dpy_bmp_lock */
NULL, /* dpy_bmp_unlock */
NULL, /* dpy_full_screen */
NULL, /* next */
};
#if (defined(__GNUC__) || defined(__TINYC__)) && defined(CONFIG_INIT_CALLS) #if (defined(__GNUC__) || defined(__TINYC__)) && defined(CONFIG_INIT_CALLS)
static void init_all_modules(void) static void init_all_modules(void)
@ -7675,10 +7546,10 @@ static void qe_init(void *opaque)
s = edit_new(b, 0, 0, 0, 0, WF_MODELINE); s = edit_new(b, 0, 0, 0, 0, WF_MODELINE);
/* at this stage, no screen is defined. Initialize a /* at this stage, no screen is defined. Initialize a
* dummy display driver to have a consistent state * null display driver to have a consistent state
* else many commands such as put_status would crash. * else many commands such as put_status would crash.
*/ */
dummy_dpy.dpy_init(&global_screen, screen_width, screen_height); dpy_init(&global_screen, NULL, screen_width, screen_height);
/* handle options */ /* handle options */
_optind = parse_command_line(argc, argv); _optind = parse_command_line(argc, argv);
@ -7696,7 +7567,7 @@ static void qe_init(void *opaque)
fprintf(stderr, "No suitable display found, exiting\n"); fprintf(stderr, "No suitable display found, exiting\n");
exit(1); exit(1);
} }
if (dpy->dpy_init(&global_screen, screen_width, screen_height) < 0) { if (dpy_init(&global_screen, dpy, screen_width, screen_height) < 0) {
/* Just disable the display and try another */ /* Just disable the display and try another */
//fprintf(stderr, "Could not initialize display '%s', exiting\n", //fprintf(stderr, "Could not initialize display '%s', exiting\n",
// dpy->name); // dpy->name);

5
qe.h
View file

@ -1121,7 +1121,7 @@ struct QEmacsState {
//struct QECharset *first_charset; //struct QECharset *first_charset;
//struct QETimer *first_timer; //struct QETimer *first_timer;
//struct VarDef *first_variable; //struct VarDef *first_variable;
//struct InputMethod *input_methods; struct InputMethod *input_methods;
EditState *first_window; EditState *first_window;
EditState *active_window; /* window in which we edit */ EditState *active_window; /* window in which we edit */
EditBuffer *first_buffer; EditBuffer *first_buffer;
@ -1264,8 +1264,7 @@ typedef struct CmdDef {
void qe_register_mode(ModeDef *m); void qe_register_mode(ModeDef *m);
void mode_completion(CompleteState *cp); void mode_completion(CompleteState *cp);
void qe_register_cmd_table(CmdDef *cmds, ModeDef *m); void qe_register_cmd_table(CmdDef *cmds, ModeDef *m);
void qe_register_binding(int key, const char *cmd_name, int qe_register_binding(int key, const char *cmd_name, ModeDef *m);
const char *mode_names);
CmdDef *qe_find_cmd(const char *cmd_name); CmdDef *qe_find_cmd(const char *cmd_name);
/* text display system */ /* text display system */

8
tty.c
View file

@ -101,8 +101,6 @@ static int tty_term_probe(void)
return 1; return 1;
} }
static QEDisplay tty_dpy;
static int tty_term_init(QEditScreen *s, static int tty_term_init(QEditScreen *s,
__unused__ int w, __unused__ int h) __unused__ int w, __unused__ int h)
{ {
@ -110,8 +108,6 @@ static int tty_term_init(QEditScreen *s,
struct termios tty; struct termios tty;
struct sigaction sig; struct sigaction sig;
memcpy(&s->dpy, &tty_dpy, sizeof(QEDisplay));
s->STDIN = stdin; s->STDIN = stdin;
s->STDOUT = stdout; s->STDOUT = stdout;
@ -295,7 +291,7 @@ static void tty_resize(__unused__ int sig)
s->clip_y2 = s->height; s->clip_y2 = s->height;
} }
static void tty_term_invalidate(void) static void tty_term_invalidate(QEditScreen *s)
{ {
tty_resize(0); tty_resize(0);
} }
@ -841,7 +837,6 @@ static QEDisplay tty_dpy = {
tty_term_probe, tty_term_probe,
tty_term_init, tty_term_init,
tty_term_close, tty_term_close,
tty_term_cursor_at,
tty_term_flush, tty_term_flush,
tty_term_is_user_input_pending, tty_term_is_user_input_pending,
tty_term_fill_rectangle, tty_term_fill_rectangle,
@ -853,6 +848,7 @@ static QEDisplay tty_dpy = {
NULL, /* dpy_selection_activate */ NULL, /* dpy_selection_activate */
NULL, /* dpy_selection_request */ NULL, /* dpy_selection_request */
tty_term_invalidate, tty_term_invalidate,
tty_term_cursor_at,
NULL, /* dpy_bmp_alloc */ NULL, /* dpy_bmp_alloc */
NULL, /* dpy_bmp_free */ NULL, /* dpy_bmp_free */
NULL, /* dpy_bmp_draw */ NULL, /* dpy_bmp_draw */

View file

@ -187,10 +187,10 @@ static int unihex_init(void)
qe_register_mode(&unihex_mode); qe_register_mode(&unihex_mode);
/* additional mode specific keys */ /* additional mode specific keys */
qe_register_binding(KEY_CTRL_LEFT, "decrease-width", "unihex"); qe_register_binding(KEY_CTRL_LEFT, "decrease-width", &unihex_mode);
qe_register_binding(KEY_CTRL_RIGHT, "increase-width", "unihex"); qe_register_binding(KEY_CTRL_RIGHT, "increase-width", &unihex_mode);
qe_register_binding(KEY_TAB, "toggle-hex", "unihex"); qe_register_binding(KEY_TAB, "toggle-hex", &unihex_mode);
qe_register_binding(KEY_SHIFT_TAB, "toggle-hex", "unihex"); qe_register_binding(KEY_SHIFT_TAB, "toggle-hex", &unihex_mode);
return 0; return 0;
} }

61
util.c
View file

@ -909,23 +909,26 @@ void keytostr(char *buf, int buf_size, int key)
int to_hex(int key) int to_hex(int key)
{ {
/* Only ASCII supported */
if (qe_isdigit(key)) if (qe_isdigit(key))
return key - '0'; return key - '0';
else if (key >= 'a' && key <= 'f') else
return key - 'a' + 10; if (qe_inrange(key | ('a' - 'A'), 'a', 'f'))
else if (key >= 'A' && key <= 'F') return (key & 7) + 9;
return key - 'A' + 10;
else else
return -1; return -1;
} }
#if 1
/* Should move all this to display.c */
typedef struct ColorDef { typedef struct ColorDef {
const char *name; const char *name;
unsigned int color; unsigned int color;
} ColorDef; } ColorDef;
static ColorDef const css_colors[] = { static ColorDef const default_colors[] = {
/*from HTML 4.0 spec */ /* From HTML 4.0 spec */
{ "black", QERGB(0x00, 0x00, 0x00) }, { "black", QERGB(0x00, 0x00, 0x00) },
{ "green", QERGB(0x00, 0x80, 0x00) }, { "green", QERGB(0x00, 0x80, 0x00) },
{ "silver", QERGB(0xc0, 0xc0, 0xc0) }, { "silver", QERGB(0xc0, 0xc0, 0xc0) },
@ -952,22 +955,18 @@ static ColorDef const css_colors[] = {
{ "grey", QERGB(0xbe, 0xbe, 0xbe) }, { "grey", QERGB(0xbe, 0xbe, 0xbe) },
{ "transparent", COLOR_TRANSPARENT }, { "transparent", COLOR_TRANSPARENT },
}; };
#define nb_css_colors countof(css_colors) #define nb_default_colors countof(default_colors)
static ColorDef *custom_colors; static ColorDef *qe_colors = (ColorDef *)default_colors;
static int nb_custom_colors; static int nb_qe_colors = nb_default_colors;
void color_completion(CompleteState *cp) void color_completion(CompleteState *cp)
{ {
ColorDef const *def; ColorDef const *def;
int count; int count;
def = custom_colors; def = qe_colors;
count = nb_custom_colors; count = nb_qe_colors;
if (!count) {
def = css_colors;
count = nb_css_colors;
}
while (count > 0) { while (count > 0) {
if (strxstart(def->name, cp->current, NULL)) if (strxstart(def->name, cp->current, NULL))
add_string(&cp->cs, def->name); add_string(&cp->cs, def->name);
@ -998,32 +997,29 @@ int css_define_color(const char *name, const char *value)
if (css_get_color(&color, value)) if (css_get_color(&color, value))
return -1; return -1;
/* First color definition: allocate custom_colors array */ /* First color definition: allocate modifiable array */
if (!nb_custom_colors) { if (qe_colors == default_colors) {
custom_colors = qe_malloc_dup(css_colors, sizeof(css_colors)); qe_colors = qe_malloc_dup(default_colors, sizeof(default_colors));
if (!custom_colors)
return -1;
nb_custom_colors = nb_css_colors;
} }
/* Make room: reallocate table in chunks of 8 entries */ /* Make room: reallocate table in chunks of 8 entries */
if (((nb_custom_colors - nb_css_colors) & 7) == 0) { if (((nb_qe_colors - nb_default_colors) & 7) == 0) {
if (!qe_realloc(&custom_colors, if (!qe_realloc(&qe_colors,
(nb_custom_colors + 8) * sizeof(ColorDef))) { (nb_qe_colors + 8) * sizeof(ColorDef))) {
return -1; return -1;
} }
} }
/* Check for redefinition */ /* Check for redefinition */
index = css_lookup_color(custom_colors, nb_custom_colors, name); index = css_lookup_color(qe_colors, nb_qe_colors, name);
if (index >= 0) { if (index >= 0) {
custom_colors[index].color = color; qe_colors[index].color = color;
return 0; return 0;
} }
def = &custom_colors[nb_custom_colors]; def = &qe_colors[nb_qe_colors];
def->name = qe_strdup(name); def->name = qe_strdup(name);
def->color = color; def->color = color;
nb_custom_colors++; nb_qe_colors++;
return 0; return 0;
} }
@ -1036,12 +1032,8 @@ int css_get_color(QEColor *color_ptr, const char *p)
unsigned char rgba[4]; unsigned char rgba[4];
/* search in tables */ /* search in tables */
def = custom_colors; def = qe_colors;
count = nb_custom_colors; count = nb_qe_colors;
if (!count) {
def = css_colors;
count = nb_css_colors;
}
index = css_lookup_color(def, count, p); index = css_lookup_color(def, count, p);
if (index >= 0) { if (index >= 0) {
*color_ptr = def[index].color; *color_ptr = def[index].color;
@ -1127,6 +1119,7 @@ int css_get_font_family(const char *str)
v = 0; /* inherit */ v = 0; /* inherit */
return v; return v;
} }
#endif /* style stuff */
/* a = a union b */ /* a = a union b */
void css_union_rect(CSSRect *a, const CSSRect *b) void css_union_rect(CSSRect *a, const CSSRect *b)

View file

@ -973,7 +973,7 @@ int video_init(void)
qe_register_mode(&video_mode); qe_register_mode(&video_mode);
qe_register_cmd_table(video_commands, &video_mode); qe_register_cmd_table(video_commands, &video_mode);
/* additional mode specific keys */ /* additional mode specific keys */
qe_register_binding('f', "toggle-full-screen", "av"); qe_register_binding('f', "toggle-full-screen", &video_mode);
return 0; return 0;
} }

View file

@ -25,8 +25,6 @@
extern int main1(int argc, char **argv); extern int main1(int argc, char **argv);
LRESULT CALLBACK qe_wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK qe_wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
extern QEDisplay win32_dpy;
static HINSTANCE _hPrev, _hInstance; static HINSTANCE _hPrev, _hInstance;
static int font_xsize; static int font_xsize;
@ -141,8 +139,6 @@ static int win_init(QEditScreen *s, int w, int h)
if (!_hPrev) if (!_hPrev)
init_application(); init_application();
memcpy(&s->dpy, &win32_dpy, sizeof(QEDisplay));
s->private = NULL; s->private = NULL;
s->media = CSS_MEDIA_SCREEN; s->media = CSS_MEDIA_SCREEN;
@ -504,7 +500,6 @@ static QEDisplay win32_dpy = {
win_probe, win_probe,
win_init, win_init,
win_close, win_close,
NULL,
win_flush, win_flush,
win_is_user_input_pending, win_is_user_input_pending,
win_fill_rectangle, win_fill_rectangle,
@ -516,6 +511,7 @@ static QEDisplay win32_dpy = {
NULL, /* dpy_selection_activate */ NULL, /* dpy_selection_activate */
NULL, /* dpy_selection_request */ NULL, /* dpy_selection_request */
NULL, /* dpy_invalidate */ NULL, /* dpy_invalidate */
NULL, /* dpy_cursor_at */
NULL, /* dpy_bmp_alloc */ NULL, /* dpy_bmp_alloc */
NULL, /* dpy_bmp_free */ NULL, /* dpy_bmp_free */
NULL, /* dpy_bmp_draw */ NULL, /* dpy_bmp_draw */

5
x11.c
View file

@ -80,7 +80,6 @@ static int update_nb;
static CSSRect update_rects[UPDATE_MAX_REGIONS]; static CSSRect update_rects[UPDATE_MAX_REGIONS];
#endif #endif
static QEDisplay x11_dpy;
static int visual_depth; static int visual_depth;
static int force_tty; static int force_tty;
@ -193,8 +192,6 @@ static int term_init(QEditScreen *s, int w, int h)
QEStyleDef default_style; QEStyleDef default_style;
XGCValues gc_val; XGCValues gc_val;
memcpy(&s->dpy, &x11_dpy, sizeof(QEDisplay));
s->private = NULL; s->private = NULL;
s->media = CSS_MEDIA_SCREEN; s->media = CSS_MEDIA_SCREEN;
@ -1679,7 +1676,6 @@ static QEDisplay x11_dpy = {
term_probe, term_probe,
term_init, term_init,
term_close, term_close,
NULL,
term_flush, term_flush,
x11_is_user_input_pending, x11_is_user_input_pending,
term_fill_rectangle, term_fill_rectangle,
@ -1691,6 +1687,7 @@ static QEDisplay x11_dpy = {
term_selection_activate, term_selection_activate,
term_selection_request, term_selection_request,
NULL, /* dpy_invalidate */ NULL, /* dpy_invalidate */
NULL, /* dpy_cursor_at */
x11_bmp_alloc, x11_bmp_alloc,
x11_bmp_free, x11_bmp_free,
x11_bmp_draw, x11_bmp_draw,