aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-13 15:02:51 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-13 15:02:51 -0400
commit563db15f881207a49f85df5b9358dabb6a8826c8 (patch)
tree8bfd7f356d602720b791a2832182b2dbf7a37b4f
parent28f813cb5a8daa4641dc1afdbf1545da709729a6 (diff)
downloadrunes-563db15f881207a49f85df5b9358dabb6a8826c8.tar.gz
runes-563db15f881207a49f85df5b9358dabb6a8826c8.zip
change cursor display based on if the window has focus or not
-rw-r--r--display.c23
-rw-r--r--display.h2
-rw-r--r--term.h1
-rw-r--r--window-xlib.c11
4 files changed, 34 insertions, 3 deletions
diff --git a/display.c b/display.c
index 03bdd5b..99d0a24 100644
--- a/display.c
+++ b/display.c
@@ -26,6 +26,7 @@ void runes_display_init(RunesTerm *t)
t->cursorcolor = cairo_pattern_create_rgba(0.0, 1.0, 0.0, 0.5);
t->show_cursor = 1;
+ t->focused = 1;
t->font_name = "monospace";
t->font_size = 14.0;
@@ -114,12 +115,30 @@ void runes_display_draw_cursor(RunesTerm *t)
runes_display_move_to(t, t->row, t->col);
cairo_get_current_point(t->cr, &x, &y);
runes_display_get_font_dimensions(t, &fontx, &fonty, &ascent);
- cairo_rectangle(t->backend_cr, x, y - ascent, fontx, fonty);
- cairo_fill(t->backend_cr);
+ if (t->focused) {
+ cairo_rectangle(t->backend_cr, x, y - ascent, fontx, fonty);
+ cairo_fill(t->backend_cr);
+ }
+ else {
+ cairo_set_line_width(t->backend_cr, 1);
+ cairo_rectangle(
+ t->backend_cr, x + 0.5, y - ascent + 0.5, fontx, fonty);
+ cairo_stroke(t->backend_cr);
+ }
cairo_restore(t->backend_cr);
}
}
+void runes_display_focus_in(RunesTerm *t)
+{
+ t->focused = 1;
+}
+
+void runes_display_focus_out(RunesTerm *t)
+{
+ t->focused = 0;
+}
+
void runes_display_move_to(RunesTerm *t, int row, int col)
{
double fontx, fonty, ascent;
diff --git a/display.h b/display.h
index 6e73a54..448ba2e 100644
--- a/display.h
+++ b/display.h
@@ -6,6 +6,8 @@ void runes_display_set_window_size(RunesTerm *t, int width, int height);
void runes_display_get_font_dimensions(
RunesTerm *t, double *fontx, double *fonty, double *ascent);
void runes_display_draw_cursor(RunesTerm *t);
+void runes_display_focus_in(RunesTerm *t);
+void runes_display_focus_out(RunesTerm *t);
void runes_display_move_to(RunesTerm *t, int row, int col);
void runes_display_show_string(RunesTerm *t, char *buf, size_t len);
void runes_display_backspace(RunesTerm *t);
diff --git a/term.h b/term.h
index 03706c5..a62821b 100644
--- a/term.h
+++ b/term.h
@@ -20,6 +20,7 @@ struct runes_term {
char font_underline;
char show_cursor;
+ char focused;
cairo_pattern_t *colors[8];
diff --git a/window-xlib.c b/window-xlib.c
index a8e4029..8ed74ac 100644
--- a/window-xlib.c
+++ b/window-xlib.c
@@ -109,7 +109,8 @@ void runes_window_backend_loop_init(RunesTerm *t, int argc, char *argv[])
XGetICValues(w->ic, XNFilterEvents, &mask, NULL);
XSelectInput(
- w->dpy, w->w, mask|KeyPressMask|StructureNotifyMask|ExposureMask);
+ w->dpy, w->w,
+ mask|KeyPressMask|StructureNotifyMask|ExposureMask|FocusChangeMask);
XSetICFocus(w->ic);
data = malloc(sizeof(RunesXlibLoopData));
@@ -285,6 +286,14 @@ static void runes_window_backend_process_event(uv_work_t *req, int status)
runes_window_backend_resize_window(
t, e->xconfigure.width, e->xconfigure.height);
break;
+ case FocusIn:
+ runes_display_focus_in(t);
+ runes_window_backend_flush(t);
+ break;
+ case FocusOut:
+ runes_display_focus_out(t);
+ runes_window_backend_flush(t);
+ break;
case ClientMessage: {
Atom a = e->xclient.data.l[0];
if (a == w->atoms[RUNES_ATOM_WM_DELETE_WINDOW]) {