embedding works nice now.

This commit is contained in:
Enno Boland (tox) 2009-09-23 09:53:30 +02:00
parent d136cb337f
commit ea0e34aa06
2 changed files with 56 additions and 27 deletions

View File

@ -18,6 +18,7 @@ LIBS = -L/usr/lib -lc ${GTKLIB} -lgthread-2.0
# flags # flags
CPPFLAGS = -DVERSION=\"${VERSION}\" CPPFLAGS = -DVERSION=\"${VERSION}\"
#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} #CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
#CFLAGS = -std=c99 -pedantic -Wall -Werror -O0 ${INCS} ${CPPFLAGS}
CFLAGS = -g -std=c99 -pedantic -Wall -Werror -O0 ${INCS} ${CPPFLAGS} CFLAGS = -g -std=c99 -pedantic -Wall -Werror -O0 ${INCS} ${CPPFLAGS}
#LDFLAGS = -s ${LIBS} #LDFLAGS = -s ${LIBS}
LDFLAGS = ${LIBS} LDFLAGS = ${LIBS}

View File

@ -31,15 +31,26 @@
enum { ColFG, ColBG, ColLast }; /* color */ enum { ColFG, ColBG, ColLast }; /* color */
enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */ enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */
/* XEMBED messages */ /* XEMBED messages */
enum { XembNotify, XembWinAct, XembWinDeact, XembReqFoc, #define XEMBED_EMBEDDED_NOTIFY 0
XembFocIn, XembFocOut, XembFocNext, XembFoxPrev, #define XEMBED_WINDOW_ACTIVATE 1
XEMBED_MODALITY_ON = 10, #define XEMBED_WINDOW_DEACTIVATE 2
XEMBED_MODALITY_OFF = 11, #define XEMBED_REQUEST_FOCUS 3
XEMBED_REGISTER_ACCELERATOR = 12, #define XEMBED_FOCUS_IN 4
XEMBED_UNREGISTER_ACCELERATOR = 13, #define XEMBED_FOCUS_OUT 5
XEMBED_ACTIVATE_ACCELERATOR = 14, #define XEMBED_FOCUS_NEXT 6
}; #define XEMBED_FOCUS_PREV 7
/* 8-9 were used for XEMBED_GRAB_KEY/XEMBED_UNGRAB_KEY */
#define XEMBED_MODALITY_ON 10
#define XEMBED_MODALITY_OFF 11
#define XEMBED_REGISTER_ACCELERATOR 12
#define XEMBED_UNREGISTER_ACCELERATOR 13
#define XEMBED_ACTIVATE_ACCELERATOR 14
/* Details for XEMBED_FOCUS_IN: */
#define XEMBED_FOCUS_CURRENT 0
#define XEMBED_FOCUS_FIRST 1
#define XEMBED_FOCUS_LAST 2
typedef union { typedef union {
int i; int i;
@ -85,8 +96,10 @@ static void destroynotify(XEvent *e);
static void die(const char *errstr, ...); static void die(const char *errstr, ...);
static void drawbar(); static void drawbar();
static void drawtext(const char *text, unsigned long col[ColLast]); static void drawtext(const char *text, unsigned long col[ColLast]);
static void enternotify(XEvent *e);
static void expose(XEvent *e); static void expose(XEvent *e);
static void focus(Client *c); static void focus(Client *c);
static void focusin(XEvent *e);
static unsigned long getcolor(const char *colstr); static unsigned long getcolor(const char *colstr);
static Client *getclient(Window w); static Client *getclient(Window w);
static Client *getfirsttab(); static Client *getfirsttab();
@ -98,7 +111,6 @@ static void killclient(const Arg *arg);
static void move(const Arg *arg); static void move(const Arg *arg);
static void spawn(const Arg *arg); static void spawn(const Arg *arg);
static void manage(Window win); static void manage(Window win);
static void maprequest(XEvent *e);
static void propertynotify(XEvent *e); static void propertynotify(XEvent *e);
static void reparentnotify(XEvent *e); static void reparentnotify(XEvent *e);
static void resize(Client *c, int w, int h); static void resize(Client *c, int w, int h);
@ -119,13 +131,14 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[DestroyNotify] = destroynotify, [DestroyNotify] = destroynotify,
[PropertyNotify] = propertynotify, [PropertyNotify] = propertynotify,
[UnmapNotify] = unmapnotify, [UnmapNotify] = unmapnotify,
[MapRequest] = maprequest,
[ButtonPress] = buttonpress, [ButtonPress] = buttonpress,
[KeyPress] = keypress, [KeyPress] = keypress,
[Expose] = expose, [Expose] = expose,
[ClientMessage] = clientmessage, [ClientMessage] = clientmessage,
[CreateNotify] = createnotify, [CreateNotify] = createnotify,
[ReparentNotify] = reparentnotify, [ReparentNotify] = reparentnotify,
[EnterNotify] = enternotify,
[FocusIn] = focusin,
}; };
static Display *dpy; static Display *dpy;
static DC dc; static DC dc;
@ -197,7 +210,7 @@ void
createnotify(XEvent *e) { createnotify(XEvent *e) {
XCreateWindowEvent *ev = &e->xcreatewindow; XCreateWindowEvent *ev = &e->xcreatewindow;
if(!getclient(ev->window)) if(ev->window != win && !getclient(ev->window))
manage(ev->window); manage(ev->window);
} }
@ -308,6 +321,10 @@ emallocz(size_t size) {
return p; return p;
} }
void enternotify(XEvent *e) {
focus(sel);
}
void void
expose(XEvent *e) { expose(XEvent *e) {
XExposeEvent *ev = &e->xexpose; XExposeEvent *ev = &e->xexpose;
@ -318,20 +335,37 @@ expose(XEvent *e) {
void void
focus(Client *c) { focus(Client *c) {
XEvent e;
if(!c) if(!c)
c = clients; c = clients;
if(!c) { if(!c) {
sel = NULL; sel = NULL;
XStoreName(dpy, win, "tabbed-"VERSION);
return; return;
} }
XRaiseWindow(dpy, c->win); XRaiseWindow(dpy, c->win);
// XSetInputFocus(dpy, c->win, RevertToNone, CurrentTime); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
XSelectInput(dpy, c->win, PropertyChangeMask|StructureNotifyMask); e.xclient.window = c->win;
e.xclient.type = ClientMessage;
e.xclient.message_type = xembedatom;
e.xclient.format = 32;
e.xclient.data.l[0] = CurrentTime;
e.xclient.data.l[1] = XEMBED_FOCUS_IN;
e.xclient.data.l[2] = XEMBED_FOCUS_CURRENT;
e.xclient.data.l[3] = 0;
e.xclient.data.l[4] = 0;
XSendEvent(dpy, root, False, NoEventMask, &e);
sel = c; sel = c;
XStoreName(dpy, win, sel->name); XStoreName(dpy, win, sel->name);
drawbar(); drawbar();
} }
void
focusin(XEvent *e) {
focus(sel);
}
unsigned long unsigned long
getcolor(const char *colstr) { getcolor(const char *colstr) {
Colormap cmap = DefaultColormap(dpy, screen); Colormap cmap = DefaultColormap(dpy, screen);
@ -523,9 +557,9 @@ manage(Window w) {
Client *c; Client *c;
XEvent e; XEvent e;
XSelectInput(dpy, w, StructureNotifyMask|PropertyChangeMask);
XWithdrawWindow(dpy, w, 0); XWithdrawWindow(dpy, w, 0);
XReparentWindow(dpy, w, win, 0, bh); XReparentWindow(dpy, w, win, 0, bh);
XSelectInput(dpy, w, PropertyChangeMask|StructureNotifyMask|EnterWindowMask);
XSync(dpy, False); XSync(dpy, False);
if(badwindow) { if(badwindow) {
badwindow = False; badwindow = False;
@ -541,7 +575,6 @@ manage(Window w) {
c->next = clients; c->next = clients;
c->win = w; c->win = w;
clients = c; clients = c;
focus(c);
updatetitle(c); updatetitle(c);
resize(c, ww, wh - bh); resize(c, ww, wh - bh);
drawbar(); drawbar();
@ -556,16 +589,11 @@ manage(Window w) {
e.xclient.data.l[3] = win; e.xclient.data.l[3] = win;
e.xclient.data.l[4] = 0; e.xclient.data.l[4] = 0;
XSendEvent(dpy, root, False, NoEventMask, &e); XSendEvent(dpy, root, False, NoEventMask, &e);
XSync(dpy, False);
focus(c);
} }
} }
void maprequest(XEvent *e) {
XMapRequestEvent *ev = &e->xmaprequest;
if(!getclient(ev->window))
manage(ev->window);
}
void void
propertynotify(XEvent *e) { propertynotify(XEvent *e) {
Client *c; Client *c;
@ -661,13 +689,13 @@ setup(void) {
XSetFont(dpy, dc.gc, dc.font.xfont->fid); XSetFont(dpy, dc.gc, dc.font.xfont->fid);
win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0, dc.norm[ColFG], dc.norm[ColBG]); win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0, dc.norm[ColFG], dc.norm[ColBG]);
XSelectInput(dpy, win, PointerMotionMask|SubstructureNotifyMask|
ButtonPressMask|ExposureMask|KeyPressMask|
LeaveWindowMask|StructureNotifyMask);
XMapRaised(dpy, win); XMapRaised(dpy, win);
XSelectInput(dpy, win, SubstructureNotifyMask|FocusChangeMask|
ButtonPressMask|ExposureMask|KeyPressMask|
StructureNotifyMask);
xerrorxlib = XSetErrorHandler(xerror); xerrorxlib = XSetErrorHandler(xerror);
XClassHint class_hint; XClassHint class_hint;
XStoreName(dpy, win, "Tabbed"); XStoreName(dpy, win, "tabbed-"VERSION);
class_hint.res_name = "tabbed"; class_hint.res_name = "tabbed";
class_hint.res_class = "Tabbed"; class_hint.res_class = "Tabbed";
XSetClassHint(dpy, win, &class_hint); XSetClassHint(dpy, win, &class_hint);