aboutsummaryrefslogtreecommitdiff
path: root/swt.c
diff options
context:
space:
mode:
Diffstat (limited to 'swt.c')
-rw-r--r--swt.c84
1 files changed, 67 insertions, 17 deletions
diff --git a/swt.c b/swt.c
index b9cc631..7427d3b 100644
--- a/swt.c
+++ b/swt.c
@@ -23,6 +23,9 @@ char *argv0;
/* macro definitions */
#define IS_SET(flag) ((win.mode & (flag)) != 0)
+#define TRUERED(x) (((x) & 0xff0000) >> 16)
+#define TRUEGREEN(x) (((x) & 0xff00) >> 8)
+#define TRUEBLUE(x) (((x) & 0xff))
#define match_then_bind(obj, inter, ver) \
if (strcmp(interface, inter.name) == 0) { \
obj = wl_registry_bind(registry, name, &inter, ver);
@@ -152,13 +155,14 @@ void wclipcopy() {
void wdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) {
+
draw_rect(
win.canvas,
ox * win.fontcache->box.width,
oy * win.fontcache->box.height,
win.fontcache->box.width,
win.fontcache->box.height,
- 0x0
+ colors[og.bg]
);
draw_char(
win.canvas,
@@ -166,7 +170,7 @@ void wdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) {
og.u,
ox * win.fontcache->box.width,
oy * win.fontcache->box.height + win.fontcache->fontsize,
- 0xffffffff
+ colors[og.fg]
);
draw_rect(
win.canvas,
@@ -174,7 +178,15 @@ void wdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) {
cy * win.fontcache->box.height,
win.fontcache->box.width,
win.fontcache->box.height,
- 0xffffffff
+ colors[g.bg]
+ );
+ draw_char(
+ win.canvas,
+ win.fontcache,
+ g.u,
+ cx * win.fontcache->box.width,
+ cy * win.fontcache->box.height + win.fontcache->fontsize,
+ colors[g.fg]
);
}
@@ -186,19 +198,27 @@ void wdrawline(Line line, int x1, int y1, int x2) {
win.canvas,
x1 * win.fontcache->box.width,
y1 * win.fontcache->box.height,
- (x2 - x1) * win.fontcache->box.width,
+ x2 * win.fontcache->box.width,
win.fontcache->box.height,
- 0
+ colors[defaultbg]
);
for (x = x1; x < x2; x++) {
+ draw_rect(
+ win.canvas,
+ x * win.fontcache->box.width,
+ y1 * win.fontcache->box.height,
+ 10,
+ win.fontcache->box.height,
+ colors[line[x].bg]
+ );
draw_char(
win.canvas,
win.fontcache,
line[x].u,
x * win.fontcache->box.width,
y1 * win.fontcache->box.height + win.fontcache->fontsize,
- 0xffffffff
+ colors[line[x].fg]
);
}
}
@@ -208,9 +228,27 @@ void wfinishdraw() {
commit_surface();
}
+ushort
+sixd_to_8bit(int x)
+{
+ return x == 0 ? 0 : 0x37 + 0x28 * x;
+}
+
void wloadcols() {
- fprintf(stderr, "LOADCOLS");
+ int i;
+
+ for (i = 0; i < sizeof(colors) / sizeof(uint32_t); ++i) {
+ if (colors[i] == 0) {
+ if (i < 6 * 6 * 6 + 16) {
+ colors[i] = sixd_to_8bit(((i - 16) / 36) % 6) << 16 |
+ sixd_to_8bit(((i - 16) / 6) % 6) << 8 |
+ sixd_to_8bit(((i - 16) / 1) % 6);
+ }
+ }
+
+ colors[i] |= 0xff000000;
+ }
}
@@ -220,9 +258,15 @@ int wsetcolorname(int, const char *) {
}
-int wgetcolor(int, unsigned char *, unsigned char *, unsigned char *) {
- fprintf(stderr, "GET COLOR\n");
- return 1;
+int wgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b) {
+ if (!BETWEEN(x, 0, sizeof(colors) / sizeof(uint32_t)))
+ return 1;
+
+ *r = (colors[x] & 0xff0000) >> 16;
+ *g = (colors[x] & 0x00ff00) >> 8;
+ *b = (colors[x] & 0x0000ff);
+
+ return 0;
}
@@ -277,7 +321,7 @@ buffer_release(void *data, struct wl_buffer *buffer)
void
draw_frame()
{
- draw_rect(win.canvas, 0, 0, win.width, win.height, 0xff000000);
+ draw_rect(win.canvas, 0, 0, win.width, win.height, colors[defaultbg]);
}
@@ -294,21 +338,25 @@ commit_surface()
void
surface_configure(void *data, struct xdg_surface *surface, uint32_t serial)
{
- int first_canvas = win.canvas == 0;
+ int first_configure = win.canvas == 0;
+ int ttywidth, ttyheight;
xdg_surface_ack_configure(surface, serial);
- if (win.geometry_changed || first_canvas) {
+ if (win.geometry_changed || first_configure) {
if (win.canvas != 0) {
free_drw(win.canvas);
}
win.canvas = create_drw(client.shm, win.width, win.height);
- draw();
+ ttywidth = win.width / win.fontcache->box.width;
+ ttyheight = win.height / win.fontcache->box.height;
+ tresize(ttywidth, ttyheight);
+ ttyresize(ttywidth, ttyheight);
+ draw_frame();
win.geometry_changed = 0;
}
- if (first_canvas)
- draw_frame();
- commit_surface();
+ if (first_configure)
+ commit_surface();
}
@@ -325,6 +373,7 @@ toplevel_configure(void *data, struct xdg_toplevel *toplevel, int32_t width, int
win.width = width;
win.height = height;
}
+
}
@@ -513,6 +562,7 @@ void
setup()
{
win.fontcache = create_font_cache(fonts, sizeof(fonts) / sizeof(FontPath), fontsize);
+ wloadcols();
client.kb.repeat.timer = timerfd_create(CLOCK_MONOTONIC, 0);
client.kb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
client.display = wl_display_connect(0);