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
******************************************************************************/
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);
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);
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) {
{ .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 }
};
/* 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));