aboutsummaryrefslogtreecommitdiff
path: root/swt.c
diff options
context:
space:
mode:
Diffstat (limited to 'swt.c')
-rw-r--r--swt.c238
1 files changed, 219 insertions, 19 deletions
diff --git a/swt.c b/swt.c
index befcfd1..4dff47c 100644
--- a/swt.c
+++ b/swt.c
@@ -9,12 +9,20 @@
#include <time.h>
#include <poll.h>
#include <errno.h>
+#include <stdlib.h>
+#include <locale.h>
+char *argv0;
#include "wayland.h"
#include "drw.h"
#include "xdg-shell-client-protocol.h"
+#include "arg.h"
+#include "util.h"
+#include "term.h"
+#include "win.h"
/* macro definitions */
+#define IS_SET(flag) ((win.mode & (flag)) != 0)
#define match_then_bind(obj, inter, ver) \
if (strcmp(interface, inter.name) == 0) { \
obj = wl_registry_bind(registry, name, &inter, ver);
@@ -33,12 +41,22 @@ typedef struct {
} surface;
Canvas *canvas;
Font *font;
+ int mode;
+ struct {
+ int x;
+ int y;
+ } cursor;
} Window;
+/* function prototypes */
static void setup();
+static void cleanup();
+static void run();
+static void usage();
static void buffer_release(void *data, struct wl_buffer *buffer);
static void draw_frame();
+static void commit_surface();
static void surface_configure(void *data, struct xdg_surface *surface, uint32_t serial);
static void toplevel_configure(void *data, struct xdg_toplevel *toplevel, int32_t width, int32_t height, struct wl_array *clients);
static void toplevel_close(void *data, struct xdg_toplevel *toplevel);
@@ -115,10 +133,109 @@ const struct wl_pointer_listener pointer_listener = {
Client client = { 0 };
Window win = { 0 };
int running = 1;
+static char *opt_font = 0;
+static char *opt_name = 0;
+static char *opt_io = 0;
+static char *opt_line = 0;
+static char *opt_title = 0;
+static char **opt_cmd = 0;
#include "config.h"
/* function implementation */
+
+void wbell() {
+ fprintf(stderr, "BELL\n");
+}
+
+
+void wclipcopy() {
+ fprintf(stderr, "CLIPCOPY\n");
+}
+
+
+void wdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) {
+ fprintf(stderr, "DRAW CURSOR: cx: %i, cy: %i, ox: %i, oy: %i\n", cx, cy, ox, oy);
+ draw_rect(win.canvas, win.cursor.x * fontsize, win.cursor.y * fontsize, fontsize, fontsize, 0x0);
+ draw_rect(win.canvas, cx * fontsize, cy * fontsize, fontsize, fontsize, 0xffffffff);
+ win.cursor.x = cx;
+ win.cursor.y = cy;
+}
+
+
+void wdrawline(Line line, int x1, int y1, int x2) {
+ int x;
+ fprintf(stderr, "DRAW LINE: x1: %i, y1: %i, x2: %i\n");
+
+ /*for (x = x1; x < x2; x++) {
+ fprintf(stderr, " line: %s\n", line[x]);
+ }*/
+}
+
+
+void wfinishdraw() {
+ fprintf(stderr, "FINISH DRAW\n");
+}
+
+
+void wloadcols() {
+ fprintf(stderr, "LOADCOLS");
+}
+
+
+int wsetcolorname(int, const char *) {
+ fprintf(stderr, "SET COLOR NAME\n");
+ return 1;
+}
+
+
+int wgetcolor(int, unsigned char *, unsigned char *, unsigned char *) {
+ fprintf(stderr, "GET COLOR\n");
+ return 1;
+}
+
+
+void wseticontitle(char *title) {
+ fprintf(stderr, "SET ICON TITLE: %s\n", title);
+}
+
+
+void wsettitle(char *title) {
+ fprintf(stderr, "SET TITLE: %s\n", title);
+}
+
+
+int
+wsetcursor(int cursor) {
+ fprintf(stderr, "SET CURSOR: %i\n", cursor);
+ return 1;
+}
+
+
+void wsetmode(int set, unsigned int flag) {
+ fprintf(stderr, "SET MODE: %i, %u\n", set, flag);
+}
+
+
+void wsetpointermotion(int set) {
+ fprintf(stderr, "SET POINTER MOTION: %i\n", set);
+}
+
+
+void wsetsel(char *str) {
+ fprintf(stderr, "SET SEL: %s\n", str);
+}
+
+
+int wstartdraw() {
+ return 1;
+ //return IS_SET(MODE_VISIBLE);
+}
+
+
+void wximspot(int, int) {}
+
+
void
buffer_release(void *data, struct wl_buffer *buffer)
{
@@ -129,7 +246,16 @@ buffer_release(void *data, struct wl_buffer *buffer)
void
draw_frame()
{
- draw_rect(win.canvas, 0, 0, win.width, win.height, 0xff00ff00);
+ draw_rect(win.canvas, 0, 0, win.width, win.height, 0xff000000);
+}
+
+
+void
+commit_surface()
+{
+ wl_surface_attach(win.surface.wl, win.canvas->buffer, 0, 0);
+ wl_surface_damage_buffer(win.surface.wl, 0, 0, win.width, win.height);
+ wl_surface_commit(win.surface.wl);
}
@@ -138,17 +264,13 @@ surface_configure(void *data, struct xdg_surface *surface, uint32_t serial)
{
xdg_surface_ack_configure(surface, serial);
- fprintf(stderr, "configure\n");
-
if (win.canvas != 0) {
free_drw(win.canvas);
}
win.canvas = create_drw(client.shm, win.width, win.height);
draw_frame();
- wl_surface_attach(win.surface.wl, win.canvas->buffer, 0, 0);
- wl_surface_damage_buffer(win.surface.wl, 0, 0, win.width, win.height);
- wl_surface_commit(win.surface.wl);
+ commit_surface();
}
@@ -304,48 +426,45 @@ keyboard_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int
void
handle_keyboard_event()
{
- char buf[8];
+ char buf[9] = { 0 };
+ int len;
if (client.kb.event.state == WL_KEYBOARD_KEY_STATE_PRESSED) {
- if (xkb_keysym_to_utf8(client.kb.event.sym, buf, sizeof(buf))) {
- fprintf(stderr, "keypress: %s\n", buf);
+ if ((len = xkb_keysym_to_utf8(client.kb.event.sym, buf, 8))) {
+ ttywrite(buf, strlen(buf), 1);
}
}
+
}
void
pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
{
- fprintf(stderr, "pointer enter: (%i, %i)\n", x, y);
}
void
pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface)
{
- fprintf(stderr, "pointer leave\n");
}
void
pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y)
{
- fprintf(stderr, "pointer motion: (%i, %i)\n", x, y);
}
void
pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
{
- fprintf(stderr, "pointer button: (b: %i, s: %i)\n", button, state);
}
void
pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
{
- fprintf(stderr, "pointer axis: (a: %i, v: %i)\n", axis, value);
}
@@ -375,19 +494,22 @@ setup()
}
-int main()
+void run()
{
struct itimerspec spec = { 0 };
- struct pollfd fds[2];
-
- setup();
+ struct pollfd fds[3];
+ int redraw = 0;
fds[0].fd = wl_display_get_fd(client.display);
fds[0].events = POLLIN;
fds[1].fd = client.kb.repeat.timer;
fds[1].events = POLLIN;
+ fds[2].fd = ttynew(opt_line, shell, opt_io, opt_cmd);
+ fds[2].events = POLLIN;
while (running) {
+ redraw = 0;
+
if (wl_display_flush(client.display) < 0) {
if (errno == EAGAIN)
continue;
@@ -400,6 +522,12 @@ int main()
break;
}
+ /* handle ttyfd at first so we have the real current screen */
+ if (fds[2].revents & POLLIN) {
+ ttyread();
+ redraw = 1;
+ }
+
if (fds[0].revents & POLLIN) {
if (wl_display_dispatch(client.display) < 0) {
running = 0;
@@ -409,12 +537,84 @@ int main()
if (fds[1].revents & POLLIN) {
handle_keyboard_event();
spec.it_value.tv_sec = client.kb.repeat.period / 1000;
- spec.it_value.tv_nsec = (client.kb.repeat.period % 1000) / 1000000;
+ spec.it_value.tv_nsec = (client.kb.repeat.period % 1000) * 1000000;
timerfd_settime(client.kb.repeat.timer, 0, &spec, 0);
+ redraw = 1;
+ }
+
+ if (redraw) {
+ draw();
+ commit_surface();
}
}
+}
+
+void
+cleanup()
+{
wl_display_disconnect(client.display);
+}
+
+
+void
+usage(void)
+{
+ die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]"
+ " [-n name] [-o file]\n"
+ " [-T title] [-t title] [-w windowid]"
+ " [[-e] command [args ...]]\n"
+ " %s [-aiv] [-c class] [-f font] [-g geometry]"
+ " [-n name] [-o file]\n"
+ " [-T title] [-t title] [-w windowid] -l line"
+ " [stty_args ...]\n", argv0, argv0);
+}
+
+
+int main(int argc, char *argv[])
+{
+
+ ARGBEGIN {
+ case 'a':
+ allowaltscreen = 0;
+ break;
+ break;
+ case 'e':
+ if (argc > 0)
+ --argc, ++argv;
+ goto run;
+ case 'f':
+ opt_font = EARGF(usage());
+ break;
+ case 'o':
+ opt_io = EARGF(usage());
+ break;
+ case 'l':
+ opt_line = EARGF(usage());
+ break;
+ case 'n':
+ opt_name = EARGF(usage());
+ break;
+ case 't':
+ case 'T':
+ opt_title = EARGF(usage());
+ break;
+ case 'v':
+ die("%s " VERSION "\n", argv0);
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+run:
+ if (argc > 0) /* eat all remaining arguments */
+ opt_cmd = argv;
+
+ setlocale(LC_CTYPE, "");
+ tnew(cols, rows);
+ setup();
+ run();
+ cleanup();
return 0;
}