long writefd(int fd, char* data, long towrite);
long readfd(int fd, char* data, long toread);
char* readfile(char* path);
+char* abspath(char* path);
int x11_getptr(XConf* x, int* ptrx, int* ptry);
uint32_t x11_getkey(XConf* x, XEvent* e);
uint32_t x11_process_key(XConf* x, XEvent* e, KeyBinding* keys);
+int x11_seturgent(XConf* x, int urgent);
void x11_centerwin(XConf* x);
void x11_init_gc(XConf* x);
#include <stdc.h>
#include <x11.h>
+#include <io.h>
#include "config.h"
void edit_file(XConf* x, Window registrar, char* path, char* addr, int force)
{
char host[8192];
- char* rpath = realpath(path, NULL);
- prop_set(x, x->self, "FILE", (rpath ? rpath : path));
+ path = abspath(path);
+ prop_set(x, x->self, "FILE", path);
prop_set(x, x->self, "ADDR", addr);
if (!gethostname(host, sizeof(host)))
{
prop_set(x, x->self, "HOST", host);
}
- free(rpath);
XChangeProperty(
x->display, registrar, XA_OPEN, XA_WINDOW, 32, PropModeAppend,
(const unsigned char *)&(x->self), 1);
}
}
}
+ free(path);
}
int main(int argc, char** argv)
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+
+char* abspath(char* path)
+{
+ char* ap = realpath(path, NULL);
+ if (!ap)
+ {
+ ap = strdup(path);
+ }
+ return ap;
+}
csr_drawn = draw_csr(x, view, fg, fheight, posx, y, csr_drawn);
if (csrsync && row->cols[i].off == view->buffer.selection.beg)
{
- XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, posx + row->cols[i].width/2, y + fheight*3/4);
+ //XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, posx + row->cols[i].width/2, y + fheight*3/4);
csrsync = false;
}
specs = realloc(specs, sizeof(XftGlyphSpec) * ++nspecs);
attr.bit_gravity = NorthWestGravity;
attr.backing_store = WhenMapped;
attr.event_mask = evmask
- | FocusChangeMask
+ | EnterWindowMask
| ExposureMask
| VisibilityChangeMask
| StructureNotifyMask
* the private use area is used to encode special keys */
return (key < 0xE000 || key > 0xF8FF ? key : RUNE_ERR);
}
+
+int x11_seturgent(XConf* x, int urgent)
+{
+ int status = 0;
+ XWMHints hints = {0}, *prevhints = XGetWMHints(x->display, x->self);
+ if (prevhints)
+ {
+ hints = *prevhints;
+ XFree(prevhints);
+ }
+ if (urgent)
+ {
+ hints.flags |= XUrgencyHint;
+ }
+ else
+ {
+ hints.flags &= ~XUrgencyHint;
+ }
+ status = XSetWMHints(x->display, x->self, &hints);
+ telem_send("URGENT(%d %d)\n", urgent, status);
+ return status;
+}
void x11_mapnotify(XConf* x, XEvent* e)
{
telem_send("XMAPNOTIFY(0x%x)\n", e->xmap.window);
- XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
+// XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
+}
+
+void x11_enternotify(XConf* x, XEvent* e)
+{
+ telem_send("XENTERNOTIFY(0x%x)\n", e->xmap.window);
+ x11_seturgent(x, 0);
}
void x11_init_gc(XConf* x)
x->gc = XCreateGC(x->display, x->self, GCGraphicsExposures, &gcv);
x->eventfns[ConfigureNotify] = x11_resize;
x->eventfns[MapNotify] = x11_mapnotify;
+ x->eventfns[EnterNotify] = x11_enternotify;
}
void x11_centerwin(XConf* x)
}
}
while (ev.type != MapNotify);
- XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
+// XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
}
XftFont* x11_font_load(XConf* x, char* name)
static void win_send(XConf* x, Window from, Window to, int mask, char* atom, size_t val)
{
+ telem_send("WIN_SEND(from: %lx, to: %lx, atom: %d)\n", from, to, atom);
XEvent ev = {0};
ev.xclient.type = ClientMessage;
ev.xclient.send_event = True;
{
if (path)
{
+ telem_send("WIN_OPEN(%lx '%s' '%s')\n", winid, path, host);
/* search for an existing window */
for (TWindow* win = Windows; win; win = win->next)
{
win->path = NULL;
char* file = readprop(x, win->win, "FILE", XA_STRING, NULL);
win->path = (file ? file : NULL);
-
+ telem_send(" %lx '%s' '%s'\n", win->win, win->path, win->host);
if (win->host && !strcmp(win->host, host) &&
win->path && !strcmp(win->path, path))
{
char* type = readprop(x, win->win, "TIDE", XA_STRING, 0);
if (!type || x11_error_get())
{
- puts("window invalid, marking for cleanup");
free(win->path), win->path = NULL;
free(win->host), win->host = NULL;
free(type);
}
else
{
- puts("window still valid, raising");
XEvent ev = {0};
ev.xclient.type = ClientMessage;
ev.xclient.send_event = True;
ev.xclient.message_type = XInternAtom(x->display, "_NET_ACTIVE_WINDOW", False);
ev.xclient.window = win->win;
ev.xclient.format = 32;
+ ev.xclient.data.l[0] = 1;
+ ev.xclient.data.l[1] = CurrentTime;
+ ev.xclient.data.l[2] = 0;
XSendEvent(x->display, x->root, False, SubstructureRedirectMask|SubstructureNotifyMask, &ev);
- XMapRaised(x->display, win->win);
win_send(x, x->self, win->win, 0, "GOTO", strtoul(addr, NULL, 0));
win_send(x, x->self, winid, 0, "DONE", 0);
free(type);
static void xclientmsg(XConf* x, XEvent* e)
{
if ((Atom)(e->xclient.data.l[0]) == XInternAtom(x->display, "WM_DELETE_WINDOW", False))
+ {
win_quit();
+ }
else if (e->xclient.message_type == XInternAtom(x->display, "GOTO", False))
+ {
+ x11_seturgent(x, 1);
win_setln(e->xclient.data.l[0]);
+ }
}
void xresize(XConf* x, XEvent* e)
if (buf_save(buf, arg) == NORMAL)
{
/* convert saved path to absolute path */
- char* path = realpath(buf->path, NULL);
+ char* path = abspath(buf->path);
buf_setpath(buf, path);
free(path);
}
static void edit_file(char* file, int line_num)
{
- char* path = realpath(file, NULL);
- if (!path) path = strdup(file); /* if file doesnt exist, use the original name */
- if (!strcmp("-", path))
+ file = abspath(file);
+ if (!strcmp("-", file))
{
job_readfd(STDIN_FILENO, win_view(EDIT));
}
else
{
- view_init(win_view(EDIT), path);
+ view_init(win_view(EDIT), file);
win_setln(line_num);
- win_title(path);
- win_prop_set("FILE", "file", path);
+ win_title(file);
+ win_prop_set("FILE", "file", file);
}
- free(path);
+ free(file);
}
int main(int argc, char** argv)