aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-05-10 00:55:10 -0400
committerJesse Luehrs <doy@tozt.net>2014-05-10 00:55:10 -0400
commit533feb18c09f4347005c21917fe78c4b11959ffa (patch)
tree7b0a29d947a1352ec9ca1cea48026a8872a1ddb8
parent2bea02ee4cbd46d7a2ffbd541ac6f64e2873200a (diff)
downloadrunes-533feb18c09f4347005c21917fe78c4b11959ffa.tar.gz
runes-533feb18c09f4347005c21917fe78c4b11959ffa.zip
factor this out
-rw-r--r--src/window-xlib.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/window-xlib.c b/src/window-xlib.c
index 311ff98..788d5a8 100644
--- a/src/window-xlib.c
+++ b/src/window-xlib.c
@@ -99,6 +99,8 @@ static void runes_window_backend_handle_button_event(
RunesTerm *t, XButtonEvent *e);
static int runes_window_backend_handle_builtin_button_press(
RunesTerm *t, XButtonEvent *e);
+static struct runes_loc runes_window_backend_get_mouse_position(
+ RunesTerm *t, int xpixel, int ypixel);
static void runes_window_backend_handle_expose_event(
RunesTerm *t, XExposeEvent *e);
static void runes_window_backend_handle_configure_event(
@@ -724,6 +726,7 @@ static void runes_window_backend_handle_button_event(
if (t->scr.mouse_reporting_press_release) {
char response[7];
char status = 0;
+ struct runes_loc loc;
if (e->type == ButtonRelease && e->button > 3) {
return;
@@ -762,21 +765,20 @@ static void runes_window_backend_handle_button_event(
status |= 16;
}
+ loc = runes_window_backend_get_mouse_position(t, e->x, e->y);
sprintf(
response, "\e[M%c%c%c",
- ' ' + (status),
- ' ' + (e->x / t->display.fontx + 1),
- ' ' + (e->y / t->display.fonty + 1));
+ ' ' + (status), ' ' + loc.col + 1, ' ' + loc.row + 1);
runes_pty_backend_write(t, response, 6);
}
else if (t->scr.mouse_reporting_press && e->type == ButtonPress) {
char response[7];
+ struct runes_loc loc;
+ loc = runes_window_backend_get_mouse_position(t, e->x, e->y);
sprintf(
response, "\e[M%c%c%c",
- ' ' + (e->button - 1),
- ' ' + (e->x / t->display.fontx + 1),
- ' ' + (e->y / t->display.fonty + 1));
+ ' ' + (e->button - 1), ' ' + loc.col + 1, ' ' + loc.row + 1);
runes_pty_backend_write(t, response, 6);
}
else {
@@ -811,6 +813,26 @@ static int runes_window_backend_handle_builtin_button_press(
return 0;
}
+static struct runes_loc runes_window_backend_get_mouse_position(
+ RunesTerm *t, int xpixel, int ypixel)
+{
+ struct runes_loc ret;
+
+ ret.row = ypixel / t->display.fonty;
+ ret.col = xpixel / t->display.fontx;
+
+ ret.row = ret.row < 0 ? 0
+ : ret.row > t->scr.grid->max.row - 1 ? t->scr.grid->max.row - 1
+ : ret.row;
+ ret.col = ret.col < 0 ? 0
+ : ret.col > t->scr.grid->max.col ? t->scr.grid->max.col
+ : ret.col;
+
+ ret.row = ret.row - t->display.row_visible_offset + t->scr.grid->row_count - t->scr.grid->max.row;
+
+ return ret;
+}
+
static void runes_window_backend_handle_expose_event(
RunesTerm *t, XExposeEvent *e)
{