From e30a4327adf3eaeac3226bf1d67edb289d23bb86 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 10 May 2019 22:46:15 -0400 Subject: [PATCH] updated logic for showing the window *after* reparenting. Added more shortcuts and mouse handling to tframe --- src/tframe.c | 91 ++++++++++++++++++++++++++++++++++++++++------------ src/tide.c | 6 ++-- 2 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/tframe.c b/src/tframe.c index f1e6380..daa0aae 100644 --- a/src/tframe.c +++ b/src/tframe.c @@ -72,6 +72,63 @@ static void xkeypress(XConf* x, XEvent* e) { view_insert(&Tags, key); } +static void get_position(int x, int y, size_t* row, size_t* col) { + int startx = ScrollWidth+3; + int maxy = Divider - 4; + x = (x < 0 ? 0 : (x > X.width ? X.width : x)); + y = (y < 0 ? 0 : (y > maxy ? maxy : y)); + *row = y / X.font->height; + *col = (startx <= x ? x - startx : 0); +} + +static void xmousebtn(XConf* x, XEvent* e) { + (void)x; + size_t row, col; + get_position(e->xbutton.x, e->xbutton.y, &row, &col); + switch (process_mouse(e->xbutton.button, (e->type == ButtonPress))) { + case MouseActExec: + case MouseActExecArg: + case MouseActNone: + break; + case MouseActSel: + view_setcursor(&Tags, row, col, win_keymodsset(ModShift)); + break; + case MouseActSelCtx: + view_select(&Tags, row, col); + break; + case MouseActSelWord: + view_selword(&Tags, row, col); + break; + case MouseActCut: + cut(NULL); + break; + case MouseActPaste: + paste(NULL); + break; + case MouseActFetch: { + FetchCmd[2] = view_fetch(&Tags, row, col, risfile); + (void)job_run(FetchCmd); + free(FetchCmd[2]); + break; + } + case MouseActScrollUp: + view_scroll(&Tags, -ScrollBy); + break; + case MouseActScrollDn: + view_scroll(&Tags, +ScrollBy); + break; + } +} + +static void xbtnmotion(XConf* x, XEvent* e) { + while (XCheckTypedEvent(x->display, MotionNotify, e)); + size_t row, col; + int xpos = e->xbutton.x, ypos = e->xbutton.y; + get_position(xpos, ypos, &row, &col); + if (e->xbutton.state & (1 << (MouseLeft + 7))) + view_setcursor(&Tags, row, col, true); +} + /* X11 Drawing Code ******************************************************************************/ @@ -89,7 +146,7 @@ static void xredraw(XConf* x) { draw_rect(x, EditBg, 0, Divider+2, csr.w, csr.h); XCopyArea(x->display, x->pixmap, x->self, x->gc, 0, 0, x->width, x->height, 0, 0); if ((retile || prev_div != Divider) && Child) { - XMoveResizeWindow(x->display, Child, -1, Divider, x->width, x->height - Divider); + XMoveResizeWindow(x->display, Child, 0, Divider+2, x->width, x->height - Divider - 2); retile = 0; } XFlush(x->display); @@ -113,17 +170,17 @@ void win_init(void) { exit(EXIT_FAILURE); } x11_mkwin(&X, 640, 480, 0 -// | FocusChangeMask | KeyPressMask -// | ButtonPressMask -// | ButtonReleaseMask -// | ButtonMotionMask -// | PropertyChangeMask -// | VisibilityChangeMask + | ButtonPressMask + | ButtonReleaseMask + | ButtonMotionMask | SubstructureRedirectMask | SubstructureNotifyMask | StructureNotifyMask | ExposureMask +// | FocusChangeMask +// | PropertyChangeMask +// | VisibilityChangeMask ); x11_init_gc(&X); @@ -131,14 +188,14 @@ void win_init(void) { x11_show(&X); /* register event handlers */ -// X.eventfns[ButtonPress] = xbtnpress; -// X.eventfns[ButtonRelease] = xbtnrelease; -// X.eventfns[MotionNotify] = xbtnmotion; X.eventfns[MapRequest] = xmaprequest; X.eventfns[ConfigureNotify] = xconfigure; X.eventfns[ClientMessage] = xclientmsg; X.eventfns[Expose] = xexpose; X.eventfns[KeyPress] = xkeypress; + X.eventfns[ButtonPress] = xmousebtn; + X.eventfns[ButtonRelease] = xmousebtn; + X.eventfns[MotionNotify] = xbtnmotion; } void win_loop(void) { @@ -215,15 +272,9 @@ static KeyBinding Bindings[41] = { { .mods = ModAny, .key = KEY_DELETE, .fn = delete }, { .mods = ModAny, .key = KEY_BACKSPACE, .fn = backspace }, -// /* External command shortcuts */ -// { .mods = ModCtrl, .key = '[', .fn = lnexec, .arg = "|i-" }, -// { .mods = ModCtrl, .key = ']', .fn = lnexec, .arg = "|i+" }, -// { .mods = ModCtrl, .key = '/', .fn = lnexec, .arg = "|c+" }, -// { .mods = ModCtrl|ModShift, .key = '?', .fn = lnexec, .arg = "|c-" }, - - { .mods = ModCtrl, .key = 'n', .fn = new_win }, -// { .mods = ModOneOrMore, .key = '\n', .fn = newline }, - + { .mods = ModCtrl, .key = 'h', .fn = highlight }, + { .mods = ModCtrl, .key = 'n', .fn = new_win }, + { .mods = ModOneOrMore, .key = '\n', .fn = newline }, { 0, 0, 0, 0 } }; @@ -234,7 +285,7 @@ int main(void) { /* Initialize the views */ view_init(&Tags, NULL); - view_putstr(&Tags, "Newcol Kill Putall Dump Exit"); + view_putstr(&Tags, "Newcol Kill Putall Dump Exit "); view_resize(&Tags, 640, 1); buf_logclear(&(Tags.buffer)); diff --git a/src/tide.c b/src/tide.c index 854f3c5..256ba3b 100644 --- a/src/tide.c +++ b/src/tide.c @@ -230,9 +230,6 @@ void win_init(void) { ); x11_init_gc(&X); x11_sel_init(&X); -#ifndef TEST - x11_show(&X); -#endif /* register event handlers */ X.eventfns[KeyPress] = xkeypress; X.eventfns[ButtonPress] = xmousebtn; @@ -681,6 +678,9 @@ int main(int argc, char** argv) { } /* now create the window and start the event loop */ +#ifndef TEST + x11_show(&X); +#endif xupdate(NULL); win_loop(); return 0; -- 2.55.0