remove debug code, use jump table for ClientMessage
This commit is contained in:
40
xoat.c
40
xoat.c
@@ -42,8 +42,6 @@ int execsh(char *cmd)
|
|||||||
void exec_cmd(char *cmd)
|
void exec_cmd(char *cmd)
|
||||||
{
|
{
|
||||||
if (!cmd || !cmd[0]) return;
|
if (!cmd || !cmd[0]) return;
|
||||||
warnx("exec_cmd %s", cmd);
|
|
||||||
|
|
||||||
signal(SIGCHLD, catch_exit);
|
signal(SIGCHLD, catch_exit);
|
||||||
if (fork()) return;
|
if (fork()) return;
|
||||||
|
|
||||||
@@ -155,8 +153,6 @@ client* window_build_client(Window win)
|
|||||||
&& c->type != atoms[_NET_WM_WINDOW_TYPE_SPLASH]
|
&& c->type != atoms[_NET_WM_WINDOW_TYPE_SPLASH]
|
||||||
? 1:0;
|
? 1:0;
|
||||||
|
|
||||||
c->trans = c->transient_for ? 1:0;
|
|
||||||
|
|
||||||
for (i = 0; i < nmonitors; i++)
|
for (i = 0; i < nmonitors; i++)
|
||||||
if (INTERSECT(monitors[i].x, monitors[i].y, monitors[i].w, monitors[i].h,
|
if (INTERSECT(monitors[i].x, monitors[i].y, monitors[i].w, monitors[i].h,
|
||||||
c->attr.x + c->attr.width/2, c->attr.y+c->attr.height/2, 1, 1))
|
c->attr.x + c->attr.width/2, c->attr.y+c->attr.height/2, 1, 1))
|
||||||
@@ -354,7 +350,7 @@ void client_place_spot(client *c, int spot, int force)
|
|||||||
{
|
{
|
||||||
if (!c) return;
|
if (!c) return;
|
||||||
|
|
||||||
if (c->trans && !force)
|
if (c->transient_for && !force)
|
||||||
{
|
{
|
||||||
client *t = window_build_client(c->transient_for);
|
client *t = window_build_client(c->transient_for);
|
||||||
spot = t->spot;
|
spot = t->spot;
|
||||||
@@ -444,7 +440,7 @@ void client_raise_family(client *c)
|
|||||||
if ((o = all.clients[i]) && client_has_state(o, atoms[_NET_WM_STATE_ABOVE]))
|
if ((o = all.clients[i]) && client_has_state(o, atoms[_NET_WM_STATE_ABOVE]))
|
||||||
client_stack_family(o, &all, &raise);
|
client_stack_family(o, &all, &raise);
|
||||||
|
|
||||||
while (c->trans)
|
while (c->transient_for)
|
||||||
{
|
{
|
||||||
client *t = window_build_client(c->transient_for);
|
client *t = window_build_client(c->transient_for);
|
||||||
if (t) c = family.clients[family.depth++] = t;
|
if (t) c = family.clients[family.depth++] = t;
|
||||||
@@ -661,7 +657,7 @@ void configure_request(XEvent *ev)
|
|||||||
{
|
{
|
||||||
XConfigureRequestEvent *e = &ev->xconfigurerequest;
|
XConfigureRequestEvent *e = &ev->xconfigurerequest;
|
||||||
client *c = window_build_client(e->window);
|
client *c = window_build_client(e->window);
|
||||||
if (c && c->manage && c->visible && !c->trans)
|
if (c && c->manage && c->visible && !c->transient_for)
|
||||||
{
|
{
|
||||||
client_update_border(c);
|
client_update_border(c);
|
||||||
client_place_spot(c, c->spot, 0);
|
client_place_spot(c, c->spot, 0);
|
||||||
@@ -770,6 +766,11 @@ void button_press(XEvent *ev)
|
|||||||
XAllowEvents(display, ReplayPointer, CurrentTime);
|
XAllowEvents(display, ReplayPointer, CurrentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message messages[ATOMS] = {
|
||||||
|
[_NET_ACTIVE_WINDOW] = client_activate,
|
||||||
|
[_NET_CLOSE_WINDOW] = client_close,
|
||||||
|
};
|
||||||
|
|
||||||
void client_message(XEvent *ev)
|
void client_message(XEvent *ev)
|
||||||
{
|
{
|
||||||
XClientMessageEvent *e = &ev->xclient;
|
XClientMessageEvent *e = &ev->xclient;
|
||||||
@@ -784,15 +785,8 @@ void client_message(XEvent *ev)
|
|||||||
execsh(self);
|
execsh(self);
|
||||||
}
|
}
|
||||||
client *c = window_build_client(e->window);
|
client *c = window_build_client(e->window);
|
||||||
if (c && c->manage)
|
if (c && c->manage && messages[e->message_type])
|
||||||
{
|
messages[e->message_type](c);
|
||||||
warnx("client message 0x%lx 0x%08lx %s", e->message_type, (long)c->window, c->class);
|
|
||||||
if (e->message_type == atoms[_NET_ACTIVE_WINDOW])
|
|
||||||
client_activate(c);
|
|
||||||
else
|
|
||||||
if (e->message_type == atoms[_NET_CLOSE_WINDOW])
|
|
||||||
client_close(c);
|
|
||||||
}
|
|
||||||
client_free(c);
|
client_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -828,7 +822,6 @@ int main(int argc, char *argv[])
|
|||||||
if (!(display = XOpenDisplay(0))) return 1;
|
if (!(display = XOpenDisplay(0))) return 1;
|
||||||
|
|
||||||
self = argv[0];
|
self = argv[0];
|
||||||
screen = DefaultScreenOfDisplay(display);
|
|
||||||
root = DefaultRootWindow(display);
|
root = DefaultRootWindow(display);
|
||||||
xerror = XSetErrorHandler(oops);
|
xerror = XSetErrorHandler(oops);
|
||||||
|
|
||||||
@@ -847,9 +840,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// default non-multi-head setup
|
// default non-multi-head setup
|
||||||
memset(monitors, 0, sizeof(monitors));
|
memset(monitors, 0, sizeof(monitors));
|
||||||
monitors[0].w = WidthOfScreen(screen);
|
monitors[0].w = WidthOfScreen(DefaultScreenOfDisplay(display));
|
||||||
monitors[0].h = HeightOfScreen(screen);
|
monitors[0].h = HeightOfScreen(DefaultScreenOfDisplay(display));
|
||||||
warnx("screen(%d): %dx%d+%d+%d", DefaultScreen(display), monitors[0].w, monitors[0].h, monitors[0].x, monitors[0].y);
|
|
||||||
|
|
||||||
// detect panel struts
|
// detect panel struts
|
||||||
query_visible_windows(&wins);
|
query_visible_windows(&wins);
|
||||||
@@ -865,7 +857,6 @@ int main(int argc, char *argv[])
|
|||||||
struts.right = MIN(MAX_STRUT, MAX(struts.right, strut.right));
|
struts.right = MIN(MAX_STRUT, MAX(struts.right, strut.right));
|
||||||
struts.top = MIN(MAX_STRUT, MAX(struts.top, strut.top));
|
struts.top = MIN(MAX_STRUT, MAX(struts.top, strut.top));
|
||||||
struts.bottom = MIN(MAX_STRUT, MAX(struts.bottom, strut.bottom));
|
struts.bottom = MIN(MAX_STRUT, MAX(struts.bottom, strut.bottom));
|
||||||
warnx("struts %ld %ld %ld %ld 0x%08lx %s", strut.left, strut.left, strut.left, strut.left, (long)c->window, c->class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stack_free(&inplay);
|
stack_free(&inplay);
|
||||||
@@ -881,7 +872,6 @@ int main(int argc, char *argv[])
|
|||||||
monitors[i].y = info[i].y_org + struts.top;
|
monitors[i].y = info[i].y_org + struts.top;
|
||||||
monitors[i].w = info[i].width;
|
monitors[i].w = info[i].width;
|
||||||
monitors[i].h = info[i].height - struts.top - struts.bottom;
|
monitors[i].h = info[i].height - struts.top - struts.bottom;
|
||||||
warnx("monitor %d %dx%d+%d+%d", i, monitors[i].w, monitors[i].h, monitors[i].x, monitors[i].y);
|
|
||||||
}
|
}
|
||||||
XFree(info);
|
XFree(info);
|
||||||
}
|
}
|
||||||
@@ -917,15 +907,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dump atoms for debug
|
|
||||||
for (i = 0; i < ATOMS; i++) warnx("atom 0x%lx %s", (long)atoms[i], atom_names[i]);
|
|
||||||
|
|
||||||
// become the window manager
|
// become the window manager
|
||||||
XSelectInput(display, root, StructureNotifyMask | SubstructureRedirectMask | SubstructureNotifyMask);
|
XSelectInput(display, root, StructureNotifyMask | SubstructureRedirectMask | SubstructureNotifyMask);
|
||||||
|
|
||||||
// ewmh support
|
// ewmh support
|
||||||
unsigned long desktop = 0, desktops = 3, pid = getpid(), viewport[2] = { 0, 0 },
|
unsigned long desktop = 0, desktops = 3, pid = getpid(), viewport[2] = { 0, 0 },
|
||||||
geometry[2] = { WidthOfScreen(screen), HeightOfScreen(screen) };
|
geometry[2] = { monitors[0].w, monitors[0].h };
|
||||||
|
|
||||||
ewmh = XCreateSimpleWindow(display, root, 0, 0, 1, 1, 0, 0, 0);
|
ewmh = XCreateSimpleWindow(display, root, 0, 0, 1, 1, 0, 0, 0);
|
||||||
|
|
||||||
@@ -967,7 +954,6 @@ int main(int argc, char *argv[])
|
|||||||
for (i = 0; i < wins.depth; i++)
|
for (i = 0; i < wins.depth; i++)
|
||||||
{
|
{
|
||||||
if (!(c = wins.clients[i]) || !c->manage) continue;
|
if (!(c = wins.clients[i]) || !c->manage) continue;
|
||||||
warnx("window 0x%08lx (%d,%d,%d) %s", (long)c->window, c->tags, c->monitor, c->spot, c->class);
|
|
||||||
|
|
||||||
window_listen(c->window);
|
window_listen(c->window);
|
||||||
client_update_border(c);
|
client_update_border(c);
|
||||||
|
|||||||
5
xoat.h
5
xoat.h
@@ -51,8 +51,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
#define INTERSECT(x,y,w,h,x1,y1,w1,h1) (OVERLAP((x),(w),(x1),(w1)) && OVERLAP((y),(h),(y1),(h1)))
|
#define INTERSECT(x,y,w,h,x1,y1,w1,h1) (OVERLAP((x),(w),(x1),(w1)) && OVERLAP((y),(h),(y1),(h1)))
|
||||||
|
|
||||||
Display *display;
|
Display *display;
|
||||||
Screen *screen;
|
|
||||||
int scr_id;
|
|
||||||
Window root;
|
Window root;
|
||||||
Time latest;
|
Time latest;
|
||||||
char *self;
|
char *self;
|
||||||
@@ -99,7 +97,7 @@ typedef struct {
|
|||||||
XSizeHints size;
|
XSizeHints size;
|
||||||
Window transient_for;
|
Window transient_for;
|
||||||
Atom type, states[MAX_NET_WM_STATES+1];
|
Atom type, states[MAX_NET_WM_STATES+1];
|
||||||
short monitor, spot, visible, trans, manage, input, urgent;
|
short monitor, spot, visible, manage, input, urgent;
|
||||||
unsigned short tags;
|
unsigned short tags;
|
||||||
char *class;
|
char *class;
|
||||||
} client;
|
} client;
|
||||||
@@ -191,6 +189,7 @@ enum {
|
|||||||
|
|
||||||
typedef void (*handler)(XEvent*);
|
typedef void (*handler)(XEvent*);
|
||||||
typedef void (*action)(void*, int, client*);
|
typedef void (*action)(void*, int, client*);
|
||||||
|
typedef void (*message)(client*);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int mod;
|
unsigned int mod;
|
||||||
|
|||||||
Reference in New Issue
Block a user