#include <sys/time.h>
#include <sys/types.h>
#include <ctype.h>
-
-#define Region _Region
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>
-#undef Region
struct XSel {
char* name;
};
/******************************************************************************/
-static struct XWin X;
+struct XWin X;
static int KeyBtnState;
static WinRegion Focused = EDIT;
static View Regions[NREGIONS];
View* view = win_view(EDIT);
size_t bend = buf_end(win_buf(EDIT));
if (bend == 0) bend = 1;
- if (!view->rows) return;
+ if (!view->rows || !view->nrows) return;
size_t vbeg = view->rows[0]->off;
size_t vend = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->len;
double scroll_vis = (double)(vend - vbeg) / (double)bend;
win_prop_set("TIDE_FILE", "file", path);
}
+void win_update(int ms) {
+ job_poll(Timeout);
+ xupdate(NULL);
+}
+
void win_loop(void) {
XMapWindow(X.display, X.self);
tide_send("ADD");
job_spawn(ConnectionNumber(X.display), xupdate, 0, 0);
while (1) {
- job_poll(Timeout);
- xupdate(NULL);
+ win_update(Timeout);
}
}
--- /dev/null
+#define _XOPEN_SOURCE 700
+#include <atf.h>
+#include "tide.c"
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/Xft/Xft.h>
+
+struct XWin {
+ Time now;
+ Window root;
+ Display* display;
+ Visual* visual;
+ Colormap colormap;
+ unsigned depth;
+ int screen;
+ /* assume a single window for now. these are its attributes */
+ Window self;
+ XftDraw* xft;
+ Pixmap pixmap;
+ int width;
+ int height;
+ XIC xic;
+ XIM xim;
+ GC gc;
+ XftFont* font;
+};
+
+extern struct XWin X;
+
+static void load_file(char* opath) {
+ char* path = realpath(opath, NULL);
+ view_init(win_view(EDIT), path);
+ win_prop_set("TIDE_FILE", "file", path);
+}
+
+static void send_focus(bool focused) {
+ XSendEvent(X.display, X.self, False, 0, (XEvent*)&(XFocusChangeEvent){
+ .type = (focused ? FocusIn : FocusOut),
+ .window = X.self,
+ });
+}
+
+static void send_key(int region, int mods, int key) {
+}
+
+static void send_btn_dn(int mods, int button, int x, int y) {
+}
+
+static void send_btn_up(int mods, int button, int x, int y) {
+}
+
+static void send_btn_drag(int mods, int button, int x, int y) {
+}
+
+#if 0
+static void send_sel_clear() {
+}
+
+static void send_sel_notify() {
+}
+
+static void send_sel_request() {
+}
+
+static void send_client_msg() {
+}
+#endif
+
+static void send_resize(int width, int height) {
+ XResizeWindow(X.display, X.self, width, height);
+ XSync(X.display, False);
+}
+
+TEST_SUITE(WinTests) {
+ /* Suite Setup
+ *************************************************************************/
+ win_init("tide", Bindings);
+
+ /* Focus Events
+ *************************************************************************/
+ TEST(window should handle gaining focus) {
+ send_focus(true);
+ win_update(0);
+ }
+
+ TEST(window should handle losing focus) {
+ send_focus(false);
+ win_update(0);
+ }
+
+ TEST(window should handle gaining then losing focus) {
+ send_focus(true);
+ send_focus(false);
+ win_update(0);
+ }
+
+ TEST(window should handle gaining then losing then gaining focus) {
+ send_focus(false);
+ send_focus(true);
+ win_update(0);
+ }
+
+ /* Resize Events
+ *************************************************************************/
+ TEST(window should resize if requested) {
+ send_resize(800, 600);
+ win_update(0);
+ CHECK(X.width == 800);
+ CHECK(X.height == 600);
+ }
+
+ TEST(window should not resize if unnecessary) {
+ int width = X.width, height = X.height;
+ send_resize(X.width, X.height);
+ win_update(0);
+ CHECK(X.width == width);
+ CHECK(X.height == height);
+ }
+
+ TEST(window should handle sizes that are too small) {
+ IGNORE("We don't handle tiny windows yet");
+ send_resize(1, 1);
+ win_update(0);
+ CHECK(X.width == 1);
+ CHECK(X.height == 1);
+ }
+
+ /* Suite TearDown
+ *************************************************************************/
+ /* nothing to do yet */
+}