From 0a8b3f9365ad73a6905141bffab3b52f737a8977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 14 Mar 2013 18:54:21 +0000 Subject: [PATCH] qemacs: update patch * cleanup * count repaints and discard unneeded ones, reduces flicker * implement mouse suppose (selection doesn't work yet) * implement window resizing * fix cursor drawing (map XOR mode for rectangles to B_OP_INVERT) * Add 1 to the font descent value, now draws text like Pe. --- .../qemacs/patches/qemacs-0.3.2dev-cvs.patch | 765 +++++++++++------- 1 file changed, 458 insertions(+), 307 deletions(-) diff --git a/app-editors/qemacs/patches/qemacs-0.3.2dev-cvs.patch b/app-editors/qemacs/patches/qemacs-0.3.2dev-cvs.patch index 9bea8cc43..4c2261f07 100644 --- a/app-editors/qemacs/patches/qemacs-0.3.2dev-cvs.patch +++ b/app-editors/qemacs/patches/qemacs-0.3.2dev-cvs.patch @@ -4,7 +4,7 @@ RCS file: /sources/qemacs/qemacs/Makefile,v retrieving revision 1.50 diff -u -r1.50 Makefile --- Makefile 5 Jun 2008 07:14:12 -0000 1.50 -+++ Makefile 13 Mar 2013 14:27:53 -0000 ++++ Makefile 14 Mar 2013 18:45:07 -0000 @@ -63,7 +63,7 @@ endif @@ -61,7 +61,7 @@ RCS file: /sources/qemacs/qemacs/cfb.c,v retrieving revision 1.8 diff -u -r1.8 cfb.c --- cfb.c 8 Apr 2008 06:55:44 -0000 1.8 -+++ cfb.c 13 Mar 2013 14:27:53 -0000 ++++ cfb.c 14 Mar 2013 18:45:07 -0000 @@ -50,7 +50,7 @@ static void cfb16_fill_rectangle(QEditScreen *s, int x1, int y1, int w, int h, QEColor color) @@ -122,7 +122,7 @@ RCS file: /sources/qemacs/qemacs/configure,v retrieving revision 1.15 diff -u -r1.15 configure --- configure 17 Apr 2008 15:06:44 -0000 1.15 -+++ configure 13 Mar 2013 14:27:53 -0000 ++++ configure 14 Mar 2013 18:45:07 -0000 @@ -45,9 +45,11 @@ ptsname="yes" gprof="no" @@ -207,7 +207,7 @@ RCS file: /sources/qemacs/qemacs/display.h,v retrieving revision 1.11 diff -u -r1.11 display.h --- display.h 11 Jan 2008 11:29:28 -0000 1.11 -+++ display.h 13 Mar 2013 14:27:53 -0000 ++++ display.h 14 Mar 2013 18:45:07 -0000 @@ -53,7 +53,7 @@ int refcount; int ascent; @@ -232,7 +232,7 @@ RCS file: /sources/qemacs/qemacs/fbfrender.c,v retrieving revision 1.10 diff -u -r1.10 fbfrender.c --- fbfrender.c 8 Jan 2008 16:37:54 -0000 1.10 -+++ fbfrender.c 13 Mar 2013 14:27:54 -0000 ++++ fbfrender.c 14 Mar 2013 18:45:07 -0000 @@ -124,7 +124,7 @@ static GlyphCache *fbf_decode_glyph1(QEFont *font, int code) @@ -257,7 +257,7 @@ RCS file: /sources/qemacs/qemacs/html2png.c,v retrieving revision 1.12 diff -u -r1.12 html2png.c --- html2png.c 11 Jan 2008 11:29:28 -0000 1.12 -+++ html2png.c 13 Mar 2013 14:27:54 -0000 ++++ html2png.c 14 Mar 2013 18:45:07 -0000 @@ -135,7 +135,7 @@ /* realloc ppm bitmap */ static int ppm_resize(QEditScreen *s, int w, int h) @@ -319,7 +319,7 @@ RCS file: /sources/qemacs/qemacs/qe.h,v retrieving revision 1.96 diff -u -r1.96 qe.h --- qe.h 4 May 2008 15:54:39 -0000 1.96 -+++ qe.h 13 Mar 2013 14:27:55 -0000 ++++ qe.h 14 Mar 2013 18:45:11 -0000 @@ -267,11 +267,11 @@ int ustristart(const unsigned int *str, const char *val, const unsigned int **ptr); static inline unsigned int *umemmove(unsigned int *dest, @@ -340,7 +340,7 @@ RCS file: /sources/qemacs/qemacs/tty.c,v retrieving revision 1.50 diff -u -r1.50 tty.c --- tty.c 23 Apr 2008 15:30:33 -0000 1.50 -+++ tty.c 13 Mar 2013 14:27:56 -0000 ++++ tty.c 14 Mar 2013 18:45:11 -0000 @@ -118,7 +118,7 @@ tty_screen = s; @@ -436,7 +436,7 @@ RCS file: /sources/qemacs/qemacs/win32.c,v retrieving revision 1.15 diff -u -r1.15 win32.c --- win32.c 23 Apr 2008 15:29:35 -0000 1.15 -+++ win32.c 13 Mar 2013 14:27:56 -0000 ++++ win32.c 14 Mar 2013 18:45:11 -0000 @@ -139,7 +139,7 @@ if (!_hPrev) init_application(); @@ -461,7 +461,7 @@ RCS file: /sources/qemacs/qemacs/x11.c,v retrieving revision 1.28 diff -u -r1.28 x11.c --- x11.c 15 Apr 2008 23:24:04 -0000 1.28 -+++ x11.c 13 Mar 2013 14:27:56 -0000 ++++ x11.c 14 Mar 2013 18:45:12 -0000 @@ -194,7 +194,7 @@ QEStyleDef default_style; XGCValues gc_val; @@ -566,9 +566,9 @@ diff -u -r1.28 x11.c l = q - x11_str; XSetFont(display, gc, xfont->fid); XDrawString16(display, dbuffer, gc, x_start, y, x11_str, l); ---- /dev/null 2013-03-13 15:41:16.406936000 +0100 -+++ haiku.cpp 2013-03-13 15:14:35.549191680 +0100 -@@ -0,0 +1,680 @@ +--- /dev/null 2013-03-14 16:10:28.351668000 +0100 ++++ haiku.cpp 2013-03-14 19:43:57.698351616 +0100 +@@ -0,0 +1,831 @@ +/* + * Haiku driver for QEmacs + * Copyright (c) 2013 François Revol. @@ -589,10 +589,7 @@ diff -u -r1.28 x11.c + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +extern "C" { -+//XXX:shouldn't be required anymore -+//#define private priv_data +#include "qe.h" -+//#undef private +} + +#include @@ -628,6 +625,10 @@ diff -u -r1.28 x11.c +static int bapp_ref_count = 0; +static int events_wr; + ++/* count of pending repaints */ ++static vint32 repaints = 0; ++//TODO:use double-buffering with a BBitmap ++ +static void haiku_handle_event(void *opaque); + +static status_t bmessage_input(QEWindow *win, QEView *view, BMessage *message) @@ -648,7 +649,7 @@ diff -u -r1.28 x11.c + ,fView(view) + {} + -+ virtual ~QEWindow() {} ++ virtual ~QEWindow() {} + +//virtual void Show(); +//virtual void Hide(); @@ -657,7 +658,7 @@ diff -u -r1.28 x11.c +virtual void DispatchMessage(BMessage *message, BHandler *handler); + +private: -+ QEView *fView; ++ QEView *fView; +}; + +class QEView: public BView @@ -666,85 +667,116 @@ diff -u -r1.28 x11.c + QEView(BRect frame, const char *name); + virtual ~QEView(); + ++virtual void MouseDown(BPoint where); ++virtual void MouseUp(BPoint where); ++virtual void MouseMoved(BPoint where, uint32 code, const BMessage *a_message); ++virtual void KeyDown(const char *bytes, int32 numBytes); ++virtual void KeyUp(const char *bytes, int32 numBytes); ++virtual void Draw(BRect updateRect); ++virtual void FrameResized(float new_width, float new_height); +#if 0 -+virtual void MouseDown(BPoint where); -+virtual void MouseUp(BPoint where); -+virtual void MouseMoved(BPoint where, uint32 code, const BMessage *a_message); -+#endif -+virtual void KeyDown(const char *bytes, int32 numBytes); -+virtual void KeyUp(const char *bytes, int32 numBytes); -+virtual void Draw(BRect updateRect); -+#if 0 -+virtual void WindowActivated(bool state); -+virtual void FrameResized(float new_width, float new_height); -+virtual void MessageReceived(BMessage *message); ++virtual void WindowActivated(bool state); ++virtual void MessageReceived(BMessage *message); +#endif +}; + + +bool QEWindow::QuitRequested() +{ -+ BMessage *message = new BMessage(B_QUIT_REQUESTED); -+ bmessage_input(this, NULL, message); -+ return false; ++ BMessage *message = new BMessage(B_QUIT_REQUESTED); ++ bmessage_input(this, NULL, message); ++ return false; +} + +void QEWindow::DispatchMessage(BMessage *message, BHandler *handler) +{ -+ uint32 mods; -+ switch (message->what) { -+ case B_KEY_DOWN: -+ if ((message->FindInt32("modifiers", (int32 *)&mods) == B_OK) && -+ (mods & B_COMMAND_KEY)) { -+ /* BWindow swallows KEY_DOWN when ALT is down... -+ * so this hack is needed. -+ */ -+ fView->KeyDown(NULL, 0); -+ return; ++ uint32 mods; ++ switch (message->what) { ++ case B_MOUSE_WHEEL_CHANGED: ++ { ++ BMessage *message = DetachCurrentMessage(); ++ bmessage_input(this, NULL, message); + } + break; -+ case B_UNMAPPED_KEY_DOWN: -+ case B_UNMAPPED_KEY_UP: -+ case B_KEY_UP: -+ //message->PrintToStream(); -+ break; -+ } -+ BWindow::DispatchMessage(message, handler); ++ case B_KEY_DOWN: ++ if ((message->FindInt32("modifiers", (int32 *)&mods) == B_OK) && ++ (mods & B_COMMAND_KEY)) { ++ /* BWindow swallows KEY_DOWN when ALT is down... ++ * so this hack is needed. ++ */ ++ fView->KeyDown(NULL, 0); ++ return; ++ } ++ break; ++ case B_UNMAPPED_KEY_DOWN: ++ case B_UNMAPPED_KEY_UP: ++ case B_KEY_UP: ++ //message->PrintToStream(); ++ break; ++ } ++ BWindow::DispatchMessage(message, handler); +} + +QEView::QEView(BRect frame, const char *name) -+ :BView(frame, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_FRAME_EVENTS) ++ :BView(frame, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_FRAME_EVENTS) +{ -+ SetViewColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR)); ++ SetViewColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR)); ++ //SetViewColor(0, 255, 0); +} + +QEView::~QEView() +{ +} + ++void QEView::MouseDown(BPoint where) ++{ ++ BMessage *message = Window()->DetachCurrentMessage(); ++ bmessage_input(NULL, this, message); ++} ++ ++void QEView::MouseUp(BPoint where) ++{ ++ BMessage *message = Window()->DetachCurrentMessage(); ++ bmessage_input(NULL, this, message); ++} ++ ++void QEView::MouseMoved(BPoint where, uint32 code, const BMessage *a_message) ++{ ++ BMessage *message = Window()->DetachCurrentMessage(); ++ bmessage_input(NULL, this, message); ++} ++ +void QEView::KeyDown(const char *bytes, int32 numBytes) +{ -+ BMessage *message = Window()->DetachCurrentMessage(); -+ //message->PrintToStream(); -+ bmessage_input(NULL, this, message); ++ BMessage *message = Window()->DetachCurrentMessage(); ++ //message->PrintToStream(); ++ bmessage_input(NULL, this, message); +} + +void QEView::KeyUp(const char *bytes, int32 numBytes) +{ -+ uint32 mods; -+ BMessage *message = Window()->DetachCurrentMessage(); -+ //message->PrintToStream(); -+ bmessage_input(NULL, this, message); ++ uint32 mods; ++ BMessage *message = Window()->DetachCurrentMessage(); ++ //message->PrintToStream(); ++ bmessage_input(NULL, this, message); +} + +void QEView::Draw(BRect updateRect) +{ -+ BMessage *message; -+ message = new BMessage(_UPDATE_); -+ message->AddRect("update_rect", updateRect); -+ bmessage_input(NULL, this, message); ++ BMessage *message; ++ message = new BMessage(_UPDATE_); ++ message->AddRect("update_rect", updateRect); ++ atomic_add(&repaints, 1); ++ bmessage_input(NULL, this, message); +} + ++void QEView::FrameResized(float new_width, float new_height) ++{ ++ BMessage *message = Window()->DetachCurrentMessage(); ++ atomic_set(&repaints, 0); ++ bmessage_input(NULL, this, message); ++ BView::FrameResized(new_width, new_height); ++} + + +static int haiku_probe(void) @@ -790,18 +822,18 @@ diff -u -r1.28 x11.c + +static void uninit_application(void) +{ -+ status_t err; -+ if (--bapp_ref_count) -+ return; -+ be_app->Lock(); -+ be_app->Quit(); -+ //XXX:HACK -+ be_app->Unlock(); -+ //be_app_messenger.SendMessage(B_QUIT_REQUESTED); -+ wait_for_thread(bapp_thid, &err); -+ //FIXME:leak or crash -+ //delete be_app; -+ be_app = NULL; ++ status_t err; ++ if (--bapp_ref_count) ++ return; ++ be_app->Lock(); ++ be_app->Quit(); ++ //XXX:HACK ++ be_app->Unlock(); ++ //be_app_messenger.SendMessage(B_QUIT_REQUESTED); ++ wait_for_thread(bapp_thid, &err); ++ //FIXME:leak or crash ++ //delete be_app; ++ be_app = NULL; +} + +static int haiku_init(QEditScreen *s, int w, int h) @@ -814,36 +846,36 @@ diff -u -r1.28 x11.c + + memcpy(&s->dpy, &haiku_dpy, sizeof(QEDisplay)); + -+ ctx = (WindowState *)malloc(sizeof(WindowState)); -+ if (ctx == NULL) -+ return -1; ++ ctx = (WindowState *)malloc(sizeof(WindowState)); ++ if (ctx == NULL) ++ return -1; + s->priv_data = ctx; + s->media = CSS_MEDIA_SCREEN; + -+ int event_pipe[2]; -+ if (pipe(event_pipe) < 0) -+ return -1; -+ fcntl(event_pipe[0], F_SETFD, FD_CLOEXEC); -+ fcntl(event_pipe[1], F_SETFD, FD_CLOEXEC); ++ int event_pipe[2]; ++ if (pipe(event_pipe) < 0) ++ return -1; ++ fcntl(event_pipe[0], F_SETFD, FD_CLOEXEC); ++ fcntl(event_pipe[1], F_SETFD, FD_CLOEXEC); + -+ ctx->events_rd = event_pipe[0]; -+ ctx->events_wr = events_wr = event_pipe[1]; ++ ctx->events_rd = event_pipe[0]; ++ ctx->events_wr = events_wr = event_pipe[1]; + + set_read_handler(event_pipe[0], haiku_handle_event, s); + + + ctx->font = BFont(be_fixed_font); + -+ font_height height; -+ ctx->font.GetHeight(&height); ++ font_height height; ++ ctx->font.GetHeight(&height); + + font_xsize = (int)ctx->font.StringWidth("n"); -+ font_ysize = (int)(height.ascent + height.descent + height.leading); ++ font_ysize = (int)(height.ascent + height.descent + height.leading + 1); + -+ if (w == 0) -+ w = 80; -+ if (h == 0) -+ h = 25; ++ if (w == 0) ++ w = 80; ++ if (h == 0) ++ h = 25; + xsize = w * font_xsize; + ysize = h * font_ysize; + @@ -856,12 +888,12 @@ diff -u -r1.28 x11.c + s->clip_x2 = s->width; + s->clip_y2 = s->height; + -+ BRect frame(0, 0, s->width - 1, s->height - 1); ++ BRect frame(0, 0, s->width - 1, s->height - 1); + -+ QEView *v = new QEView(frame, "qemacs"); -+ ctx->v = v; ++ QEView *v = new QEView(frame, "qemacs"); ++ ctx->v = v; + -+ frame.OffsetTo(200, 200); ++ frame.OffsetTo(200, 200); + + ctx->w = new QEWindow(frame, "qemacs", v); + ctx->w->AddChild(ctx->v); @@ -876,14 +908,23 @@ diff -u -r1.28 x11.c + +static void haiku_close(QEditScreen *s) +{ -+ WindowState *ctx = (WindowState *)s->priv_data; -+ ctx->w->Lock(); -+ ctx->w->Quit(); ++ WindowState *ctx = (WindowState *)s->priv_data; ++ ctx->w->Lock(); ++ ctx->w->Quit(); + free(s->priv_data); +} + +static void haiku_flush(QEditScreen *s) +{ ++ WindowState *ctx = (WindowState *)s->priv_data; ++ //fprintf(stderr, "%s()\n", __FUNCTION__); ++ ++ ctx->v->LockLooper(); ++ ++ // doesn't really help ++ ctx->v->Sync(); ++ ++ ctx->v->UnlockLooper(); +} + +static int haiku_is_user_input_pending(QEditScreen *s) @@ -896,7 +937,7 @@ diff -u -r1.28 x11.c +static void haiku_handle_event(void *opaque) +{ + QEditScreen *s = (QEditScreen *)opaque; -+ WindowState *ctx = (WindowState *)s->priv_data; ++ WindowState *ctx = (WindowState *)s->priv_data; + unsigned char buf[16]; + bigtime_t timestamp_ms; + BMessage *event; @@ -911,208 +952,309 @@ diff -u -r1.28 x11.c + return; + //event->PrintToStream(); + -+ switch(event->what) { -+ case B_QUIT_REQUESTED: -+ -+ // cancel pending operation -+ ev->key_event.type = QE_KEY_EVENT; -+ ev->key_event.key = KEY_CTRL('g'); -+ qe_handle_event(ev); -+ -+ // simulate C-x C-c -+ ev->key_event.type = QE_KEY_EVENT; -+ ev->key_event.key = KEY_CTRL('x'); -+ qe_handle_event(ev); -+ ev->key_event.type = QE_KEY_EVENT; -+ ev->key_event.key = KEY_CTRL('c'); -+ qe_handle_event(ev); -+ break; -+ -+ case _UPDATE_: -+ // TODO: flush queued -+ ev->expose_event.type = QE_EXPOSE_EVENT; ++ switch(event->what) { ++ case B_QUIT_REQUESTED: ++ ++ // cancel pending operation ++ ev->key_event.type = QE_KEY_EVENT; ++ ev->key_event.key = KEY_CTRL('g'); + qe_handle_event(ev); ++ ++ // simulate C-x C-c ++ ev->key_event.type = QE_KEY_EVENT; ++ ev->key_event.key = KEY_CTRL('x'); ++ qe_handle_event(ev); ++ ev->key_event.type = QE_KEY_EVENT; ++ ev->key_event.key = KEY_CTRL('c'); ++ qe_handle_event(ev); ++ break; ++ ++ case _UPDATE_: ++ // flush queued repaints ++ if (atomic_set(&repaints, 0)) { ++ ev->expose_event.type = QE_EXPOSE_EVENT; ++ qe_handle_event(ev); ++ } ++ break; ++ ++ case B_VIEW_RESIZED: ++ { ++ int32 width, height; ++ int columns, rows; ++ //event->PrintToStream(); ++/* ++ if (event->FindInt32("width", &width) < B_OK) ++ break; ++ if (event->FindInt32("height", &height) < B_OK) ++ break; ++*/ ++ ++ ctx->v->LockLooper(); ++ ++ width = ctx->v->Bounds().IntegerWidth() + 1; ++ height = ctx->v->Bounds().IntegerHeight() + 1; ++ ++ if (width != s->width || height != s->height) ++ ctx->v->Invalidate(ctx->v->Bounds()); ++ ++ s->width = width; ++ s->height = height; ++ ++ ctx->v->UnlockLooper(); ++ ++ //ev->expose_event.type = QE_EXPOSE_EVENT; ++ //qe_handle_event(ev); ++ } ++ break; ++ ++ case B_MOUSE_MOVED: ++ { ++ BPoint pt; ++ ++ ev->button_event.type = QE_MOTION_EVENT; ++ ev->button_event.x = (int)pt.x; ++ ev->button_event.y = (int)pt.y; ++ qe_handle_event(ev); ++ } ++ break; ++ ++ case B_MOUSE_DOWN: ++ case B_MOUSE_UP: ++ { ++ BPoint pt; ++ uint32 buttons; ++ ++ if (event->what == B_MOUSE_DOWN) ++ ev->button_event.type = QE_BUTTON_PRESS_EVENT; ++ else ++ ev->button_event.type = QE_BUTTON_RELEASE_EVENT; ++ ++ if (event->FindPoint("where", &pt) < B_OK) ++ pt = BPoint(0,0); ++ ev->button_event.x = (int)pt.x; ++ ev->button_event.y = (int)pt.y; ++ ++ if (event->FindInt32("buttons", (int32 *)&buttons) < B_OK) ++ buttons = (event->what == B_MOUSE_UP)?0:B_PRIMARY_MOUSE_BUTTON; ++ ++ ++ if (buttons & B_PRIMARY_MOUSE_BUTTON) ++ ev->button_event.button = QE_BUTTON_LEFT; ++ else if (buttons & B_SECONDARY_MOUSE_BUTTON) ++ ev->button_event.button = QE_BUTTON_MIDDLE; ++ else if (buttons & B_TERTIARY_MOUSE_BUTTON) ++ ev->button_event.button = QE_BUTTON_RIGHT; ++ ++ qe_handle_event(ev); ++ } ++ break; ++ ++ case B_MOUSE_WHEEL_CHANGED: ++ { ++ float delta; ++ ++ ev->button_event.type = QE_BUTTON_PRESS_EVENT; ++ ++ if (event->FindFloat("be:wheel_delta_y", &delta) < B_OK) ++ delta = 0.0; ++ ++ if (delta > 0) ++ ev->button_event.button = QE_WHEEL_DOWN; ++ else if (delta < 0) ++ ev->button_event.button = QE_WHEEL_UP; ++ else ++ break; ++ ++ qe_handle_event(ev); ++ } + break; + -+ case B_KEY_UP: -+ break; ++ case B_KEY_UP: ++ break; + -+ case B_KEY_DOWN: -+ { -+ unsigned int mods = 0; -+ uint32 state; -+ //event->PrintToStream(); -+ uint32 scancode; -+ uint32 raw_char; -+ const char *bytes; -+ char buff[6]; -+ int numbytes = 0; -+ int i; ++ case B_KEY_DOWN: ++ { ++ unsigned int mods = 0; ++ uint32 state; ++ //event->PrintToStream(); ++ uint32 scancode; ++ uint32 raw_char; ++ const char *bytes; ++ char buff[6]; ++ int numbytes = 0; ++ int i; + -+ if (event->FindInt64("when", ×tamp_ms) < B_OK) -+ timestamp_ms = 0LL; -+ if (event->FindInt32("modifiers", (int32 *)&state) < B_OK) -+ state = modifiers(); -+ if (event->FindInt32("key", (int32 *)&scancode) < B_OK) -+ scancode = 0; -+ if (event->FindInt32("raw_char", (int32 *)&raw_char) < B_OK) -+ raw_char = 0; ++ if (event->FindInt64("when", ×tamp_ms) < B_OK) ++ timestamp_ms = 0LL; ++ if (event->FindInt32("modifiers", (int32 *)&state) < B_OK) ++ state = modifiers(); ++ if (event->FindInt32("key", (int32 *)&scancode) < B_OK) ++ scancode = 0; ++ if (event->FindInt32("raw_char", (int32 *)&raw_char) < B_OK) ++ raw_char = 0; + -+ /* check for byte[] first, -+ because C-space gives bytes="" (and byte[0] = '\0') */ -+ for (i = 0; i < 5; i++) { -+ buff[i] = '\0'; -+ if (event->FindInt8("byte", i, (int8 *)&buff[i]) < B_OK) -+ break; -+ } ++ /* check for byte[] first, ++ because C-space gives bytes="" (and byte[0] = '\0') */ ++ for (i = 0; i < 5; i++) { ++ buff[i] = '\0'; ++ if (event->FindInt8("byte", i, (int8 *)&buff[i]) < B_OK) ++ break; ++ } + -+ if (i) { -+ bytes = buff; -+ numbytes = i; -+ } else if (event->FindString("bytes", &bytes) < B_OK) -+ bytes = ""; ++ if (i) { ++ bytes = buff; ++ numbytes = i; ++ } else if (event->FindString("bytes", &bytes) < B_OK) ++ bytes = ""; + -+ if (!numbytes) -+ numbytes = strlen(bytes); ++ if (!numbytes) ++ numbytes = strlen(bytes); + -+ shift = (state & B_SHIFT_KEY); ++ shift = (state & B_SHIFT_KEY); + ctrl = (state & B_CONTROL_KEY); + meta = (state & (B_LEFT_OPTION_KEY | B_COMMAND_KEY)); + + //fprintf(stderr, "%cshift %cctrl %cmeta numbytes %d \n", shift ? ' ' : '!', ctrl ? ' ' : '!', meta ? ' ' : '!', numbytes); + -+ char byte = 0; -+ if (numbytes == 1) { -+ byte = bytes[0]; -+ if (state & B_CONTROL_KEY) -+ byte = (char)raw_char; -+ switch (byte) { -+ case B_BACKSPACE: -+ key = KEY_BS; -+ if (meta) -+ key = KEY_META(KEY_BS); -+ break; -+ case B_TAB: -+ key = KEY_TAB; -+ break; -+ case B_ENTER: -+ key = KEY_RET; -+ break; -+ case B_ESCAPE: -+ key = KEY_ESC; -+ break; -+ case B_SPACE: -+ key = KEY_SPC; -+ break; -+ case B_DELETE: -+ key = KEY_DELETE; -+ break; -+ case B_INSERT: -+ key = KEY_INSERT; -+ break; -+ case B_HOME: -+ key = ctrl ? KEY_CTRL_HOME : KEY_HOME; -+ break; -+ case B_END: -+ key = ctrl ? KEY_CTRL_END : KEY_END; -+ break; -+ case B_PAGE_UP: -+ key = KEY_PAGEUP; -+ break; -+ case B_PAGE_DOWN: -+ key = KEY_PAGEDOWN; -+ break; -+ case B_LEFT_ARROW: -+ key = ctrl ? KEY_CTRL_LEFT : KEY_LEFT; -+ break; -+ case B_RIGHT_ARROW: -+ key = ctrl ? KEY_CTRL_RIGHT : KEY_RIGHT; -+ break; -+ case B_UP_ARROW: -+ key = KEY_UP; -+ break; -+ case B_DOWN_ARROW: -+ key = KEY_DOWN; -+ break; -+ case B_FUNCTION_KEY: -+ switch (scancode) { -+ case B_F1_KEY: -+ case B_F2_KEY: -+ case B_F3_KEY: -+ case B_F4_KEY: -+ case B_F5_KEY: -+ case B_F6_KEY: -+ case B_F7_KEY: -+ case B_F8_KEY: -+ case B_F9_KEY: -+ case B_F10_KEY: -+ case B_F11_KEY: -+ case B_F12_KEY: -+ key = KEY_F1 + scancode - B_F1_KEY; -+ break; -+ case B_PRINT_KEY: -+ case B_SCROLL_KEY: -+ case B_PAUSE_KEY: -+ default: -+ break; -+ } -+ break; -+ case 0: -+ break; -+ default: -+ if (byte >= ' ' && byte <= '~') -+ if (meta) -+ key = KEY_META(' ') + byte - ' '; -+ else if (ctrl) -+ key = KEY_CTRL(byte); -+ else -+ key = byte; ++ char byte = 0; ++ if (numbytes == 1) { ++ byte = bytes[0]; ++ if (state & B_CONTROL_KEY) ++ byte = (char)raw_char; ++ switch (byte) { ++ case B_BACKSPACE: ++ key = KEY_BS; ++ if (meta) ++ key = KEY_META(KEY_BS); ++ break; ++ case B_TAB: ++ key = KEY_TAB; ++ break; ++ case B_ENTER: ++ key = KEY_RET; ++ break; ++ case B_ESCAPE: ++ key = KEY_ESC; ++ break; ++ case B_SPACE: ++ key = KEY_SPC; ++ break; ++ case B_DELETE: ++ key = KEY_DELETE; ++ break; ++ case B_INSERT: ++ key = KEY_INSERT; ++ break; ++ case B_HOME: ++ key = ctrl ? KEY_CTRL_HOME : KEY_HOME; ++ break; ++ case B_END: ++ key = ctrl ? KEY_CTRL_END : KEY_END; ++ break; ++ case B_PAGE_UP: ++ key = KEY_PAGEUP; ++ break; ++ case B_PAGE_DOWN: ++ key = KEY_PAGEDOWN; ++ break; ++ case B_LEFT_ARROW: ++ key = ctrl ? KEY_CTRL_LEFT : KEY_LEFT; ++ break; ++ case B_RIGHT_ARROW: ++ key = ctrl ? KEY_CTRL_RIGHT : KEY_RIGHT; ++ break; ++ case B_UP_ARROW: ++ key = KEY_UP; ++ break; ++ case B_DOWN_ARROW: ++ key = KEY_DOWN; ++ break; ++ case B_FUNCTION_KEY: ++ switch (scancode) { ++ case B_F1_KEY: ++ case B_F2_KEY: ++ case B_F3_KEY: ++ case B_F4_KEY: ++ case B_F5_KEY: ++ case B_F6_KEY: ++ case B_F7_KEY: ++ case B_F8_KEY: ++ case B_F9_KEY: ++ case B_F10_KEY: ++ case B_F11_KEY: ++ case B_F12_KEY: ++ key = KEY_F1 + scancode - B_F1_KEY; ++ break; ++ case B_PRINT_KEY: ++ case B_SCROLL_KEY: ++ case B_PAUSE_KEY: ++ default: ++ break; ++ } ++ break; ++ case 0: ++ break; ++ default: ++ if (byte >= ' ' && byte <= '~') ++ if (meta) ++ key = KEY_META(' ') + byte - ' '; ++ else if (ctrl) ++ key = KEY_CTRL(byte); ++ else ++ key = byte; + -+ } -+ } else { -+ const char *p = bytes; -+ key = utf8_decode(&p); -+ } ++ } ++ } else { ++ const char *p = bytes; ++ key = utf8_decode(&p); ++ } + -+ got_key: -+ if (key) { -+ ev->key_event.type = QE_KEY_EVENT; -+ ev->key_event.key = key; -+ qe_handle_event(ev); -+ } -+ } -+ break; -+ } ++ got_key: ++ if (key) { ++ ev->key_event.type = QE_KEY_EVENT; ++ ev->key_event.key = key; ++ qe_handle_event(ev); ++ } ++ } ++ break; ++ } + -+ delete event; ++ delete event; +} + +static void haiku_fill_rectangle(QEditScreen *s, + int x1, int y1, int w, int h, QEColor color) +{ -+ WindowState *ctx = (WindowState *)s->priv_data; -+ //fprintf(stderr, "%s()\n", __FUNCTION__); ++ WindowState *ctx = (WindowState *)s->priv_data; ++ //fprintf(stderr, "%s()\n", __FUNCTION__); ++ drawing_mode oldMode; + -+ /* XXX: suppress XOR mode */ -+ if (color == QECOLOR_XOR) -+ color = QERGB(0xff, 0xff, 0xff); ++ BRect r(x1, y1, x1 + w - 1, y1 + h - 1); ++ rgb_color c = {(color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, ++ 0xff}; + -+ BRect r(x1, y1, x1 + w - 1, y1 + h - 1); -+ rgb_color c = {(color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, -+ 0xff}; ++ ctx->v->LockLooper(); + -+ ctx->v->LockLooper(); ++ oldMode = ctx->v->DrawingMode(); + -+ ctx->v->SetHighColor(c); -+ ctx->v->FillRect(r); -+ -+ ctx->v->UnlockLooper(); ++ /* XXX: suppress XOR mode */ ++ if (color == QECOLOR_XOR) ++ ctx->v->SetDrawingMode(B_OP_INVERT); ++ else ++ ctx->v->SetHighColor(c); ++ ctx->v->FillRect(r); ++ ++ /* XXX: suppress XOR mode */ ++ if (color == QECOLOR_XOR) ++ ctx->v->SetDrawingMode(oldMode); ++ ++ ctx->v->UnlockLooper(); +} + +static QEFont *haiku_open_font(QEditScreen *s, int style, int size) +{ -+ WindowState *ctx = (WindowState *)s->priv_data; -+ //fprintf(stderr, "%s()\n", __FUNCTION__); ++ WindowState *ctx = (WindowState *)s->priv_data; ++ //fprintf(stderr, "%s()\n", __FUNCTION__); + QEFont *font; + + font = (QEFont *)malloc(sizeof(QEFont)); @@ -1122,18 +1264,18 @@ diff -u -r1.28 x11.c + // TODO: use style / size + BFont *f = new BFont(ctx->font); + -+ font_height height; ++ font_height height; + f->GetHeight(&height); + font->ascent = (int)height.ascent; -+ font->descent = (int)(height.descent + height.leading); ++ font->descent = (int)(height.descent + height.leading + 1); + font->priv_data = f; + return font; +} + +static void haiku_close_font(QEditScreen *s, QEFont *font) +{ -+ BFont *f = (BFont *)font->priv_data; -+ delete f; ++ BFont *f = (BFont *)font->priv_data; ++ delete f; + free(font); +} + @@ -1141,7 +1283,7 @@ diff -u -r1.28 x11.c + QECharMetrics *metrics, + const unsigned int *str, int len) +{ -+ //TODO: use BFont::GetEscapements() or StringWidth() ++ //TODO: use BFont::GetEscapements() or StringWidth() + int i, x; + metrics->font_ascent = font->ascent; + metrics->font_descent = font->descent; @@ -1155,38 +1297,38 @@ diff -u -r1.28 x11.c + int x1, int y, const unsigned int *str, int len, + QEColor color) +{ -+ WindowState *ctx = (WindowState *)s->priv_data; -+ BFont *f = (BFont *)(font->priv_data); ++ WindowState *ctx = (WindowState *)s->priv_data; ++ BFont *f = (BFont *)(font->priv_data); + int i; -+ //fprintf(stderr, "%s()\n", __FUNCTION__); ++ //fprintf(stderr, "%s()\n", __FUNCTION__); + + /* XXX: suppress XOR mode */ + if (color == QECOLOR_XOR) + color = QERGB(0xff, 0xff, 0xff); + -+ rgb_color c = {(color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, -+ 0xff}; ++ rgb_color c = {(color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, ++ 0xff}; + -+ ctx->v->LockLooper(); ++ ctx->v->LockLooper(); + -+ ctx->v->SetHighColor(c); -+ ctx->v->SetLowColor(B_TRANSPARENT_COLOR); -+ ctx->v->SetFont(f); -+ ctx->v->MovePenTo(x1, y - 1); ++ ctx->v->SetHighColor(c); ++ ctx->v->SetLowColor(B_TRANSPARENT_COLOR); ++ ctx->v->SetFont(f); ++ ctx->v->MovePenTo(x1, y - 1); + + char buf[10]; + unsigned int cc; + -+ BString text; ++ BString text; + for(i=0;iv->DrawString(buf); ++ cc = str[i]; ++ unicode_to_charset(buf, cc, &charset_utf8); ++ text << buf; ++ //ctx->v->DrawString(buf); + } -+ ctx->v->DrawString(text.String()); -+ -+ ctx->v->UnlockLooper(); ++ ctx->v->DrawString(text.String()); ++ ++ ctx->v->UnlockLooper(); + + //TextOutW(haiku_ctx.hdc, x1, y - font->ascent, buf, len); +} @@ -1194,16 +1336,16 @@ diff -u -r1.28 x11.c +static void haiku_set_clip(QEditScreen *s, + int x, int y, int w, int h) +{ -+ WindowState *ctx = (WindowState *)s->priv_data; -+ //fprintf(stderr, "%s(,%d, %d, %d, %d)\n", __FUNCTION__, x, y, w, h); ++ WindowState *ctx = (WindowState *)s->priv_data; ++ //fprintf(stderr, "%s(,%d, %d, %d, %d)\n", __FUNCTION__, x, y, w, h); + + BRegion clip(BRect(x, y, x + w - 1, y + h - 1)); + -+ ctx->v->LockLooper(); ++ ctx->v->LockLooper(); + -+ ctx->v->ConstrainClippingRegion(&clip); ++ ctx->v->ConstrainClippingRegion(&clip); + -+ ctx->v->UnlockLooper(); ++ ctx->v->UnlockLooper(); +} + +extern QEDisplay haiku_dpy = { @@ -1221,6 +1363,15 @@ diff -u -r1.28 x11.c + haiku_set_clip, + NULL, /* no selection handling */ + NULL, /* no selection handling */ ++ 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 */ +}; + +static CmdOptionDef cmd_options[] = { @@ -1231,17 +1382,17 @@ diff -u -r1.28 x11.c + +static int haiku_init(void) +{ -+ QEmacsState *qs = &qe_state; ++ QEmacsState *qs = &qe_state; + -+ /* override default res path, to find config file at native location */ -+ BPath path; -+ BString old(":"); -+ old << qs->res_path; ++ /* override default res path, to find config file at native location */ ++ BPath path; ++ BString old(":"); ++ old << qs->res_path; + qs->res_path[0] = '\0'; -+ if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { -+ path.Append("qemacs"); ++ if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { ++ path.Append("qemacs"); + pstrcat(qs->res_path, sizeof(qs->res_path), path.Path()); -+ } ++ } + pstrcat(qs->res_path, sizeof(qs->res_path), old.String()); + + qe_register_cmd_line_options(cmd_options);